>From fabe98d01d43a7b8157726407f344a943a233ad7 Mon Sep 17 00:00:00 2001 From: Michal Novotny Date: Mon, 20 Sep 2010 14:22:28 +0200 Subject: [PATCH] Make NIC model fallback to default when specified model is not supported Hi, this is the patch to introduce a NIC model fallback to default when model specified is not supported. It's been tested on x86_64 host with current version of qemu-dm using the RHEL-5 i386 virtual machine and by trying to setup the invalid (unsupported) model of NIC device. Also, the new constant in the net.h called the DEFAULT_NIC_MODEL has been introduced to be able to change the default NIC model easily. This variable is being used to set the default NIC model when necessary. It's been tested by running a guest with NIC model set to be "eee" which is not supported and when the guest was started I tried to issue "lspci" to list all the PCI devices and there was Realtek RTL-8239 (AS) card which is basically the ne2k_pci card (default for Xen-4.1 qemu-dm) so the old default has been preserved and it's being used as a fallback. Michal Signed-off-by: Michal Novotny --- hw/pc.c | 2 +- net.c | 11 ++++++++++- net.h | 3 +++ vl.c | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index 4c9a164..3b6d15d 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -1077,7 +1077,7 @@ vga_bios_error: if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0)) pc_init_ne2k_isa(nd, i8259); else - pci_nic_init(pci_bus, nd, -1, "ne2k_pci"); + pci_nic_init(pci_bus, nd, -1, NIC_DEFAULT_MODEL); } qemu_system_hot_add_init(); diff --git a/net.c b/net.c index 720027c..f10ba8b 100644 --- a/net.c +++ b/net.c @@ -1610,12 +1610,21 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models, if (!nd->model) nd->model = strdup(default_model); +again: if (strcmp(nd->model, "?") != 0) { for (i = 0 ; models[i]; i++) if (strcmp(nd->model, models[i]) == 0) return; - fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model); + if (strcmp(nd->model, NIC_DEFAULT_MODEL) != 0) { + fprintf(stderr, "qemu: Unsupported NIC model: %s, using default: %s\n", + nd->model, NIC_DEFAULT_MODEL); + nd->model = strdup(NIC_DEFAULT_MODEL); + goto again; + } + else + fprintf(stderr, "qemu: Unsupported default NIC model: %s (probably a bug)\n", nd->model); + exit_status = 1; } diff --git a/net.h b/net.h index bc749d9..e7626f4 100644 --- a/net.h +++ b/net.h @@ -3,6 +3,9 @@ #include "qemu-common.h" +/* Default NIC model to be used - also used as a fallback model when model specified doesn't exist */ +#define NIC_DEFAULT_MODEL "ne2k_pci" + /* VLANs support */ typedef ssize_t (IOReadvHandler)(void *, const struct iovec *, int); diff --git a/vl.c b/vl.c index 1673cd4..25db3a0 100644 --- a/vl.c +++ b/vl.c @@ -5727,7 +5727,7 @@ int main(int argc, char **argv, char **envp) char buf[1024]; if (net_boot & (1 << i)) { if (model == NULL) - model = "ne2k_pci"; + model = NIC_DEFAULT_MODEL; snprintf(buf, sizeof(buf), "%s/pxe-%s.bin", bios_dir, model); if (get_image_size(buf) > 0) { if (nb_option_roms >= MAX_OPTION_ROMS) { -- 1.5.5.6