Commit 6687b79d authored by Laszlo Ersek's avatar Laszlo Ersek Committed by Stefan Hajnoczi

convert net_client_init() to OptsVisitor

The net_client_init() prototype is kept intact.

Based on "is_netdev", the QemuOpts-rooted QemuOpt-list is parsed as a
Netdev or a NetLegacy. The original meat of net_client_init() is moved to
and simplified in net_client_init1():

Fields not common between -net and -netdev are clearly separated. Getting
the name for the init functions is cleaner: Netdev::id is mandatory, and
all init functions handle a NULL NetLegacy::name. NetLegacy::vlan
explicitly depends on -net (see below).

Verifying the "type=" option for -netdev can be turned into a switch.

Format validation with qemu_opts_validate() can be removed because the
visitor covers it. Relatedly, the "net_client_types" array is reduced to
an array of init functions that can be directly indexed by opts->kind.
(Help text is available in the schema JSON.)

The outermost negation in the condition around qemu_find_vlan() was
flattened, because it expresses the dependent code's requirements more
clearly.

VLAN lookup is avoided if there's no init function to pass the VLAN to.

Whenever the value of type=... is needed, we substitute
NetClientOptionsKind_lookup[kind].

The individual init functions are not converted yet, thus the original
QemuOpts instance is passed transparently.

v1->v2:
- NetLegacy::name is optional. Tracked it through all init functions: they
  all handle a NULL name. Updated commit message accordingly.

v2->v3:
- NetLegacy::id is allowed and takes precedence over NetLegacy::name.
Signed-off-by: default avatarLaszlo Ersek <lersek@redhat.com>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
parent 2be64a68
This diff is collapsed.
......@@ -144,7 +144,8 @@ static int net_dump_init(VLANState *vlan, const char *device,
return 0;
}
int net_init_dump(QemuOpts *opts, const char *name, VLANState *vlan)
int net_init_dump(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan)
{
int len;
const char *file;
......
......@@ -26,7 +26,9 @@
#include "net.h"
#include "qemu-common.h"
#include "qapi-types.h"
int net_init_dump(QemuOpts *opts, const char *name, VLANState *vlan);
int net_init_dump(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan);
#endif /* QEMU_NET_DUMP_H */
......@@ -708,7 +708,8 @@ static int net_init_slirp_configs(const char *name, const char *value, void *opa
return 0;
}
int net_init_slirp(QemuOpts *opts, const char *name, VLANState *vlan)
int net_init_slirp(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan)
{
struct slirp_config_str *config;
const char *vhost;
......
......@@ -27,10 +27,12 @@
#include "qemu-common.h"
#include "qdict.h"
#include "qemu-option.h"
#include "qapi-types.h"
#ifdef CONFIG_SLIRP
int net_init_slirp(QemuOpts *opts, const char *name, VLANState *vlan);
int net_init_slirp(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan);
void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict);
void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict);
......
......@@ -586,7 +586,8 @@ static int net_socket_udp_init(VLANState *vlan,
return 0;
}
int net_init_socket(QemuOpts *opts, const char *name, VLANState *vlan)
int net_init_socket(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan)
{
if (qemu_opt_get(opts, "fd")) {
int fd;
......
......@@ -26,7 +26,9 @@
#include "net.h"
#include "qemu-common.h"
#include "qapi-types.h"
int net_init_socket(QemuOpts *opts, const char *name, VLANState *vlan);
int net_init_socket(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan);
#endif /* QEMU_NET_SOCKET_H */
......@@ -699,7 +699,8 @@ static int tap_win32_init(VLANState *vlan, const char *model,
return 0;
}
int net_init_tap(QemuOpts *opts, const char *name, VLANState *vlan)
int net_init_tap(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan)
{
const char *ifname;
......
......@@ -513,7 +513,8 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
return -1;
}
int net_init_bridge(QemuOpts *opts, const char *name, VLANState *vlan)
int net_init_bridge(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan)
{
TAPState *s;
int fd, vnet_hdr;
......@@ -583,7 +584,8 @@ static int net_tap_init(QemuOpts *opts, int *vnet_hdr)
return fd;
}
int net_init_tap(QemuOpts *opts, const char *name, VLANState *vlan)
int net_init_tap(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan)
{
TAPState *s;
int fd, vnet_hdr = 0;
......
......@@ -28,11 +28,13 @@
#include "qemu-common.h"
#include "qemu-option.h"
#include "qapi-types.h"
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
int net_init_tap(QemuOpts *opts, const char *name, VLANState *vlan);
int net_init_tap(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan);
int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required);
......@@ -57,6 +59,7 @@ int tap_get_fd(VLANClientState *vc);
struct vhost_net;
struct vhost_net *tap_get_vhost_net(VLANClientState *vc);
int net_init_bridge(QemuOpts *opts, const char *name, VLANState *vlan);
int net_init_bridge(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan);
#endif /* QEMU_NET_TAP_H */
......@@ -110,7 +110,8 @@ static int net_vde_init(VLANState *vlan, const char *model,
return 0;
}
int net_init_vde(QemuOpts *opts, const char *name, VLANState *vlan)
int net_init_vde(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan)
{
const char *sock;
const char *group;
......
......@@ -26,10 +26,12 @@
#include "qemu-common.h"
#include "qemu-option.h"
#include "qapi-types.h"
#ifdef CONFIG_VDE
int net_init_vde(QemuOpts *opts, const char *name, VLANState *vlan);
int net_init_vde(QemuOpts *opts, const NetClientOptions *new_opts,
const char *name, VLANState *vlan);
#endif /* CONFIG_VDE */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment