[fedora-virt-maint] rpms/qemu/devel qemu-do-not-exit-on-pci-hotplug-invalid-nic1.patch, NONE, 1.1 qemu-do-not-exit-on-pci-hotplug-invalid-nic2.patch, NONE, 1.1 qemu.spec, 1.133, 1.134

Mark McLoughlin markmc at fedoraproject.org
Mon Sep 28 16:42:19 UTC 2009


Author: markmc

Update of /cvs/pkgs/rpms/qemu/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv1253

Modified Files:
	qemu.spec 
Added Files:
	qemu-do-not-exit-on-pci-hotplug-invalid-nic1.patch 
	qemu-do-not-exit-on-pci-hotplug-invalid-nic2.patch 
Log Message:
* Mon Sep 28 2009 Mark McLoughlin <markmc at redhat.com> - 2:0.11.0-2
- Fix pci hotplug to not exit if supplied an invalid NIC model (#524022)


qemu-do-not-exit-on-pci-hotplug-invalid-nic1.patch:
 hw/pci.c |   25 +++++++++----------------
 net.c    |    6 +++---
 net.h    |    5 ++---
 3 files changed, 14 insertions(+), 22 deletions(-)

--- NEW FILE qemu-do-not-exit-on-pci-hotplug-invalid-nic1.patch ---
>From 0ce1af6e7d4b1e2ffa4dedf6d415c4d86a1af490 Mon Sep 17 00:00:00 2001
From: Markus Armbruster <armbru at redhat.com>
Date: Fri, 25 Sep 2009 03:53:50 +0200
Subject: [PATCH] Make it obvious that pci_nic_init() can't fail

Before this patch, pci_nic_init() returns NULL when it can't find the
model in pci_nic_models[].  Except this can't happen, because
qemu_check_nic_model_list() just searched for model in
pci_nic_models[], and terminated the program on failure.

Repeating the search here is pointless.  Instead, change
qemu_check_nic_model_list() to return the model's array index.

Signed-off-by: Markus Armbruster <armbru at redhat.com>
Signed-off-by: Mark McLoughlin <markmc at redhat.com
Fedora-patch: qemu-do-not-exit-on-pci-hotplug-invalid-nic1.patch
---
 hw/pci.c |   25 +++++++++----------------
 net.c    |    6 +++---
 net.h    |    4 ++--
 3 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index a575d4a..eb990f9 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -937,22 +937,15 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
     DeviceState *dev;
     int i;
 
-    qemu_check_nic_model_list(nd, pci_nic_models, default_model);
-
-    for (i = 0; pci_nic_models[i]; i++) {
-        if (strcmp(nd->model, pci_nic_models[i]) == 0) {
-            pci_dev = pci_create(pci_nic_names[i], devaddr);
-            dev = &pci_dev->qdev;
-            if (nd->id)
-                dev->id = qemu_strdup(nd->id);
-            dev->nd = nd;
-            qdev_init(dev);
-            nd->private = dev;
-            return pci_dev;
-        }
-    }
-
-    return NULL;
+    i = qemu_check_nic_model_list(nd, pci_nic_models, default_model);
+    pci_dev = pci_create(pci_nic_names[i], devaddr);
+    dev = &pci_dev->qdev;
+    if (nd->id)
+        dev->id = qemu_strdup(nd->id);
+    dev->nd = nd;
+    qdev_init(dev);
+    nd->private = dev;
+    return pci_dev;
 }
 
 typedef struct {
diff --git a/net.c b/net.c
index da2f428..047e72e 100644
--- a/net.c
+++ b/net.c
@@ -2553,8 +2553,8 @@ void qemu_check_nic_model(NICInfo *nd, const char *model)
     qemu_check_nic_model_list(nd, models, model);
 }
 
