New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tcmur_device: fix racy between reopening devices and reporting events #695
Conversation
tcmur_device.c
Outdated
| @@ -46,26 +46,15 @@ int __tcmu_reopen_dev(struct tcmu_device *dev, int retries) | |||
| int ret, attempt = 0; | |||
| bool needs_close = false; | |||
|
|
|||
| assert(rdev->flags & TCMUR_DEV_FLAG_IN_RECOVERY); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be done with rdev->rdev_lock held (i.e. on line 50)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not that critical IMO. But I will fix it.
target.c
Outdated
| @@ -336,11 +336,14 @@ int tcmu_add_dev_to_recovery_list(struct tcmu_device *dev) | |||
| goto done; | |||
| } | |||
| list_add(&tpg_recovery_list, &tpg->recovery_entry); | |||
| rdev->flags |= TCMUR_DEV_FLAG_IN_RECOVERY; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be done after adding rdev to tpg->devs list:
add_to_list:
list_add(&tpg->devs, &rdev->recovery_entry);
rdev->flags |= TCMUR_DEV_FLAG_IN_RECOVERY;
Otherwise TCMUR_DEV_FLAG_IN_RECOVERY wouldn't get set in the "another device already kicked off recovery" case (or, if it somehow would, it's really not obvious).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I will fix it.
target.c
Outdated
| @@ -336,11 +336,14 @@ int tcmu_add_dev_to_recovery_list(struct tcmu_device *dev) | |||
| goto done; | |||
| } | |||
| list_add(&tpg_recovery_list, &tpg->recovery_entry); | |||
| rdev->flags |= TCMUR_DEV_FLAG_IN_RECOVERY; | |||
| rdev->conn_lost_cnt++; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The increment should stay in __tcmu_notify_conn_lost IMO. The point of my suggestion was to keep related things close and not mix them:
- set
TCMUR_DEV_FLAG_IN_RECOVERYin the function that addsrdevto the respective list (usingrdev->recovery_entry) - increment
rdev->conn_lost_cntin the function that handles a lost connection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
target.c
Outdated
|
|
||
| add_to_list: | ||
| list_add(&tpg->devs, &rdev->recovery_entry); | ||
| done: | ||
| tcmu_release_alua_grps(&alua_list); | ||
| pthread_mutex_unlock(&tpg_recovery_lock); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add a blank line here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
To make sure all the in-flight IOs have been finished before flushing the event_work. Or just after we flush the event_work a new timedout IO callback could come and then it will fire a new event work, which may access the device while we are closing the device later. Signed-off-by: Xiubo Li <xiubli@redhat.com>
To make sure all the in-flight IOs have been finished before flushing the event_work. Or just after we flush the event_work a new timedout IO callback could come and then it will fire a new event work, which may access the device while we are closing the device later.
Signed-off-by: Xiubo Li xiubli@redhat.com