All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes
@ 2009-09-25  1:53 Markus Armbruster
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 1/6] Fix pci_vga_init() not to ignore bus argument Markus Armbruster
                   ` (8 more replies)
  0 siblings, 9 replies; 14+ messages in thread
From: Markus Armbruster @ 2009-09-25  1:53 UTC (permalink / raw)
  To: qemu-devel

Markus Armbruster (6):
  Fix pci_vga_init() not to ignore bus argument
  Fix pci_add storage not to exit on bad first argument
  Make it obvious that pci_nic_init() can't fail
  Fix pci_add nic not to exit on bad model
  pci_create() is now unused, remove it
  Rename pci_create_noinit() to pci_create()

 hw/ide/pci.c           |    2 +-
 hw/mips_malta.c        |    2 +-
 hw/pc.c                |    2 +-
 hw/pci-hotplug.c       |   12 ++++++-
 hw/pci.c               |   72 ++++++++++++++++++++++++-----------------------
 hw/pci.h               |    6 ++-
 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 +-
 hw/vga-pci.c           |    2 +-
 net.c                  |   41 ++++++++++++++++----------
 net.h                  |    5 ++-
 18 files changed, 92 insertions(+), 70 deletions(-)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 1/6] Fix pci_vga_init() not to ignore bus argument
  2009-09-25  1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
@ 2009-09-25  1:53 ` Markus Armbruster
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 2/6] Fix pci_add storage not to exit on bad first argument Markus Armbruster
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: Markus Armbruster @ 2009-09-25  1:53 UTC (permalink / raw)
  To: qemu-devel

Commit a414c306 converted all VGA devices to qdev.  It used
pci_create_simple() for all devices, except for this one it used
pci_create().  That's wrong, because it uses PCI bus#0 regardless of
the bus argument.  Fix by switching to pci_create_noinit().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/vga-pci.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/vga-pci.c b/hw/vga-pci.c
index 6038cec..129ff48 100644
--- a/hw/vga-pci.c
+++ b/hw/vga-pci.c
@@ -137,7 +137,7 @@ int pci_vga_init(PCIBus *bus,
 {
     PCIDevice *dev;
 
-    dev = pci_create("VGA", NULL);
+    dev = pci_create_noinit(bus, -1, "VGA");
     qdev_prop_set_uint32(&dev->qdev, "bios-offset", vga_bios_offset);
     qdev_prop_set_uint32(&dev->qdev, "bios-size", vga_bios_offset);
     qdev_init(&dev->qdev);
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 2/6] Fix pci_add storage not to exit on bad first argument
  2009-09-25  1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 1/6] Fix pci_vga_init() not to ignore bus argument Markus Armbruster
@ 2009-09-25  1:53 ` Markus Armbruster
  2009-09-25 16:36   ` [Qemu-devel] " Markus Armbruster
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 3/6] Make it obvious that pci_nic_init() can't fail Markus Armbruster
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 14+ messages in thread
From: Markus Armbruster @ 2009-09-25  1:53 UTC (permalink / raw)
  To: qemu-devel

Monitor command "pci_add ADDR storage ..." does its work in
qemu_pci_hot_add_nic().  It called pci_create(..., ADDR) to create the
device.  That's wrong, because pci_create() terminates the program
when ADDR is invalid.

Use pci_get_bus_devfn() and pci_create_noinit() instead.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/pci-hotplug.c |   12 ++++++++++--
 hw/pci.c         |    2 +-
 hw/pci.h         |    1 +
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index f3dc421..d6093ba 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -107,6 +107,8 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
     DriveInfo *dinfo = NULL;
     int type = -1;
     char buf[128];
+    PCIBus *bus;
+    int devfn;
 
     if (get_param_value(buf, sizeof(buf), "if", opts)) {
         if (!strcmp(buf, "scsi"))
@@ -134,16 +136,22 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
         dinfo = NULL;
     }
 
