qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/5] Net patches
@ 2015-06-24 15:37 Stefan Hajnoczi
  2015-06-24 15:37 ` [Qemu-devel] [PULL 1/5] net: add missing "netmap" to host_net_devices[] Stefan Hajnoczi
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2015-06-24 15:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi

The following changes since commit a3206972a9eab65ec8e8f9ae320ad628ba4b58f1:

  Merge remote-tracking branch 'remotes/armbru/tags/pull-monitor-2015-06-22' into staging (2015-06-23 10:38:00 +0100)

are available in the git repository at:

  git://github.com/stefanha/qemu.git tags/net-pull-request

for you to fetch changes up to 1e81aba5ac0b908ab859bf8ddf43ece33732d49c:

  net: simplify net_client_init1() (2015-06-24 16:33:42 +0100)

----------------------------------------------------------------

----------------------------------------------------------------

Stefan Hajnoczi (5):
  net: add missing "netmap" to host_net_devices[]
  net: replace net_client_init1() netdev whitelist with blacklist
  net: raise an error if -net type is invalid
  net: drop if expression that is always true
  net: simplify net_client_init1()

 net/net.c | 91 ++++++++++++++++++++++++++-------------------------------------
 1 file changed, 37 insertions(+), 54 deletions(-)

-- 
2.4.3

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

* [Qemu-devel] [PULL 1/5] net: add missing "netmap" to host_net_devices[]
  2015-06-24 15:37 [Qemu-devel] [PULL 0/5] Net patches Stefan Hajnoczi
@ 2015-06-24 15:37 ` Stefan Hajnoczi
  2015-06-24 15:37 ` [Qemu-devel] [PULL 2/5] net: replace net_client_init1() netdev whitelist with blacklist Stefan Hajnoczi
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2015-06-24 15:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi

Although hmp-commands.hx lists "netmap" as a valid host_net_add type,
the command rejects it because it's missing from the list.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1432743412-15943-2-git-send-email-stefanha@redhat.com
---
 net/net.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/net.c b/net/net.c
index cc36c7b..f43af97 100644
--- a/net/net.c
+++ b/net/net.c
@@ -60,6 +60,9 @@ const char *host_net_devices[] = {
 #ifdef CONFIG_NET_BRIDGE
     "bridge",
 #endif
+#ifdef CONFIG_NETMAP
+    "netmap",
+#endif
 #ifdef CONFIG_SLIRP
     "user",
 #endif
-- 
2.4.3

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

* [Qemu-devel] [PULL 2/5] net: replace net_client_init1() netdev whitelist with blacklist
  2015-06-24 15:37 [Qemu-devel] [PULL 0/5] Net patches Stefan Hajnoczi
  2015-06-24 15:37 ` [Qemu-devel] [PULL 1/5] net: add missing "netmap" to host_net_devices[] Stefan Hajnoczi
@ 2015-06-24 15:37 ` Stefan Hajnoczi
  2015-06-24 15:37 ` [Qemu-devel] [PULL 3/5] net: raise an error if -net type is invalid Stefan Hajnoczi
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2015-06-24 15:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi

It's cumbersome to keep the whitelist up-to-date.  New netdev backends
should most likely be allowed so a blacklist makes more sense than a
whitelist.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-id: 1432743412-15943-3-git-send-email-stefanha@redhat.com
---
 net/net.c | 28 +++-------------------------
 1 file changed, 3 insertions(+), 25 deletions(-)

diff --git a/net/net.c b/net/net.c
index f43af97..63450c0 100644
--- a/net/net.c
+++ b/net/net.c
@@ -925,31 +925,9 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
         opts = u.netdev->opts;
         name = u.netdev->id;
 
