Commit 29944a2f authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Jim Harris
Browse files

vhost: remove vhost external events



Removed their various usages inside the core vhost code
together with the external events themselves. External
events were completely replaced by spdk_vhost_lock()
and spdk_vhost_dev_find().

Change-Id: I1f9d0268c27a06e2eecab9e7d179b1fd54d4223d
Signed-off-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/440379


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent dd4f161b
Loading
Loading
Loading
Loading
+0 −31
Original line number Diff line number Diff line
@@ -327,37 +327,6 @@ int spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev);
 */
struct spdk_bdev *spdk_vhost_blk_get_dev(struct spdk_vhost_dev *ctrlr);


/**
 * Call function on reactor of given vhost device. If device is not in use, the
 * event will be called right away on the caller's thread.
 *
 * This function is thread safe.
 *
 * \param vdev_name name of the vhost device to run this event on.
 * \param fn function to be called. The first parameter of callback function is
 * either actual spdk_vhost_dev pointer or NULL in case vdev with given name doesn't
 * exist. The second param is user provided argument *arg*.
 * \param arg parameter to be passed to *fn*.
 */
void spdk_vhost_call_external_event(const char *vdev_name, spdk_vhost_event_fn fn, void *arg);

/**
 * Call function for each available vhost device on
 * it's reactor.  This will call given function in a chain,
 * meaning that each callback will be called after the
 * previous one has finished. After given function has
 * been called for all vdevs, it will be called once
 * again with first param - vhost device- set to NULL.
 *
 * This function is thread safe.
 *
 * \param fn function to be called for each vdev. The first param will be
 * either vdev pointer or NULL. The second param is user provided argument *arg*.
 * \param arg parameter to be passed to *fn*.
 */
void spdk_vhost_call_external_event_foreach(spdk_vhost_event_fn fn, void *arg);

#ifdef __cplusplus
}
#endif
+33 −83
Original line number Diff line number Diff line
@@ -1308,17 +1308,6 @@ destroy_connection(int vid)
	pthread_mutex_unlock(&g_spdk_vhost_mutex);
}

void
spdk_vhost_call_external_event(const char *ctrlr_name, spdk_vhost_event_fn fn, void *arg)
{
	struct spdk_vhost_dev *vdev;

	pthread_mutex_lock(&g_spdk_vhost_mutex);
	vdev = spdk_vhost_dev_find(ctrlr_name);
	fn(vdev, arg);
	pthread_mutex_unlock(&g_spdk_vhost_mutex);
}

