All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH V3] net: don't use set/get_pointer() in set/get_netdev()
@ 2014-10-13  5:16 Jason Wang
  2014-12-19  9:15 ` Markus Armbruster
  2014-12-19 11:31 ` Stefan Hajnoczi
  0 siblings, 2 replies; 3+ messages in thread
From: Jason Wang @ 2014-10-13  5:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Jason Wang, Markus Armbruster, Stefan Hajnoczi, mst

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 V2:
- Use error_setg() instead of error_set_from_qdev_prop_error() for E2BIG error.
- Clean the return part of the set_netdev() since
  eror_set_from_qdev_prop_error() does nothing when err is 0.
Changes from V1:
- validate ncs pointer before accessing them, this fixes the qtest failure
  on arm.
---
 hw/core/qdev-properties-system.c | 70 ++++++++++++++++++++++------------------
 1 file changed, 38 insertions(+), 32 deletions(-)

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 84caa1d..03a6e68 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -176,41 +176,68 @@ 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 : "");
 
-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 queues, err = 0, 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;
+        error_setg(errp, "queues of backend '%s'(%d) exceeds QEMU limitation(%d)",
+                   str, queues, MAX_QUEUE_NUM);
         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;
             goto err;
         }
 
@@ -220,30 +247,9 @@ static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
 
     peers_ptr->queues = queues;
 
-    return 0;
-
 err:
-    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 = {
-- 
1.8.3.1

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

* Re: [Qemu-devel] [PATCH V3] net: don't use set/get_pointer() in set/get_netdev()
  2014-10-13  5:16 [Qemu-devel] [PATCH V3] net: don't use set/get_pointer() in set/get_netdev() Jason Wang
@ 2014-12-19  9:15 ` Markus Armbruster
  2014-12-19 11:31 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2014-12-19  9:15 UTC (permalink / raw)
  To: Jason Wang; +Cc: Peter Maydell, qemu-devel, Stefan Hajnoczi, mst

This one fell through the cracks, sorry.

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 V2:
> - Use error_setg() instead of error_set_from_qdev_prop_error() for E2BIG error.
> - Clean the return part of the set_netdev() since
>   eror_set_from_qdev_prop_error() does nothing when err is 0.
> Changes from V1:
> - validate ncs pointer before accessing them, this fixes the qtest failure
>   on arm.
> ---
>  hw/core/qdev-properties-system.c | 70 ++++++++++++++++++++++------------------
>  1 file changed, 38 insertions(+), 32 deletions(-)
>
> diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
> index 84caa1d..03a6e68 100644
> --- a/hw/core/qdev-properties-system.c
> +++ b/hw/core/qdev-properties-system.c
> @@ -176,41 +176,68 @@ 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 : "");
>  
> -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 queues, err = 0, 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;
> +        error_setg(errp, "queues of backend '%s'(%d) exceeds QEMU limitation(%d)",
> +                   str, queues, MAX_QUEUE_NUM);
>          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;
>              goto err;
>          }
>  
> @@ -220,30 +247,9 @@ static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
>  
>      peers_ptr->queues = queues;
>  
> -    return 0;
> -
>  err:

Label err isn't the error path, it's the common path.  It also clashes
with local variable err.  Both harmless, but perhaps it could be renamed
to out on commit.

> -    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 = {

Reviewed-by: Markus Armbruster <armbru@redhat.com>

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

* Re: [Qemu-devel] [PATCH V3] net: don't use set/get_pointer() in set/get_netdev()
  2014-10-13  5:16 [Qemu-devel] [PATCH V3] net: don't use set/get_pointer() in set/get_netdev() Jason Wang
  2014-12-19  9:15 ` Markus Armbruster
@ 2014-12-19 11:31 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2014-12-19 11:31 UTC (permalink / raw)
  To: Jason Wang; +Cc: Peter Maydell, Markus Armbruster, qemu-devel, mst

[-- Attachment #1: Type: text/plain, Size: 1437 bytes --]

On Mon, Oct 13, 2014 at 01:16:37PM +0800, Jason Wang wrote:
> 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 V2:
> - Use error_setg() instead of error_set_from_qdev_prop_error() for E2BIG error.
> - Clean the return part of the set_netdev() since
>   eror_set_from_qdev_prop_error() does nothing when err is 0.
> Changes from V1:
> - validate ncs pointer before accessing them, this fixes the qtest failure
>   on arm.
> ---
>  hw/core/qdev-properties-system.c | 70 ++++++++++++++++++++++------------------
>  1 file changed, 38 insertions(+), 32 deletions(-)

Renamed 'err' label to 'out' as suggested by Markus.

Thanks, applied to my net tree:
https://github.com/stefanha/qemu/commits/net

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

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

end of thread, other threads:[~2014-12-19 11:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-13  5:16 [Qemu-devel] [PATCH V3] net: don't use set/get_pointer() in set/get_netdev() Jason Wang
2014-12-19  9:15 ` Markus Armbruster
2014-12-19 11:31 ` Stefan Hajnoczi

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.