xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libxl: Set vfb and vkb devid if not done so by the caller
@ 2013-01-03 22:01 Jim Fehlig
  2013-01-11 12:24 ` Ian Campbell
  0 siblings, 1 reply; 2+ messages in thread
From: Jim Fehlig @ 2013-01-03 22:01 UTC (permalink / raw)
  To: xen-devel

Other devices set a sensible devid if the caller has not done so.
Do the same for vfb and vkb.  While at it, factor out the common code
used to determine a sensible devid, so it can be used by other
libxl__device_*_add functions.

    Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 tools/libxl/libxl.c |   59 ++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 20 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 8d921bc..73e0dc3 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1710,6 +1710,26 @@ out:
     return;
 }
 
+/* common function to get next device id */
+static int libxl__device_nextid(libxl__gc *gc, uint32_t domid, char *device)
+{
+    char *dompath, **l;
+    unsigned int nb;
+    int nextid = -1;
+
+    if (!(dompath = libxl__xs_get_dompath(gc, domid)))
+        return nextid;
+
+    l = libxl__xs_directory(gc, XBT_NULL,
+                            GCSPRINTF("%s/device/%s", dompath, device), &nb);
+    if (l == NULL || nb == 0)
+        nextid = 0;
+    else
+        nextid = strtoul(l[nb - 1], NULL, 10) + 1;
+
+    return nextid;
+}
+
 /******************************************************************************/
 int libxl__device_vtpm_setdefault(libxl__gc *gc, libxl_device_vtpm *vtpm)
 {
@@ -1741,8 +1761,7 @@ void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
     flexarray_t *front;
     flexarray_t *back;
     libxl__device *device;
-    char *dompath, **l;
-    unsigned int nb, rc;
+    unsigned int rc;
 
     rc = libxl__device_vtpm_setdefault(gc, vtpm);
     if (rc) goto out;
@@ -1750,18 +1769,11 @@ void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
     front = flexarray_make(gc, 16, 1);
     back = flexarray_make(gc, 16, 1);
 
-    if(vtpm->devid == -1) {
-        if (!(dompath = libxl__xs_get_dompath(gc, domid))) {
+    if (vtpm->devid == -1) {
+        if ((vtpm->devid = libxl__device_nextid(gc, domid, "vtpm") < 0)) {
             rc = ERROR_FAIL;
             goto out;
         }
-        l = libxl__xs_directory(gc, XBT_NULL,
-              GCSPRINTF("%s/device/vtpm", dompath), &nb);
-        if(l == NULL || nb == 0) {
-            vtpm->devid = 0;
-        } else {
-            vtpm->devid = strtoul(l[nb - 1], NULL, 10) + 1;
-        }
     }
 
     GCNEW(device);
@@ -2808,8 +2820,7 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
     flexarray_t *front;
     flexarray_t *back;
     libxl__device *device;
-    char *dompath, **l;
-    unsigned int nb, rc;
+    unsigned int rc;
 
     rc = libxl__device_nic_setdefault(gc, nic, domid);
     if (rc) goto out;
@@ -2818,16 +2829,10 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
     back = flexarray_make(gc, 16, 1);
 
     if (nic->devid == -1) {
-        if (!(dompath = libxl__xs_get_dompath(gc, domid))) {
+        if ((nic->devid = libxl__device_nextid(gc, domid, "vif") < 0)) {
             rc = ERROR_FAIL;
             goto out;
         }
-        if (!(l = libxl__xs_directory(gc, XBT_NULL,
-                                     libxl__sprintf(gc, "%s/device/vif", dompath), &nb))) {
-            nic->devid = 0;
-        } else {
-            nic->devid = strtoul(l[nb - 1], NULL, 10) + 1;
-        }
     }
 
     GCNEW(device);
@@ -3192,6 +3197,13 @@ int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
     front = flexarray_make(gc, 16, 1);
     back = flexarray_make(gc, 16, 1);
 
+    if (vkb->devid == -1) {
+        if ((vkb->devid = libxl__device_nextid(gc, domid, "vkb") < 0)) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+    }
+
     rc = libxl__device_from_vkb(gc, domid, vkb, &device);
     if (rc != 0) goto out;
 
@@ -3282,6 +3294,13 @@ int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb)
     front = flexarray_make(gc, 16, 1);
     back = flexarray_make(gc, 16, 1);
 
+    if (vfb->devid == -1) {
+        if ((vfb->devid = libxl__device_nextid(gc, domid, "vfb") < 0)) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+    }
+
     rc = libxl__device_from_vfb(gc, domid, vfb, &device);
     if (rc != 0) goto out;
 
-- 
1.7.9.2

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

* Re: [PATCH] libxl: Set vfb and vkb devid if not done so by the caller
  2013-01-03 22:01 [PATCH] libxl: Set vfb and vkb devid if not done so by the caller Jim Fehlig
@ 2013-01-11 12:24 ` Ian Campbell
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Campbell @ 2013-01-11 12:24 UTC (permalink / raw)
  To: Jim Fehlig; +Cc: xen-devel@lists.xen.org

On Thu, 2013-01-03 at 22:01 +0000, Jim Fehlig wrote:
> Other devices set a sensible devid if the caller has not done so.
> Do the same for vfb and vkb.  While at it, factor out the common code
> used to determine a sensible devid, so it can be used by other
> libxl__device_*_add functions.

