Skip to content

Commit

Permalink
tcmur_device: rename the state_lock to rdev_lock
Browse files Browse the repository at this point in the history
Signed-off-by: Xiubo Li <[email protected]>
  • Loading branch information
lxbsz committed Sep 9, 2021
1 parent a744c87 commit 314b56c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 73 deletions.
8 changes: 4 additions & 4 deletions alua.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,12 @@ static int alua_sync_state(struct tcmu_device *dev,
* the first command sent to us so clear
* lock state to avoid later blacklist errors.
*/
pthread_mutex_lock(&rdev->state_lock);
pthread_mutex_lock(&rdev->rdev_lock);
if (rdev->lock_state == TCMUR_DEV_LOCK_WRITE_LOCKED) {
tcmu_dev_dbg(dev, "Dropping lock\n");
rdev->lock_state = TCMUR_DEV_LOCK_UNLOCKED;
}
pthread_mutex_unlock(&rdev->state_lock);
pthread_mutex_unlock(&rdev->rdev_lock);
}
}

Expand Down Expand Up @@ -560,7 +560,7 @@ int alua_implicit_transition(struct tcmu_device *dev, struct tcmulib_cmd *cmd,
if (!lock_is_required(dev))
return ret;

pthread_mutex_lock(&rdev->state_lock);
pthread_mutex_lock(&rdev->rdev_lock);
if (rdev->lock_state == TCMUR_DEV_LOCK_WRITE_LOCKED) {
/* For both read/write cases in this state is good */
goto done;
Expand Down Expand Up @@ -617,7 +617,7 @@ int alua_implicit_transition(struct tcmu_device *dev, struct tcmulib_cmd *cmd,
}

done:
pthread_mutex_unlock(&rdev->state_lock);
pthread_mutex_unlock(&rdev->rdev_lock);
return ret;
}

Expand Down
32 changes: 16 additions & 16 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,14 +615,14 @@ static void tcmur_stop_device(void *arg)
struct tcmur_device *rdev = tcmu_dev_get_private(dev);
bool is_open = false;

pthread_mutex_lock(&rdev->state_lock);
pthread_mutex_lock(&rdev->rdev_lock);
/* check if this was already called due to thread cancelation */
if (rdev->flags & TCMUR_DEV_FLAG_STOPPED) {
pthread_mutex_unlock(&rdev->state_lock);
pthread_mutex_unlock(&rdev->rdev_lock);
return;
}
rdev->flags |= TCMUR_DEV_FLAG_STOPPING;
pthread_mutex_unlock(&rdev->state_lock);
pthread_mutex_unlock(&rdev->rdev_lock);

/*
* The lock thread can fire off the recovery thread, so make sure
Expand All @@ -633,19 +633,19 @@ static void tcmur_stop_device(void *arg)

tcmu_release_dev_lock(dev);

pthread_mutex_lock(&rdev->state_lock);
pthread_mutex_lock(&rdev->rdev_lock);
if (rdev->flags & TCMUR_DEV_FLAG_IS_OPEN) {
rdev->flags &= ~TCMUR_DEV_FLAG_IS_OPEN;
is_open = true;
}
pthread_mutex_unlock(&rdev->state_lock);
pthread_mutex_unlock(&rdev->rdev_lock);

if (is_open)
rhandler->close(dev);

pthread_mutex_lock(&rdev->state_lock);
pthread_mutex_lock(&rdev->rdev_lock);
rdev->flags |= TCMUR_DEV_FLAG_STOPPED;
pthread_mutex_unlock(&rdev->state_lock);
pthread_mutex_unlock(&rdev->rdev_lock);

tcmu_dev_dbg(dev, "cmdproc cleanup done\n");
}
Expand Down Expand Up @@ -872,10 +872,10 @@ static void *tcmur_cmdproc_thread(void *arg)
* requests that LIO has completed. We only need to wait for replies
* for outstanding requests so throttle the cmdproc thread now.
*/
pthread_mutex_lock(&rdev->state_lock);
pthread_mutex_lock(&rdev->rdev_lock);
if (rdev->flags & TCMUR_DEV_FLAG_STOPPING)
dev_stopping = true;
pthread_mutex_unlock(&rdev->state_lock);
pthread_mutex_unlock(&rdev->rdev_lock);
}

