Skip to content

Commit

Permalink
tcmur_device: add priv lock support
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lxbsz committed Aug 26, 2021
1 parent 30c5a96 commit c0f145b
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 28 deletions.
14 changes: 13 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,12 +1020,18 @@ static int dev_added(struct tcmu_device *dev)
tcmu_dev_dbg(dev, "Got block_size %d, size in bytes %"PRId64"\n",
block_size, dev_size);

ret = pthread_spin_init(&rdev->cmds_list_lock, 0);
ret = pthread_mutex_init(&rdev->priv_lock, NULL);
if (ret) {
ret = -ret;
goto free_rdev;
}

ret = pthread_spin_init(&rdev->cmds_list_lock, 0);
if (ret) {
ret = -ret;
goto cleanup_priv_lock;
}

ret = pthread_mutex_init(&rdev->caw_lock, NULL);
if (ret) {
ret = -ret;
Expand Down Expand Up @@ -1096,6 +1102,8 @@ static int dev_added(struct tcmu_device *dev)
pthread_mutex_destroy(&rdev->caw_lock);
cleanup_dev_lock:
pthread_spin_destroy(&rdev->cmds_list_lock);
cleanup_priv_lock:
pthread_mutex_destroy(&rdev->priv_lock);
free_rdev:
free(rdev);
return ret;
Expand Down Expand Up @@ -1146,6 +1154,10 @@ static void dev_removed(struct tcmu_device *dev)
if (ret != 0)
tcmu_err("could not cleanup mailbox lock %d\n", ret);

ret = pthread_mutex_destroy(&rdev->priv_lock);
if (ret != 0)
tcmu_err("could not cleanup priv lock %d\n", ret);

free(rdev);

tcmu_dev_dbg(dev, "removed from tcmu-runner\n");
Expand Down
Loading

0 comments on commit c0f145b

Please sign in to comment.