-void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
-                               const char *default_model)
+int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
+                              const char *default_model)
 {
     int i, exit_status = 0;
 
@@ -2564,7 +2564,7 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
     if (strcmp(nd->model, "?") != 0) {
         for (i = 0 ; models[i]; i++)
             if (strcmp(nd->model, models[i]) == 0)
-                return;
+                return i;
 
         fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model);
         exit_status = 1;
diff --git a/net.h b/net.h
index 94db0d7..9662988 100644
--- a/net.h
+++ b/net.h
@@ -80,8 +80,8 @@ void qemu_purge_queued_packets(VLANClientState *vc);
 void qemu_flush_queued_packets(VLANClientState *vc);
 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
 void qemu_check_nic_model(NICInfo *nd, const char *model);
-void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
-                               const char *default_model);
+int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
+                              const char *default_model);
 void qemu_handler_true(void *opaque);
 
 void do_info_network(Monitor *mon);
-- 
1.6.2.5


qemu-do-not-exit-on-pci-hotplug-invalid-nic2.patch:
 hw/mips_malta.c        |    2 +-
 hw/pc.c                |    2 +-
 hw/pci.c               |   19 ++++++++++++++++++-
 hw/pci.h               |    2 ++
 hw/ppc440_bamboo.c     |    2 +-
 hw/ppc_newworld.c      |    2 +-
 hw/ppc_oldworld.c      |    2 +-
 hw/ppc_prep.c          |    2 +-
 hw/ppce500_mpc8544ds.c |    2 +-
 hw/r2d.c               |    2 +-
 hw/realview.c          |    2 +-
 hw/sun4u.c             |    2 +-
 hw/versatilepb.c       |    2 +-
 net.c                  |   41 +++++++++++++++++++++++++----------------
 net.h                  |    6 +++---
 15 files changed, 59 insertions(+), 31 deletions(-)

--- NEW FILE qemu-do-not-exit-on-pci-hotplug-invalid-nic2.patch ---
>From 0ba615f4e6ecf13839b7688c762961aa1d092504 Mon Sep 17 00:00:00 2001
From: Markus Armbruster <armbru at redhat.com>
Date: Fri, 25 Sep 2009 03:53:51 +0200
Subject: [PATCH] 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.

[markmc:

  - rebase to stable-0.11
  - drop qemu_error() usage
  - go back to pci_create() in pci_nic_init
  - qdev_init() doesn't have an error return
]

Signed-off-by: Markus Armbruster <armbru at redhat.com>
Signed-off-by: Mark McLoughlin <markmc at redhat.com>
Fedora-patch: qemu-do-not-exit-on-pci-hotplug-invalid-nic2.patch
---
 hw/mips_malta.c        |    2 +-
 hw/pc.c                |    2 +-
 hw/pci.c               |   19 ++++++++++++++++++-
 hw/pci.h               |    2 ++
 hw/ppc440_bamboo.c     |    2 +-
 hw/ppc_newworld.c      |    2 +-
 hw/ppc_oldworld.c      |    2 +-
 hw/ppc_prep.c          |    2 +-
 hw/ppce500_mpc8544ds.c |    2 +-
 hw/r2d.c               |    2 +-
 hw/realview.c          |    2 +-
 hw/sun4u.c             |    2 +-
 hw/versatilepb.c       |    2 +-
 net.c                  |   41 +++++++++++++++++++++++++----------------
 net.h                  |    5 +++--
 15 files changed, 59 insertions(+), 30 deletions(-)

diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index 7728e58..ed86d4b 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -486,7 +486,7 @@ static void network_init(void)
             /* The malta board has a PCNet card using PCI SLOT 11 */
             default_devaddr = "0b";
 
-        pci_nic_init(nd, "pcnet", default_devaddr);
+        pci_nic_init_nofail(nd, "pcnet", default_devaddr);
     }
 }
 
diff --git a/hw/pc.c b/hw/pc.c
index bcd2989..3b226f4 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -1360,7 +1360,7 @@ static void pc_init1(ram_addr_t ram_size,
         if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
             pc_init_ne2k_isa(nd, i8259);
         else
-            pci_nic_init(nd, "rtl8139", NULL);
+            pci_nic_init_nofail(nd, "rtl8139", NULL);
     }
 
     piix4_acpi_system_hot_add_init(cpu_model);
diff --git a/hw/pci.c b/hw/pci.c
index eb990f9..9bcf49d 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -937,7 +937,10 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
     DeviceState *dev;
     int i;
 