/*
Expand Down Expand Up @@ -1038,15 +1038,15 @@ static int dev_added(struct tcmu_device *dev)
goto cleanup_caw_lock;
}

ret = pthread_mutex_init(&rdev->state_lock, NULL);
ret = pthread_mutex_init(&rdev->rdev_lock, NULL);
if (ret) {
ret = -ret;
goto cleanup_format_lock;
}

ret = setup_io_work_queue(dev);
if (ret < 0)
goto cleanup_state_lock;
goto cleanup_rdev_lock;

ret = setup_aio_tracking(rdev);
if (ret < 0)
Expand Down Expand Up @@ -1088,8 +1088,8 @@ static int dev_added(struct tcmu_device *dev)
cleanup_aio_tracking(rdev);
cleanup_io_work_queue:
cleanup_io_work_queue(dev, true);
cleanup_state_lock:
pthread_mutex_destroy(&rdev->state_lock);
cleanup_rdev_lock:
pthread_mutex_destroy(&rdev->rdev_lock);
cleanup_format_lock:
pthread_mutex_destroy(&rdev->format_lock);
cleanup_caw_lock:
Expand All @@ -1106,9 +1106,9 @@ static void dev_removed(struct tcmu_device *dev)
struct tcmur_device *rdev = tcmu_dev_get_private(dev);
int ret;

pthread_mutex_lock(&rdev->state_lock);
pthread_mutex_lock(&rdev->rdev_lock);
rdev->flags |= TCMUR_DEV_FLAG_STOPPING;
pthread_mutex_unlock(&rdev->state_lock);
pthread_mutex_unlock(&rdev->rdev_lock);

/*
* The order of cleaning up worker threads and calling ->removed()
Expand All @@ -1130,7 +1130,7 @@ static void dev_removed(struct tcmu_device *dev)

tcmur_destroy_work(rdev->event_work);

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

Expand Down
2 changes: 1 addition & 1 deletion target.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
static struct list_head tpg_recovery_list = LIST_HEAD_INIT(tpg_recovery_list);
/*
* Locking ordering:
* rdev->state_lock
* rdev->rdev_lock
* tpg_recovery_lock
*/
static pthread_mutex_t tpg_recovery_lock = PTHREAD_MUTEX_INITIALIZER;
Expand Down
8 changes: 4 additions & 4 deletions tcmur_cmd_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2329,9 +2329,9 @@ void tcmur_set_pending_ua(struct tcmu_device *dev, int ua)
{
struct tcmur_device *rdev = tcmu_dev_get_private(dev);

pthread_mutex_lock(&rdev->state_lock);
pthread_mutex_lock(&rdev->rdev_lock);
rdev->pending_uas |= (1 << ua);
pthread_mutex_unlock(&rdev->state_lock);
pthread_mutex_unlock(&rdev->rdev_lock);
}

/*
Expand All @@ -2348,7 +2348,7 @@ static int handle_pending_ua(struct tcmur_device *rdev, struct tcmulib_cmd *cmd)
/* The kernel will handle REPORT_LUNS */
return TCMU_STS_NOT_HANDLED;
}
pthread_mutex_lock(&rdev->state_lock);
pthread_mutex_lock(&rdev->rdev_lock);

if (!rdev->pending_uas) {
ret = TCMU_STS_NOT_HANDLED;
Expand All @@ -2364,7 +2364,7 @@ static int handle_pending_ua(struct tcmur_device *rdev, struct tcmulib_cmd *cmd)
rdev->pending_uas &= ~(1 << ua);

unlock:
pthread_mutex_unlock(&rdev->state_lock);
pthread_mutex_unlock(&rdev->rdev_lock);
return ret;
}

Expand Down
Loading

0 comments on commit 314b56c

Please sign in to comment.