Skip to contentSkip to conversation

net: improve error message for missing netdev backend

PATCH In review Daniel P. Berrangé 5 participants 8 messages Oct 3, 2022 – Oct 28, 2022 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: improve error message for missing netdev backend

The current message when using '-net user...' with SLIRP disabled at compile time is:

qemu-system-x86_64: -net user: Parameter 'type' expects a net backend type (maybe it is not compiled into this binary)

An observation is that we're using the 'netdev->type' field here which is an enum value, produced after QAPI has converted from its string form.

IOW, at this point in the code, we know that the user's specified type name was a valid network backend. The only possible scenario that can make the backend init function be NULL, is if support for that backend was disabled at build time. Given this, we don't need to caveat our error message with a 'maybe' hint, we can be totally explicit.

The use of QERR_INVALID_PARAMETER_VALUE doesn't really lend itself to user friendly error message text. Since this is not used to set a specific QAPI error class, we can simply stop using this pre-formatted error text and provide something better.

Thus the new message is:

qemu-system-x86_64: -net user: network backend 'user' is not compiled into this binary

The case of passing 'hubport' for -net is also given a message reminding people they should have used -netdev/-nic instead, as this backend type is only valid for the modern syntax.

---

NB, this does not make any difference to people who were relying on the QEMU built-in default hub that was created if you don't list any -net / -netdev / -nic argument, only those using explicit args.

 net/net.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
net/net.c +11 -7
index 2db160e063..8ddafacf13 100644
@@ -1036,19 +1036,23 @@ static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
     if (is_netdev) {
         if (netdev->type == NET_CLIENT_DRIVER_NIC ||
             !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a netdev backend type");
+            error_setg(errp, "network backend '%s' is not compiled into this binary",
+                       NetClientDriver_str(netdev->type));
             return -1;
         }
     } else {
         if (netdev->type == NET_CLIENT_DRIVER_NONE) {
             return 0; /* nothing to do */
         }
-        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT ||
-            !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a net backend type (maybe it is not compiled "
-                       "into this binary)");
+        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT) {
+            error_setg(errp, "network backend '%s' is only supported with -netdev/-nic",
+                       NetClientDriver_str(netdev->type));
+            return -1;
+        }
+
+        if (!net_client_init_fun[netdev->type]) {
+            error_setg(errp, "network backend '%s' is not compiled into this binary",
+                       NetClientDriver_str(netdev->type));
             return -1;
         }
 
Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 23 lines · Daniel P. Berrangé

The current message when using '-net user...' with SLIRP disabled at compile time is:

qemu-system-x86_64: -net user: Parameter 'type' expects a net backend type (maybe it is not compiled into this binary)

An observation is that we're using the 'netdev->type' field here which is an enum value, produced after QAPI has converted from its string form.

IOW, at this point in the code, we know that the user's specified type name was a valid network backend. The only possible scenario that can make the backend init function be NULL, is if support for that backend was disabled at build time. Given this, we don't need to caveat our error message with a 'maybe' hint, we can be totally explicit.

The use of QERR_INVALID_PARAMETER_VALUE doesn't really lend itself to user friendly error message text. Since this is not used to set a specific QAPI error class, we can simply stop using this pre-formatted error text and provide something better.

Thus the new message is:

Quoted 7 lines

qemu-system-x86_64: -net user: network backend 'user' is not compiled into this binary

The case of passing 'hubport' for -net is also given a message reminding people they should have used -netdev/-nic instead, as this backend type is only valid for the modern syntax.

lgtm

Quoted 47 lines

---

NB, this does not make any difference to people who were relying on the QEMU built-in default hub that was created if you don't list any -net /

(quoted diff) +0 -1
-netdev / -nic argument, only those using explicit args.
 
 net/net.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
