Skip to content

Commit c0f145b

Browse files
committed
tcmur_device: add priv lock support
When the tcmu-runner detect that the lock is lost, it will try to queue a work event to reopen the image and at the same time queue a work event to update the service status. While the reopen is not atomic, and there has a gap between image close and image open, during which the rbd image's state resource will be released and if the update status event is fired, we will hit the crash bug. This commit will add one rdev->priv_lock to protect the private data in rdev struct. For the service status updating code just skip it if it's in the reopen gap. And for all the other IOs just return EBUSY to let the client try it again. Signed-off-by: Xiubo Li <[email protected]>
1 parent 30c5a96 commit c0f145b

File tree

3 files changed

+185
-28
lines changed

3 files changed

+185
-28
lines changed

main.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,12 +1020,18 @@ static int dev_added(struct tcmu_device *dev)
10201020
tcmu_dev_dbg(dev, "Got block_size %d, size in bytes %"PRId64"\n",
10211021
block_size, dev_size);
10221022

1023-
ret = pthread_spin_init(&rdev->cmds_list_lock, 0);
1023+
ret = pthread_mutex_init(&rdev->priv_lock, NULL);
10241024
if (ret) {
10251025
ret = -ret;
10261026
goto free_rdev;
10271027
}
10281028

1029+
ret = pthread_spin_init(&rdev->cmds_list_lock, 0);
1030+
if (ret) {
1031+
ret = -ret;
1032+
goto cleanup_priv_lock;
1033+
}
1034+
10291035
ret = pthread_mutex_init(&rdev->caw_lock, NULL);
10301036
if (ret) {
10311037
ret = -ret;
@@ -1096,6 +1102,8 @@ static int dev_added(struct tcmu_device *dev)
10961102
pthread_mutex_destroy(&rdev->caw_lock);
10971103
cleanup_dev_lock:
10981104
pthread_spin_destroy(&rdev->cmds_list_lock);
1105+
cleanup_priv_lock:
1106+
pthread_mutex_destroy(&rdev->priv_lock);
10991107
free_rdev:
11001108
free(rdev);
11011109
return ret;
@@ -1146,6 +1154,10 @@ static void dev_removed(struct tcmu_device *dev)
11461154
if (ret != 0)
11471155
tcmu_err("could not cleanup mailbox lock %d\n", ret);
11481156

1157+
ret = pthread_mutex_destroy(&rdev->priv_lock);
1158+
if (ret != 0)
1159+
tcmu_err("could not cleanup priv lock %d\n", ret);
1160+
11491161
free(rdev);
11501162

11511163
tcmu_dev_dbg(dev, "removed from tcmu-runner\n");

0 commit comments

Comments
 (0)