From 01cec2499f821b70bad4405243f9351dbe839447 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 1 Sep 2022 10:15:40 +0000 Subject: [PATCH] vhost: add start_session vhost_blk_start and vhost_scsi_start are now just a single vhost_user_session_send_event() call, so make this more generic by adding a top-level start_session function. Now this function will do the vhost_user_session_send_event(), using the user_dev_backend's start_session function pointer. Signed-off-by: Jim Harris Change-Id: Ia89ba15011e231f0474405fb7225e713dcc920bf Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14327 Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu Reviewed-by: Tomasz Zawadzki Tested-by: SPDK CI Jenkins --- lib/vhost/rte_vhost_user.c | 12 +++++++++++- lib/vhost/vhost_blk.c | 11 ++--------- lib/vhost/vhost_internal.h | 2 +- lib/vhost/vhost_scsi.c | 14 ++++---------- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/vhost/rte_vhost_user.c b/lib/vhost/rte_vhost_user.c index 1a7596c22..d817c1872 100644 --- a/lib/vhost/rte_vhost_user.c +++ b/lib/vhost/rte_vhost_user.c @@ -919,6 +919,16 @@ new_connection(int vid) return 0; } +static int +vhost_user_session_start(struct spdk_vhost_dev *vdev, struct spdk_vhost_session *vsession) +{ + const struct spdk_vhost_user_dev_backend *backend; + + backend = to_user_dev(vdev)->user_backend; + + return vhost_user_session_send_event(vsession, backend->start_session, 3, "start session"); +} + static int start_device(int vid) { @@ -1040,7 +1050,7 @@ start_device(int vid) vhost_user_session_set_coalescing(vdev, vsession, NULL); vhost_session_mem_register(vsession->mem); vsession->initialized = true; - rc = to_user_dev(vdev)->user_backend->start_session(vsession); + rc = vhost_user_session_start(vdev, vsession); if (rc != 0) { vhost_session_mem_unregister(vsession->mem); free(vsession->mem); diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 75c73df81..7afe3fccf 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -1291,8 +1291,8 @@ alloc_task_pool(struct spdk_vhost_blk_session *bvsession) } static int -vhost_blk_start_cb(struct spdk_vhost_dev *vdev, - struct spdk_vhost_session *vsession, void *unused) +vhost_blk_start(struct spdk_vhost_dev *vdev, + struct spdk_vhost_session *vsession, void *unused) { struct spdk_vhost_blk_session *bvsession = to_blk_session(vsession); struct spdk_vhost_blk_dev *bvdev; @@ -1363,13 +1363,6 @@ out: return rc; } -static int -vhost_blk_start(struct spdk_vhost_session *vsession) -{ - return vhost_user_session_send_event(vsession, vhost_blk_start_cb, - 3, "start session"); -} - static int destroy_session_poller_cb(void *arg) { diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index fdde86b40..f0aa0b198 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -216,7 +216,7 @@ struct spdk_vhost_user_dev_backend { */ size_t session_ctx_size; - int (*start_session)(struct spdk_vhost_session *vsession); + spdk_vhost_session_fn start_session; int (*stop_session)(struct spdk_vhost_session *vsession); }; diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index a7c75543b..4714a1175 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -112,7 +112,8 @@ struct spdk_vhost_scsi_task { struct spdk_vhost_virtqueue *vq; }; -static int vhost_scsi_start(struct spdk_vhost_session *vsession); +static int vhost_scsi_start(struct spdk_vhost_dev *vdev, + struct spdk_vhost_session *vsession, void *unused); static int vhost_scsi_stop(struct spdk_vhost_session *vsession); static void vhost_scsi_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w); @@ -1351,8 +1352,8 @@ alloc_task_pool(struct spdk_vhost_scsi_session *svsession) } static int -vhost_scsi_start_cb(struct spdk_vhost_dev *vdev, - struct spdk_vhost_session *vsession, void *unused) +vhost_scsi_start(struct spdk_vhost_dev *vdev, + struct spdk_vhost_session *vsession, void *unused) { struct spdk_vhost_scsi_session *svsession = to_scsi_session(vsession); struct spdk_vhost_scsi_dev *svdev; @@ -1412,13 +1413,6 @@ out: return rc; } -static int -vhost_scsi_start(struct spdk_vhost_session *vsession) -{ - return vhost_user_session_send_event(vsession, vhost_scsi_start_cb, - 3, "start session"); -} - static int destroy_session_poller_cb(void *arg) {