net/net.c +11 -8
index 2db160e063..8ddafacf13 100644
@@ -1036,19 +1036,23 @@ static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
     if (is_netdev) {
         if (netdev->type == NET_CLIENT_DRIVER_NIC ||
             !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a netdev backend type");
+            error_setg(errp, "network backend '%s' is not compiled into this binary",
+                       NetClientDriver_str(netdev->type));
             return -1;
         }
     } else {
         if (netdev->type == NET_CLIENT_DRIVER_NONE) {
             return 0; /* nothing to do */
         }
-        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT ||
-            !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a net backend type (maybe it is not compiled "
-                       "into this binary)");
+        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT) {
+            error_setg(errp, "network backend '%s' is only supported with -netdev/-nic",
+                       NetClientDriver_str(netdev->type));
+            return -1;
+        }
+
+        if (!net_client_init_fun[netdev->type]) {
+            error_setg(errp, "network backend '%s' is not compiled into this binary",
+                       NetClientDriver_str(netdev->type));
             return -1;
         }
 
--

2.37.3

#2 lore raw
In reply to Daniel P. Berrangé
Quoted 5 lines · On Montag, 3. Oktober 2022 12:06:12 CEST Daniel P. Berrangé wrote:

The current message when using '-net user...' with SLIRP disabled at compile time is:

qemu-system-x86_64: -net user: Parameter 'type' expects a net backend type
(maybe it is not compiled into this binary)

Is this intended as alternative to Marc-André's previous patch? If yes, then same applies here: what about people not passing any networking arg to QEMU? They would not get any error message at all, right?

https://lore.kernel.org/all/2973900.g0HVWOepMQ@silver/

Quoted 15 lines

An observation is that we're using the 'netdev->type' field here which is an enum value, produced after QAPI has converted from its string form.

IOW, at this point in the code, we know that the user's specified type name was a valid network backend. The only possible scenario that can make the backend init function be NULL, is if support for that backend was disabled at build time. Given this, we don't need to caveat our error message with a 'maybe' hint, we can be totally explicit.

The use of QERR_INVALID_PARAMETER_VALUE doesn't really lend itself to user friendly error message text. Since this is not used to set a specific QAPI error class, we can simply stop using this pre-formatted error text and provide something better.

Quoted 4 lines

Thus the new message is:

qemu-system-x86_64: -net user: network backend 'user' is not compiled into
this binary

And why not naming the child, i.e. that QEMU was built without slirp?

Quoted 48 lines

The case of passing 'hubport' for -net is also given a message reminding people they should have used -netdev/-nic instead, as this backend type is only valid for the modern syntax.

---

NB, this does not make any difference to people who were relying on the QEMU built-in default hub that was created if you don't list any -net /

(quoted diff) +0 -1
-netdev / -nic argument, only those using explicit args.
 
 net/net.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
