All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	afaerber@suse.de, qemu-devel@nongnu.org,
	Stefan Hajnoczi <stefanha@redhat.com>,
	mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH V2] net: don't use set/get_pointer() in set/get_netdev()
Date: Mon, 13 Oct 2014 11:31:16 +0800	[thread overview]
Message-ID: <543B4784.4030603@redhat.com> (raw)
In-Reply-To: <87bnpkkrfn.fsf@blackfin.pond.sub.org>

On 10/10/2014 09:03 PM, Markus Armbruster wrote:
> Jason Wang <jasowang@redhat.com> writes:
>
>> Commit 1ceef9f27359cbe92ef124bf74de6f792e71f6fb (net: multiqueue
>> support) tries to use set_pointer() and get_pointer() to set and get
>> NICPeers which is not a pointer defined in DEFINE_PROP_NETDEV. This
>> trick works but result a unclean and fragile implementation (e.g
>> print_netdev and parse_netdev).
>>
>> This patch solves this issue by not using set/get_pinter() and set and
>> get netdev directly in set_netdev() and get_netdev(). After this the
>> parse_netdev() and print_netdev() were no longer used and dropped from
>> the source.
>>
>> Cc: Markus Armbruster <armbru@redhat.com>
>> Cc: Stefan Hajnoczi <stefanha@redhat.com>
>> Cc: Peter Maydell <peter.maydell@linaro.org>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>> Changes from V1:
>> - validate ncs pointer before accessing them, this fixes the qtest failure
>>   on arm.
>> ---
>>  hw/core/qdev-properties-system.c | 71 ++++++++++++++++++++++------------------
>>  1 file changed, 39 insertions(+), 32 deletions(-)
>>
>> diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
>> index ae0900f..6939ea5 100644
>> --- a/hw/core/qdev-properties-system.c
>> +++ b/hw/core/qdev-properties-system.c
>> @@ -176,41 +176,67 @@ PropertyInfo qdev_prop_chr = {
>>  };
>>  
>>  /* --- netdev device --- */
>> +static void get_netdev(Object *obj, Visitor *v, void *opaque,
>> +                       const char *name, Error **errp)
>> +{
>> +    DeviceState *dev = DEVICE(obj);
>> +    Property *prop = opaque;
>> +    NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
>> +    char *p = g_strdup(peers_ptr->ncs[0] ? peers_ptr->ncs[0]->name : "");
> Can ->ncs[0]->name ever be null?

Seems not, id is mandatory for netdev.
>
>>  
>> -static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
>> +    visit_type_str(v, &p, name, errp);
>> +    g_free(p);
>> +}
>> +
>> +static void set_netdev(Object *obj, Visitor *v, void *opaque,
>> +                       const char *name, Error **errp)
>>  {
>> -    NICPeers *peers_ptr = (NICPeers *)ptr;
>> +    DeviceState *dev = DEVICE(obj);
>> +    Property *prop = opaque;
>> +    NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
>>      NetClientState **ncs = peers_ptr->ncs;
>>      NetClientState *peers[MAX_QUEUE_NUM];
>> -    int queues, i = 0;
>> -    int ret;
>> +    Error *local_err = NULL;
>> +    int err, queues, i = 0;
>> +    char *str;
>> +
>> +    if (dev->realized) {
>> +        qdev_prop_set_after_realize(dev, name, errp);
>> +        return;
>> +    }
>> +
>> +    visit_type_str(v, &str, name, &local_err);
>> +    if (local_err) {
>> +        error_propagate(errp, local_err);
>> +        return;
>> +    }
>>  
>>      queues = qemu_find_net_clients_except(str, peers,
>>                                            NET_CLIENT_OPTIONS_KIND_NIC,
>>                                            MAX_QUEUE_NUM);
>>      if (queues == 0) {
>> -        ret = -ENOENT;
>> +        err = -ENOENT;
>>          goto err;
>>      }
>>  
>>      if (queues > MAX_QUEUE_NUM) {
>> -        ret = -E2BIG;
>> +        err = -E2BIG;
> error_set_from_qdev_prop_error() does not accept -E2BIG.
>
> You could call error_setg(...) directly instead.

Ok.
>>          goto err;
>>      }
>>  
>>      for (i = 0; i < queues; i++) {
>>          if (peers[i] == NULL) {
>> -            ret = -ENOENT;
>> +            err = -ENOENT;
>>              goto err;
>>          }
>>  
>>          if (peers[i]->peer) {
>> -            ret = -EEXIST;
>> +            err = -EEXIST;
>>              goto err;
>>          }
>>  
>>          if (ncs[i]) {
>> -            ret = -EINVAL;
>> +            err = -EINVAL;
> error_set_from_qdev_prop_error() does not accept -EINVAL, either.

Ok.
>>              goto err;
>>          }
>>  
>> @@ -219,31 +245,12 @@ static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
>>      }
>>  
>>      peers_ptr->queues = queues;
>> -
>> -    return 0;
>> +    g_free(str);
>> +    return;
>>  
>>  err:
> Label err clashes with local variable err.  Harmless, but maybe you'd
> like to rename one of them.

It was used in "error_set_from_qdev_prop_error(errp, err, dev, prop, str);"
>> -    return ret;
>> -}
>> -
>> -static char *print_netdev(void *ptr)
>> -{
>> -    NetClientState *netdev = ptr;
>> -    const char *val = netdev->name ? netdev->name : "";
>> -
>> -    return g_strdup(val);
>> -}
>> -
>> -static void get_netdev(Object *obj, Visitor *v, void *opaque,
>> -                       const char *name, Error **errp)
>> -{
>> -    get_pointer(obj, v, opaque, print_netdev, name, errp);
>> -}
>> -
>> -static void set_netdev(Object *obj, Visitor *v, void *opaque,
>> -                       const char *name, Error **errp)
>> -{
>> -    set_pointer(obj, v, opaque, parse_netdev, name, errp);
>> +    error_set_from_qdev_prop_error(errp, err, dev, prop, str);
>> +    g_free(str);
>>  }
>>  
>>  PropertyInfo qdev_prop_netdev = {
> Instead of
>
>         g_free(str);
>         return;
>
>     err:
>         error_set_from_qdev_prop_error(errp, err, dev, prop, str);
>         g_free(str);
>     }
>
> You could exploit that error_set_from_qdev_prop_error() does nothing
> when err is 0:
>
>     out:
>         g_free(str);
>         error_set_from_qdev_prop_error(errp, err, dev, prop, str);
>         g_free(str);
>     }

This looks more clean, will do.

Thanks

  reply	other threads:[~2014-10-13  3:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-09  3:10 [Qemu-devel] [PATCH V2] net: don't use set/get_pointer() in set/get_netdev() Jason Wang
2014-10-10 13:03 ` Markus Armbruster
2014-10-13  3:31   ` Jason Wang [this message]
2014-10-13  4:53     ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=543B4784.4030603@redhat.com \
    --to=jasowang@redhat.com \
    --cc=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.