summaryrefslogtreecommitdiffstats
path: root/net.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2009-09-25 03:53:51 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-05 09:32:53 -0500
commit07caea315a85ebfe90851f9c2e4ef3fdd24117b5 (patch)
tree153e42950d500a7c6219539941ff7c1f81a6487b /net.c
parent9ee05825d9eaf7fe3aaed5ed04b83612ede704a0 (diff)
downloadhqemu-07caea315a85ebfe90851f9c2e4ef3fdd24117b5.zip
hqemu-07caea315a85ebfe90851f9c2e4ef3fdd24117b5.tar.gz
Fix pci_add nic not to exit on bad model
Monitor command "pci_add ADDR nic model=MODEL" uses pci_nic_init() to create the NIC. When MODEL is unknown or "?", this prints to stderr and terminates the program. Change pci_nic_init() not to treat "?" specially, and to return NULL on failure. Switch uses during startup to new convenience wrapper pci_nic_init_nofail(), which behaves just like pci_nic_init() used to do. Bonus bug fix: we now check for qdev_init() failing there. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'net.c')
-rw-r--r--net.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/net.c b/net.c
index 2feabbc..dc274c7 100644
--- a/net.c
+++ b/net.c
@@ -2348,6 +2348,19 @@ static int nic_get_free_idx(void)
return -1;
}
+int qemu_show_nic_models(const char *arg, const char *const *models)
+{
+ int i;
+
+ if (!arg || strcmp(arg, "?"))
+ return 0;
+
+ fprintf(stderr, "qemu: Supported NIC models: ");
+ for (i = 0 ; models[i]; i++)
+ fprintf(stderr, "%s%c", models[i], models[i+1] ? ',' : '\n');
+ return 1;
+}
+
void qemu_check_nic_model(NICInfo *nd, const char *model)
{
const char *models[2];
@@ -2355,31 +2368,27 @@ void qemu_check_nic_model(NICInfo *nd, const char *model)
models[0] = model;
models[1] = NULL;
- qemu_check_nic_model_list(nd, models, model);
+ if (qemu_show_nic_models(nd->model, models))
+ exit(0);
+ if (qemu_find_nic_model(nd, models, model) < 0)
+ exit(1);
}
-int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
- const char *default_model)
+int qemu_find_nic_model(NICInfo *nd, const char * const *models,
+ const char *default_model)
{
- int i, exit_status = 0;
+ int i;
if (!nd->model)
nd->model = strdup(default_model);
- if (strcmp(nd->model, "?") != 0) {
- for (i = 0 ; models[i]; i++)
- if (strcmp(nd->model, models[i]) == 0)
- return i;
-
- fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model);
- exit_status = 1;
+ for (i = 0 ; models[i]; i++) {
+ if (strcmp(nd->model, models[i]) == 0)
+ return i;
}
- fprintf(stderr, "qemu: Supported NIC models: ");
- for (i = 0 ; models[i]; i++)
- fprintf(stderr, "%s%c", models[i], models[i+1] ? ',' : '\n');
-
- exit(exit_status);
+ qemu_error("qemu: Unsupported NIC model: %s\n", nd->model);
+ return -1;
}
static int net_handle_fd_param(Monitor *mon, const char *param)
OpenPOWER on IntegriCloud