diff mbox

[13/16] convert net_init_vde() to NetClientOptions

Message ID 1337683555-13301-14-git-send-email-lersek@redhat.com
State New
Headers show

Commit Message

Laszlo Ersek May 22, 2012, 10:45 a.m. UTC
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 net/vde.c |   37 +++++++++++++++++++++++++++++--------
 1 files changed, 29 insertions(+), 8 deletions(-)

Comments

Paolo Bonzini June 5, 2012, 9:04 p.m. UTC | #1
Il 22/05/2012 12:45, Laszlo Ersek ha scritto:
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  net/vde.c |   37 +++++++++++++++++++++++++++++--------
>  1 files changed, 29 insertions(+), 8 deletions(-)
> 
> diff --git a/net/vde.c b/net/vde.c
> index 8e60f68..35e8113 100644
> --- a/net/vde.c
> +++ b/net/vde.c
> @@ -110,20 +110,41 @@ static int net_vde_init(VLANState *vlan, const char *model,
>      return 0;
>  }
>  
> -int net_init_vde(QemuOpts *opts, const NetClientOptions *new_opts,
> +int net_init_vde(QemuOpts *old_opts, const NetClientOptions *opts,
>                   const char *name, VLANState *vlan)
>  {
> -    const char *sock;
> -    const char *group;
>      int port, mode;
>  
> -    sock  = qemu_opt_get(opts, "sock");
> -    group = qemu_opt_get(opts, "group");
> +    const NetdevVdeOptions *vde;
>  
> -    port = qemu_opt_get_number(opts, "port", 0);
> -    mode = qemu_opt_get_number(opts, "mode", 0700);
> +    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_VDE);
> +    vde = opts->vde;
>  
> -    if (net_vde_init(vlan, "vde", name, sock, port, group, mode) == -1) {
> +    if (vde->has_port) {
> +        if (vde->port > INT_MAX) {
> +            error_report("invalid port: %"PRId64, vde->port);
> +            return -1;
> +        }
> +        port = vde->port;
> +    }
> +    else {
> +        port = 0;
> +    }
> +
> +    if (vde->has_mode) {
> +        if (vde->mode > INT_MAX) {
> +            error_report("invalid mode: %"PRId64, vde->mode);
> +            return -1;
> +        }
> +        mode = vde->mode;
> +    }
> +    else {
> +        mode = 0700;
> +    }
> +
> +    /* missing optional values have been initialized to "all bits zero" */
> +    if (net_vde_init(vlan, "vde", name, vde->sock, port, vde->group, mode) ==
> +         -1) {
>          return -1;
>      }
>  

Same observation about checking < 0.

I wonder if it works to declare all these fields to be int32 in the
schema?  That would simplify the series nicely.

Paolo
diff mbox

Patch

diff --git a/net/vde.c b/net/vde.c
index 8e60f68..35e8113 100644
--- a/net/vde.c
+++ b/net/vde.c
@@ -110,20 +110,41 @@  static int net_vde_init(VLANState *vlan, const char *model,
     return 0;
 }
 
-int net_init_vde(QemuOpts *opts, const NetClientOptions *new_opts,
+int net_init_vde(QemuOpts *old_opts, const NetClientOptions *opts,
                  const char *name, VLANState *vlan)
 {
-    const char *sock;
-    const char *group;
     int port, mode;
 
-    sock  = qemu_opt_get(opts, "sock");
-    group = qemu_opt_get(opts, "group");
+    const NetdevVdeOptions *vde;
 
-    port = qemu_opt_get_number(opts, "port", 0);
-    mode = qemu_opt_get_number(opts, "mode", 0700);
+    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_VDE);
+    vde = opts->vde;
 
-    if (net_vde_init(vlan, "vde", name, sock, port, group, mode) == -1) {
+    if (vde->has_port) {
+        if (vde->port > INT_MAX) {
+            error_report("invalid port: %"PRId64, vde->port);
+            return -1;
+        }
+        port = vde->port;
+    }
+    else {
+        port = 0;
+    }
+
+    if (vde->has_mode) {
+        if (vde->mode > INT_MAX) {
+            error_report("invalid mode: %"PRId64, vde->mode);
+            return -1;
+        }
+        mode = vde->mode;
+    }
+    else {
+        mode = 0700;
+    }
+
+    /* missing optional values have been initialized to "all bits zero" */
+    if (net_vde_init(vlan, "vde", name, vde->sock, port, vde->group, mode) ==
+         -1) {
         return -1;
     }