Commit 880ddb74 authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Jim Harris
Browse files

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: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/466731


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarVitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 5d6361b5
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -556,14 +556,10 @@ spdk_vhost_blk_get_dev(struct spdk_vhost_dev *vdev)
	return bvdev->bdev;
}

static int
vhost_session_bdev_remove_cb(struct spdk_vhost_dev *vdev,
			     struct spdk_vhost_session *vsession,
			     void *ctx)
static void
vhost_dev_bdev_remove_cpl_cb(struct spdk_vhost_dev *vdev, void *ctx)
{
	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);

@@ -571,6 +567,17 @@ vhost_session_bdev_remove_cb(struct spdk_vhost_dev *vdev,
	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,
			     void *ctx)
{
	struct spdk_vhost_blk_session *bvsession;

	if (vsession == NULL) {
		vhost_dev_bdev_remove_cpl_cb(vdev, ctx);
		return 0;
	}

+49 −26
Original line number Diff line number Diff line
@@ -197,25 +197,32 @@ remove_scsi_tgt(struct spdk_vhost_scsi_dev *svdev,
		     svdev->vdev.name, scsi_tgt_num);
}

static int
vhost_scsi_session_process_removed(struct spdk_vhost_dev *vdev,
				   struct spdk_vhost_session *vsession, void *ctx)
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_session *svsession;
	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);

	/* 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 0;
		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)
{
	unsigned scsi_tgt_num = (unsigned)(uintptr_t)ctx;
	struct spdk_vhost_scsi_session *svsession;
	struct spdk_scsi_dev_session_state *state;

	if (vsession == NULL) {
		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,25 +1068,32 @@ struct scsi_tgt_hotplug_ctx {
	bool async_fini;
};

static int
vhost_scsi_session_remove_tgt(struct spdk_vhost_dev *vdev,
			      struct spdk_vhost_session *vsession, void *_ctx)
static void
vhost_scsi_dev_remove_tgt_cpl_cb(struct spdk_vhost_dev *vdev, void *_ctx)
{
	struct scsi_tgt_hotplug_ctx *ctx = _ctx;
	unsigned scsi_tgt_num = ctx->scsi_tgt_num;
	struct spdk_vhost_scsi_session *svsession;
	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);
		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)
{
	struct scsi_tgt_hotplug_ctx *ctx = _ctx;
	unsigned scsi_tgt_num = ctx->scsi_tgt_num;
	struct spdk_vhost_scsi_session *svsession;
	struct spdk_scsi_dev_session_state *state;

	if (vsession == NULL) {
		vhost_scsi_dev_remove_tgt_cpl_cb(vdev, _ctx);
		return 0;
	}