All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit c73ce19f authored by Stefano Stabellini's avatar Stefano Stabellini

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

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: default avatarStefano Stabellini <>
Acked-by: default avatarIan Jackson <>
Committed-by: default avatarIan Jackson <>
parent ba8bec7e
......@@ -69,6 +69,14 @@ int flexarray_append(flexarray_t *array, void *ptr)
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;
......@@ -28,6 +28,7 @@ _hidden void flexarray_free(flexarray_t *array);
_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);
......@@ -1887,27 +1887,26 @@ int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb)
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),
......@@ -228,10 +228,10 @@ static void libxl_create_pci_backend_device(libxl__gc *gc, flexarray_t *back, in
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 @@ static int libxl_create_pci_backend(libxl__gc *gc, uint32_t domid, libxl_device_
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);
"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 @@ static int libxl_device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_de
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));
t = xs_transaction_start(ctx->xsh);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment