diff mbox

[15/16] convert net_init_bridge() to NetClientOptions

Message ID 1337683555-13301-16-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/tap.c |   23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)

Comments

Paolo Bonzini June 5, 2012, 9:05 p.m. UTC | #1
Il 22/05/2012 12:45, Laszlo Ersek ha scritto:
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  net/tap.c |   23 ++++++++++++-----------
>  1 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/net/tap.c b/net/tap.c
> index 7501eba..fdaab2b 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -512,21 +512,22 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
>      return -1;
>  }
>  
> -int net_init_bridge(QemuOpts *opts, const NetClientOptions *new_opts,
> +int net_init_bridge(QemuOpts *old_opts, const NetClientOptions *opts,
>                      const char *name, VLANState *vlan)
>  {
> +    const NetdevBridgeOptions *bridge;
> +    const char *helper, *br;
> +
>      TAPState *s;
>      int fd, vnet_hdr;
>  
> -    if (!qemu_opt_get(opts, "br")) {
> -        qemu_opt_set(opts, "br", DEFAULT_BRIDGE_INTERFACE);
> -    }
> -    if (!qemu_opt_get(opts, "helper")) {
> -        qemu_opt_set(opts, "helper", DEFAULT_BRIDGE_HELPER);
> -    }
> +    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_BRIDGE);
> +    bridge = opts->bridge;
> +
> +    helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
> +    br     = bridge->has_br     ? bridge->br     : DEFAULT_BRIDGE_INTERFACE;

Don't hate me for this, but why not do the same for strdup calls?

    foo = bar->has_foo ? g_strdup(bar->foo) : NULL;

earlier in the series?

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo
Laszlo Ersek June 6, 2012, 12:16 p.m. UTC | #2
On 06/05/12 23:05, Paolo Bonzini wrote:
> Il 22/05/2012 12:45, Laszlo Ersek ha scritto:
>> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
>> ---
>>  net/tap.c |   23 ++++++++++++-----------
>>  1 files changed, 12 insertions(+), 11 deletions(-)
>>
>> diff --git a/net/tap.c b/net/tap.c
>> index 7501eba..fdaab2b 100644
>> --- a/net/tap.c
>> +++ b/net/tap.c
>> @@ -512,21 +512,22 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
>>      return -1;
>>  }
>>  
>> -int net_init_bridge(QemuOpts *opts, const NetClientOptions *new_opts,
>> +int net_init_bridge(QemuOpts *old_opts, const NetClientOptions *opts,
>>                      const char *name, VLANState *vlan)
>>  {
>> +    const NetdevBridgeOptions *bridge;
>> +    const char *helper, *br;
>> +
>>      TAPState *s;
>>      int fd, vnet_hdr;
>>  
>> -    if (!qemu_opt_get(opts, "br")) {
>> -        qemu_opt_set(opts, "br", DEFAULT_BRIDGE_INTERFACE);
>> -    }
>> -    if (!qemu_opt_get(opts, "helper")) {
>> -        qemu_opt_set(opts, "helper", DEFAULT_BRIDGE_HELPER);
>> -    }
>> +    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_BRIDGE);
>> +    bridge = opts->bridge;
>> +
>> +    helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
>> +    br     = bridge->has_br     ? bridge->br     : DEFAULT_BRIDGE_INTERFACE;
> 
> Don't hate me for this, but why not do the same for strdup calls?
> 
>     foo = bar->has_foo ? g_strdup(bar->foo) : NULL;
> 
> earlier in the series?

(I think you mean net_init_nic() in [PATCH 09/16] "convert
net_init_nic() to NetClientOptions".)

I didn't deliberately avoid the conditional operator there. The
net_init_nic() structure seemed OK; it sets all such pointers to
all-bits-zero in a batch (memset()) and only changes those whose
corresponding optarg (QemuOpt) is set. It seemed natural and didn't
summon ?: to my mind.

net_init_bridge() OTOH sets the defaults too on a case-by-case basis,
and it was screaming after ?:.

... No hate whatsoever :)

Laszlo
Paolo Bonzini June 6, 2012, 2:13 p.m. UTC | #3
Il 06/06/2012 14:16, Laszlo Ersek ha scritto:
> The net_init_nic() structure seemed OK; it sets all such pointers to 
> all-bits-zero in a batch (memset()) and only changes those whose 
> corresponding optarg (QemuOpt) is set.

Makes sense.

Paolo
diff mbox

Patch

diff --git a/net/tap.c b/net/tap.c
index 7501eba..fdaab2b 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -512,21 +512,22 @@  static int net_bridge_run_helper(const char *helper, const char *bridge)
     return -1;
 }
 
-int net_init_bridge(QemuOpts *opts, const NetClientOptions *new_opts,
+int net_init_bridge(QemuOpts *old_opts, const NetClientOptions *opts,
                     const char *name, VLANState *vlan)
 {
+    const NetdevBridgeOptions *bridge;
+    const char *helper, *br;
+
     TAPState *s;
     int fd, vnet_hdr;
 
-    if (!qemu_opt_get(opts, "br")) {
-        qemu_opt_set(opts, "br", DEFAULT_BRIDGE_INTERFACE);
-    }
-    if (!qemu_opt_get(opts, "helper")) {
-        qemu_opt_set(opts, "helper", DEFAULT_BRIDGE_HELPER);
-    }
+    assert(opts->kind == NET_CLIENT_OPTIONS_KIND_BRIDGE);
+    bridge = opts->bridge;
+
+    helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
+    br     = bridge->has_br     ? bridge->br     : DEFAULT_BRIDGE_INTERFACE;
 
-    fd = net_bridge_run_helper(qemu_opt_get(opts, "helper"),
-                               qemu_opt_get(opts, "br"));
+    fd = net_bridge_run_helper(helper, br);
     if (fd == -1) {
         return -1;
     }
@@ -541,8 +542,8 @@  int net_init_bridge(QemuOpts *opts, const NetClientOptions *new_opts,
         return -1;
     }
 
-    snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s",
-             qemu_opt_get(opts, "helper"), qemu_opt_get(opts, "br"));
+    snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper,
+             br);
 
     return 0;
 }