Skip to content
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

Merged
merged 1 commit into from Mar 23, 2023

Conversation

lxbsz
Copy link
Collaborator

@lxbsz lxbsz commented Mar 20, 2023

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

tcmur_device.c Show resolved Hide resolved
tcmur_device.c Show resolved Hide resolved
@lxbsz lxbsz requested review from idryomov and pkalever and removed request for idryomov and pkalever March 22, 2023 02:45
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);

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)?

Copy link
Collaborator Author

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;

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).

Copy link
Collaborator Author

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++;

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_RECOVERY in the function that adds rdev to the respective list (using rdev->recovery_entry)
  • increment rdev->conn_lost_cnt in the function that handles a lost connection

Copy link
Collaborator Author

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);

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.

Copy link
Collaborator Author

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>
@lxbsz lxbsz merged commit 3c931e4 into open-iscsi:main Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants