[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-4.1-testing] # HG changeset patch



# HG changeset patch
# User Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
# Date 1299690253 0
# Node ID 16aea83d4719d295828f6d1968b887d86a98920f
# Parent  1f5818838aa6a028590d42f8dcad12247339db9c
# HG changeset patch
# User Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
# Date 1299690214 0
# Node ID 0fa941c0ec45b3490d8ffa74ae0a271dfc14445e
# Parent  65d26504e843420a1f3db6052464c052f83160e3
libxl: introduce flexarray_append_pair

Introduce flexarray_append_pair: a simple syntactic sugar to add a pair
of pointers to a flexarray, very useful when adding pairs of strings to
xenstore.

Replace flexarray_vappend calls (and one pair of flexarray_append)
with flexarray_append_pair calls when dealing with flexarrays that are
going to be used with libxl__xs_kvs_of_flexarray:

NULL is a valid pointer value in these cases while flexarray_vappend
uses NULL as vargs terminator, so the old code is buggy.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---


diff -r 1f5818838aa6 -r 16aea83d4719 tools/libxl/flexarray.c
--- a/tools/libxl/flexarray.c   Mon Mar 07 16:15:47 2011 +0000
+++ b/tools/libxl/flexarray.c   Wed Mar 09 17:04:13 2011 +0000
@@ -69,6 +69,14 @@
     return flexarray_set(array, array->count, ptr);
 }
 
