vhost: prepare to add a separate cpl cb to foreach_session()

Currently vhost_dev_foreach_session() accepts a single
callback function for both iterating through all active
sessions and for signaling the end of iteration (called
last time with vsession param == NULL). Now that the
final signal has completely different semantics and is
called on a specific thread, it makes sense to put in
a separate function.

In this patch we prepare separate functions for the final
call, but still call them in the original callback. In
a separate patch we'll start passing both functions
directly to foreach_session().

Change-Id: I9f4338d9696f7bd15ca2d6655c6a3851569aff75
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/466731
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Vitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-07-20 23:30:56 +02:00 committed by Jim Harris
parent 5d6361b5dd
commit 880ddb7436
2 changed files with 63 additions and 33 deletions

View File

@ -556,6 +556,19 @@ spdk_vhost_blk_get_dev(struct spdk_vhost_dev *vdev)
return bvdev->bdev;
}
static void
vhost_dev_bdev_remove_cpl_cb(struct spdk_vhost_dev *vdev, void *ctx)
{
/* All sessions have been notified, time to close the bdev */
struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);
assert(bvdev != NULL);
spdk_bdev_close(bvdev->bdev_desc);
bvdev->bdev_desc = NULL;
bvdev->bdev = NULL;
}
static int
vhost_session_bdev_remove_cb(struct spdk_vhost_dev *vdev,
struct spdk_vhost_session *vsession,
@ -564,13 +577,7 @@ vhost_session_bdev_remove_cb(struct spdk_vhost_dev *vdev,
struct spdk_vhost_blk_session *bvsession;
if (vsession == NULL) {
/* All sessions have been notified, time to close the bdev */
struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);
assert(bvdev != NULL);
spdk_bdev_close(bvdev->bdev_desc);
bvdev->bdev_desc = NULL;
bvdev->bdev = NULL;
vhost_dev_bdev_remove_cpl_cb(vdev, ctx);
return 0;
}

View File

@ -197,6 +197,22 @@ remove_scsi_tgt(struct spdk_vhost_scsi_dev *svdev,
svdev->vdev.name, scsi_tgt_num);
}
static void
vhost_scsi_dev_process_removed_cpl_cb(struct spdk_vhost_dev *vdev, void *ctx)
{
unsigned scsi_tgt_num = (unsigned)(uintptr_t)ctx;
struct spdk_vhost_scsi_dev *svdev = SPDK_CONTAINEROF(vdev,
struct spdk_vhost_scsi_dev, vdev);
/* all sessions have already detached the device */
if (svdev->scsi_dev_state[scsi_tgt_num].status != VHOST_SCSI_DEV_REMOVING) {
/* device was already removed in the meantime */
return;
}
remove_scsi_tgt(svdev, scsi_tgt_num);
}
static int
vhost_scsi_session_process_removed(struct spdk_vhost_dev *vdev,
struct spdk_vhost_session *vsession, void *ctx)
@ -206,16 +222,7 @@ vhost_scsi_session_process_removed(struct spdk_vhost_dev *vdev,
struct spdk_scsi_dev_session_state *state;
if (vsession == NULL) {
/* all sessions have already detached the device */
struct spdk_vhost_scsi_dev *svdev = SPDK_CONTAINEROF(vdev,
struct spdk_vhost_scsi_dev, vdev);
if (svdev->scsi_dev_state[scsi_tgt_num].status != VHOST_SCSI_DEV_REMOVING) {
/* device was already removed in the meantime */
return 0;
}
remove_scsi_tgt(svdev, scsi_tgt_num);
vhost_scsi_dev_process_removed_cpl_cb(vdev, ctx);
return 0;
}
@ -913,6 +920,21 @@ vhost_scsi_lun_hotremove(const struct spdk_scsi_lun *lun, void *arg)
spdk_vhost_scsi_dev_remove_tgt(&svdev->vdev, scsi_dev_num, NULL, NULL);
}
static void
vhost_scsi_dev_add_tgt_cpl_cb(struct spdk_vhost_dev *vdev, void *ctx)
{
unsigned scsi_tgt_num = (unsigned)(uintptr_t)ctx;
struct spdk_vhost_scsi_dev *svdev = SPDK_CONTAINEROF(vdev,
struct spdk_vhost_scsi_dev, vdev);
struct spdk_scsi_dev_vhost_state *vhost_sdev;
vhost_sdev = &svdev->scsi_dev_state[scsi_tgt_num];
/* All sessions have added the target */
assert(vhost_sdev->status == VHOST_SCSI_DEV_ADDING);
vhost_sdev->status = VHOST_SCSI_DEV_PRESENT;
}
static int
vhost_scsi_session_add_tgt(struct spdk_vhost_dev *vdev,
struct spdk_vhost_session *vsession, void *ctx)
@ -924,13 +946,7 @@ vhost_scsi_session_add_tgt(struct spdk_vhost_dev *vdev,
int rc;
if (vsession == NULL) {
struct spdk_vhost_scsi_dev *svdev = SPDK_CONTAINEROF(vdev,
struct spdk_vhost_scsi_dev, vdev);
vhost_sdev = &svdev->scsi_dev_state[scsi_tgt_num];
/* All sessions have added the target */
assert(vhost_sdev->status == VHOST_SCSI_DEV_ADDING);
vhost_sdev->status = VHOST_SCSI_DEV_PRESENT;
vhost_scsi_dev_add_tgt_cpl_cb(vdev, ctx);
return 0;
}
@ -1052,6 +1068,21 @@ struct scsi_tgt_hotplug_ctx {
bool async_fini;
};
static void
vhost_scsi_dev_remove_tgt_cpl_cb(struct spdk_vhost_dev *vdev, void *_ctx)
{
struct scsi_tgt_hotplug_ctx *ctx = _ctx;
struct spdk_vhost_scsi_dev *svdev = SPDK_CONTAINEROF(vdev,
struct spdk_vhost_scsi_dev, vdev);
if (!ctx->async_fini) {
/* there aren't any active sessions, so remove the dev and exit */
remove_scsi_tgt(svdev, ctx->scsi_tgt_num);
}
free(ctx);
}
static int
vhost_scsi_session_remove_tgt(struct spdk_vhost_dev *vdev,
struct spdk_vhost_session *vsession, void *_ctx)
@ -1062,15 +1093,7 @@ vhost_scsi_session_remove_tgt(struct spdk_vhost_dev *vdev,
struct spdk_scsi_dev_session_state *state;
if (vsession == NULL) {
struct spdk_vhost_scsi_dev *svdev = SPDK_CONTAINEROF(vdev,
struct spdk_vhost_scsi_dev, vdev);
if (!ctx->async_fini) {
/* there aren't any active sessions, so remove the dev and exit */
remove_scsi_tgt(svdev, scsi_tgt_num);
}
free(ctx);
vhost_scsi_dev_remove_tgt_cpl_cb(vdev, _ctx);
return 0;
}