[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] qemu-options: introduce parse_net_client
From: |
Hogan Wang |
Subject: |
[PATCH 2/3] qemu-options: introduce parse_net_client |
Date: |
Tue, 28 Jul 2020 15:11:03 +0800 |
From: w00506750 <hogan.wang@huawei.com>
introduce parse_net_client to parse netdev/nic/net clients.
Signed-off-by: Hogan Wang <hogan.wang@huawei.com>
---
include/net/net.h | 1 -
net/net.c | 9 ---------
qemu-options.hx | 8 +++++---
softmmu/vl.c | 30 ++++++++++++------------------
4 files changed, 17 insertions(+), 31 deletions(-)
diff --git a/include/net/net.h b/include/net/net.h
index e7ef42d62b..d41dad5a96 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -198,7 +198,6 @@ extern NICInfo nd_table[MAX_NICS];
extern const char *host_net_devices[];
/* from net.c */
-int net_client_parse(QemuOptsList *opts_list, const char *str);
int net_init_clients(Error **errp);
void net_check_clients(void);
void net_cleanup(void);
diff --git a/net/net.c b/net/net.c
index bbaedb3c7a..7380ab0123 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1507,15 +1507,6 @@ int net_init_clients(Error **errp)
return 0;
}
-int net_client_parse(QemuOptsList *opts_list, const char *optarg)
-{
- if (!qemu_opts_parse_noisily(opts_list, optarg, true)) {
- return -1;
- }
-
- return 0;
-}
-
/* From FreeBSD */
/* XXX: optimize */
uint32_t net_crc32(const uint8_t *p, int len)
diff --git a/qemu-options.hx b/qemu-options.hx
index 988fa4026b..cf811c552e 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2433,7 +2433,8 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
" configure a vhost-vdpa network,Establish a vhost-vdpa
netdev\n"
#endif
"-netdev hubport,id=str,hubid=n[,netdev=nd]\n"
- " configure a hub port on the hub with ID 'n'\n",
QEMU_ARCH_ALL)
+ " configure a hub port on the hub with ID 'n'\n",
QEMU_ARCH_ALL, \
+ parse_net_client)
DEF("nic", HAS_ARG, QEMU_OPTION_nic,
"-nic [tap|bridge|"
#ifdef CONFIG_SLIRP
@@ -2456,7 +2457,7 @@ DEF("nic", HAS_ARG, QEMU_OPTION_nic,
" macaddr) and connect it to the given host network
backend\n"
"-nic none use it alone to have zero network devices (the default is
to\n"
" provided a 'user' network connection)\n",
- QEMU_ARCH_ALL)
+ QEMU_ARCH_ALL, parse_net_client)
DEF("net", HAS_ARG, QEMU_OPTION_net,
"-net nic[,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n"
" configure or create an on-board (or machine default) NIC
and\n"
@@ -2475,7 +2476,8 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
#endif
"socket][,option][,option][,...]\n"
" old way to initialize a host network interface\n"
- " (use the -netdev option if possible instead)\n",
QEMU_ARCH_ALL)
+ " (use the -netdev option if possible instead)\n",
QEMU_ARCH_ALL, \
+ parse_net_client)
SRST
``-nic
[tap|bridge|user|l2tpv3|vde|netmap|vhost-user|socket][,...][,mac=macaddr][,model=mn]``
This option is a shortcut for configuring both the on-board
diff --git a/softmmu/vl.c b/softmmu/vl.c
index edb24fd3f7..6a0a49c7c7 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -1725,6 +1725,18 @@ static int parse_linux_boot(const QEMUOption *popt,
const char* optarg)
return 0;
}
+static int parse_net_client(const QEMUOption *popt, const char* optarg)
+{
+ QemuOptsList *opts;
+
+ default_net = 0;
+ opts = qemu_find_opts(popt->name);
+ if (!qemu_opts_parse_noisily(opts, optarg, true)) {
+ return -1;
+ }
+ return 0;
+}
+
static const QEMUOption qemu_options[] = {
{ "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
#define QEMU_OPTIONS_GENERATE_OPTIONS
@@ -3110,24 +3122,6 @@ void qemu_init(int argc, char **argv, char **envp)
case QEMU_OPTION_no_fd_bootchk:
fd_bootchk = 0;
break;
- case QEMU_OPTION_netdev:
- default_net = 0;
- if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
- exit(1);
- }
- break;
- case QEMU_OPTION_nic:
- default_net = 0;
- if (net_client_parse(qemu_find_opts("nic"), optarg) == -1) {
- exit(1);
- }
- break;
- case QEMU_OPTION_net:
- default_net = 0;
- if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
- exit(1);
- }
- break;
#ifdef CONFIG_LIBISCSI
case QEMU_OPTION_iscsi:
opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
--
2.27.0