All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: Thomas Huth <thuth@redhat.com>, Jason Wang <jasowang@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 2/3] net: allow using any PCI NICs in -net or -nic
Date: Tue, 6 Mar 2018 20:14:01 -0300	[thread overview]
Message-ID: <ce3c5abe-5d57-3bde-0949-db17ce82c7cc@amsat.org> (raw)
In-Reply-To: <20180306164957.24275-3-pbonzini@redhat.com>

On 03/06/2018 01:49 PM, Paolo Bonzini wrote:
> Remove the hard-coded list of PCI NIC names; instead, fill an array
> using all PCI devices listed under DEVICE_CATEGORY_NETWORK. Keep
> the old shortcut "virtio" for virtio-net-pci.
> 
> Suggested-by: Thomas Huth <thuth@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  hw/pci/pci.c | 61 ++++++++++++++++++++++++++++++------------------------------
>  1 file changed, 30 insertions(+), 31 deletions(-)
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 2174c254eb..aa24a26680 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1815,49 +1815,48 @@ PciInfoList *qmp_query_pci(Error **errp)
>      return head;
>  }
>  
> -static const char * const pci_nic_models[] = {
> -    "ne2k_pci",
> -    "i82551",
> -    "i82557b",
> -    "i82559er",
> -    "rtl8139",
> -    "e1000",
> -    "pcnet",
> -    "virtio",
> -    "sungem",
> -    NULL
> -};
> -
> -static const char * const pci_nic_names[] = {
> -    "ne2k_pci",
> -    "i82551",
> -    "i82557b",
> -    "i82559er",
> -    "rtl8139",
> -    "e1000",
> -    "pcnet",
> -    "virtio-net-pci",
> -    "sungem",
> -    NULL
> -};
> -
>  /* Initialize a PCI NIC.  */
>  PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
>                                 const char *default_model,
>                                 const char *default_devaddr)
>  {
>      const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr;
> +    GSList *list;
> +    GPtrArray *pci_nic_models;
>      PCIBus *bus;
>      PCIDevice *pci_dev;
>      DeviceState *dev;
>      int devfn;
>      int i;
>  
> -    if (qemu_show_nic_models(nd->model, pci_nic_models)) {
> +    if (!strcmp(nd->model, "virtio")) {
> +        g_free(nd->model);
> +        nd->model = g_strdup("virtio-net-pci");
> +    }
> +
> +    list = object_class_get_list_sorted(TYPE_PCI_DEVICE, false);
> +    pci_nic_models = g_ptr_array_new_with_free_func(g_free);
> +    while (list) {
> +        DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, list->data,
> +                                             TYPE_DEVICE);
> +        GSList *next;
> +        if (test_bit(DEVICE_CATEGORY_NETWORK, dc->categories) &&
> +            dc->user_creatable) {
> +            const char *name = object_class_get_name(list->data) ;
> +            g_ptr_array_add(pci_nic_models, (gpointer)name);
> +        }
> +        next = list->next;
> +        g_slist_free_1(list);
> +        list = next;
> +    }
> +    g_ptr_array_add(pci_nic_models, NULL);
> +
> +    if (qemu_show_nic_models(nd->model, (const char **)pci_nic_models->pdata)) {
>          exit(0);
>      }
>  
> -    i = qemu_find_nic_model(nd, pci_nic_models, default_model);
> +    i = qemu_find_nic_model(nd, (const char **)pci_nic_models->pdata,
> +                            default_model);
>      if (i < 0) {
>          exit(1);
>      }
> @@ -1865,15 +1864,15 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
>      bus = pci_get_bus_devfn(&devfn, rootbus, devaddr);
>      if (!bus) {
>          error_report("Invalid PCI device address %s for device %s",
> -                     devaddr, pci_nic_names[i]);
> +                     devaddr, nd->model);
>          exit(1);
>      }
>  
> -    pci_dev = pci_create(bus, devfn, pci_nic_names[i]);
> +    pci_dev = pci_create(bus, devfn, nd->model);
>      dev = &pci_dev->qdev;
>      qdev_set_nic_properties(dev, nd);
>      qdev_init_nofail(dev);
> -
> +    g_ptr_array_free(pci_nic_models, true);
>      return pci_dev;
>  }
>  
> 

  reply	other threads:[~2018-03-06 23:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-06 16:49 [Qemu-devel] [PATCH 0/3] change q35 default NIC to e1000e Paolo Bonzini
2018-03-06 16:49 ` [Qemu-devel] [PATCH 1/3] qom: introduce object_class_get_list_sorted Paolo Bonzini
2018-03-06 23:13   ` Philippe Mathieu-Daudé
2018-03-06 16:49 ` [Qemu-devel] [PATCH 2/3] net: allow using any PCI NICs in -net or -nic Paolo Bonzini
2018-03-06 23:14   ` Philippe Mathieu-Daudé [this message]
2018-03-06 16:49 ` [Qemu-devel] [PATCH 3/3] q35: change default NIC to e1000e Paolo Bonzini
2018-03-06 18:15 ` [Qemu-devel] [PATCH 0/3] change q35 " no-reply
2018-03-06 20:09 ` no-reply
2018-03-06 19:45 [Qemu-devel] [PATCH v2 " Paolo Bonzini
2018-03-06 19:45 ` [Qemu-devel] [PATCH 2/3] net: allow using any PCI NICs in -net or -nic Paolo Bonzini
2018-03-08  9:02   ` Thomas Huth
2018-03-08 10:44     ` Paolo Bonzini
2018-03-08 17:28 [Qemu-devel] [PATCH v3 0/3] change q35 default NIC to e1000e Paolo Bonzini
2018-03-08 17:28 ` [Qemu-devel] [PATCH 2/3] net: allow using any PCI NICs in -net or -nic Paolo Bonzini
2018-03-08 18:53   ` Philippe Mathieu-Daudé
2018-03-08 18:59   ` Thomas Huth
2018-03-09  7:09   ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ce3c5abe-5d57-3bde-0949-db17ce82c7cc@amsat.org \
    --to=f4bug@amsat.org \
    --cc=jasowang@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.