-    i = qemu_check_nic_model_list(nd, pci_nic_models, default_model);
+    i = qemu_find_nic_model(nd, pci_nic_models, default_model);
+    if (i < 0)
+        return NULL;
+
     pci_dev = pci_create(pci_nic_names[i], devaddr);
     dev = &pci_dev->qdev;
     if (nd->id)
@@ -948,6 +951,20 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
     return pci_dev;
 }
 
+PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,
+                               const char *default_devaddr)
+{
+    PCIDevice *res;
+
+    if (qemu_show_nic_models(nd->model, pci_nic_models))
+        exit(0);
+
+    res = pci_nic_init(nd, default_model, default_devaddr);
+    if (!res)
+        exit(1);
+    return res;
+}
+
 typedef struct {
     PCIDevice dev;
     PCIBus *bus;
diff --git a/hw/pci.h b/hw/pci.h
index 7ca3ba9..18a05f5 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -291,6 +291,8 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,
 
 PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
                         const char *default_devaddr);
+PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,
+                               const char *default_devaddr);
 void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len);
 uint32_t pci_data_read(void *opaque, uint32_t addr, int len);
 int pci_bus_num(PCIBus *s);
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index c74aa2f..9f22623 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -128,7 +128,7 @@ static void bamboo_init(ram_addr_t ram_size,
         for (i = 0; i < nb_nics; i++) {
             /* There are no PCI NICs on the Bamboo board, but there are
              * PCI slots, so we can pick whatever default model we want. */
-            pci_nic_init(&nd_table[i], "e1000", NULL);
+            pci_nic_init_nofail(&nd_table[i], "e1000", NULL);
         }
     }
 
diff --git a/hw/ppc_newworld.c b/hw/ppc_newworld.c
index 45480ea..5fa9e82 100644
--- a/hw/ppc_newworld.c
+++ b/hw/ppc_newworld.c
@@ -304,7 +304,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
                                serial_hds[0], serial_hds[1], ESCC_CLOCK, 4);
 
     for(i = 0; i < nb_nics; i++)
-        pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
+        pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
 
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
         fprintf(stderr, "qemu: too many IDE bus\n");
diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c
index 5c745a0..49c8a00 100644
--- a/hw/ppc_oldworld.c
+++ b/hw/ppc_oldworld.c
@@ -315,7 +315,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
                                serial_hds[1], ESCC_CLOCK, 4);
 
     for(i = 0; i < nb_nics; i++)
-        pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
+        pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
 
 
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 7a21977..a8f0002 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -681,7 +681,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
         if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {
             isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]);
         } else {
-            pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
+            pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
         }
     }
 
diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index db52cdd..5f2b526 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -228,7 +228,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
 
         /* Register network interfaces. */
         for (i = 0; i < nb_nics; i++) {
-            pci_nic_init(&nd_table[i], "virtio", NULL);
+            pci_nic_init_nofail(&nd_table[i], "virtio", NULL);
         }
     }
 
