From 1672c1127ce026f147b4eaee193669678b2cb6fc Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Tue, 11 Jan 2022 11:48:33 +0100 Subject: [PATCH] lib/vhost: use spdk_vhost_dev_next() iterator In later patches rte_vhost functions will be moved to rte_vhost_user.c. To prepare for this, iterator is used in place of accessing g_vhost_devices. While here, followed the same style of iterating in spdk_vhost_config_json(). Signed-off-by: Tomasz Zawadzki Change-Id: I1b73c00dfe1391f359421d044686e49a8c6c9176 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11022 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Konrad Sztyber --- lib/vhost/vhost.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 431e854ee..892ecca4f 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -781,7 +781,8 @@ vhost_session_find_by_vid(int vid) struct spdk_vhost_dev *vdev; struct spdk_vhost_session *vsession; - TAILQ_FOREACH(vdev, &g_vhost_devices, tailq) { + for (vdev = spdk_vhost_dev_next(NULL); vdev != NULL; + vdev = spdk_vhost_dev_next(vdev)) { TAILQ_FOREACH(vsession, &vdev->vsessions, tailq) { if (vsession->vid == vid) { return vsession; @@ -1578,7 +1579,8 @@ session_shutdown(void *arg) struct spdk_vhost_dev *vdev = NULL; struct spdk_vhost_session *vsession; - TAILQ_FOREACH(vdev, &g_vhost_devices, tailq) { + for (vdev = spdk_vhost_dev_next(NULL); vdev != NULL; + vdev = spdk_vhost_dev_next(vdev)) { spdk_vhost_lock(); TAILQ_FOREACH(vsession, &vdev->vsessions, tailq) { if (vsession->started) { @@ -1626,8 +1628,8 @@ spdk_vhost_config_json(struct spdk_json_write_ctx *w) spdk_json_write_array_begin(w); spdk_vhost_lock(); - vdev = spdk_vhost_dev_next(NULL); - while (vdev != NULL) { + for (vdev = spdk_vhost_dev_next(NULL); vdev != NULL; + vdev = spdk_vhost_dev_next(vdev)) { vdev->backend->write_config_json(vdev, w); spdk_vhost_get_coalescing(vdev, &delay_base_us, &iops_threshold); @@ -1643,7 +1645,6 @@ spdk_vhost_config_json(struct spdk_json_write_ctx *w) spdk_json_write_object_end(w); } - vdev = spdk_vhost_dev_next(vdev); } spdk_vhost_unlock();