diff mbox

[01/15] net: Improve error message for -net hubport a bit

Message ID 1431432187-10993-2-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster May 12, 2015, 12:02 p.m. UTC
Type "hubport" is valid only with -netdev.  Unfortunately, that's
detected late and the error message doesn't explain why:

    $ qemu-system-i386 -net hubport,id=foo,hubid=0
    qemu-system-i386: -net hubport,id=foo,hubid=0: Device 'hubport' could not be initialized

Improve the error message to "Parameter 'type' expects a net type".

Not fixed: -net hubport without the parameters required by -netdev
hubport still asks for those parameters:

    $ qemu-system-i386 -net hubport
    qemu-system-i386: -net hubport: Parameter 'hubid' is missing

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 net/hub.c | 5 +----
 net/net.c | 5 +++++
 2 files changed, 6 insertions(+), 4 deletions(-)

Comments

Eric Blake May 14, 2015, 3:13 p.m. UTC | #1
On 05/12/2015 06:02 AM, Markus Armbruster wrote:
> Type "hubport" is valid only with -netdev.  Unfortunately, that's
> detected late and the error message doesn't explain why:
> 
>     $ qemu-system-i386 -net hubport,id=foo,hubid=0
>     qemu-system-i386: -net hubport,id=foo,hubid=0: Device 'hubport' could not be initialized
> 
> Improve the error message to "Parameter 'type' expects a net type".
> 
> Not fixed: -net hubport without the parameters required by -netdev
> hubport still asks for those parameters:
> 
>     $ qemu-system-i386 -net hubport
>     qemu-system-i386: -net hubport: Parameter 'hubid' is missing
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  net/hub.c | 5 +----
>  net/net.c | 5 +++++
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/net/hub.c b/net/hub.c
index 2b60ab9..261f8cc 100644
--- a/net/hub.c
+++ b/net/hub.c
@@ -286,12 +286,9 @@  int net_init_hubport(const NetClientOptions *opts, const char *name,
     const NetdevHubPortOptions *hubport;
 
     assert(opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT);
+    assert(!peer);
     hubport = opts->hubport;
 
-    if (peer) {
-        return -EINVAL;
-    }
-
     net_hub_add_port(hubport->hubid, name);
     return 0;
 }
diff --git a/net/net.c b/net/net.c
index 0be084d..06affd6 100644
--- a/net/net.c
+++ b/net/net.c
@@ -875,6 +875,11 @@  static int net_client_init1(const void *object, int is_netdev, Error **errp)
     } else {
         u.net = object;
         opts = u.net->opts;
+        if (opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT) {
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "type",
+                      "a net type");
+            return -1;
+        }
         /* missing optional values have been initialized to "all bits zero" */
         name = u.net->has_id ? u.net->id : u.net->name;
     }