From 216991edec29b203689ba03fd9846427d6ec4915 Mon Sep 17 00:00:00 2001 From: zhipeng Lu Date: Mon, 16 Jan 2023 11:59:05 +0800 Subject: [PATCH] vhost_rpc:add sessions information for vhost_get_controllers we can get sessions information by vhost_get_controllers Signed-off-by: zhipeng Lu Change-Id: I8e63aea64d02b3467a62f30a712e1dcbf6fb8854 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16315 Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins Reviewed-by: Konrad Sztyber Community-CI: Mellanox Build Bot --- lib/vhost/rte_vhost_user.c | 21 +++++++++++++++++++ lib/vhost/vhost_internal.h | 1 + lib/vhost/vhost_rpc.c | 3 +++ .../spdkcli_details_vhost_ctrl.test.match | 1 + 4 files changed, 26 insertions(+) diff --git a/lib/vhost/rte_vhost_user.c b/lib/vhost/rte_vhost_user.c index e1b931530..a91f6f7c1 100644 --- a/lib/vhost/rte_vhost_user.c +++ b/lib/vhost/rte_vhost_user.c @@ -1956,3 +1956,24 @@ vhost_user_fini(spdk_vhost_fini_cb vhost_cb) } pthread_detach(tid); } + +void +vhost_session_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w) +{ + struct spdk_vhost_session *vsession; + struct spdk_vhost_user_dev *user_dev; + + user_dev = to_user_dev(vdev); + pthread_mutex_lock(&user_dev->lock); + TAILQ_FOREACH(vsession, &user_dev->vsessions, tailq) { + spdk_json_write_object_begin(w); + spdk_json_write_named_uint32(w, "vid", vsession->vid); + spdk_json_write_named_uint32(w, "id", vsession->id); + spdk_json_write_named_string(w, "name", vsession->name); + spdk_json_write_named_bool(w, "started", vsession->started); + spdk_json_write_named_uint32(w, "max_queues", vsession->max_queues); + spdk_json_write_named_uint32(w, "inflight_task_cnt", vsession->task_cnt); + spdk_json_write_object_end(w); + } + pthread_mutex_unlock(&user_dev->lock); +} diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index 7b66d3a35..1fe18df89 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -595,6 +595,7 @@ struct spdk_virtio_blk_transport *virtio_blk_tgt_get_transport(const char *trans const struct spdk_virtio_blk_transport_ops *virtio_blk_get_transport_ops( const char *transport_name); +void vhost_session_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w); /* * Macro used to register new transports. diff --git a/lib/vhost/vhost_rpc.c b/lib/vhost/vhost_rpc.c index a80bede47..35fb512d3 100644 --- a/lib/vhost/vhost_rpc.c +++ b/lib/vhost/vhost_rpc.c @@ -332,6 +332,9 @@ _rpc_get_vhost_controller(struct spdk_json_write_ctx *w, struct spdk_vhost_dev * 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_named_string(w, "socket", vdev->path); + spdk_json_write_named_array_begin(w, "sessions"); + vhost_session_info_json(vdev, w); + spdk_json_write_array_end(w); spdk_json_write_named_object_begin(w, "backend_specific"); vhost_dump_info_json(vdev, w); diff --git a/test/spdkcli/match_files/spdkcli_details_vhost_ctrl.test.match b/test/spdkcli/match_files/spdkcli_details_vhost_ctrl.test.match index 7e045fb7d..8d1737b6b 100644 --- a/test/spdkcli/match_files/spdkcli_details_vhost_ctrl.test.match +++ b/test/spdkcli/match_files/spdkcli_details_vhost_ctrl.test.match @@ -18,5 +18,6 @@ "ctrlr": "vhost_scsi1", "delay_base_us": 20, "iops_threshold": 1000000, + "sessions": [], "socket": "$(S)/vhost_scsi1" }