-        switch (opts->kind) {
-#ifdef CONFIG_SLIRP
-        case NET_CLIENT_OPTIONS_KIND_USER:
-#endif
-        case NET_CLIENT_OPTIONS_KIND_TAP:
-        case NET_CLIENT_OPTIONS_KIND_SOCKET:
-#ifdef CONFIG_VDE
-        case NET_CLIENT_OPTIONS_KIND_VDE:
-#endif
-#ifdef CONFIG_NETMAP
-        case NET_CLIENT_OPTIONS_KIND_NETMAP:
-#endif
-#ifdef CONFIG_NET_BRIDGE
-        case NET_CLIENT_OPTIONS_KIND_BRIDGE:
-#endif
-        case NET_CLIENT_OPTIONS_KIND_HUBPORT:
-#ifdef CONFIG_VHOST_NET_USED
-        case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
-#endif
-#ifdef CONFIG_L2TPV3
-        case NET_CLIENT_OPTIONS_KIND_L2TPV3:
-#endif
-            break;
-
-        default:
+        if (opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP ||
+            opts->kind == NET_CLIENT_OPTIONS_KIND_NIC ||
+            !net_client_init_fun[opts->kind]) {
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
                        "a netdev backend type");
             return -1;
-- 
2.4.3

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

* [Qemu-devel] [PULL 3/5] net: raise an error if -net type is invalid
  2015-06-24 15:37 [Qemu-devel] [PULL 0/5] Net patches Stefan Hajnoczi
  2015-06-24 15:37 ` [Qemu-devel] [PULL 1/5] net: add missing "netmap" to host_net_devices[] Stefan Hajnoczi
  2015-06-24 15:37 ` [Qemu-devel] [PULL 2/5] net: replace net_client_init1() netdev whitelist with blacklist Stefan Hajnoczi
@ 2015-06-24 15:37 ` Stefan Hajnoczi
  2015-06-24 15:37 ` [Qemu-devel] [PULL 4/5] net: drop if expression that is always true Stefan Hajnoczi
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2015-06-24 15:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi

When a -net type is used that was not compiled into the binary there
should be an error message.

Note the special case for -net none, which is a no-op.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-id: 1432743412-15943-4-git-send-email-stefanha@redhat.com
---
 net/net.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/net/net.c b/net/net.c
index 63450c0..7c1b203 100644
--- a/net/net.c
+++ b/net/net.c
@@ -942,6 +942,17 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
         }
         /* missing optional values have been initialized to "all bits zero" */
         name = u.net->has_id ? u.net->id : u.net->name;