diff --git a/hw/r2d.c b/hw/r2d.c
index 8ce6832..af229d4 100644
--- a/hw/r2d.c
+++ b/hw/r2d.c
@@ -231,7 +231,7 @@ static void r2d_init(ram_addr_t ram_size,
 
     /* NIC: rtl8139 on-board, and 2 slots. */
     for (i = 0; i < nb_nics; i++)
-        pci_nic_init(&nd_table[i], "rtl8139", i==0 ? "2" : NULL);
+        pci_nic_init_nofail(&nd_table[i], "rtl8139", i==0 ? "2" : NULL);
 
     /* Todo: register on board registers */
     if (kernel_filename) {
diff --git a/hw/realview.c b/hw/realview.c
index 8e176b9..70c129b 100644
--- a/hw/realview.c
+++ b/hw/realview.c
@@ -125,7 +125,7 @@ static void realview_init(ram_addr_t ram_size,
             smc91c111_init(nd, 0x4e000000, pic[28]);
             done_smc = 1;
         } else {
-            pci_nic_init(nd, "rtl8139", NULL);
+            pci_nic_init_nofail(nd, "rtl8139", NULL);
         }
     }
 
diff --git a/hw/sun4u.c b/hw/sun4u.c
index 9d2a7f5..9fb5dcd 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -497,7 +497,7 @@ static void sun4uv_init(ram_addr_t RAM_size,
     }
 
     for(i = 0; i < nb_nics; i++)
-        pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
+        pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
 
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
         fprintf(stderr, "qemu: too many IDE bus\n");
diff --git a/hw/versatilepb.c b/hw/versatilepb.c
index 3371121..8e06c31 100644
--- a/hw/versatilepb.c
+++ b/hw/versatilepb.c
@@ -212,7 +212,7 @@ static void versatile_init(ram_addr_t ram_size,
             smc91c111_init(nd, 0x10010000, sic[25]);
             done_smc = 1;
         } else {
-            pci_nic_init(nd, "rtl8139", NULL);
+            pci_nic_init_nofail(nd, "rtl8139", NULL);
         }
     }
     if (usb_enabled) {
diff --git a/net.c b/net.c
index 047e72e..3572c48 100644
--- a/net.c
+++ b/net.c
@@ -2543,6 +2543,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];
@@ -2550,31 +2563,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 = qemu_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);
+    fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model);
+    return -1;
 }
 
 static int net_handle_fd_param(Monitor *mon, const char *param)
diff --git a/net.h b/net.h
index 9662988..07b4c9a 100644
--- a/net.h
+++ b/net.h
@@ -79,9 +79,10 @@ ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
 void qemu_purge_queued_packets(VLANClientState *vc);
 void qemu_flush_queued_packets(VLANClientState *vc);
 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
+int qemu_show_nic_models(const char *arg, const char *const *models);
 void qemu_check_nic_model(NICInfo *nd, const char *model);
-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);
 void qemu_handler_true(void *opaque);
 
 void do_info_network(Monitor *mon);
-- 
1.6.2.5



Index: qemu.spec
===================================================================
RCS file: /cvs/pkgs/rpms/qemu/devel/qemu.spec,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -p -r1.133 -r1.134
--- qemu.spec	28 Sep 2009 07:39:30 -0000	1.133
+++ qemu.spec	28 Sep 2009 16:42:19 -0000	1.134
@@ -1,7 +1,7 @@
 Summary: QEMU is a FAST! processor emulator
 Name: qemu
 Version: 0.11.0
-Release: 1%{?dist}
+Release: 2%{?dist}
 # Epoch because we pushed a qemu-1.0 package
 Epoch: 2
 License: GPLv2+ and LGPLv2+ and BSD
@@ -39,6 +39,10 @@ Patch04: qemu-add-ksm-support.patch
 # Fix issue causing NIC hotplug confusion when no model is specified (#524022)
 Patch05: qemu-correctly-free-nic-info-structure.patch
 
+# Do not exit during PCI hotplug when an invalid NIC model is passed (#524022)
+Patch06: qemu-do-not-exit-on-pci-hotplug-invalid-nic1.patch
+Patch07: qemu-do-not-exit-on-pci-hotplug-invalid-nic1.patch
+
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildRequires: SDL-devel zlib-devel which texi2html gnutls-devel cyrus-sasl-devel
 BuildRequires: rsync dev86 iasl
@@ -227,6 +231,8 @@ such as kvmtrace and kvm_stat.
 %patch03 -p1
 %patch04 -p1
 %patch05 -p1
+%patch06 -p1
+%patch07 -p1
 
 %build
 # systems like rhel build system does not have a recent enough linker so
@@ -520,6 +526,9 @@ fi
 %{_mandir}/man1/qemu-img.1*
 
 %changelog
+* Mon Sep 28 2009 Mark McLoughlin <markmc at redhat.com> - 2:0.11.0-2
+- Fix pci hotplug to not exit if supplied an invalid NIC model (#524022)
+
 * Mon Sep 28 2009 Mark McLoughlin <markmc at redhat.com> - 2:0.11.0-1
 - Update to 0.11.0 release
 - Drop a couple of upstreamed patches




More information about the Fedora-virt-maint mailing list