convert net_init_nic() to NetClientOptions

v1->v2:
- NetLegacyNicOptions::vectors is of type uint32

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
This commit is contained in:
Laszlo Ersek 2012-07-17 16:17:14 +02:00 committed by Stefan Hajnoczi
parent 6687b79d63
commit 2456f36f18
1 changed files with 22 additions and 17 deletions

39
net.c
View File

@ -748,12 +748,15 @@ int net_handle_fd_param(Monitor *mon, const char *param)
return fd; return fd;
} }
static int net_init_nic(QemuOpts *opts, const NetClientOptions *new_opts, static int net_init_nic(QemuOpts *old_opts, const NetClientOptions *opts,
const char *name, VLANState *vlan) const char *name, VLANState *vlan)
{ {
int idx; int idx;
NICInfo *nd; NICInfo *nd;
const char *netdev; const NetLegacyNicOptions *nic;
assert(opts->kind == NET_CLIENT_OPTIONS_KIND_NIC);
nic = opts->nic;
idx = nic_get_free_idx(); idx = nic_get_free_idx();
if (idx == -1 || nb_nics >= MAX_NICS) { if (idx == -1 || nb_nics >= MAX_NICS) {
@ -765,10 +768,10 @@ static int net_init_nic(QemuOpts *opts, const NetClientOptions *new_opts,
memset(nd, 0, sizeof(*nd)); memset(nd, 0, sizeof(*nd));
if ((netdev = qemu_opt_get(opts, "netdev"))) { if (nic->has_netdev) {
nd->netdev = qemu_find_netdev(netdev); nd->netdev = qemu_find_netdev(nic->netdev);
if (!nd->netdev) { if (!nd->netdev) {
error_report("netdev '%s' not found", netdev); error_report("netdev '%s' not found", nic->netdev);
return -1; return -1;
} }
} else { } else {
@ -778,26 +781,28 @@ static int net_init_nic(QemuOpts *opts, const NetClientOptions *new_opts,
if (name) { if (name) {
nd->name = g_strdup(name); nd->name = g_strdup(name);
} }
if (qemu_opt_get(opts, "model")) { if (nic->has_model) {
nd->model = g_strdup(qemu_opt_get(opts, "model")); nd->model = g_strdup(nic->model);
} }
if (qemu_opt_get(opts, "addr")) { if (nic->has_addr) {
nd->devaddr = g_strdup(qemu_opt_get(opts, "addr")); nd->devaddr = g_strdup(nic->addr);
} }
if (qemu_opt_get(opts, "macaddr") && if (nic->has_macaddr &&
net_parse_macaddr(nd->macaddr.a, qemu_opt_get(opts, "macaddr")) < 0) { net_parse_macaddr(nd->macaddr.a, nic->macaddr) < 0) {
error_report("invalid syntax for ethernet address"); error_report("invalid syntax for ethernet address");
return -1; return -1;
} }
qemu_macaddr_default_if_unset(&nd->macaddr); qemu_macaddr_default_if_unset(&nd->macaddr);
nd->nvectors = qemu_opt_get_number(opts, "vectors", if (nic->has_vectors) {
DEV_NVECTORS_UNSPECIFIED); if (nic->vectors > 0x7ffffff) {
if (nd->nvectors != DEV_NVECTORS_UNSPECIFIED && error_report("invalid # of vectors: %"PRIu32, nic->vectors);
(nd->nvectors < 0 || nd->nvectors > 0x7ffffff)) { return -1;
error_report("invalid # of vectors: %d", nd->nvectors); }
return -1; nd->nvectors = nic->vectors;
} else {
nd->nvectors = DEV_NVECTORS_UNSPECIFIED;
} }
nd->used = 1; nd->used = 1;