Skip to content

Commit 91c8e1f

Browse files
wyr-7CV-Bowen
authored andcommitted
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 <wangyongrong@xiaomi.com> Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
1 parent 249ef79 commit 91c8e1f

4 files changed

Lines changed: 48 additions & 14 deletions

File tree

‎nshlib/Kconfig‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,11 @@ config NSH_DISABLE_VIRTIO
681681
default DEFAULT_SMALL
682682
depends on DRIVERS_VIRTIO
683683

684+
config NSH_DISABLE_VHOST
685+
bool "Disable vhost"
686+
default DEFAULT_SMALL
687+
depends on DRIVERS_VHOST
688+
684689
config NSH_DISABLE_SET
685690
bool "Disable set"
686691
default DEFAULT_SMALL

‎nshlib/nsh.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,10 @@ int cmd_switchboot(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
12001200
int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
12011201
#endif
12021202

1203+
#if defined(CONFIG_DRIVERS_VHOST) && !defined(CONFIG_NSH_DISABLE_VHOST)
1204+
int cmd_vhost(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
1205+
#endif
1206+
12031207
#ifndef CONFIG_NSH_DISABLE_SET
12041208
int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
12051209
#endif

‎nshlib/nsh_command.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,10 @@ static const struct cmdmap_s g_cmdmap[] =
674674
CMD_MAP("virtio", cmd_virtio, 2, 3, "dump [type]"),
675675
#endif
676676

677+
#if defined(CONFIG_DRIVERS_VHOST) && !defined(CONFIG_NSH_DISABLE_VHOST)
678+
CMD_MAP("vhost", cmd_vhost, 2, 3, "dump [type]"),
679+
#endif
680+
677681
#if !defined(CONFIG_DISABLE_MOUNTPOINT)
678682
# ifndef CONFIG_NSH_DISABLE_UMOUNT
679683
CMD_MAP("umount", cmd_umount, 2, 3, "[-f] <dir-path>"),

‎nshlib/nsh_syscmds.c‎

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <nuttx/rptun/rptun.h>
3232
#include <nuttx/streams.h>
3333
#include <nuttx/virtio/virtio.h>
34+
#include <nuttx/vhost/vhost.h>
3435
#include <sys/boardctl.h>
3536
#include <sys/ioctl.h>
3637
#include <sys/param.h>
@@ -1110,13 +1111,13 @@ int cmd_ulimit(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
11101111
* Name: cmd_virtio_usage
11111112
****************************************************************************/
11121113

1113-
#if defined(CONFIG_DRIVERS_VIRTIO) && !defined(CONFIG_NSH_DISABLE_VIRTIO)
1114-
static int cmd_virtio_usage(FAR struct nsh_vtbl_s *vtbl,
1115-
FAR char **argv)
1114+
#if (defined(CONFIG_DRIVERS_VIRTIO) && !defined(CONFIG_NSH_DISABLE_VIRTIO)) \
1115+
|| (defined(CONFIG_DRIVERS_VHOST) && !defined(CONFIG_NSH_DISABLE_VHOST))
1116+
static int cmd_virtio_common_usage(FAR struct nsh_vtbl_s *vtbl,
1117+
FAR char **argv)
11161118
{
11171119
nsh_output(vtbl, "Usage:\n");
1118-
nsh_output(vtbl, " %s dump [type] - Dump VirtIO device info\n",
1119-
argv[0]);
1120+
nsh_output(vtbl, " %s dump [type] - Dump device info\n", argv[0]);
11201121
nsh_output(vtbl, " %s -h - Show this help message\n\n",
11211122
argv[0]);
11221123
nsh_output(vtbl, "Supported types:\n");
@@ -1134,16 +1135,14 @@ static int cmd_virtio_usage(FAR struct nsh_vtbl_s *vtbl,
11341135
nsh_output(vtbl, " Sound - Sound devices\n");
11351136
nsh_output(vtbl, " RPMB - RPMB devices\n\n");
11361137
nsh_output(vtbl, "Description:\n");
1137-
nsh_output(vtbl, " Display information about registered VirtIO\n");
1138+
nsh_output(vtbl, " Display information about registered %s\n", argv[0]);
11381139
nsh_output(vtbl, " devices. Output is sent to syslog.\n");
11391140
return OK;
11401141
}
11411142

1142-
/****************************************************************************
1143-
* Name: cmd_virtio
1144-
****************************************************************************/
1145-
1146-
int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
1143+
static int cmd_virtio_common(FAR struct nsh_vtbl_s *vtbl, int argc,
1144+
FAR char **argv, FAR const char *devpath,
1145+
int ioc_cmd)
11471146
{
11481147
FAR const char *dev_name = NULL;
11491148
int fd;
@@ -1156,7 +1155,7 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
11561155
}
11571156
else if (strcmp(argv[1], "-h") == 0)
11581157
{
1159-
return cmd_virtio_usage(vtbl, argv);
1158+
return cmd_virtio_common_usage(vtbl, argv);
11601159
}
11611160
else if (strcmp(argv[1], "dump") != 0)
11621161
{
@@ -1171,7 +1170,7 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
11711170
dev_name = argv[2];
11721171
}
11731172

1174-
fd = open("/dev/virtio", O_CLOEXEC);
1173+
fd = open(devpath, O_CLOEXEC);
11751174
if (fd < 0)
11761175
{
11771176
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)
11801179

11811180
/* Pass type name string to kernel, kernel will parse it */
11821181

1183-
ret = ioctl(fd, VIRTIOIOC_DUMP, (unsigned long)dev_name);
1182+
ret = ioctl(fd, ioc_cmd, (unsigned long)dev_name);
11841183
close(fd);
11851184

11861185
if (ret < 0)
@@ -1192,3 +1191,25 @@ int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
11921191
return OK;
11931192
}
11941193
#endif
1194+
1195+
/****************************************************************************
1196+
* Name: cmd_virtio
1197+
****************************************************************************/
1198+
1199+
#if defined(CONFIG_DRIVERS_VIRTIO) && !defined(CONFIG_NSH_DISABLE_VIRTIO)
1200+
int cmd_virtio(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
1201+
{
1202+
return cmd_virtio_common(vtbl, argc, argv, "/dev/virtio", VIRTIOIOC_DUMP);
1203+
}
1204+
#endif
1205+
1206+
/****************************************************************************
1207+
* Name: cmd_vhost
1208+
****************************************************************************/
1209+
1210+
#if defined(CONFIG_DRIVERS_VHOST) && !defined(CONFIG_NSH_DISABLE_VHOST)
1211+
int cmd_vhost(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
1212+
{
1213+
return cmd_virtio_common(vtbl, argc, argv, "/dev/vhost", VHOSTIOC_DUMP);
1214+
}
1215+
#endif

0 commit comments

Comments
 (0)