All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Fix the "-nic help" option
@ 2022-11-10 12:52 Thomas Huth
  2022-11-10 12:52 ` [PATCH v2 1/3] net: Move the code to collect available NIC models to a separate function Thomas Huth
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Thomas Huth @ 2022-11-10 12:52 UTC (permalink / raw)
  To: qemu-devel, Jason Wang
  Cc: Michael S. Tsirkin, pbonzini, Marcel Apfelbaum, Claudio Fontana,
	Alex Bennée

Running QEMU with "-nic help" used to work in QEMU 5.2 and earlier
versions, but since QEMU 6.0 it just complains that "help" is not
a valid value here. This patch series fixes this problem and also
extends the help output here to list the available NIC models, too.

v2: 
 - Add function comment in the first patch
 - Add Reviewed-by in the third patch

Thomas Huth (3):
  net: Move the code to collect available NIC models to a separate
    function
  net: Restore printing of the help text with "-nic help"
  net: Replace "Supported NIC models" with "Available NIC models"

 include/net/net.h | 14 +++++++++++++
 hw/pci/pci.c      | 29 +--------------------------
 net/net.c         | 50 ++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 62 insertions(+), 31 deletions(-)

-- 
2.31.1



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

* [PATCH v2 1/3] net: Move the code to collect available NIC models to a separate function
  2022-11-10 12:52 [PATCH v2 0/3] Fix the "-nic help" option Thomas Huth
@ 2022-11-10 12:52 ` Thomas Huth
  2022-11-10 12:52 ` [PATCH v2 2/3] net: Restore printing of the help text with "-nic help" Thomas Huth
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2022-11-10 12:52 UTC (permalink / raw)
  To: qemu-devel, Jason Wang
  Cc: Michael S. Tsirkin, pbonzini, Marcel Apfelbaum, Claudio Fontana,
	Alex Bennée

The code that collects the available NIC models is not really specific
to PCI anymore and will be required in the next patch, too, so let's
move this into a new separate function in net.c instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 include/net/net.h | 14 ++++++++++++++
 hw/pci/pci.c      | 29 +----------------------------
 net/net.c         | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/include/net/net.h b/include/net/net.h
index 3db75ff841..31d9b980c7 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -201,6 +201,20 @@ void net_socket_rs_init(SocketReadState *rs,
                         bool vnet_hdr);
 NetClientState *qemu_get_peer(NetClientState *nc, int queue_index);
 
+/**
+ * qemu_get_nic_models:
+ * @device_type: Defines which devices should be taken into consideration
+ *               (e.g. TYPE_DEVICE for all devices, or TYPE_PCI_DEVICE for PCI)
+ *
+ * Get an array of pointers to names of NIC devices that are available in
+ * the QEMU binary. The array is terminated with a NULL pointer entry.
+ * The caller is responsible for freeing the memory when it is not required
+ * anymore, e.g. with g_ptr_array_free(..., true).
+ *
+ * Returns: Pointer to the array that contains the pointers to the names.
+ */
+GPtrArray *qemu_get_nic_models(const char *device_type);
+
 /* NIC info */
 
 #define MAX_NICS 8
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 2f450f6a72..2b7b343e82 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1964,7 +1964,6 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
                                const char *default_devaddr)
 {
     const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr;
-    GSList *list;
     GPtrArray *pci_nic_models;
     PCIBus *bus;
     PCIDevice *pci_dev;
@@ -1979,33 +1978,7 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
         nd->model = g_strdup("virtio-net-pci");
     }
 
-    list = object_class_get_list_sorted(TYPE_PCI_DEVICE, false);
-    pci_nic_models = g_ptr_array_new();
-    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);
-            /*
-             * A network device might also be something else than a NIC, see
-             * e.g. the "rocker" device. Thus we have to look for the "netdev"
-             * property, too. Unfortunately, some devices like virtio-net only
-             * create this property during instance_init, so we have to create
-             * a temporary instance here to be able to check it.
-             */
-            Object *obj = object_new_with_class(OBJECT_CLASS(dc));
-            if (object_property_find(obj, "netdev")) {
-                g_ptr_array_add(pci_nic_models, (gpointer)name);
-            }
-            object_unref(obj);
-        }
-        next = list->next;
-        g_slist_free_1(list);
-        list = next;
-    }
-    g_ptr_array_add(pci_nic_models, NULL);
+    pci_nic_models = qemu_get_nic_models(TYPE_PCI_DEVICE);
 
     if (qemu_show_nic_models(nd->model, (const char **)pci_nic_models->pdata)) {
         exit(0);
diff --git a/net/net.c b/net/net.c
index 840ad9dca5..49cced691f 100644
--- a/net/net.c
+++ b/net/net.c
@@ -899,6 +899,40 @@ static int nic_get_free_idx(void)
     return -1;
 }
 
+GPtrArray *qemu_get_nic_models(const char *device_type)
+{
+    GPtrArray *nic_models = g_ptr_array_new();
+    GSList *list = object_class_get_list_sorted(device_type, false);
+
+    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);
+            /*
+             * A network device might also be something else than a NIC, see
+             * e.g. the "rocker" device. Thus we have to look for the "netdev"
+             * property, too. Unfortunately, some devices like virtio-net only
+             * create this property during instance_init, so we have to create
+             * a temporary instance here to be able to check it.
+             */
+            Object *obj = object_new_with_class(OBJECT_CLASS(dc));
+            if (object_property_find(obj, "netdev")) {
+                g_ptr_array_add(nic_models, (gpointer)name);
+            }
+            object_unref(obj);
+        }
+        next = list->next;
+        g_slist_free_1(list);
+        list = next;
+    }
+    g_ptr_array_add(nic_models, NULL);
+
+    return nic_models;
+}
+
 int qemu_show_nic_models(const char *arg, const char *const *models)
 {
     int i;
-- 
2.31.1



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

* [PATCH v2 2/3] net: Restore printing of the help text with "-nic help"
  2022-11-10 12:52 [PATCH v2 0/3] Fix the "-nic help" option Thomas Huth
  2022-11-10 12:52 ` [PATCH v2 1/3] net: Move the code to collect available NIC models to a separate function Thomas Huth
