diff --git a/include/spdk/vhost.h b/include/spdk/vhost.h index dfb0f0af28..f0e8fba589 100644 --- a/include/spdk/vhost.h +++ b/include/spdk/vhost.h @@ -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 diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 0a20327be5..412f279024 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -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) -{ - spdk_vhost_fini_cb fini_cb = arg; - - if (vdev != NULL) { - spdk_vhost_dev_remove(vdev); - /* don't care if it fails, there's nothing we can do for now */ - return 0; - } - - /* 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; + struct spdk_vhost_dev *vdev, *tmp; - spdk_vhost_call_external_event_foreach(_spdk_vhost_fini_remove_vdev_cb, fini_cb); + 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 */ + vdev = tmp; + } + spdk_vhost_unlock(); + + /* All devices are removed now. */ + free(g_num_ctrlrs); + 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) -{ - struct spdk_vhost_write_config_json_ctx *ctx = arg; - 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; - } - - vdev->backend->write_config_json(vdev, ctx->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_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_object_end(ctx->w); - } - - return 0; -} - 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_event_call(done_ev); - return; - } - - ctx->w = w; - ctx->done_ev = done_ev; + struct spdk_vhost_dev *vdev; + uint32_t delay_base_us; + uint32_t iops_threshold; spdk_json_write_array_begin(w); - spdk_vhost_call_external_event_foreach(spdk_vhost_config_json_cb, ctx); + 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(w); + spdk_json_write_named_string(w, "method", "set_vhost_controller_coalescing"); + + 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(w); + } + vdev = spdk_vhost_dev_next(vdev); + } + spdk_vhost_unlock(); + + spdk_json_write_array_end(w); + spdk_event_call(done_ev); } SPDK_LOG_REGISTER_COMPONENT("vhost", SPDK_LOG_VHOST) diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index ddd22c12a5..a32c482a97 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -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 diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index 1e74c0ec51..b641f713bf 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -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(); } } }