+
+        if (opts->kind == NET_CLIENT_OPTIONS_KIND_NONE) {
+            return 0; /* nothing to do */
+        }
+
+        if (!net_client_init_fun[opts->kind]) {
+            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
+                       "a net backend type (maybe it is not compiled "
+                       "into this binary)");
+            return -1;
+        }
     }
 
     if (net_client_init_fun[opts->kind]) {
-- 
2.4.3

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

* [Qemu-devel] [PULL 4/5] net: drop if expression that is always true
  2015-06-24 15:37 [Qemu-devel] [PULL 0/5] Net patches Stefan Hajnoczi
                   ` (2 preceding siblings ...)
  2015-06-24 15:37 ` [Qemu-devel] [PULL 3/5] net: raise an error if -net type is invalid Stefan Hajnoczi
@ 2015-06-24 15:37 ` Stefan Hajnoczi
  2015-06-24 15:37 ` [Qemu-devel] [PULL 5/5] net: simplify net_client_init1() Stefan Hajnoczi
  2015-06-25 14:23 ` [Qemu-devel] [PULL 0/5] Net patches Peter Maydell
  5 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2015-06-24 15:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi

Both is_netdev and !is_netdev paths already check that
net_client_init_func[opts->kind] is non-NULL so there is no need for the
if statement.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-id: 1432743412-15943-5-git-send-email-stefanha@redhat.com
---
 net/net.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/net/net.c b/net/net.c
index 7c1b203..8e5b6f6 100644
--- a/net/net.c
+++ b/net/net.c
@@ -919,6 +919,7 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
     } u;
     const NetClientOptions *opts;
     const char *name;
+    NetClientState *peer = NULL;
 
     if (is_netdev) {
         u.netdev = object;
@@ -955,25 +956,21 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
         }
     }
 
-    if (net_client_init_fun[opts->kind]) {
-        NetClientState *peer = NULL;
+    /* Do not add to a vlan if it's a -netdev or a nic with a netdev=
+     * parameter. */
+    if (!is_netdev &&
+        (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
+         !opts->nic->has_netdev)) {
+        peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL);
+    }
 
-        /* Do not add to a vlan if it's a -netdev or a nic with a netdev=
-         * parameter. */
-        if (!is_netdev &&
-            (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
-             !opts->nic->has_netdev)) {
-            peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL);
-        }
-
-        if (net_client_init_fun[opts->kind](opts, name, peer, errp) < 0) {
-            /* FIXME drop when all init functions store an Error */
-            if (errp && !*errp) {
-                error_setg(errp, QERR_DEVICE_INIT_FAILED,
-                           NetClientOptionsKind_lookup[opts->kind]);
-            }
-            return -1;
+    if (net_client_init_fun[opts->kind](opts, name, peer, errp) < 0) {
+        /* FIXME drop when all init functions store an Error */
+        if (errp && !*errp) {
+            error_setg(errp, QERR_DEVICE_INIT_FAILED,
+                       NetClientOptionsKind_lookup[opts->kind]);
         }
+        return -1;
     }
     return 0;
 }
-- 
2.4.3

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

* [Qemu-devel] [PULL 5/5] net: simplify net_client_init1()
  2015-06-24 15:37 [Qemu-devel] [PULL 0/5] Net patches Stefan Hajnoczi
                   ` (3 preceding siblings ...)
  2015-06-24 15:37 ` [Qemu-devel] [PULL 4/5] net: drop if expression that is always true Stefan Hajnoczi
@ 2015-06-24 15:37 ` Stefan Hajnoczi
  2015-06-25 14:23 ` [Qemu-devel] [PULL 0/5] Net patches Peter Maydell
  5 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2015-06-24 15:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi

Drop the union and move the hubport creation into the !is_netdev case.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-id: 1432743412-15943-6-git-send-email-stefanha@redhat.com
---
 net/net.c | 38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/net/net.c b/net/net.c
index 8e5b6f6..6ff7fec 100644
--- a/net/net.c
+++ b/net/net.c
@@ -913,18 +913,14 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
 
 static int net_client_init1(const void *object, int is_netdev, Error **errp)
 {
-    union {
-        const Netdev    *netdev;
-        const NetLegacy *net;
-    } u;
     const NetClientOptions *opts;
     const char *name;
     NetClientState *peer = NULL;
 
     if (is_netdev) {
-        u.netdev = object;
-        opts = u.netdev->opts;
-        name = u.netdev->id;
+        const Netdev *netdev = object;
+        opts = netdev->opts;
+        name = netdev->id;
 
         if (opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP ||
             opts->kind == NET_CLIENT_OPTIONS_KIND_NIC ||
@@ -934,19 +930,19 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
             return -1;
         }
     } else {
-        u.net = object;
-        opts = u.net->opts;
-        if (opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT) {
-            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
-                       "a net type");
-            return -1;
-        }
+        const NetLegacy *net = object;
+        opts = net->opts;
         /* missing optional values have been initialized to "all bits zero" */
-        name = u.net->has_id ? u.net->id : u.net->name;
+        name = net->has_id ? net->id : net->name;
 
         if (opts->kind == NET_CLIENT_OPTIONS_KIND_NONE) {
             return 0; /* nothing to do */
         }
+        if (opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT) {
+            error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
+                       "a net type");
+            return -1;
+        }
 
         if (!net_client_init_fun[opts->kind]) {
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
@@ -954,14 +950,12 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
                        "into this binary)");
             return -1;
         }
-    }
 
-    /* Do not add to a vlan if it's a -netdev or a nic with a netdev=
-     * parameter. */
-    if (!is_netdev &&
-        (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
-         !opts->nic->has_netdev)) {
-        peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL);
+        /* Do not add to a vlan if it's a nic with a netdev= parameter. */
+        if (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
+            !opts->nic->has_netdev) {
+            peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL);
+        }
     }
 
     if (net_client_init_fun[opts->kind](opts, name, peer, errp) < 0) {
-- 
2.4.3

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

* Re: [Qemu-devel] [PULL 0/5] Net patches
  2015-06-24 15:37 [Qemu-devel] [PULL 0/5] Net patches Stefan Hajnoczi
                   ` (4 preceding siblings ...)
  2015-06-24 15:37 ` [Qemu-devel] [PULL 5/5] net: simplify net_client_init1() Stefan Hajnoczi
@ 2015-06-25 14:23 ` Peter Maydell
  5 siblings, 0 replies; 7+ messages in thread
From: Peter Maydell @ 2015-06-25 14:23 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: QEMU Developers

On 24 June 2015 at 16:37, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> The following changes since commit a3206972a9eab65ec8e8f9ae320ad628ba4b58f1:
>
>   Merge remote-tracking branch 'remotes/armbru/tags/pull-monitor-2015-06-22' into staging (2015-06-23 10:38:00 +0100)
>
> are available in the git repository at:
>
>   git://github.com/stefanha/qemu.git tags/net-pull-request
>
> for you to fetch changes up to 1e81aba5ac0b908ab859bf8ddf43ece33732d49c:
>
>   net: simplify net_client_init1() (2015-06-24 16:33:42 +0100)
>
> ----------------------------------------------------------------
>
> ----------------------------------------------------------------
>
> Stefan Hajnoczi (5):
>   net: add missing "netmap" to host_net_devices[]
>   net: replace net_client_init1() netdev whitelist with blacklist
>   net: raise an error if -net type is invalid
>   net: drop if expression that is always true
>   net: simplify net_client_init1()

Applied, thanks.

-- PMM

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

end of thread, other threads:[~2015-06-25 14:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-24 15:37 [Qemu-devel] [PULL 0/5] Net patches Stefan Hajnoczi
2015-06-24 15:37 ` [Qemu-devel] [PULL 1/5] net: add missing "netmap" to host_net_devices[] Stefan Hajnoczi
2015-06-24 15:37 ` [Qemu-devel] [PULL 2/5] net: replace net_client_init1() netdev whitelist with blacklist Stefan Hajnoczi
2015-06-24 15:37 ` [Qemu-devel] [PULL 3/5] net: raise an error if -net type is invalid Stefan Hajnoczi
2015-06-24 15:37 ` [Qemu-devel] [PULL 4/5] net: drop if expression that is always true Stefan Hajnoczi
2015-06-24 15:37 ` [Qemu-devel] [PULL 5/5] net: simplify net_client_init1() Stefan Hajnoczi
2015-06-25 14:23 ` [Qemu-devel] [PULL 0/5] Net patches Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).