Skip to content

Commit

Permalink
Drop in_lock_thread from __tcmu_reopen_dev
Browse files Browse the repository at this point in the history
We know if the lock thread is running and if we are in it, so no need to
have the caller tell us.

Signed-off-by: Mike Christie <mchristi@redhat.com>
  • Loading branch information
Mike Christie committed Mar 18, 2019
1 parent 3d298ee commit 5798ba6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion target.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static void *tgt_port_grp_recovery_thread_fn(void *arg)
*/
list_for_each_safe(&tpg->devs, rdev, tmp_rdev, recovery_entry) {
list_del(&rdev->recovery_entry);
ret = __tcmu_reopen_dev(rdev->dev, false, -1);
ret = __tcmu_reopen_dev(rdev->dev, -1);
if (ret) {
tcmu_dev_err(rdev->dev, "Could not reinitialize device. (err %d).\n",
ret);
Expand Down
18 changes: 11 additions & 7 deletions tcmur_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ bool tcmu_dev_in_recovery(struct tcmu_device *dev)
/*
* TCMUR_DEV_FLAG_IN_RECOVERY must be set before calling
*/
int __tcmu_reopen_dev(struct tcmu_device *dev, bool in_lock_thread, int retries)
int __tcmu_reopen_dev(struct tcmu_device *dev, int retries)
{
struct tcmur_device *rdev = tcmu_get_daemon_dev_private(dev);
struct tcmur_handler *rhandler = tcmu_get_runner_handler(dev);
int ret, attempt = 0;
bool needs_close = false;
bool cancel_lock = false;

tcmu_dev_dbg(dev, "Waiting for outstanding commands to complete\n");
ret = aio_wait_for_empty_queue(rdev);
Expand All @@ -55,14 +56,18 @@ int __tcmu_reopen_dev(struct tcmu_device *dev, bool in_lock_thread, int retries)
ret = 0;
goto done;
}

if (rdev->lock_state == TCMUR_DEV_LOCK_LOCKING &&
pthread_self() != rdev->lock_thread)
cancel_lock = true;
pthread_mutex_unlock(&rdev->state_lock);

/*
* There are no SCSI commands running but there may be
* async lock requests in progress that might be accessing
* the device.
*/
if (!in_lock_thread)
if (cancel_lock)
tcmu_cancel_lock_thread(dev);

/*
Expand Down Expand Up @@ -115,10 +120,9 @@ int __tcmu_reopen_dev(struct tcmu_device *dev, bool in_lock_thread, int retries)
/*
* tcmu_reopen_dev - close and open device.
* @dev: device to reopen
* @in_lock_thread: true if called from locking thread.
* @retries: number of times to retry open() call. -1 indicates infinite.
*/
int tcmu_reopen_dev(struct tcmu_device *dev, bool in_lock_thread, int retries)
int tcmu_reopen_dev(struct tcmu_device *dev, int retries)
{
struct tcmur_device *rdev = tcmu_get_daemon_dev_private(dev);

Expand All @@ -130,7 +134,7 @@ int tcmu_reopen_dev(struct tcmu_device *dev, bool in_lock_thread, int retries)
rdev->flags |= TCMUR_DEV_FLAG_IN_RECOVERY;
pthread_mutex_unlock(&rdev->state_lock);

return __tcmu_reopen_dev(dev, in_lock_thread, retries);
return __tcmu_reopen_dev(dev, retries);
}

void tcmu_cancel_recovery(struct tcmu_device *dev)
Expand Down Expand Up @@ -310,7 +314,7 @@ int tcmu_get_lock_tag(struct tcmu_device *dev, uint16_t *tag)
* commands started before it via the aio wait call.
*/
tcmu_dev_dbg(dev, "Could not access dev. Try reopen.");
ret = tcmu_reopen_dev(dev, false, 0);
ret = tcmu_reopen_dev(dev, 0);
if (!ret && retry < 1) {
retry++;
goto retry;
Expand Down Expand Up @@ -388,7 +392,7 @@ int tcmu_acquire_dev_lock(struct tcmu_device *dev, bool is_sync,

if (reopen) {
tcmu_dev_dbg(dev, "Try to reopen device. %d\n", retries);
ret = tcmu_reopen_dev(dev, true, 0);
ret = tcmu_reopen_dev(dev, 0);
if (ret) {
tcmu_dev_err(dev, "Could not reopen device while taking lock. Err %d.\n",
ret);
Expand Down
4 changes: 2 additions & 2 deletions tcmur_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ int tcmu_cancel_lock_thread(struct tcmu_device *dev);
void tcmu_notify_conn_lost(struct tcmu_device *dev);
void tcmu_notify_lock_lost(struct tcmu_device *dev);

int __tcmu_reopen_dev(struct tcmu_device *dev, bool in_lock_thread, int retries);
int tcmu_reopen_dev(struct tcmu_device *dev, bool in_lock_thread, int retries);
int __tcmu_reopen_dev(struct tcmu_device *dev, int retries);
int tcmu_reopen_dev(struct tcmu_device *dev, int retries);

int tcmu_acquire_dev_lock(struct tcmu_device *dev, bool is_sync, uint16_t tag);
void tcmu_release_dev_lock(struct tcmu_device *dev);
Expand Down

0 comments on commit 5798ba6

Please sign in to comment.