Thanks, that's a nice cleanup at the same time.

>     Signed-off-by: Jim Fehlig <jfehlig@suse.com>

Acked + applied.

> ---
>  tools/libxl/libxl.c |   59 ++++++++++++++++++++++++++++++++++-----------------
>  1 file changed, 39 insertions(+), 20 deletions(-)
> 
> diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
> index 8d921bc..73e0dc3 100644
> --- a/tools/libxl/libxl.c
> +++ b/tools/libxl/libxl.c
> @@ -1710,6 +1710,26 @@ out:
>      return;
>  }
>  
> +/* common function to get next device id */
> +static int libxl__device_nextid(libxl__gc *gc, uint32_t domid, char *device)
> +{
> +    char *dompath, **l;
> +    unsigned int nb;
> +    int nextid = -1;
> +
> +    if (!(dompath = libxl__xs_get_dompath(gc, domid)))
> +        return nextid;
> +
> +    l = libxl__xs_directory(gc, XBT_NULL,
> +                            GCSPRINTF("%s/device/%s", dompath, device), &nb);
> +    if (l == NULL || nb == 0)
> +        nextid = 0;
> +    else
> +        nextid = strtoul(l[nb - 1], NULL, 10) + 1;
> +
> +    return nextid;
> +}
> +
>  /******************************************************************************/
>  int libxl__device_vtpm_setdefault(libxl__gc *gc, libxl_device_vtpm *vtpm)
>  {
> @@ -1741,8 +1761,7 @@ void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
>      flexarray_t *front;
>      flexarray_t *back;
>      libxl__device *device;
> -    char *dompath, **l;
> -    unsigned int nb, rc;
> +    unsigned int rc;
>  
>      rc = libxl__device_vtpm_setdefault(gc, vtpm);
>      if (rc) goto out;
> @@ -1750,18 +1769,11 @@ void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
>      front = flexarray_make(gc, 16, 1);
>      back = flexarray_make(gc, 16, 1);
>  
> -    if(vtpm->devid == -1) {
> -        if (!(dompath = libxl__xs_get_dompath(gc, domid))) {
> +    if (vtpm->devid == -1) {
> +        if ((vtpm->devid = libxl__device_nextid(gc, domid, "vtpm") < 0)) {
>              rc = ERROR_FAIL;
>              goto out;
>          }
> -        l = libxl__xs_directory(gc, XBT_NULL,
> -              GCSPRINTF("%s/device/vtpm", dompath), &nb);
> -        if(l == NULL || nb == 0) {
> -            vtpm->devid = 0;
> -        } else {
> -            vtpm->devid = strtoul(l[nb - 1], NULL, 10) + 1;
> -        }
>      }
>  
>      GCNEW(device);
> @@ -2808,8 +2820,7 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
>      flexarray_t *front;
>      flexarray_t *back;
>      libxl__device *device;
> -    char *dompath, **l;
> -    unsigned int nb, rc;
> +    unsigned int rc;
>  
>      rc = libxl__device_nic_setdefault(gc, nic, domid);
>      if (rc) goto out;
> @@ -2818,16 +2829,10 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
>      back = flexarray_make(gc, 16, 1);
>  
>      if (nic->devid == -1) {
> -        if (!(dompath = libxl__xs_get_dompath(gc, domid))) {
> +        if ((nic->devid = libxl__device_nextid(gc, domid, "vif") < 0)) {
>              rc = ERROR_FAIL;
>              goto out;
>          }
> -        if (!(l = libxl__xs_directory(gc, XBT_NULL,
> -                                     libxl__sprintf(gc, "%s/device/vif", dompath), &nb))) {
> -            nic->devid = 0;
> -        } else {
> -            nic->devid = strtoul(l[nb - 1], NULL, 10) + 1;
> -        }
>      }
>  
>      GCNEW(device);
> @@ -3192,6 +3197,13 @@ int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid,
>      front = flexarray_make(gc, 16, 1);
>      back = flexarray_make(gc, 16, 1);
>  
> +    if (vkb->devid == -1) {
> +        if ((vkb->devid = libxl__device_nextid(gc, domid, "vkb") < 0)) {
> +            rc = ERROR_FAIL;
> +            goto out;
> +        }
> +    }
> +
>      rc = libxl__device_from_vkb(gc, domid, vkb, &device);
>      if (rc != 0) goto out;
>  
> @@ -3282,6 +3294,13 @@ int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb)
>      front = flexarray_make(gc, 16, 1);
>      back = flexarray_make(gc, 16, 1);
>  
> +    if (vfb->devid == -1) {
> +        if ((vfb->devid = libxl__device_nextid(gc, domid, "vfb") < 0)) {
> +            rc = ERROR_FAIL;
> +            goto out;
> +        }
> +    }
> +
>      rc = libxl__device_from_vfb(gc, domid, vfb, &device);
>      if (rc != 0) goto out;
>  

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

end of thread, other threads:[~2013-01-11 12:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-03 22:01 [PATCH] libxl: Set vfb and vkb devid if not done so by the caller Jim Fehlig
2013-01-11 12:24 ` Ian Campbell

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).