@ 2022-11-10 12:52 ` Thomas Huth
  2022-11-10 12:52 ` [PATCH v2 3/3] net: Replace "Supported NIC models" with "Available NIC models" Thomas Huth
  2022-12-15 15:23 ` [PATCH v2 0/3] Fix the "-nic help" option Thomas Huth
  3 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2022-11-10 12:52 UTC (permalink / raw)
  To: qemu-devel, Jason Wang
  Cc: Michael S. Tsirkin, pbonzini, Marcel Apfelbaum, Claudio Fontana,
	Alex Bennée

Running QEMU with "-nic help" used to work in QEMU 5.2 and earlier versions
(it showed the available netdev backends), but this feature got broken during
some refactoring in version 6.0. Let's restore the old behavior, and while
we're at it, let's also print the available NIC models here now since this
option can be used to configure both, netdev backend and model in one go.

Fixes: ad6f932fe8 ("net: do not exit on "netdev_add help" monitor command")
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 net/net.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/net/net.c b/net/net.c
index 49cced691f..cdd3ebc515 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1569,8 +1569,18 @@ static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp)
     const char *type;
 
     type = qemu_opt_get(opts, "type");
-    if (type && g_str_equal(type, "none")) {
-        return 0;    /* Nothing to do, default_net is cleared in vl.c */
+    if (type) {
+        if (g_str_equal(type, "none")) {
+            return 0;    /* Nothing to do, default_net is cleared in vl.c */
+        }
+        if (is_help_option(type)) {
+            GPtrArray *nic_models = qemu_get_nic_models(TYPE_DEVICE);
+            show_netdevs();
+            printf("\n");
+            qemu_show_nic_models(type, (const char **)nic_models->pdata);
+            g_ptr_array_free(nic_models, true);
+            exit(0);
+        }
     }
 
     idx = nic_get_free_idx();
-- 
2.31.1



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

* [PATCH v2 3/3] net: Replace "Supported NIC models" with "Available NIC models"
  2022-11-10 12:52 [PATCH v2 0/3] Fix the "-nic help" option Thomas Huth
  2022-11-10 12:52 ` [PATCH v2 1/3] net: Move the code to collect available NIC models to a separate function Thomas Huth
  2022-11-10 12:52 ` [PATCH v2 2/3] net: Restore printing of the help text with "-nic help" Thomas Huth
@ 2022-11-10 12:52 ` Thomas Huth
  2022-12-15 15:23 ` [PATCH v2 0/3] Fix the "-nic help" option Thomas Huth
  3 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2022-11-10 12:52 UTC (permalink / raw)
  To: qemu-devel, Jason Wang
  Cc: Michael S. Tsirkin, pbonzini, Marcel Apfelbaum, Claudio Fontana,
	Alex Bennée

Just because a NIC model is compiled into the QEMU binary does not
necessary mean that it can be used with each and every machine.
So let's rather talk about "available" models instead of "supported"
models, just to avoid confusion.

Reviewed-by: Claudio Fontana <cfontana@suse.de>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 net/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/net.c b/net/net.c
index cdd3ebc515..5d96c8858f 100644
--- a/net/net.c
+++ b/net/net.c
@@ -941,7 +941,7 @@ int qemu_show_nic_models(const char *arg, const char *const *models)
         return 0;
     }
 
-    printf("Supported NIC models:\n");
+    printf("Available NIC models:\n");
     for (i = 0 ; models[i]; i++) {
         printf("%s\n", models[i]);
     }
-- 
2.31.1



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

* Re: [PATCH v2 0/3] Fix the "-nic help" option
  2022-11-10 12:52 [PATCH v2 0/3] Fix the "-nic help" option Thomas Huth
                   ` (2 preceding siblings ...)
  2022-11-10 12:52 ` [PATCH v2 3/3] net: Replace "Supported NIC models" with "Available NIC models" Thomas Huth
@ 2022-12-15 15:23 ` Thomas Huth
  2022-12-16  7:38   ` Jason Wang
  3 siblings, 1 reply; 6+ messages in thread
From: Thomas Huth @ 2022-12-15 15:23 UTC (permalink / raw)
  To: qemu-devel, Jason Wang
  Cc: Michael S. Tsirkin, pbonzini, Marcel Apfelbaum, Claudio Fontana,
	Alex Bennée

On 10/11/2022 13.52, Thomas Huth wrote:
> Running QEMU with "-nic help" used to work in QEMU 5.2 and earlier
> versions, but since QEMU 6.0 it just complains that "help" is not
> a valid value here. This patch series fixes this problem and also
> extends the help output here to list the available NIC models, too.
> 
> v2:
>   - Add function comment in the first patch
>   - Add Reviewed-by in the third patch
> 
> Thomas Huth (3):
>    net: Move the code to collect available NIC models to a separate
>      function
>    net: Restore printing of the help text with "-nic help"
>    net: Replace "Supported NIC models" with "Available NIC models"
> 
>   include/net/net.h | 14 +++++++++++++
>   hw/pci/pci.c      | 29 +--------------------------
>   net/net.c         | 50 ++++++++++++++++++++++++++++++++++++++++++++---
>   3 files changed, 62 insertions(+), 31 deletions(-)
> 

Friendly ping!

  Thomas



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

* Re: [PATCH v2 0/3] Fix the "-nic help" option
  2022-12-15 15:23 ` [PATCH v2 0/3] Fix the "-nic help" option Thomas Huth