net/net.c +8 -8
index 2db160e063..8ddafacf13 100644
@@ -1036,19 +1036,23 @@ static int net_client_init1(const Netdev *netdev,
 bool is_netdev, Error **errp) if (is_netdev) {
         if (netdev->type == NET_CLIENT_DRIVER_NIC ||
             !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a netdev backend type");
+            error_setg(errp, "network backend '%s' is not compiled into
 this binary", +                       NetClientDriver_str(netdev->type));
             return -1;
         }
     } else {
         if (netdev->type == NET_CLIENT_DRIVER_NONE) {
             return 0; /* nothing to do */
         }
-        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT ||
-            !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a net backend type (maybe it is not compiled "
-                       "into this binary)");
+        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT) {
+            error_setg(errp, "network backend '%s' is only supported with
-netdev/-nic", +                       NetClientDriver_str(netdev->type));
+            return -1;
+        }
+
+        if (!net_client_init_fun[netdev->type]) {
+            error_setg(errp, "network backend '%s' is not compiled into
 this binary", +                       NetClientDriver_str(netdev->type));
             return -1;
         }
#3 lore raw
Quoted 8 lines · Christian Schoenebeck
Quoted 5 lines · On Montag, 3. Oktober 2022 12:06:12 CEST Daniel P. Berrangé wrote:

The current message when using '-net user...' with SLIRP disabled at compile time is:

qemu-system-x86_64: -net user: Parameter 'type' expects a net backend type
(maybe it is not compiled into this binary)

Is this intended as alternative to Marc-André's previous patch?

This is a patch that should be applied regardless of any other change, because the error message we report here today is awful and needs improving.

Quoted 3 lines

If yes, then
same applies here: what about people not passing any networking arg to QEMU? They would not get any error message at all, right?

Yes, I mentioned that in the text that you've quoted below....

Quoted 15 lines
Quoted 15 lines

An observation is that we're using the 'netdev->type' field here which is an enum value, produced after QAPI has converted from its string form.

IOW, at this point in the code, we know that the user's specified type name was a valid network backend. The only possible scenario that can make the backend init function be NULL, is if support for that backend was disabled at build time. Given this, we don't need to caveat our error message with a 'maybe' hint, we can be totally explicit.

The use of QERR_INVALID_PARAMETER_VALUE doesn't really lend itself to user friendly error message text. Since this is not used to set a specific QAPI error class, we can simply stop using this pre-formatted error text and provide something better.

Quoted 6 lines
Quoted 4 lines

Thus the new message is:

qemu-system-x86_64: -net user: network backend 'user' is not compiled into
this binary

And why not naming the child, i.e. that QEMU was built without slirp?

There are several network backends that can be conditionally disabled at build time, and IMHO its overkill to give a different message for each one. This message is sufficient to show users where to go next.

Quoted 11 lines
Quoted 11 lines

The case of passing 'hubport' for -net is also given a message reminding people they should have used -netdev/-nic instead, as this backend type is only valid for the modern syntax.

---

NB, this does not make any difference to people who were relying on the QEMU built-in default hub that was created if you don't list any -net / -netdev / -nic argument, only those using explicit args.

.... here.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#4 lore raw
Quoted 16 lines · On Montag, 3. Oktober 2022 14:50:04 CEST Daniel P. Berrangé wrote:
Quoted 10 lines · Christian Schoenebeck
Quoted 7 lines · On Montag, 3. Oktober 2022 12:06:12 CEST Daniel P. Berrangé wrote:

The current message when using '-net user...' with SLIRP disabled at

compile time is:
qemu-system-x86_64: -net user: Parameter 'type' expects a net backend type

(maybe it is not compiled into this binary)

Is this intended as alternative to Marc-André's previous patch?

This is a patch that should be applied regardless of any other change, because the error message we report here today is awful and needs improving.

Quoted 7 lines
Quoted 5 lines

If yes, then

same applies here: what about people not passing any networking arg to QEMU? They would not get any error message at all, right?

Yes, I mentioned that in the text that you've quoted below....

Yeah, missed that one, sorry.

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines

An observation is that we're using the 'netdev->type' field here which is an enum value, produced after QAPI has converted from its string form.

IOW, at this point in the code, we know that the user's specified type name was a valid network backend. The only possible scenario that can make the backend init function be NULL, is if support for that backend was disabled at build time. Given this, we don't need to caveat our error message with a 'maybe' hint, we can be totally explicit.

The use of QERR_INVALID_PARAMETER_VALUE doesn't really lend itself to user friendly error message text. Since this is not used to set a specific QAPI error class, we can simply stop using this pre-formatted error text and provide something better.

Thus the new message is:
qemu-system-x86_64: -net user: network backend 'user' is not compiled into

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

this binary

And why not naming the child, i.e. that QEMU was built without slirp?

There are several network backends that can be conditionally disabled at build time, and IMHO its overkill to give a different message for each one. This message is sufficient to show users where to go next.

Yes, but that is not a user friendly error message, especially for people who never dealt with QEMU's networking options before. That message does not make it obvious how to find the solution IMO.

What about a web link to the QEMU networking docs where this issue could then be clarified in a more user friendly manner? #anchors_are_cheap

Quoted 17 lines
Quoted 10 lines
Quoted 10 lines

The case of passing 'hubport' for -net is also given a message reminding people they should have used -netdev/-nic instead, as this backend type is only valid for the modern syntax.

---

NB, this does not make any difference to people who were relying on the QEMU built-in default hub that was created if you don't list any -net / -netdev / -nic argument, only those using explicit args.

.... here.

With regards,
Daniel

Reviewed-by on v1 1/1
#5 lore raw
In reply to Daniel P. Berrangé
Quoted 63 lines · Daniel P. Berrangé

The current message when using '-net user...' with SLIRP disabled at compile time is:

qemu-system-x86_64: -net user: Parameter 'type' expects a net backend type (maybe it is not compiled into this binary)

An observation is that we're using the 'netdev->type' field here which is an enum value, produced after QAPI has converted from its string form.

IOW, at this point in the code, we know that the user's specified type name was a valid network backend. The only possible scenario that can make the backend init function be NULL, is if support for that backend was disabled at build time. Given this, we don't need to caveat our error message with a 'maybe' hint, we can be totally explicit.

The use of QERR_INVALID_PARAMETER_VALUE doesn't really lend itself to user friendly error message text. Since this is not used to set a specific QAPI error class, we can simply stop using this pre-formatted error text and provide something better.

Thus the new message is:

qemu-system-x86_64: -net user: network backend 'user' is not compiled into this binary

The case of passing 'hubport' for -net is also given a message reminding people they should have used -netdev/-nic instead, as this backend type is only valid for the modern syntax.

---

NB, this does not make any difference to people who were relying on the QEMU built-in default hub that was created if you don't list any -net /

(quoted diff) +0 -1
-netdev / -nic argument, only those using explicit args.
 
  net/net.c | 18 +++++++++++-------
  1 file changed, 11 insertions(+), 7 deletions(-)
net/net.c +4 -7
index 2db160e063..8ddafacf13 100644
@@ -1036,19 +1036,23 @@ static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
      if (is_netdev) {
          if (netdev->type == NET_CLIENT_DRIVER_NIC ||
              !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a netdev backend type");
+            error_setg(errp, "network backend '%s' is not compiled into this binary",
+                       NetClientDriver_str(netdev->type));
              return -1;
          }
      } else {
          if (netdev->type == NET_CLIENT_DRIVER_NONE) {
              return 0; /* nothing to do */
          }
-        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT ||
-            !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a net backend type (maybe it is not compiled "
-                       "into this binary)");
+        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT) {
+            error_setg(errp, "network backend '%s' is only supported with -netdev/-nic",

net/net.c static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp) · line 1058

Quoted 10 lines
net/net.c +7 -0
+                       NetClientDriver_str(netdev->type));
+            return -1;
+        }
+
+        if (!net_client_init_fun[netdev->type]) {
+            error_setg(errp, "network backend '%s' is not compiled into this binary",
+                       NetClientDriver_str(netdev->type));
              return -1;
          }
 
#6 lore raw
In reply to Daniel P. Berrangé

ping: Jason, are you willing to queue this since it has two positive reviews.

Quoted 76 lines · Daniel P. Berrangé

The current message when using '-net user...' with SLIRP disabled at compile time is:

qemu-system-x86_64: -net user: Parameter 'type' expects a net backend type (maybe it is not compiled into this binary)

An observation is that we're using the 'netdev->type' field here which is an enum value, produced after QAPI has converted from its string form.

IOW, at this point in the code, we know that the user's specified type name was a valid network backend. The only possible scenario that can make the backend init function be NULL, is if support for that backend was disabled at build time. Given this, we don't need to caveat our error message with a 'maybe' hint, we can be totally explicit.

The use of QERR_INVALID_PARAMETER_VALUE doesn't really lend itself to user friendly error message text. Since this is not used to set a specific QAPI error class, we can simply stop using this pre-formatted error text and provide something better.

Thus the new message is:

qemu-system-x86_64: -net user: network backend 'user' is not compiled into this binary

The case of passing 'hubport' for -net is also given a message reminding people they should have used -netdev/-nic instead, as this backend type is only valid for the modern syntax.

---

NB, this does not make any difference to people who were relying on the QEMU built-in default hub that was created if you don't list any -net /

(quoted diff) +0 -1
-netdev / -nic argument, only those using explicit args.
 
 net/net.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
net/net.c +11 -7
index 2db160e063..8ddafacf13 100644
@@ -1036,19 +1036,23 @@ static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
     if (is_netdev) {
         if (netdev->type == NET_CLIENT_DRIVER_NIC ||
             !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a netdev backend type");
+            error_setg(errp, "network backend '%s' is not compiled into this binary",
+                       NetClientDriver_str(netdev->type));
             return -1;
         }
     } else {
         if (netdev->type == NET_CLIENT_DRIVER_NONE) {
             return 0; /* nothing to do */
         }
-        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT ||
-            !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a net backend type (maybe it is not compiled "
-                       "into this binary)");
+        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT) {
+            error_setg(errp, "network backend '%s' is only supported with -netdev/-nic",
+                       NetClientDriver_str(netdev->type));
+            return -1;
+        }
+
+        if (!net_client_init_fun[netdev->type]) {
+            error_setg(errp, "network backend '%s' is not compiled into this binary",
+                       NetClientDriver_str(netdev->type));
             return -1;
         }
 
Signature · 1 line
2.37.3

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw
Quoted 4 lines · Daniel P. Berrangé

ping: Jason, are you willing to queue this since it has two positive reviews.

Yes, I've queued this.

Thanks

Quoted 85 lines · Daniel P. Berrangé
Quoted 74 lines

The current message when using '-net user...' with SLIRP disabled at compile time is:

qemu-system-x86_64: -net user: Parameter 'type' expects a net backend type (maybe it is not compiled into this binary)

An observation is that we're using the 'netdev->type' field here which is an enum value, produced after QAPI has converted from its string form.

IOW, at this point in the code, we know that the user's specified type name was a valid network backend. The only possible scenario that can make the backend init function be NULL, is if support for that backend was disabled at build time. Given this, we don't need to caveat our error message with a 'maybe' hint, we can be totally explicit.

The use of QERR_INVALID_PARAMETER_VALUE doesn't really lend itself to user friendly error message text. Since this is not used to set a specific QAPI error class, we can simply stop using this pre-formatted error text and provide something better.

Thus the new message is:

qemu-system-x86_64: -net user: network backend 'user' is not compiled into this binary

The case of passing 'hubport' for -net is also given a message reminding people they should have used -netdev/-nic instead, as this backend type is only valid for the modern syntax.

---

NB, this does not make any difference to people who were relying on the QEMU built-in default hub that was created if you don't list any -net /

(quoted diff) +0 -1
-netdev / -nic argument, only those using explicit args.
 
 net/net.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
net/net.c +11 -8
index 2db160e063..8ddafacf13 100644
@@ -1036,19 +1036,23 @@ static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
     if (is_netdev) {
         if (netdev->type == NET_CLIENT_DRIVER_NIC ||
             !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a netdev backend type");
+            error_setg(errp, "network backend '%s' is not compiled into this binary",
+                       NetClientDriver_str(netdev->type));
             return -1;
         }
     } else {
         if (netdev->type == NET_CLIENT_DRIVER_NONE) {
             return 0; /* nothing to do */
         }
-        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT ||
-            !net_client_init_fun[netdev->type]) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a net backend type (maybe it is not compiled "
-                       "into this binary)");
+        if (netdev->type == NET_CLIENT_DRIVER_HUBPORT) {
+            error_setg(errp, "network backend '%s' is only supported with -netdev/-nic",
+                       NetClientDriver_str(netdev->type));
+            return -1;
+        }
+
+        if (!net_client_init_fun[netdev->type]) {
+            error_setg(errp, "network backend '%s' is not compiled into this binary",
+                       NetClientDriver_str(netdev->type));
             return -1;
         }
 
--
Quoted 2 lines

2.37.3

With regards,
Daniel
--

|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|