+    bus = pci_get_bus_devfn(&devfn, devaddr);
+    if (!bus) {
+        monitor_printf(mon, "Invalid PCI device address %s\n", devaddr);
+        return NULL;
+    }
+
     switch (type) {
     case IF_SCSI:
-        dev = pci_create("lsi53c895a", devaddr);
+        dev = pci_create_noinit(bus, devfn, "lsi53c895a");
         break;
     case IF_VIRTIO:
         if (!dinfo) {
             monitor_printf(mon, "virtio requires a backing file/device.\n");
             return NULL;
         }
-        dev = pci_create("virtio-blk-pci", devaddr);
+        dev = pci_create_noinit(bus, devfn, "virtio-blk-pci");
         qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
         break;
     default:
diff --git a/hw/pci.c b/hw/pci.c
index 64d70ed..5be21d7 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -265,7 +265,7 @@ int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
     return 0;
 }
 
-static PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
+PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
 {
     int dom, bus;
     unsigned slot;
diff --git a/hw/pci.h b/hw/pci.h
index caba5c8..356405e 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -260,6 +260,7 @@ int pci_bus_num(PCIBus *s);
 void pci_for_each_device(int bus_num, void (*fn)(PCIDevice *d));
 PCIBus *pci_find_bus(int bus_num);
 PCIDevice *pci_find_device(int bus_num, int slot, int function);
+PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
 
 int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
                      unsigned *slotp);
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 3/6] Make it obvious that pci_nic_init() can't fail
  2009-09-25  1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 1/6] Fix pci_vga_init() not to ignore bus argument Markus Armbruster
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 2/6] Fix pci_add storage not to exit on bad first argument Markus Armbruster
@ 2009-09-25  1:53 ` Markus Armbruster
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 4/6] Fix pci_add nic not to exit on bad model Markus Armbruster
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: Markus Armbruster @ 2009-09-25  1:53 UTC (permalink / raw)
  To: qemu-devel

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@redhat.com>
---
 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 5be21d7..92262f7 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -815,22 +815,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 3fdf1e6..0eba08b 100644
--- a/net.c
+++ b/net.c
@@ -2358,8 +2358,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;
 
@@ -2369,7 +2369,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 1479826..c93cc99 100644
--- a/net.h
+++ b/net.h
@@ -76,8 +76,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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 4/6] Fix pci_add nic not to exit on bad model
  2009-09-25  1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
                   ` (2 preceding siblings ...)
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 3/6] Make it obvious that pci_nic_init() can't fail Markus Armbruster
@ 2009-09-25  1:53 ` Markus Armbruster
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 5/6] pci_create() is now unused, remove it Markus Armbruster
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: Markus Armbruster @ 2009-09-25  1:53 UTC (permalink / raw)
  To: qemu-devel

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>
---
 hw/mips_malta.c        |    2 +-
 hw/pc.c                |    2 +-
 hw/pci.c               |   33 ++++++++++++++++++++++++++++++---
 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, 71 insertions(+), 32 deletions(-)

diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index e09e971..2137034 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -489,7 +489,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 bc2875e..ac56495 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -1351,7 +1351,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);
         else
-            pci_nic_init(nd, "e1000", NULL);
+            pci_nic_init_nofail(nd, "e1000", NULL);
     }
 
     piix4_acpi_system_hot_add_init();
diff --git a/hw/pci.c b/hw/pci.c
index 92262f7..e43b53e 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -811,21 +811,48 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
                         const char *default_devaddr)
 {
     const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr;
+    PCIBus *bus;
+    int devfn;
     PCIDevice *pci_dev;
     DeviceState *dev;
     int i;
 
-    i = qemu_check_nic_model_list(nd, pci_nic_models, default_model);
-    pci_dev = pci_create(pci_nic_names[i], devaddr);
+    i = qemu_find_nic_model(nd, pci_nic_models, default_model);
+    if (i < 0)
+        return NULL;
+
+    bus = pci_get_bus_devfn(&devfn, devaddr);
+    if (!bus) {
+        qemu_error("Invalid PCI device address %s for device %s\n",
+                   devaddr, pci_nic_names[i]);
+        return NULL;
+    }
+
+    pci_dev = pci_create_noinit(bus, devfn, pci_nic_names[i]);
     dev = &pci_dev->qdev;
     if (nd->id)
         dev->id = qemu_strdup(nd->id);
     dev->nd = nd;
-    qdev_init(dev);
+    if (qdev_init(dev) < 0)
+        return NULL;
     nd->private = dev;
     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 356405e..51c5085 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -254,6 +254,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 8a6b7ce..a488240 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -119,7 +119,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 6bd5234..d1a82bf 100644
--- a/hw/ppc_newworld.c
+++ b/hw/ppc_newworld.c
@@ -320,7 +320,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 bb8c969..79f17e8 100644
--- a/hw/ppc_oldworld.c
+++ b/hw/ppc_oldworld.c
@@ -333,7 +333,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 0525b1e..a94cdde 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -697,7 +697,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], 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 5044194..ea30816 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -219,7 +219,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
     if (pci_bus) {
         /* 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 ea19ff6..f8a5968 100644
--- a/hw/r2d.c
+++ b/hw/r2d.c
@@ -236,7 +236,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 a18e773..c494a20 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 2c97d9d..333092f 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -616,7 +616,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 29b85ae..e8ebdf1 100644
--- a/hw/versatilepb.c
+++ b/hw/versatilepb.c
@@ -213,7 +213,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 0eba08b..2d5899f 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)
diff --git a/net.h b/net.h
index c93cc99..dfce8d6 100644
--- a/net.h
+++ b/net.h
@@ -75,9 +75,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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 5/6] pci_create() is now unused, remove it
  2009-09-25  1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
                   ` (3 preceding siblings ...)
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 4/6] Fix pci_add nic not to exit on bad model Markus Armbruster
@ 2009-09-25  1:53 ` Markus Armbruster
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 6/6] Rename pci_create_noinit() to pci_create() Markus Armbruster
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: Markus Armbruster @ 2009-09-25  1:53 UTC (permalink / raw)
  To: qemu-devel


Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/pci.c |   18 ------------------
 hw/pci.h |    1 -
 2 files changed, 0 insertions(+), 19 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index e43b53e..ec0fc7c 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -764,24 +764,6 @@ void pci_info(Monitor *mon)
     pci_for_each_device(0, pci_info_device);
 }
 
-PCIDevice *pci_create(const char *name, const char *devaddr)
-{
-    PCIBus *bus;
-    int devfn;
-    DeviceState *dev;
-
-    bus = pci_get_bus_devfn(&devfn, devaddr);
-    if (!bus) {
-        fprintf(stderr, "Invalid PCI device address %s for device %s\n",
-                devaddr, name);
-        exit(1);
-    }
-
-    dev = qdev_create(&bus->qbus, name);
-    qdev_prop_set_uint32(dev, "addr", devfn);
-    return (PCIDevice *)dev;
-}
-
 static const char * const pci_nic_models[] = {
     "ne2k_pci",
     "i82551",
diff --git a/hw/pci.h b/hw/pci.h
index 51c5085..689461f 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -336,7 +336,6 @@ typedef struct {
 void pci_qdev_register(PCIDeviceInfo *info);
 void pci_qdev_register_many(PCIDeviceInfo *info);
 
-PCIDevice *pci_create(const char *name, const char *devaddr);
 PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name);
 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
 
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 6/6] Rename pci_create_noinit() to pci_create()
  2009-09-25  1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
                   ` (4 preceding siblings ...)
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 5/6] pci_create() is now unused, remove it Markus Armbruster
@ 2009-09-25  1:53 ` Markus Armbruster
  2009-09-25 10:44 ` [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Gerd Hoffmann
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 14+ messages in thread
From: Markus Armbruster @ 2009-09-25  1:53 UTC (permalink / raw)
  To: qemu-devel

It's qdev_create() specialized for PCI, so name it accordingly.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/pci.c     |    2 +-
 hw/pci-hotplug.c |    4 ++--
 hw/pci.c         |    6 +++---
 hw/pci.h         |    2 +-
 hw/vga-pci.c     |    2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index 89ecd44..58130d1 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -443,7 +443,7 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
 {
     PCIDevice *dev;
 
-    dev = pci_create_noinit(bus, -1, "CMD646 IDE");
+    dev = pci_create(bus, -1, "CMD646 IDE");
     qdev_prop_set_uint32(&dev->qdev, "secondary", secondary_ide_enabled);
     qdev_init(&dev->qdev);
 
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index d6093ba..dfd2cf3 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -144,14 +144,14 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
 
     switch (type) {
     case IF_SCSI:
-        dev = pci_create_noinit(bus, devfn, "lsi53c895a");
+        dev = pci_create(bus, devfn, "lsi53c895a");
         break;
     case IF_VIRTIO:
         if (!dinfo) {
             monitor_printf(mon, "virtio requires a backing file/device.\n");
             return NULL;
         }
-        dev = pci_create_noinit(bus, devfn, "virtio-blk-pci");
+        dev = pci_create(bus, devfn, "virtio-blk-pci");
         qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
         break;
     default:
diff --git a/hw/pci.c b/hw/pci.c
index ec0fc7c..b3ba575 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -810,7 +810,7 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
         return NULL;
     }
 
-    pci_dev = pci_create_noinit(bus, devfn, pci_nic_names[i]);
+    pci_dev = pci_create(bus, devfn, pci_nic_names[i]);
     dev = &pci_dev->qdev;
     if (nd->id)
         dev->id = qemu_strdup(nd->id);
@@ -925,7 +925,7 @@ void pci_qdev_register_many(PCIDeviceInfo *info)
     }
 }
 
-PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name)
+PCIDevice *pci_create(PCIBus *bus, int devfn, const char *name)
 {
     DeviceState *dev;
 
@@ -936,7 +936,7 @@ PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name)
 
 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
 {
-    PCIDevice *dev = pci_create_noinit(bus, devfn, name);
+    PCIDevice *dev = pci_create(bus, devfn, name);
     qdev_init(&dev->qdev);
     return dev;
 }
diff --git a/hw/pci.h b/hw/pci.h
index 689461f..7f034ff 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -336,7 +336,7 @@ typedef struct {
 void pci_qdev_register(PCIDeviceInfo *info);
 void pci_qdev_register_many(PCIDeviceInfo *info);
 
-PCIDevice *pci_create_noinit(PCIBus *bus, int devfn, const char *name);
+PCIDevice *pci_create(PCIBus *bus, int devfn, const char *name);
 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
 
 /* lsi53c895a.c */
diff --git a/hw/vga-pci.c b/hw/vga-pci.c
index 129ff48..314ef03 100644
--- a/hw/vga-pci.c
+++ b/hw/vga-pci.c
@@ -137,7 +137,7 @@ int pci_vga_init(PCIBus *bus,
 {
     PCIDevice *dev;
 
-    dev = pci_create_noinit(bus, -1, "VGA");
+    dev = pci_create(bus, -1, "VGA");
     qdev_prop_set_uint32(&dev->qdev, "bios-offset", vga_bios_offset);
     qdev_prop_set_uint32(&dev->qdev, "bios-size", vga_bios_offset);
     qdev_init(&dev->qdev);
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes
  2009-09-25  1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
                   ` (5 preceding siblings ...)
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 6/6] Rename pci_create_noinit() to pci_create() Markus Armbruster
@ 2009-09-25 10:44 ` Gerd Hoffmann
  2009-09-25 14:12   ` Markus Armbruster
  2009-09-25 16:26 ` Luiz Capitulino
  2009-09-28 16:05 ` Mark McLoughlin
  8 siblings, 1 reply; 14+ messages in thread
From: Gerd Hoffmann @ 2009-09-25 10:44 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel

On 09/25/09 03:53, Markus Armbruster wrote:
> Markus Armbruster (6):
>    Fix pci_vga_init() not to ignore bus argument
>    Fix pci_add storage not to exit on bad first argument
>    Make it obvious that pci_nic_init() can't fail
>    Fix pci_add nic not to exit on bad model
>    pci_create() is now unused, remove it
>    Rename pci_create_noinit() to pci_create()

Nice cleanup.

Acked-by: Gerd Hoffmann <kraxel@redhat.com>

cheers,
   Gerd

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes
  2009-09-25 10:44 ` [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Gerd Hoffmann
@ 2009-09-25 14:12   ` Markus Armbruster
  0 siblings, 0 replies; 14+ messages in thread
From: Markus Armbruster @ 2009-09-25 14:12 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

Gerd Hoffmann <kraxel@redhat.com> writes:

> On 09/25/09 03:53, Markus Armbruster wrote:
>> Markus Armbruster (6):
>>    Fix pci_vga_init() not to ignore bus argument
>>    Fix pci_add storage not to exit on bad first argument
>>    Make it obvious that pci_nic_init() can't fail
>>    Fix pci_add nic not to exit on bad model
>>    pci_create() is now unused, remove it
>>    Rename pci_create_noinit() to pci_create()
>
> Nice cleanup.
>
> Acked-by: Gerd Hoffmann <kraxel@redhat.com>

Thanks.  415 occurences of exit() outside tests remaining...

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes
  2009-09-25  1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
                   ` (6 preceding siblings ...)
  2009-09-25 10:44 ` [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Gerd Hoffmann
@ 2009-09-25 16:26 ` Luiz Capitulino
  2009-09-28 16:05 ` Mark McLoughlin
  8 siblings, 0 replies; 14+ messages in thread
From: Luiz Capitulino @ 2009-09-25 16:26 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel

On Fri, 25 Sep 2009 03:53:47 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Markus Armbruster (6):
>   Fix pci_vga_init() not to ignore bus argument
>   Fix pci_add storage not to exit on bad first argument
>   Make it obvious that pci_nic_init() can't fail
>   Fix pci_add nic not to exit on bad model
>   pci_create() is now unused, remove it
>   Rename pci_create_noinit() to pci_create()

 The Right Thing :) and it (obviously) fixes the problem with
pci_add for me.

 The only nitpick is that by passing an invalid NIC on command
line would make qemu dump valid NIC models.. But not an issue,
anyway.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Qemu-devel] Re: [PATCH 2/6] Fix pci_add storage not to exit on bad first argument
  2009-09-25  1:53 ` [Qemu-devel] [PATCH 2/6] Fix pci_add storage not to exit on bad first argument Markus Armbruster
@ 2009-09-25 16:36   ` Markus Armbruster
  0 siblings, 0 replies; 14+ messages in thread
From: Markus Armbruster @ 2009-09-25 16:36 UTC (permalink / raw)
  To: qemu-devel

Markus Armbruster <armbru@redhat.com> writes:

> Monitor command "pci_add ADDR storage ..." does its work in
> qemu_pci_hot_add_nic().  It called pci_create(..., ADDR) to create the

Oops, make that qmu_pci_hot_add_storage().

> device.  That's wrong, because pci_create() terminates the program
> when ADDR is invalid.
>
> Use pci_get_bus_devfn() and pci_create_noinit() instead.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes
  2009-09-25  1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
                   ` (7 preceding siblings ...)
  2009-09-25 16:26 ` Luiz Capitulino
@ 2009-09-28 16:05 ` Mark McLoughlin
  2009-09-28 16:16   ` Mark McLoughlin
  8 siblings, 1 reply; 14+ messages in thread
From: Mark McLoughlin @ 2009-09-28 16:05 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel

On Fri, 2009-09-25 at 03:53 +0200, Markus Armbruster wrote:
> Markus Armbruster (6):
>   Fix pci_vga_init() not to ignore bus argument
>   Fix pci_add storage not to exit on bad first argument
>   Make it obvious that pci_nic_init() can't fail
>   Fix pci_add nic not to exit on bad model
>   pci_create() is now unused, remove it
>   Rename pci_create_noinit() to pci_create()

Looks like a good series to me too

Acked-by: Mark McLoughlin <markmc@redhat.com>

Cheers,
Mark.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes
  2009-09-28 16:05 ` Mark McLoughlin
@ 2009-09-28 16:16   ` Mark McLoughlin
  2009-09-28 19:14     ` Markus Armbruster
  0 siblings, 1 reply; 14+ messages in thread
From: Mark McLoughlin @ 2009-09-28 16:16 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel

On Mon, 2009-09-28 at 17:05 +0100, Mark McLoughlin wrote:
> On Fri, 2009-09-25 at 03:53 +0200, Markus Armbruster wrote:
> > Markus Armbruster (6):
> >   Fix pci_vga_init() not to ignore bus argument
> >   Fix pci_add storage not to exit on bad first argument
> >   Make it obvious that pci_nic_init() can't fail
> >   Fix pci_add nic not to exit on bad model
> >   pci_create() is now unused, remove it
> >   Rename pci_create_noinit() to pci_create()
> 
> Looks like a good series to me too
> 
> Acked-by: Mark McLoughlin <markmc@redhat.com>

Oh, and IMHO, at least patches 3 and 4 makes sense for stable-0.11;
patch 4 just needs an update for e1000 being the default model now

Patch 2 might make sense too with a little massaging

Cheers,
Mark.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes
  2009-09-28 16:16   ` Mark McLoughlin
@ 2009-09-28 19:14     ` Markus Armbruster
  0 siblings, 0 replies; 14+ messages in thread
From: Markus Armbruster @ 2009-09-28 19:14 UTC (permalink / raw)
  To: Mark McLoughlin; +Cc: qemu-devel

Mark McLoughlin <markmc@redhat.com> writes:

> On Mon, 2009-09-28 at 17:05 +0100, Mark McLoughlin wrote:
>> On Fri, 2009-09-25 at 03:53 +0200, Markus Armbruster wrote:
>> > Markus Armbruster (6):
>> >   Fix pci_vga_init() not to ignore bus argument
>> >   Fix pci_add storage not to exit on bad first argument
>> >   Make it obvious that pci_nic_init() can't fail
>> >   Fix pci_add nic not to exit on bad model
>> >   pci_create() is now unused, remove it
>> >   Rename pci_create_noinit() to pci_create()
>> 
>> Looks like a good series to me too
>> 
>> Acked-by: Mark McLoughlin <markmc@redhat.com>
>
> Oh, and IMHO, at least patches 3 and 4 makes sense for stable-0.11;
> patch 4 just needs an update for e1000 being the default model now
>
> Patch 2 might make sense too with a little massaging

Yes.  The others are mere cleanup, doubt they're appropriate for stable.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2009-09-28 19:15 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-25  1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
2009-09-25  1:53 ` [Qemu-devel] [PATCH 1/6] Fix pci_vga_init() not to ignore bus argument Markus Armbruster
2009-09-25  1:53 ` [Qemu-devel] [PATCH 2/6] Fix pci_add storage not to exit on bad first argument Markus Armbruster
2009-09-25 16:36   ` [Qemu-devel] " Markus Armbruster
2009-09-25  1:53 ` [Qemu-devel] [PATCH 3/6] Make it obvious that pci_nic_init() can't fail Markus Armbruster
2009-09-25  1:53 ` [Qemu-devel] [PATCH 4/6] Fix pci_add nic not to exit on bad model Markus Armbruster
2009-09-25  1:53 ` [Qemu-devel] [PATCH 5/6] pci_create() is now unused, remove it Markus Armbruster
2009-09-25  1:53 ` [Qemu-devel] [PATCH 6/6] Rename pci_create_noinit() to pci_create() Markus Armbruster
2009-09-25 10:44 ` [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Gerd Hoffmann
2009-09-25 14:12   ` Markus Armbruster
2009-09-25 16:26 ` Luiz Capitulino
2009-09-28 16:05 ` Mark McLoughlin
2009-09-28 16:16   ` Mark McLoughlin
2009-09-28 19:14     ` Markus Armbruster

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.