+int flexarray_append_pair(flexarray_t *array, void *ptr1, void *ptr2)
+{
+    int rc = flexarray_append(array, ptr1);
+    if (!rc)
+        rc = flexarray_append(array, ptr2);
+    return rc;
+}
+
 int flexarray_vappend(flexarray_t *array, ...)
 {
     va_list va;
diff -r 1f5818838aa6 -r 16aea83d4719 tools/libxl/flexarray.h
--- a/tools/libxl/flexarray.h   Mon Mar 07 16:15:47 2011 +0000
+++ b/tools/libxl/flexarray.h   Wed Mar 09 17:04:13 2011 +0000
@@ -28,6 +28,7 @@
 _hidden int flexarray_grow(flexarray_t *array, int extents);
 _hidden int flexarray_set(flexarray_t *array, unsigned int index, void *ptr);
 _hidden int flexarray_append(flexarray_t *array, void *ptr);
+_hidden int flexarray_append_pair(flexarray_t *array, void *ptr1, void *ptr2);
 _hidden int flexarray_vappend(flexarray_t *array, ...);
 _hidden int flexarray_get(flexarray_t *array, int index, void **ptr);
 
diff -r 1f5818838aa6 -r 16aea83d4719 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Mon Mar 07 16:15:47 2011 +0000
+++ b/tools/libxl/libxl.c       Wed Mar 09 17:04:13 2011 +0000
@@ -1887,27 +1887,26 @@
     device.domid = vfb->domid;
     device.kind = DEVICE_VFB;
 
-    flexarray_vappend(back, "frontend-id", libxl__sprintf(&gc, "%d", 
vfb->domid), NULL);
-    flexarray_vappend(back, "online", "1", NULL);
-    flexarray_vappend(back, "state", libxl__sprintf(&gc, "%d", 1), NULL);
-    flexarray_vappend(back, "domain", libxl__domid_to_name(&gc, domid), NULL);
-    flexarray_vappend(back, "vnc", libxl__sprintf(&gc, "%d", vfb->vnc), NULL);
-    flexarray_vappend(back, "vnclisten", vfb->vnclisten, NULL);
-    flexarray_append(back, "vncpasswd");
-    flexarray_append(back, vfb->vncpasswd);
-    flexarray_vappend(back, "vncdisplay", libxl__sprintf(&gc, "%d", 
vfb->vncdisplay), NULL);
-    flexarray_vappend(back, "vncunused", libxl__sprintf(&gc, "%d", 
vfb->vncunused), NULL);
-    flexarray_vappend(back, "sdl", libxl__sprintf(&gc, "%d", vfb->sdl), NULL);
-    flexarray_vappend(back, "opengl", libxl__sprintf(&gc, "%d", vfb->opengl), 
NULL);
+    flexarray_append_pair(back, "frontend-id", libxl__sprintf(&gc, "%d", 
vfb->domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state", libxl__sprintf(&gc, "%d", 1));
+    flexarray_append_pair(back, "domain", libxl__domid_to_name(&gc, domid));
+    flexarray_append_pair(back, "vnc", libxl__sprintf(&gc, "%d", vfb->vnc));
+    flexarray_append_pair(back, "vnclisten", vfb->vnclisten);
+    flexarray_append_pair(back, "vncpasswd", vfb->vncpasswd);
+    flexarray_append_pair(back, "vncdisplay", libxl__sprintf(&gc, "%d", 
vfb->vncdisplay));
+    flexarray_append_pair(back, "vncunused", libxl__sprintf(&gc, "%d", 
vfb->vncunused));
+    flexarray_append_pair(back, "sdl", libxl__sprintf(&gc, "%d", vfb->sdl));
+    flexarray_append_pair(back, "opengl", libxl__sprintf(&gc, "%d", 
vfb->opengl));
     if (vfb->xauthority) {
-        flexarray_vappend(back, "xauthority", vfb->xauthority, NULL);
+        flexarray_append_pair(back, "xauthority", vfb->xauthority);
     }
     if (vfb->display) {
-        flexarray_vappend(back, "display", vfb->display, NULL);
+        flexarray_append_pair(back, "display", vfb->display);
     }
 
-    flexarray_vappend(front, "backend-id", libxl__sprintf(&gc, "%d", 
vfb->backend_domid), NULL);
-    flexarray_vappend(front, "state", libxl__sprintf(&gc, "%d", 1), NULL);
+    flexarray_append_pair(front, "backend-id", libxl__sprintf(&gc, "%d", 
vfb->backend_domid));
+    flexarray_append_pair(front, "state", libxl__sprintf(&gc, "%d", 1));
 
     libxl__device_generic_add(ctx, &device,
                              libxl__xs_kvs_of_flexarray(&gc, back, 
back->count),
diff -r 1f5818838aa6 -r 16aea83d4719 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c   Mon Mar 07 16:15:47 2011 +0000
+++ b/tools/libxl/libxl_pci.c   Wed Mar 09 17:04:13 2011 +0000
@@ -228,10 +228,10 @@
     flexarray_append(back, libxl__sprintf(gc, "dev-%d", num));
     flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, 
pcidev->bus, pcidev->dev, pcidev->func));
     if (pcidev->vdevfn)
-        flexarray_vappend(back, libxl__sprintf(gc, "vdevfn-%d", num), 
libxl__sprintf(gc, "%x", pcidev->vdevfn), NULL);
+        flexarray_append_pair(back, libxl__sprintf(gc, "vdevfn-%d", num), 
libxl__sprintf(gc, "%x", pcidev->vdevfn));
     flexarray_append(back, libxl__sprintf(gc, "opts-%d", num));
     flexarray_append(back, libxl__sprintf(gc, "msitranslate=%d,power_mgmt=%d", 
pcidev->msitranslate, pcidev->power_mgmt));
-    flexarray_vappend(back, libxl__sprintf(gc, "state-%d", num), 
libxl__sprintf(gc, "%d", 1), NULL);
+    flexarray_append_pair(back, libxl__sprintf(gc, "state-%d", num), 
libxl__sprintf(gc, "%d", 1));
 }
 
 static int libxl_create_pci_backend(libxl__gc *gc, uint32_t domid, 
libxl_device_pci *pcidev, int num)
@@ -261,18 +261,17 @@
     device.domid = domid;
     device.kind = DEVICE_PCI;
 
-    flexarray_vappend(back, "frontend-id", libxl__sprintf(gc, "%d", domid),
-                      "online", "1", "state", libxl__sprintf(gc, "%d", 1),
-                      "domain", libxl__domid_to_name(gc, domid), NULL);
+    flexarray_append_pair(back, "frontend-id", libxl__sprintf(gc, "%d", 
domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state", libxl__sprintf(gc, "%d", 1));
+    flexarray_append_pair(back, "domain", libxl__domid_to_name(gc, domid));
 
     for (i = 0; i < num; i++, pcidev++)
         libxl_create_pci_backend_device(gc, back, i, pcidev);
 
-    flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num), NULL);
-
-    flexarray_vappend(front,
-                      "backend-id", libxl__sprintf(gc, "%d", 0),
-                      "state", libxl__sprintf(gc, "%d", 1), NULL);
+    flexarray_append_pair(back, "num_devs", libxl__sprintf(gc, "%d", num));
+    flexarray_append_pair(front, "backend-id", libxl__sprintf(gc, "%d", 0));
+    flexarray_append_pair(front, "state", libxl__sprintf(gc, "%d", 1));
 
     libxl__device_generic_add(ctx, &device,
                              libxl__xs_kvs_of_flexarray(gc, back, back->count),
@@ -311,9 +310,9 @@
     LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Adding new pci device to xenstore");
     num = atoi(num_devs);
     libxl_create_pci_backend_device(gc, back, num, pcidev);
-    flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num + 1), 
NULL);
+    flexarray_append_pair(back, "num_devs", libxl__sprintf(gc, "%d", num + 1));
     if (!starting)
-        flexarray_vappend(back, "state", libxl__sprintf(gc, "%d", 7), NULL);
+        flexarray_append_pair(back, "state", libxl__sprintf(gc, "%d", 7));
 
 retry_transaction:
     t = xs_transaction_start(ctx->xsh);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.