This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 03802d70f nshlib: add the vhost command
03802d70f is described below
commit 03802d70fcfa53329e6e50b2dd3362aaa8550aca
Author: wangyongrong <[email protected]>
AuthorDate: Fri Nov 13 17:02:02 2026 +0800
nshlib: add the vhost command
Add "vhost dump [type]", the device-side twin of "virtio dump": it opens
/dev/vhost and issues VHOSTIOC_DUMP. Both commands share one
implementation that takes the device node and the ioctl. Disable it with
CONFIG_NSH_DISABLE_VHOST.
Signed-off-by: wangyongrong <[email protected]>
Signed-off-by: Bowen Wang <[email protected]>
---
nshlib/Kconfig | 5 +++++
nshlib/nsh.h | 4 ++++
nshlib/nsh_command.c | 4 ++++
nshlib/nsh_syscmds.c | 49 +++++++++++++++++++++++++++++++++++--------------
4 files changed, 48 insertions(+), 14 deletions(-)
diff --git a/nshlib/Kconfig b/nshlib/Kconfig
index 9d69636e2..b76bce475 100644
--- a/nshlib/Kconfig
+++ b/nshlib/Kconfig
@@ -681,6 +681,11 @@ config NSH_DISABLE_VIRTIO
default DEFAULT_SMALL
depends on DRIVERS_VIRTIO
+config NSH_DISABLE_VHOST
+ bool "Disable vhost"
+ default DEFAULT_SMALL
+ depends on DRIVERS_VHOST
+
config NSH_DISABLE_SET
bool "Disable set"
default DEFAULT_SMALL
diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index 078b059d5..aabe78396 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -1189,6 +1189,10 @@ int cmd_switchboot(FAR struct nsh_vtbl_s *vtbl, int
argc, FAR char **argv);
int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
#endif
+#if defined(CONFIG_DRIVERS_VHOST) && !defined(CONFIG_NSH_DISABLE_VHOST)
+ int cmd_vhost(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
+#endif
+
#ifndef CONFIG_NSH_DISABLE_SET
int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
#endif
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index 42e2fbf0c..22609c0cf 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -674,6 +674,10 @@ static const struct cmdmap_s g_cmdmap[] =
CMD_MAP("virtio", cmd_virtio, 2, 3, "dump [type]"),
#endif
+#if defined(CONFIG_DRIVERS_VHOST) && !defined(CONFIG_NSH_DISABLE_VHOST)
+ CMD_MAP("vhost", cmd_vhost, 2, 3, "dump [type]"),
+#endif
+
#if !defined(CONFIG_DISABLE_MOUNTPOINT)
# ifndef CONFIG_NSH_DISABLE_UMOUNT
CMD_MAP("umount", cmd_umount, 2, 3, "[-f] <dir-path>"),
diff --git a/nshlib/nsh_syscmds.c b/nshlib/nsh_syscmds.c
index 4b200f158..081a2b08f 100644
--- a/nshlib/nsh_syscmds.c
+++ b/nshlib/nsh_syscmds.c
@@ -31,6 +31,7 @@
#include <nuttx/rptun/rptun.h>
#include <nuttx/streams.h>
#include <nuttx/virtio/virtio.h>
+#include <nuttx/vhost/vhost.h>
#include <sys/boardctl.h>
#include <sys/ioctl.h>
#include <sys/param.h>
@@ -1110,13 +1111,13 @@ int cmd_ulimit(FAR struct nsh_vtbl_s *vtbl, int argc,
FAR char **argv)
* Name: cmd_virtio_usage
****************************************************************************/
-#if defined(CONFIG_DRIVERS_VIRTIO) && !defined(CONFIG_NSH_DISABLE_VIRTIO)
-static int cmd_virtio_usage(FAR struct nsh_vtbl_s *vtbl,
- FAR char **argv)
+#if (defined(CONFIG_DRIVERS_VIRTIO) && !defined(CONFIG_NSH_DISABLE_VIRTIO)) \
+ || (defined(CONFIG_DRIVERS_VHOST) && !defined(CONFIG_NSH_DISABLE_VHOST))
+static int cmd_virtio_common_usage(FAR struct nsh_vtbl_s *vtbl,
+ FAR char **argv)
{
nsh_output(vtbl, "Usage:\n");
- nsh_output(vtbl, " %s dump [type] - Dump VirtIO device info\n",
- argv[0]);
+ nsh_output(vtbl, " %s dump [type] - Dump device info\n", argv[0]);
nsh_output(vtbl, " %s -h - Show this help message\n\n",
argv[0]);
nsh_output(vtbl, "Supported types:\n");
@@ -1134,16 +1135,14 @@ static int cmd_virtio_usage(FAR struct nsh_vtbl_s *vtbl,
nsh_output(vtbl, " Sound - Sound devices\n");
nsh_output(vtbl, " RPMB - RPMB devices\n\n");
nsh_output(vtbl, "Description:\n");
- nsh_output(vtbl, " Display information about registered VirtIO\n");
+ nsh_output(vtbl, " Display information about registered %s\n", argv[0]);
nsh_output(vtbl, " devices. Output is sent to syslog.\n");
return OK;
}
-/****************************************************************************
- * Name: cmd_virtio
- ****************************************************************************/
-
-int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+static int cmd_virtio_common(FAR struct nsh_vtbl_s *vtbl, int argc,
+ FAR char **argv, FAR const char *devpath,
+ int ioc_cmd)
{
FAR const char *dev_name = NULL;
int fd;
@@ -1156,7 +1155,7 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR
char **argv)
}
else if (strcmp(argv[1], "-h") == 0)
{
- return cmd_virtio_usage(vtbl, argv);
+ return cmd_virtio_common_usage(vtbl, argv);
}
else if (strcmp(argv[1], "dump") != 0)
{
@@ -1171,7 +1170,7 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR
char **argv)
dev_name = argv[2];
}
- fd = open("/dev/virtio", O_CLOEXEC);
+ fd = open(devpath, O_CLOEXEC);
if (fd < 0)
{
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
@@ -1180,7 +1179,7 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR
char **argv)
/* Pass type name string to kernel, kernel will parse it */
- ret = ioctl(fd, VIRTIOIOC_DUMP, (unsigned long)dev_name);
+ ret = ioctl(fd, ioc_cmd, (unsigned long)dev_name);
close(fd);
if (ret < 0)
@@ -1192,3 +1191,25 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc,
FAR char **argv)
return OK;
}
#endif
+
+/****************************************************************************
+ * Name: cmd_virtio
+ ****************************************************************************/
+
+#if defined(CONFIG_DRIVERS_VIRTIO) && !defined(CONFIG_NSH_DISABLE_VIRTIO)
+int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+{
+ return cmd_virtio_common(vtbl, argc, argv, "/dev/virtio", VIRTIOIOC_DUMP);
+}
+#endif
+
+/****************************************************************************
+ * Name: cmd_vhost
+ ****************************************************************************/
+
+#if defined(CONFIG_DRIVERS_VHOST) && !defined(CONFIG_NSH_DISABLE_VHOST)
+int cmd_vhost(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+{
+ return cmd_virtio_common(vtbl, argc, argv, "/dev/vhost", VHOSTIOC_DUMP);
+}
+#endif