Skip to contentSkip to conversation

net: Reinstate '-net nic, model=help' output as documented in man page

PATCH In review David Woodhouse 3 participants 4 messages Jul 9, 2024 – Jul 26, 2024 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: Reinstate '-net nic, model=help' output as documented in man page

From: David Woodhouse <[email protected]>

While refactoring the NIC initialization code, I broke '-net nic,model=help' which no longer outputs a list of available NIC models.

Fixes 2cdeca04adab ("net: report list of available models according to platform")
---
 net/net.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
net/net.c +22 -3
index 6938da05e0..2eb8bc9c0b 100644
@@ -1139,6 +1139,21 @@ NICInfo *qemu_find_nic_info(const char *typename, bool match_default,
     return NULL;
 }
 
+static bool is_nic_model_help_option(const char *model)
+{
+    if (model && is_help_option(model)) {
+        /*
+         * Trigger the help output by instantiating the hash table which
+         * will gather tha available models as they get registered.
+         */
+        if (!nic_model_help) {
+            nic_model_help = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                                   g_free, NULL);
+        }
+        return true;
+    }
+    return false;
+}
 
 /* "I have created a device. Please configure it if you can" */
 bool qemu_configure_nic_device(DeviceState *dev, bool match_default,
@@ -1722,6 +1737,12 @@ void net_check_clients(void)
 
 static int net_init_client(void *dummy, QemuOpts *opts, Error **errp)
 {
+    const char *model = qemu_opt_get_del(opts, "model");
+
+    if (is_nic_model_help_option(model)) {
+        return 0;
+    }
+
     return net_client_init(opts, false, errp);
 }
 
@@ -1778,9 +1799,7 @@ static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp)
     memset(ni, 0, sizeof(*ni));
     ni->model = qemu_opt_get_del(opts, "model");
 
-    if (!nic_model_help && !g_strcmp0(ni->model, "help")) {
-        nic_model_help = g_hash_table_new_full(g_str_hash, g_str_equal,
-                                               g_free, NULL);
+    if (is_nic_model_help_option(ni->model)) {
         return 0;
     }
 
Signature · 1 line
2.44.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · David Woodhouse

From: David Woodhouse <[email protected]>

While refactoring the NIC initialization code, I broke '-net nic,model=help' which no longer outputs a list of available NIC models.

Fixes 2cdeca04adab ("net: report list of available models according to platform")

Thanks,

/mjt

Quoted 54 lines
---
  net/net.c | 25 ++++++++++++++++++++++---
  1 file changed, 22 insertions(+), 3 deletions(-)
net/net.c +22 -3
index 6938da05e0..2eb8bc9c0b 100644
@@ -1139,6 +1139,21 @@ NICInfo *qemu_find_nic_info(const char *typename, bool match_default,
      return NULL;
  }
 
+static bool is_nic_model_help_option(const char *model)
+{
+    if (model && is_help_option(model)) {
+        /*
+         * Trigger the help output by instantiating the hash table which
+         * will gather tha available models as they get registered.
+         */
+        if (!nic_model_help) {
+            nic_model_help = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                                   g_free, NULL);
+        }
+        return true;
+    }
+    return false;
+}
 
  /* "I have created a device. Please configure it if you can" */
  bool qemu_configure_nic_device(DeviceState *dev, bool match_default,
@@ -1722,6 +1737,12 @@ void net_check_clients(void)
 
  static int net_init_client(void *dummy, QemuOpts *opts, Error **errp)
  {
+    const char *model = qemu_opt_get_del(opts, "model");
+
+    if (is_nic_model_help_option(model)) {
+        return 0;
+    }
+
      return net_client_init(opts, false, errp);
  }
 
@@ -1778,9 +1799,7 @@ static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp)
      memset(ni, 0, sizeof(*ni));
      ni->model = qemu_opt_get_del(opts, "model");
 
-    if (!nic_model_help && !g_strcmp0(ni->model, "help")) {
-        nic_model_help = g_hash_table_new_full(g_str_hash, g_str_equal,
-                                               g_free, NULL);
+    if (is_nic_model_help_option(ni->model)) {
          return 0;
      }
 
Signature · 4 lines
GPG Key transition (from rsa2048 to rsa4096) since 2024-04-24.
New key: rsa4096/61AD3D98ECDF2C8E  9D8B E14E 3F2A 9DD7 9199  28F1 61AD 3D98 ECDF 2C8E
Old key: rsa2048/457CE0A0804465C5  6EE1 95D1 886E 8FFB 810D  4324 457C E0A0 8044 65C5
Transition statement: http://www.corpit.ru/mjt/gpg-transition-2024.txt
#2 lore raw
Quoted 11 lines · Michael Tokarev
Quoted 7 lines · David Woodhouse

From: David Woodhouse <[email protected]>

While refactoring the NIC initialization code, I broke '-net nic,model=help' which no longer outputs a list of available NIC models.

Fixes 2cdeca04adab ("net: report list of available models according to platform")

Ping?

#3 lore raw
Quoted 8 lines · David Woodhouse
Quoted 6 lines · Michael Tokarev
Quoted 5 lines · David Woodhouse

From: David Woodhouse <[email protected]>

While refactoring the NIC initialization code, I broke '-net nic,model=help' which no longer outputs a list of available NIC models.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Fixes 2cdeca04adab ("net: report list of available models according to platform")

Ping?

Queued.

Thanks