static void
spdk_vhost_external_event_foreach_continue(struct spdk_vhost_dev *vdev,
		struct spdk_vhost_session *vsession,
@@ -1364,19 +1353,6 @@ spdk_vhost_dev_foreach_session(struct spdk_vhost_dev *vdev,
	spdk_vhost_external_event_foreach_continue(vdev, vsession, fn, arg);
}

void
spdk_vhost_call_external_event_foreach(spdk_vhost_event_fn fn, void *arg)
{
	struct spdk_vhost_dev *vdev, *tmp;

	pthread_mutex_lock(&g_spdk_vhost_mutex);
	TAILQ_FOREACH_SAFE(vdev, &g_spdk_vhost_devices, tailq, tmp) {
		fn(vdev, arg);
	}
	fn(NULL, arg);
	pthread_mutex_unlock(&g_spdk_vhost_mutex);
}

void
spdk_vhost_lock(void)
{
@@ -1438,29 +1414,25 @@ spdk_vhost_init(void)
	return 0;
}

static int
_spdk_vhost_fini_remove_vdev_cb(struct spdk_vhost_dev *vdev, void *arg)
static void
_spdk_vhost_fini(void *arg1, void *arg2)
{
	spdk_vhost_fini_cb fini_cb = arg;
	spdk_vhost_fini_cb fini_cb = arg1;
	struct spdk_vhost_dev *vdev, *tmp;

	if (vdev != NULL) {
	spdk_vhost_lock();
	vdev = spdk_vhost_dev_next(NULL);
	while (vdev != NULL) {
		tmp = spdk_vhost_dev_next(vdev);
		spdk_vhost_dev_remove(vdev);
		/* don't care if it fails, there's nothing we can do for now */
		return 0;
		vdev = tmp;
	}
	spdk_vhost_unlock();

	/* All devices are removed now. */
	free(g_num_ctrlrs);
	fini_cb();
	return 0;
}

static void
_spdk_vhost_fini(void *arg1, void *arg2)
{
	spdk_vhost_fini_cb fini_cb = arg1;

	spdk_vhost_call_external_event_foreach(_spdk_vhost_fini_remove_vdev_cb, fini_cb);
}

void
@@ -1484,61 +1456,39 @@ spdk_vhost_fini(spdk_vhost_fini_cb fini_cb)
	pthread_detach(tid);
}

struct spdk_vhost_write_config_json_ctx {
	struct spdk_json_write_ctx *w;
	struct spdk_event *done_ev;
};

static int
spdk_vhost_config_json_cb(struct spdk_vhost_dev *vdev, void *arg)
void
spdk_vhost_config_json(struct spdk_json_write_ctx *w, struct spdk_event *done_ev)
{
	struct spdk_vhost_write_config_json_ctx *ctx = arg;
	struct spdk_vhost_dev *vdev;
	uint32_t delay_base_us;
	uint32_t iops_threshold;

	if (vdev == NULL) {
		spdk_json_write_array_end(ctx->w);
		spdk_event_call(ctx->done_ev);
		free(ctx);
		return 0;
	}
	spdk_json_write_array_begin(w);

	vdev->backend->write_config_json(vdev, ctx->w);
	spdk_vhost_lock();
	vdev = spdk_vhost_dev_next(NULL);
	while (vdev != NULL) {
		vdev->backend->write_config_json(vdev, w);

		spdk_vhost_get_coalescing(vdev, &delay_base_us, &iops_threshold);
		if (delay_base_us) {
		spdk_json_write_object_begin(ctx->w);
		spdk_json_write_named_string(ctx->w, "method", "set_vhost_controller_coalescing");
			spdk_json_write_object_begin(w);
			spdk_json_write_named_string(w, "method", "set_vhost_controller_coalescing");

		spdk_json_write_named_object_begin(ctx->w, "params");
		spdk_json_write_named_string(ctx->w, "ctrlr", vdev->name);
		spdk_json_write_named_uint32(ctx->w, "delay_base_us", delay_base_us);
		spdk_json_write_named_uint32(ctx->w, "iops_threshold", iops_threshold);
		spdk_json_write_object_end(ctx->w);
			spdk_json_write_named_object_begin(w, "params");
			spdk_json_write_named_string(w, "ctrlr", vdev->name);
			spdk_json_write_named_uint32(w, "delay_base_us", delay_base_us);
			spdk_json_write_named_uint32(w, "iops_threshold", iops_threshold);
			spdk_json_write_object_end(w);

		spdk_json_write_object_end(ctx->w);
			spdk_json_write_object_end(w);
		}

	return 0;
		vdev = spdk_vhost_dev_next(vdev);
	}
	spdk_vhost_unlock();

void
spdk_vhost_config_json(struct spdk_json_write_ctx *w, struct spdk_event *done_ev)
{
	struct spdk_vhost_write_config_json_ctx *ctx;

	ctx = calloc(1, sizeof(*ctx));
	if (!ctx) {
	spdk_json_write_array_end(w);
	spdk_event_call(done_ev);
		return;
	}

	ctx->w = w;
	ctx->done_ev = done_ev;

	spdk_json_write_array_begin(w);

	spdk_vhost_call_external_event_foreach(spdk_vhost_config_json_cb, ctx);
}

SPDK_LOG_REGISTER_COMPONENT("vhost", SPDK_LOG_VHOST)
+6 −10
Original line number Diff line number Diff line
@@ -596,21 +596,17 @@ _spdk_vhost_session_bdev_remove_cb(struct spdk_vhost_dev *vdev, struct spdk_vhos
	return 0;
}

static int
_bdev_remove_cb(struct spdk_vhost_dev *vdev, void *arg)
{
	SPDK_WARNLOG("Controller %s: Hot-removing bdev - all further requests will fail.\n",
		     vdev->name);
	spdk_vhost_dev_foreach_session(vdev, _spdk_vhost_session_bdev_remove_cb, NULL);
	return 0;
}

static void
bdev_remove_cb(void *remove_ctx)
{
	struct spdk_vhost_blk_dev *bvdev = remove_ctx;

	spdk_vhost_call_external_event(bvdev->vdev.name, _bdev_remove_cb, bvdev);
	SPDK_WARNLOG("Controller %s: Hot-removing bdev - all further requests will fail.\n",
		     bvdev->vdev.name);

	spdk_vhost_lock();
	spdk_vhost_dev_foreach_session(&bvdev->vdev, _spdk_vhost_session_bdev_remove_cb, NULL);
	spdk_vhost_unlock();
}

static void
+5 −13
Original line number Diff line number Diff line
@@ -208,15 +208,6 @@ spdk_vhost_scsi_session_process_removed(struct spdk_vhost_dev *vdev,
	return 0;
}

static int
spdk_vhost_scsi_dev_process_removed(struct spdk_vhost_dev *vdev, void *arg)
{
	spdk_vhost_dev_foreach_session(vdev,
				       spdk_vhost_scsi_session_process_removed,
				       arg);
	return 0;
}

static void
process_removed_devs(struct spdk_vhost_scsi_session *svsession)
{
@@ -232,11 +223,12 @@ process_removed_devs(struct spdk_vhost_scsi_session *svsession)
			/* detach the device from this session */
			spdk_scsi_dev_free_io_channels(dev);
			state->dev = NULL;
			/* try to detach it globally. we need a lock in order to modify
			 * the vdev, so use an external event */
			spdk_vhost_call_external_event(svsession->svdev->vdev.name,
						       spdk_vhost_scsi_dev_process_removed,
			/* try to detach it globally */
			spdk_vhost_lock();
			spdk_vhost_dev_foreach_session(&svsession->svdev->vdev,
						       spdk_vhost_scsi_session_process_removed,
						       (void *)(uintptr_t)i);
			spdk_vhost_unlock();
		}
	}
}