@ 2022-12-16  7:38   ` Jason Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Wang @ 2022-12-16  7:38 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, Michael S. Tsirkin, pbonzini, Marcel Apfelbaum,
	Claudio Fontana, Alex Bennée

On Thu, Dec 15, 2022 at 11:23 PM Thomas Huth <thuth@redhat.com> wrote:
>
> On 10/11/2022 13.52, Thomas Huth wrote:
> > Running QEMU with "-nic help" used to work in QEMU 5.2 and earlier
> > versions, but since QEMU 6.0 it just complains that "help" is not
> > a valid value here. This patch series fixes this problem and also
> > extends the help output here to list the available NIC models, too.
> >
> > v2:
> >   - Add function comment in the first patch
> >   - Add Reviewed-by in the third patch
> >
> > Thomas Huth (3):
> >    net: Move the code to collect available NIC models to a separate
> >      function
> >    net: Restore printing of the help text with "-nic help"
> >    net: Replace "Supported NIC models" with "Available NIC models"
> >
> >   include/net/net.h | 14 +++++++++++++
> >   hw/pci/pci.c      | 29 +--------------------------
> >   net/net.c         | 50 ++++++++++++++++++++++++++++++++++++++++++++---
> >   3 files changed, 62 insertions(+), 31 deletions(-)
> >
>
> Friendly ping!

I've queued this series.

Thanks

>
>   Thomas
>



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

end of thread, other threads:[~2022-12-16  7:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10 12:52 [PATCH v2 0/3] Fix the "-nic help" option Thomas Huth
2022-11-10 12:52 ` [PATCH v2 1/3] net: Move the code to collect available NIC models to a separate function Thomas Huth
2022-11-10 12:52 ` [PATCH v2 2/3] net: Restore printing of the help text with "-nic help" Thomas Huth
2022-11-10 12:52 ` [PATCH v2 3/3] net: Replace "Supported NIC models" with "Available NIC models" Thomas Huth
2022-12-15 15:23 ` [PATCH v2 0/3] Fix the "-nic help" option Thomas Huth
2022-12-16  7:38   ` Jason Wang

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.