tools/libxl/flexarray.c | 24 +++
tools/libxl/flexarray.h | 3 +
tools/libxl/libxl.c | 370 ++++++++++++++++++++++-------------------------
tools/libxl/libxl_dm.c | 183 ++++++++++-------------
tools/libxl/libxl_pci.c | 73 +++-----
5 files changed, 305 insertions(+), 348 deletions(-)
# HG changeset patch
# User Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
# Date 1294416341 0
# Node ID 61dbad8d84446b3969309dda1cf24c7c464a6b24
# Parent 2bde4e48657ec8087778a5924bf2d07f02666c39
xl: Implement flexarray_append() and flexarray_vappend()
Makes a lot of code simpler and nicer and saves a fair amount of screen
real-estate
Signed-off-by: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
diff -r 2bde4e48657e -r 61dbad8d8444 tools/libxl/flexarray.c
--- a/tools/libxl/flexarray.c Fri Jan 07 16:05:06 2011 +0000
+++ b/tools/libxl/flexarray.c Fri Jan 07 16:05:41 2011 +0000
@@ -14,6 +14,7 @@
*/
#include "libxl_internal.h"
+#include <stdarg.h>
flexarray_t *flexarray_make(int size, int autogrow)
{
@@ -21,6 +22,7 @@ flexarray_t *flexarray_make(int size, in
if (array) {
array->size = size;
array->autogrow = autogrow;
+ array->count = 0;
array->data = calloc(size, sizeof(void *));
}
return array;
@@ -56,10 +58,32 @@ int flexarray_set(flexarray_t *array, un
if (flexarray_grow(array, newsize - array->size))
return 2;
}
+ if ( index + 1 > array->count )
+ array->count = index + 1;
array->data[index] = ptr;
return 0;
}
+int flexarray_append(flexarray_t *array, void *ptr)
+{
+ return flexarray_set(array, array->count, ptr);
+}
+
+int flexarray_vappend(flexarray_t *array, ...)
+{
+ va_list va;
+ void *ptr;
+ int ret;
+
+ va_start(va, array);
+ for(ret = 0; (ptr = va_arg(va, void *)); ret++) {
+ if ( flexarray_append(array, ptr) )
+ break;
+ }
+ va_end(va);
+ return ret;
+}
+
int flexarray_get(flexarray_t *array, int index, void **ptr)
{
if (index >= array->size)
diff -r 2bde4e48657e -r 61dbad8d8444 tools/libxl/flexarray.h
--- a/tools/libxl/flexarray.h Fri Jan 07 16:05:06 2011 +0000
+++ b/tools/libxl/flexarray.h Fri Jan 07 16:05:41 2011 +0000
@@ -19,6 +19,7 @@
typedef struct flexarray {
int size;
int autogrow;
+ unsigned int count;
void **data; /* array of pointer */
} flexarray_t;
@@ -26,6 +27,8 @@ _hidden flexarray_t *flexarray_make(int
_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_vappend(flexarray_t *array, ...);
_hidden int flexarray_get(flexarray_t *array, int index, void **ptr);
_hidden void **flexarray_contents(flexarray_t *array);
diff -r 2bde4e48657e -r 61dbad8d8444 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Fri Jan 07 16:05:06 2011 +0000
+++ b/tools/libxl/libxl.c Fri Jan 07 16:05:41 2011 +0000
@@ -1075,8 +1075,6 @@ int libxl_device_disk_add(libxl_ctx *ctx
flexarray_t *front;
flexarray_t *back;
char *backend_type;
- unsigned int boffset = 0;
- unsigned int foffset = 0;
int devid;
libxl__device device;
int major, minor, rc;
@@ -1111,11 +1109,11 @@ int libxl_device_disk_add(libxl_ctx *ctx
case PHYSTYPE_PHY: {
libxl__device_physdisk_major_minor(disk->physpath, &major, &minor);
- flexarray_set(back, boffset++, "physical-device");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%x:%x", major,
minor));
-
- flexarray_set(back, boffset++, "params");
- flexarray_set(back, boffset++, disk->physpath);
+ flexarray_append(back, "physical-device");
+ flexarray_append(back, libxl__sprintf(&gc, "%x:%x", major, minor));
+
+ flexarray_append(back, "params");
+ flexarray_append(back, disk->physpath);
device.backend_kind = DEVICE_VBD;
break;
@@ -1134,20 +1132,20 @@ int libxl_device_disk_add(libxl_ctx *ctx
rc = ERROR_FAIL;
goto out_free;
}
- flexarray_set(back, boffset++, "tapdisk-params");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%s:%s",
libxl__device_disk_string_of_phystype(disk->phystype), disk->physpath));
- flexarray_set(back, boffset++, "params");
- flexarray_set(back, boffset++, libxl__strdup(&gc, dev));
+ flexarray_append(back, "tapdisk-params");
+ flexarray_append(back, libxl__sprintf(&gc, "%s:%s",
libxl__device_disk_string_of_phystype(disk->phystype), disk->physpath));
+ flexarray_append(back, "params");
+ flexarray_append(back, libxl__strdup(&gc, dev));
backend_type = "phy";
libxl__device_physdisk_major_minor(dev, &major, &minor);
- flexarray_set(back, boffset++, "physical-device");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%x:%x",
major, minor));
+ flexarray_append(back, "physical-device");
+ flexarray_append(back, libxl__sprintf(&gc, "%x:%x", major,
minor));
device.backend_kind = DEVICE_VBD;
break;
}
- flexarray_set(back, boffset++, "params");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%s:%s",
+ flexarray_append(back, "params");
+ flexarray_append(back, libxl__sprintf(&gc, "%s:%s",
libxl__device_disk_string_of_phystype(disk->phystype), disk->physpath));
if (libxl__blktap_enabled(&gc))
@@ -1162,40 +1160,40 @@ int libxl_device_disk_add(libxl_ctx *ctx
goto out_free;
}
- flexarray_set(back, boffset++, "frontend-id");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", disk->domid));
- flexarray_set(back, boffset++, "online");
- flexarray_set(back, boffset++, "1");
- flexarray_set(back, boffset++, "removable");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d",
(disk->unpluggable) ? 1 : 0));
- flexarray_set(back, boffset++, "bootable");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
- flexarray_set(back, boffset++, "state");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
- flexarray_set(back, boffset++, "dev");
- flexarray_set(back, boffset++, disk->virtpath);
- flexarray_set(back, boffset++, "type");
- flexarray_set(back, boffset++, backend_type);
- flexarray_set(back, boffset++, "mode");
- flexarray_set(back, boffset++, disk->readwrite ? "w" : "r");
-
- flexarray_set(front, foffset++, "backend-id");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d",
disk->backend_domid));
- flexarray_set(front, foffset++, "state");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1));
- flexarray_set(front, foffset++, "virtual-device");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", devid));
- flexarray_set(front, foffset++, "device-type");
- flexarray_set(front, foffset++, disk->is_cdrom ? "cdrom" : "disk");
+ flexarray_append(back, "frontend-id");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", disk->domid));
+ flexarray_append(back, "online");
+ flexarray_append(back, "1");
+ flexarray_append(back, "removable");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", (disk->unpluggable) ? 1 :
0));
+ flexarray_append(back, "bootable");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", 1));
+ flexarray_append(back, "state");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", 1));
+ flexarray_append(back, "dev");
+ flexarray_append(back, disk->virtpath);
+ flexarray_append(back, "type");
+ flexarray_append(back, backend_type);
+ flexarray_append(back, "mode");
+ flexarray_append(back, disk->readwrite ? "w" : "r");
+
+ flexarray_append(front, "backend-id");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", disk->backend_domid));
+ flexarray_append(front, "state");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", 1));
+ flexarray_append(front, "virtual-device");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", devid));
+ flexarray_append(front, "device-type");
+ flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
if (0 /* protocol != native*/) {
- flexarray_set(front, foffset++, "protocol");
- flexarray_set(front, foffset++, "x86_32-abi"); /* hardcoded ! */
+ flexarray_append(front, "protocol");
+ flexarray_append(front, "x86_32-abi"); /* hardcoded ! */
}
libxl__device_generic_add(ctx, &device,
- libxl__xs_kvs_of_flexarray(&gc, back, boffset),
- libxl__xs_kvs_of_flexarray(&gc, front, foffset));
+ libxl__xs_kvs_of_flexarray(&gc, back,
back->count),
+ libxl__xs_kvs_of_flexarray(&gc, front,
front->count));
rc = 0;
@@ -1274,8 +1272,6 @@ int libxl_device_nic_add(libxl_ctx *ctx,
libxl__gc gc = LIBXL_INIT_GC(ctx);
flexarray_t *front;
flexarray_t *back;
- unsigned int boffset = 0;
- unsigned int foffset = 0;
libxl__device device;
char *dompath, **l;
unsigned int nb, rc;
@@ -1311,41 +1307,41 @@ int libxl_device_nic_add(libxl_ctx *ctx,
device.domid = nic->domid;
device.kind = DEVICE_VIF;
- flexarray_set(back, boffset++, "frontend-id");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", nic->domid));
- flexarray_set(back, boffset++, "online");
- flexarray_set(back, boffset++, "1");
- flexarray_set(back, boffset++, "state");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
- flexarray_set(back, boffset++, "script");
- flexarray_set(back, boffset++, nic->script);
- flexarray_set(back, boffset++, "mac");
- flexarray_set(back, boffset++, libxl__sprintf(&gc,
"%02x:%02x:%02x:%02x:%02x:%02x",
+ flexarray_append(back, "frontend-id");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", nic->domid));
+ flexarray_append(back, "online");
+ flexarray_append(back, "1");
+ flexarray_append(back, "state");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", 1));
+ flexarray_append(back, "script");
+ flexarray_append(back, nic->script);
+ flexarray_append(back, "mac");
+ flexarray_append(back, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
nic->mac[0], nic->mac[1],
nic->mac[2],
nic->mac[3], nic->mac[4],
nic->mac[5]));
- flexarray_set(back, boffset++, "bridge");
- flexarray_set(back, boffset++, libxl__strdup(&gc, nic->bridge));
- flexarray_set(back, boffset++, "handle");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", nic->devid));
-
- flexarray_set(front, foffset++, "backend-id");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d",
nic->backend_domid));
- flexarray_set(front, foffset++, "state");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1));
- flexarray_set(front, foffset++, "handle");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", nic->devid));
- flexarray_set(front, foffset++, "mac");
- flexarray_set(front, foffset++, libxl__sprintf(&gc,
"%02x:%02x:%02x:%02x:%02x:%02x",
+ flexarray_append(back, "bridge");
+ flexarray_append(back, libxl__strdup(&gc, nic->bridge));
+ flexarray_append(back, "handle");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", nic->devid));
+
+ flexarray_append(front, "backend-id");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", nic->backend_domid));
+ flexarray_append(front, "state");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", 1));
+ flexarray_append(front, "handle");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", nic->devid));
+ flexarray_append(front, "mac");
+ flexarray_append(front, libxl__sprintf(&gc,
"%02x:%02x:%02x:%02x:%02x:%02x",
nic->mac[0], nic->mac[1],
nic->mac[2],
nic->mac[3], nic->mac[4],
nic->mac[5]));
if (0 /* protocol != native*/) {
- flexarray_set(front, foffset++, "protocol");
- flexarray_set(front, foffset++, "x86_32-abi"); /* hardcoded ! */
+ flexarray_append(front, "protocol");
+ flexarray_append(front, "x86_32-abi"); /* hardcoded ! */
}
libxl__device_generic_add(ctx, &device,
- libxl__xs_kvs_of_flexarray(&gc, back, boffset),
- libxl__xs_kvs_of_flexarray(&gc, front, foffset));
+ libxl__xs_kvs_of_flexarray(&gc, back,
back->count),
+ libxl__xs_kvs_of_flexarray(&gc, front,
front->count));
/* FIXME: wait for plug */
rc = 0;
@@ -1433,7 +1429,6 @@ int libxl_device_net2_add(libxl_ctx *ctx
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
flexarray_t *front, *back;
- unsigned int boffset = 0, foffset = 0;
libxl__device device;
char *dompath, *dom, **l;
unsigned int nb;
@@ -1472,65 +1467,65 @@ int libxl_device_net2_add(libxl_ctx *ctx
device.domid = net2->domid;
device.kind = DEVICE_VIF2;
- flexarray_set(back, boffset++, "domain");
- flexarray_set(back, boffset++, dom);
- flexarray_set(back, boffset++, "frontend-id");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", net2->domid));
-
- flexarray_set(back, boffset++, "local-trusted");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d",
net2->back_trusted));
- flexarray_set(back, boffset++, "mac");
- flexarray_set(back, boffset++, libxl__sprintf(&gc,
"%02x:%02x:%02x:%02x:%02x:%02x",
+ flexarray_append(back, "domain");
+ flexarray_append(back, dom);
+ flexarray_append(back, "frontend-id");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", net2->domid));
+
+ flexarray_append(back, "local-trusted");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", net2->back_trusted));
+ flexarray_append(back, "mac");
+ flexarray_append(back, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
net2->back_mac[0],
net2->back_mac[1],
net2->back_mac[2],
net2->back_mac[3],
net2->back_mac[4],
net2->back_mac[5]));
- flexarray_set(back, boffset++, "remote-trusted");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", net2->trusted));
- flexarray_set(back, boffset++, "remote-mac");
- flexarray_set(back, boffset++, libxl__sprintf(&gc,
"%02x:%02x:%02x:%02x:%02x:%02x",
+ flexarray_append(back, "remote-trusted");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", net2->trusted));
+ flexarray_append(back, "remote-mac");
+ flexarray_append(back, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
net2->front_mac[0],
net2->front_mac[1],
net2->front_mac[2],
net2->front_mac[3],
net2->front_mac[4],
net2->front_mac[5]));
- flexarray_set(back, boffset++, "max-bypasses");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d",
net2->max_bypasses));
- flexarray_set(back, boffset++, "filter-mac");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d",
!!(net2->filter_mac)));
- flexarray_set(back, boffset++, "handle");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", net2->devid));
- flexarray_set(back, boffset++, "online");
- flexarray_set(back, boffset++, "1");
- flexarray_set(back, boffset++, "state");
- flexarray_set(back, boffset++, "1");
-
- flexarray_set(front, foffset++, "backend-id");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d",
net2->backend_domid));
-
- flexarray_set(front, foffset++, "local-trusted");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", net2->trusted));
- flexarray_set(front, foffset++, "mac");
- flexarray_set(front, foffset++, libxl__sprintf(&gc,
"%02x:%02x:%02x:%02x:%02x:%02x",
+ flexarray_append(back, "max-bypasses");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", net2->max_bypasses));
+ flexarray_append(back, "filter-mac");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", !!(net2->filter_mac)));
+ flexarray_append(back, "handle");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", net2->devid));
+ flexarray_append(back, "online");
+ flexarray_append(back, "1");
+ flexarray_append(back, "state");
+ flexarray_append(back, "1");
+
+ flexarray_append(front, "backend-id");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", net2->backend_domid));
+
+ flexarray_append(front, "local-trusted");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", net2->trusted));
+ flexarray_append(front, "mac");
+ flexarray_append(front, libxl__sprintf(&gc,
"%02x:%02x:%02x:%02x:%02x:%02x",
net2->front_mac[0],
net2->front_mac[1],
net2->front_mac[2],
net2->front_mac[3],
net2->front_mac[4],
net2->front_mac[5]));
- flexarray_set(front, foffset++, "remote-trusted");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d",
net2->back_trusted));
- flexarray_set(front, foffset++, "remote-mac");
- flexarray_set(front, foffset++, libxl__sprintf(&gc,
"%02x:%02x:%02x:%02x:%02x:%02x",
+ flexarray_append(front, "remote-trusted");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", net2->back_trusted));
+ flexarray_append(front, "remote-mac");
+ flexarray_append(front, libxl__sprintf(&gc,
"%02x:%02x:%02x:%02x:%02x:%02x",
net2->back_mac[0],
net2->back_mac[1],
net2->back_mac[2],
net2->back_mac[3],
net2->back_mac[4],
net2->back_mac[5]));
- flexarray_set(front, foffset++, "filter-mac");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d",
!!(net2->filter_mac)));
- flexarray_set(front, foffset++, "state");
- flexarray_set(front, foffset++, "1");
+ flexarray_append(front, "filter-mac");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", !!(net2->filter_mac)));
+ flexarray_append(front, "state");
+ flexarray_append(front, "1");
libxl__device_generic_add(ctx, &device,
- libxl__xs_kvs_of_flexarray(&gc, back, boffset),
- libxl__xs_kvs_of_flexarray(&gc, front, foffset));
+ libxl__xs_kvs_of_flexarray(&gc, back,
back->count),
+ libxl__xs_kvs_of_flexarray(&gc, front,
front->count));
/* FIXME: wait for plug */
rc = 0;
@@ -1624,8 +1619,6 @@ int libxl_device_console_add(libxl_ctx *
libxl__gc gc = LIBXL_INIT_GC(ctx);
flexarray_t *front;
flexarray_t *back;
- unsigned int boffset = 0;
- unsigned int foffset = 0;
libxl__device device;
int rc;
@@ -1647,48 +1640,48 @@ int libxl_device_console_add(libxl_ctx *
device.domid = console->domid;
device.kind = DEVICE_CONSOLE;
- flexarray_set(back, boffset++, "frontend-id");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", console->domid));
- flexarray_set(back, boffset++, "online");
- flexarray_set(back, boffset++, "1");
- flexarray_set(back, boffset++, "state");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
- flexarray_set(back, boffset++, "domain");
- flexarray_set(back, boffset++, libxl__domid_to_name(&gc, domid));
- flexarray_set(back, boffset++, "protocol");
- flexarray_set(back, boffset++, LIBXL_XENCONSOLE_PROTOCOL);
-
- flexarray_set(front, foffset++, "backend-id");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d",
console->backend_domid));
- flexarray_set(front, foffset++, "limit");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d",
LIBXL_XENCONSOLE_LIMIT));
- flexarray_set(front, foffset++, "type");
+ flexarray_append(back, "frontend-id");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", console->domid));
+ flexarray_append(back, "online");
+ flexarray_append(back, "1");
+ flexarray_append(back, "state");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", 1));
+ flexarray_append(back, "domain");
+ flexarray_append(back, libxl__domid_to_name(&gc, domid));
+ flexarray_append(back, "protocol");
+ flexarray_append(back, LIBXL_XENCONSOLE_PROTOCOL);
+
+ flexarray_append(front, "backend-id");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", console->backend_domid));
+ flexarray_append(front, "limit");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", LIBXL_XENCONSOLE_LIMIT));
+ flexarray_append(front, "type");
if (console->consback == LIBXL_CONSBACK_XENCONSOLED)
- flexarray_set(front, foffset++, "xenconsoled");
+ flexarray_append(front, "xenconsoled");
else
- flexarray_set(front, foffset++, "ioemu");
- flexarray_set(front, foffset++, "output");
- flexarray_set(front, foffset++, console->output);
+ flexarray_append(front, "ioemu");
+ flexarray_append(front, "output");
+ flexarray_append(front, console->output);
if (device.devid == 0) {
if (console->build_state == NULL) {
rc = ERROR_INVAL;
goto out_free;
}
- flexarray_set(front, foffset++, "port");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%"PRIu32,
console->build_state->console_port));
- flexarray_set(front, foffset++, "ring-ref");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%lu",
console->build_state->console_mfn));
+ flexarray_append(front, "port");
+ flexarray_append(front, libxl__sprintf(&gc, "%"PRIu32,
console->build_state->console_port));
+ flexarray_append(front, "ring-ref");
+ flexarray_append(front, libxl__sprintf(&gc, "%lu",
console->build_state->console_mfn));
} else {
- flexarray_set(front, foffset++, "state");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1));
- flexarray_set(front, foffset++, "protocol");
- flexarray_set(front, foffset++, LIBXL_XENCONSOLE_PROTOCOL);
+ flexarray_append(front, "state");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", 1));
+ flexarray_append(front, "protocol");
+ flexarray_append(front, LIBXL_XENCONSOLE_PROTOCOL);
}
libxl__device_generic_add(ctx, &device,
- libxl__xs_kvs_of_flexarray(&gc, back, boffset),
- libxl__xs_kvs_of_flexarray(&gc, front, foffset));
+ libxl__xs_kvs_of_flexarray(&gc, back,
back->count),
+ libxl__xs_kvs_of_flexarray(&gc, front,
front->count));
rc = 0;
out_free:
flexarray_free(back);
@@ -1704,8 +1697,6 @@ int libxl_device_vkb_add(libxl_ctx *ctx,
libxl__gc gc = LIBXL_INIT_GC(ctx);
flexarray_t *front;
flexarray_t *back;
- unsigned int boffset = 0;
- unsigned int foffset = 0;
libxl__device device;
int rc;
@@ -1727,23 +1718,23 @@ int libxl_device_vkb_add(libxl_ctx *ctx,
device.domid = vkb->domid;
device.kind = DEVICE_VKBD;
- flexarray_set(back, boffset++, "frontend-id");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vkb->domid));
- flexarray_set(back, boffset++, "online");
- flexarray_set(back, boffset++, "1");
- flexarray_set(back, boffset++, "state");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
- flexarray_set(back, boffset++, "domain");
- flexarray_set(back, boffset++, libxl__domid_to_name(&gc, domid));
-
- flexarray_set(front, foffset++, "backend-id");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d",
vkb->backend_domid));
- flexarray_set(front, foffset++, "state");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1));
+ flexarray_append(back, "frontend-id");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", vkb->domid));
+ flexarray_append(back, "online");
+ flexarray_append(back, "1");
+ flexarray_append(back, "state");
+ flexarray_append(back, libxl__sprintf(&gc, "%d", 1));
+ flexarray_append(back, "domain");
+ flexarray_append(back, libxl__domid_to_name(&gc, domid));
+
+ flexarray_append(front, "backend-id");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", vkb->backend_domid));
+ flexarray_append(front, "state");
+ flexarray_append(front, libxl__sprintf(&gc, "%d", 1));
libxl__device_generic_add(ctx, &device,
- libxl__xs_kvs_of_flexarray(&gc, back, boffset),
- libxl__xs_kvs_of_flexarray(&gc, front, foffset));
+ libxl__xs_kvs_of_flexarray(&gc, back,
back->count),
+ libxl__xs_kvs_of_flexarray(&gc, front,
front->count));
rc = 0;
out_free:
flexarray_free(back);
@@ -1904,8 +1895,6 @@ int libxl_device_vfb_add(libxl_ctx *ctx,
libxl__gc gc = LIBXL_INIT_GC(ctx);
flexarray_t *front;
flexarray_t *back;
- unsigned int boffset = 0;
- unsigned int foffset = 0;
libxl__device device;
int rc;
@@ -1927,45 +1916,30 @@ int libxl_device_vfb_add(libxl_ctx *ctx,
device.domid = vfb->domid;
device.kind = DEVICE_VFB;
- flexarray_set(back, boffset++, "frontend-id");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->domid));
- flexarray_set(back, boffset++, "online");
- flexarray_set(back, boffset++, "1");
- flexarray_set(back, boffset++, "state");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
- flexarray_set(back, boffset++, "domain");
- flexarray_set(back, boffset++, libxl__domid_to_name(&gc, domid));
- flexarray_set(back, boffset++, "vnc");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->vnc));
- flexarray_set(back, boffset++, "vnclisten");
- flexarray_set(back, boffset++, vfb->vnclisten);
- flexarray_set(back, boffset++, "vncpasswd");
- flexarray_set(back, boffset++, vfb->vncpasswd);
- flexarray_set(back, boffset++, "vncdisplay");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->vncdisplay));
- flexarray_set(back, boffset++, "vncunused");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->vncunused));
- flexarray_set(back, boffset++, "sdl");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->sdl));
- flexarray_set(back, boffset++, "opengl");
- flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->opengl));
+ 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_vappend(back, "vncpasswd", vfb->vncpasswd, NULL);
+ 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);
if (vfb->xauthority) {
- flexarray_set(back, boffset++, "xauthority");
- flexarray_set(back, boffset++, vfb->xauthority);
+ flexarray_vappend(back, "xauthority", vfb->xauthority, NULL);
}
if (vfb->display) {
- flexarray_set(back, boffset++, "display");
- flexarray_set(back, boffset++, vfb->display);
+ flexarray_vappend(back, "display", vfb->display, NULL);
}
- flexarray_set(front, foffset++, "backend-id");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d",
vfb->backend_domid));
- flexarray_set(front, foffset++, "state");
- flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1));
+ flexarray_vappend(front, "backend-id", libxl__sprintf(&gc, "%d",
vfb->backend_domid), NULL);
+ flexarray_vappend(front, "state", libxl__sprintf(&gc, "%d", 1), NULL);
libxl__device_generic_add(ctx, &device,
- libxl__xs_kvs_of_flexarray(&gc, back, boffset),
- libxl__xs_kvs_of_flexarray(&gc, front, foffset));
+ libxl__xs_kvs_of_flexarray(&gc, back,
back->count),
+ libxl__xs_kvs_of_flexarray(&gc, front,
front->count));
rc = 0;
out_free:
flexarray_free(front);
diff -r 2bde4e48657e -r 61dbad8d8444 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c Fri Jan 07 16:05:06 2011 +0000
+++ b/tools/libxl/libxl_dm.c Fri Jan 07 16:05:41 2011 +0000
@@ -32,101 +32,88 @@ static char ** libxl_build_device_model_
libxl_device_nic *vifs,
int num_vifs)
{
- int num = 0, i;
+ int i;
flexarray_t *dm_args;
dm_args = flexarray_make(16, 1);
if (!dm_args)
return NULL;
- flexarray_set(dm_args, num++, "qemu-dm");
- flexarray_set(dm_args, num++, "-d");
+ flexarray_vappend(dm_args, "qemu-dm", "-d", libxl__sprintf(gc, "%d",
info->domid), NULL);
- flexarray_set(dm_args, num++, libxl__sprintf(gc, "%d", info->domid));
+ if (info->dom_name)
+ flexarray_vappend(dm_args, "-domain-name", info->dom_name, NULL);
- if (info->dom_name) {
- flexarray_set(dm_args, num++, "-domain-name");
- flexarray_set(dm_args, num++, info->dom_name);
- }
if (info->vnc || info->vncdisplay || info->vnclisten || info->vncunused) {
- flexarray_set(dm_args, num++, "-vnc");
+ flexarray_append(dm_args, "-vnc");
if (info->vncdisplay) {
if (info->vnclisten && strchr(info->vnclisten, ':') == NULL) {
- flexarray_set(
- dm_args, num++,
+ flexarray_append(dm_args,
libxl__sprintf(gc, "%s:%d%s",
info->vnclisten,
info->vncdisplay,
info->vncpasswd ? ",password" : ""));
} else {
- flexarray_set(dm_args, num++, libxl__sprintf(gc,
"127.0.0.1:%d", info->vncdisplay));
+ flexarray_append(dm_args, libxl__sprintf(gc, "127.0.0.1:%d",
info->vncdisplay));
}
} else if (info->vnclisten) {
if (strchr(info->vnclisten, ':') != NULL) {
- flexarray_set(dm_args, num++, info->vnclisten);
+ flexarray_append(dm_args, info->vnclisten);
} else {
- flexarray_set(dm_args, num++, libxl__sprintf(gc, "%s:0",
info->vnclisten));
+ flexarray_append(dm_args, libxl__sprintf(gc, "%s:0",
info->vnclisten));
}
} else {
- flexarray_set(dm_args, num++, "127.0.0.1:0");
+ flexarray_append(dm_args, "127.0.0.1:0");
}
if (info->vncunused) {
- flexarray_set(dm_args, num++, "-vncunused");
+ flexarray_append(dm_args, "-vncunused");
}
}
if (info->sdl) {
- flexarray_set(dm_args, num++, "-sdl");
+ flexarray_append(dm_args, "-sdl");
if (!info->opengl) {
- flexarray_set(dm_args, num++, "-disable-opengl");
+ flexarray_append(dm_args, "-disable-opengl");
}
}
if (info->keymap) {
- flexarray_set(dm_args, num++, "-k");
- flexarray_set(dm_args, num++, info->keymap);
+ flexarray_vappend(dm_args, "-k", info->keymap, NULL);
}
if (info->nographic && (!info->sdl && !info->vnc)) {
- flexarray_set(dm_args, num++, "-nographic");
+ flexarray_append(dm_args, "-nographic");
}
if (info->serial) {
- flexarray_set(dm_args, num++, "-serial");
- flexarray_set(dm_args, num++, info->serial);
+ flexarray_vappend(dm_args, "-serial", info->serial, NULL);
}
if (info->type == XENFV) {
int ioemu_vifs = 0;
if (info->videoram) {
- flexarray_set(dm_args, num++, "-videoram");
- flexarray_set(dm_args, num++, libxl__sprintf(gc, "%d",
info->videoram));
+ flexarray_vappend(dm_args, "-videoram", libxl__sprintf(gc, "%d",
info->videoram), NULL);
}
if (info->stdvga) {
- flexarray_set(dm_args, num++, "-std-vga");
+ flexarray_append(dm_args, "-std-vga");
}
if (info->boot) {
- flexarray_set(dm_args, num++, "-boot");
- flexarray_set(dm_args, num++, info->boot);
+ flexarray_vappend(dm_args, "-boot", info->boot, NULL);
}
if (info->usb || info->usbdevice) {
- flexarray_set(dm_args, num++, "-usb");
+ flexarray_append(dm_args, "-usb");
if (info->usbdevice) {
- flexarray_set(dm_args, num++, "-usbdevice");
- flexarray_set(dm_args, num++, info->usbdevice);
+ flexarray_vappend(dm_args, "-usbdevice", info->usbdevice,
NULL);
}
}
if (info->soundhw) {
- flexarray_set(dm_args, num++, "-soundhw");
- flexarray_set(dm_args, num++, info->soundhw);
+ flexarray_vappend(dm_args, "-soundhw", info->soundhw, NULL);
}
if (info->apic) {
- flexarray_set(dm_args, num++, "-acpi");
+ flexarray_append(dm_args, "-acpi");
}
if (info->vcpus > 1) {
- flexarray_set(dm_args, num++, "-vcpus");
- flexarray_set(dm_args, num++, libxl__sprintf(gc, "%d",
info->vcpus));
+ flexarray_vappend(dm_args, "-vcpus", libxl__sprintf(gc, "%d",
info->vcpus), NULL);
}
if (info->vcpu_avail) {
- flexarray_set(dm_args, num++, "-vcpu_avail");
- flexarray_set(dm_args, num++, libxl__sprintf(gc, "0x%x",
info->vcpu_avail));
+ flexarray_vappend(dm_args, "-vcpu_avail", libxl__sprintf(gc,
"0x%x", info->vcpu_avail), NULL);
}
for (i = 0; i < num_vifs; i++) {
if (vifs[i].nictype == NICTYPE_IOEMU) {
@@ -138,33 +125,30 @@ static char ** libxl_build_device_model_
ifname = libxl__sprintf(gc, "tap%d.%d", info->domid,
vifs[i].devid);
else
ifname = vifs[i].ifname;
- flexarray_set(dm_args, num++, "-net");
- flexarray_set(dm_args, num++, libxl__sprintf(gc,
"nic,vlan=%d,macaddr=%s,model=%s",
- vifs[i].devid, smac, vifs[i].model));
- flexarray_set(dm_args, num++, "-net");
- flexarray_set(dm_args, num++, libxl__sprintf(gc,
"tap,vlan=%d,ifname=%s,bridge=%s,script=no",
- vifs[i].devid, ifname, vifs[i].bridge));
+ flexarray_vappend(dm_args,
+ "-net", libxl__sprintf(gc,
"nic,vlan=%d,macaddr=%s,model=%s",
+ vifs[i].devid, smac,
vifs[i].model),
+ "-net", libxl__sprintf(gc,
"tap,vlan=%d,ifname=%s,bridge=%s,script=no",
+ vifs[i].devid, ifname,
vifs[i].bridge), NULL);
ioemu_vifs++;
}
}
/* If we have no emulated nics, tell qemu not to create any */
if ( ioemu_vifs == 0 ) {
- flexarray_set(dm_args, num++, "-net");
- flexarray_set(dm_args, num++, "none");
+ flexarray_vappend(dm_args, "-net", "none", NULL);
}
}
if (info->saved_state) {
- flexarray_set(dm_args, num++, "-loadvm");
- flexarray_set(dm_args, num++, info->saved_state);
+ flexarray_vappend(dm_args, "-loadvm", info->saved_state, NULL);
}
for (i = 0; info->extra && info->extra[i] != NULL; i++)
- flexarray_set(dm_args, num++, info->extra[i]);
- flexarray_set(dm_args, num++, "-M");
+ flexarray_append(dm_args, info->extra[i]);
+ flexarray_append(dm_args, "-M");
if (info->type == XENPV)
- flexarray_set(dm_args, num++, "xenpv");
+ flexarray_append(dm_args, "xenpv");
else
- flexarray_set(dm_args, num++, "xenfv");
- flexarray_set(dm_args, num++, NULL);
+ flexarray_append(dm_args, "xenfv");
+ flexarray_append(dm_args, NULL);
return (char **) flexarray_contents(dm_args);
}
@@ -173,33 +157,29 @@ static char ** libxl_build_device_model_
libxl_device_nic *vifs,
int num_vifs)
{
- int num = 0, i;
flexarray_t *dm_args;
- int nb;
libxl_device_disk *disks;
+ int nb, i;
dm_args = flexarray_make(16, 1);
if (!dm_args)
return NULL;
- flexarray_set(dm_args, num++, libxl__strdup(gc, info->device_model));
-
- flexarray_set(dm_args, num++, "-xen-domid");
- flexarray_set(dm_args, num++, libxl__sprintf(gc, "%d", info->domid));
+ flexarray_vappend(dm_args, libxl__strdup(gc, info->device_model),
+ "-xen-domid", libxl__sprintf(gc, "%d", info->domid),
NULL);
if (info->type == XENPV) {
- flexarray_set(dm_args, num++, "-xen-attach");
+ flexarray_append(dm_args, "-xen-attach");
}
if (info->dom_name) {
- flexarray_set(dm_args, num++, "-name");
- flexarray_set(dm_args, num++, info->dom_name);
+ flexarray_vappend(dm_args, "-name", info->dom_name, NULL);
}
if (info->vnc || info->vncdisplay || info->vnclisten || info->vncunused) {
int display = 0;
const char *listen = "127.0.0.1";
- flexarray_set(dm_args, num++, "-vnc");
+ flexarray_append(dm_args, "-vnc");
if (info->vncdisplay) {
display = info->vncdisplay;
@@ -211,66 +191,59 @@ static char ** libxl_build_device_model_
}
if (strchr(listen, ':') != NULL)
- flexarray_set(dm_args, num++,
+ flexarray_append(dm_args,
libxl__sprintf(gc, "%s%s", listen,
info->vncunused ? ",to=99" : ""));
else
- flexarray_set(dm_args, num++,
+ flexarray_append(dm_args,
libxl__sprintf(gc, "%s:%d%s", listen, display,
info->vncunused ? ",to=99" : ""));
}
if (info->sdl) {
- flexarray_set(dm_args, num++, "-sdl");
+ flexarray_append(dm_args, "-sdl");
}
if (info->type == XENPV && !info->nographic) {
- flexarray_set(dm_args, num++, "-vga");
- flexarray_set(dm_args, num++, "xenfb");
+ flexarray_vappend(dm_args, "-vga", "xenfb", NULL);
}
if (info->keymap) {
- flexarray_set(dm_args, num++, "-k");
- flexarray_set(dm_args, num++, info->keymap);
+ flexarray_vappend(dm_args, "-k", info->keymap, NULL);
}
if (info->nographic && (!info->sdl && !info->vnc)) {
- flexarray_set(dm_args, num++, "-nographic");
+ flexarray_append(dm_args, "-nographic");
}
if (info->serial) {
- flexarray_set(dm_args, num++, "-serial");
- flexarray_set(dm_args, num++, info->serial);
+ flexarray_vappend(dm_args, "-serial", info->serial, NULL);
}
if (info->type == XENFV) {
int ioemu_vifs = 0;
if (info->stdvga) {
- flexarray_set(dm_args, num++, "-vga");
- flexarray_set(dm_args, num++, "std");
+ flexarray_vappend(dm_args, "-vga", "std", NULL);
}
if (info->boot) {
- flexarray_set(dm_args, num++, "-boot");
- flexarray_set(dm_args, num++, libxl__sprintf(gc, "order=%s",
info->boot));
+ flexarray_vappend(dm_args, "-boot", libxl__sprintf(gc, "order=%s",
info->boot), NULL);
}
if (info->usb || info->usbdevice) {
- flexarray_set(dm_args, num++, "-usb");
+ flexarray_append(dm_args, "-usb");
if (info->usbdevice) {
- flexarray_set(dm_args, num++, "-usbdevice");
- flexarray_set(dm_args, num++, info->usbdevice);
+ flexarray_vappend(dm_args, "-usbdevice", info->usbdevice,
NULL);
}
}
if (info->soundhw) {
- flexarray_set(dm_args, num++, "-soundhw");
- flexarray_set(dm_args, num++, info->soundhw);
+ flexarray_vappend(dm_args, "-soundhw", info->soundhw, NULL);
}
if (!info->apic) {
- flexarray_set(dm_args, num++, "-no-acpi");
+ flexarray_append(dm_args, "-no-acpi");
}
if (info->vcpus > 1) {
- flexarray_set(dm_args, num++, "-smp");
+ flexarray_append(dm_args, "-smp");
if (info->vcpu_avail)
- flexarray_set(dm_args, num++, libxl__sprintf(gc,
"%d,maxcpus=%d", info->vcpus, info->vcpu_avail));
+ flexarray_append(dm_args, libxl__sprintf(gc, "%d,maxcpus=%d",
info->vcpus, info->vcpu_avail));
else
- flexarray_set(dm_args, num++, libxl__sprintf(gc, "%d",
info->vcpus));
+ flexarray_append(dm_args, libxl__sprintf(gc, "%d",
info->vcpus));
}
for (i = 0; i < num_vifs; i++) {
if (vifs[i].nictype == NICTYPE_IOEMU) {
@@ -283,52 +256,52 @@ static char ** libxl_build_device_model_
} else {
ifname = vifs[i].ifname;
}
- flexarray_set(dm_args, num++, "-net");
- flexarray_set(dm_args, num++, libxl__sprintf(gc,
"nic,vlan=%d,macaddr=%s,model=%s",
+ flexarray_append(dm_args, "-net");
+ flexarray_append(dm_args, libxl__sprintf(gc,
"nic,vlan=%d,macaddr=%s,model=%s",
vifs[i].devid, smac, vifs[i].model));
- flexarray_set(dm_args, num++, "-net");
- flexarray_set(dm_args, num++, libxl__sprintf(gc,
"tap,vlan=%d,ifname=%s,script=no",
+ flexarray_append(dm_args, "-net");
+ flexarray_append(dm_args, libxl__sprintf(gc,
"tap,vlan=%d,ifname=%s,script=no",
vifs[i].devid, ifname));
ioemu_vifs++;
}
}
/* If we have no emulated nics, tell qemu not to create any */
if ( ioemu_vifs == 0 ) {
- flexarray_set(dm_args, num++, "-net");
- flexarray_set(dm_args, num++, "none");
+ flexarray_append(dm_args, "-net");
+ flexarray_append(dm_args, "none");
}
}
if (info->saved_state) {
- flexarray_set(dm_args, num++, "-loadvm");
- flexarray_set(dm_args, num++, info->saved_state);
+ flexarray_append(dm_args, "-loadvm");
+ flexarray_append(dm_args, info->saved_state);
}
for (i = 0; info->extra && info->extra[i] != NULL; i++)
- flexarray_set(dm_args, num++, info->extra[i]);
- flexarray_set(dm_args, num++, "-M");
+ flexarray_append(dm_args, info->extra[i]);
+ flexarray_append(dm_args, "-M");
if (info->type == XENPV)
- flexarray_set(dm_args, num++, "xenpv");
+ flexarray_append(dm_args, "xenpv");
else
- flexarray_set(dm_args, num++, "xenfv");
+ flexarray_append(dm_args, "xenfv");
/* RAM Size */
- flexarray_set(dm_args, num++, "-m");
- flexarray_set(dm_args, num++, libxl__sprintf(gc, "%d", info->target_ram));
+ flexarray_append(dm_args, "-m");
+ flexarray_append(dm_args, libxl__sprintf(gc, "%d", info->target_ram));
if (info->type == XENFV) {
disks = libxl_device_disk_list(libxl__gc_owner(gc), info->domid, &nb);
for (i; i < nb; i++) {
if (disks[i].is_cdrom) {
- flexarray_set(dm_args, num++, "-cdrom");
- flexarray_set(dm_args, num++, libxl__strdup(gc,
disks[i].physpath));
+ flexarray_append(dm_args, "-cdrom");
+ flexarray_append(dm_args, libxl__strdup(gc,
disks[i].physpath));
} else {
- flexarray_set(dm_args, num++, libxl__sprintf(gc, "-%s",
disks[i].virtpath));
- flexarray_set(dm_args, num++, libxl__strdup(gc,
disks[i].physpath));
+ flexarray_append(dm_args, libxl__sprintf(gc, "-%s",
disks[i].virtpath));
+ flexarray_append(dm_args, libxl__strdup(gc,
disks[i].physpath));
}
libxl_device_disk_destroy(&disks[i]);
}
free(disks);
}
- flexarray_set(dm_args, num++, NULL);
+ flexarray_append(dm_args, NULL);
return (char **) flexarray_contents(dm_args);
}
diff -r 2bde4e48657e -r 61dbad8d8444 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c Fri Jan 07 16:05:06 2011 +0000
+++ b/tools/libxl/libxl_pci.c Fri Jan 07 16:05:41 2011 +0000
@@ -226,8 +226,6 @@ static int libxl_create_pci_backend(libx
libxl_ctx *ctx = libxl__gc_owner(gc);
flexarray_t *front;
flexarray_t *back;
- unsigned int boffset = 0;
- unsigned int foffset = 0;
libxl__device device;
int i;
@@ -248,39 +246,28 @@ static int libxl_create_pci_backend(libx
device.domid = domid;
device.kind = DEVICE_PCI;
- flexarray_set(back, boffset++, "frontend-id");
- flexarray_set(back, boffset++, libxl__sprintf(gc, "%d", domid));
- flexarray_set(back, boffset++, "online");
- flexarray_set(back, boffset++, "1");
- flexarray_set(back, boffset++, "state");
- flexarray_set(back, boffset++, libxl__sprintf(gc, "%d", 1));
- flexarray_set(back, boffset++, "domain");
- flexarray_set(back, boffset++, libxl__domid_to_name(gc, domid));
+ 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);
for (i = 0; i < num; i++) {
- flexarray_set(back, boffset++, libxl__sprintf(gc, "key-%d", i));
- flexarray_set(back, boffset++, libxl__sprintf(gc, PCI_BDF,
pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func));
- flexarray_set(back, boffset++, libxl__sprintf(gc, "dev-%d", i));
- flexarray_set(back, boffset++, libxl__sprintf(gc, PCI_BDF,
pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func));
+ flexarray_append(back, libxl__sprintf(gc, "key-%d", i));
+ flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain,
pcidev->bus, pcidev->dev, pcidev->func));
+ flexarray_append(back, libxl__sprintf(gc, "dev-%d", i));
+ flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain,
pcidev->bus, pcidev->dev, pcidev->func));
if (pcidev->vdevfn) {
- flexarray_set(back, boffset++, libxl__sprintf(gc, "vdevfn-%d", i));
- flexarray_set(back, boffset++, libxl__sprintf(gc, "%x",
pcidev->vdevfn));
+ flexarray_vappend(back, libxl__sprintf(gc, "vdevfn-%d", i),
libxl__sprintf(gc, "%x", pcidev->vdevfn), NULL);
}
- flexarray_set(back, boffset++, libxl__sprintf(gc, "opts-%d", i));
- flexarray_set(back, boffset++, libxl__sprintf(gc,
"msitranslate=%d,power_mgmt=%d", pcidev->msitranslate, pcidev->power_mgmt));
- flexarray_set(back, boffset++, libxl__sprintf(gc, "state-%d", i));
- flexarray_set(back, boffset++, libxl__sprintf(gc, "%d", 1));
+ flexarray_append(back, libxl__sprintf(gc, "opts-%d", i));
+ flexarray_append(back, libxl__sprintf(gc,
"msitranslate=%d,power_mgmt=%d", pcidev->msitranslate, pcidev->power_mgmt));
+ flexarray_vappend(back, libxl__sprintf(gc, "state-%d", i),
libxl__sprintf(gc, "%d", 1), NULL);
}
- flexarray_set(back, boffset++, "num_devs");
- flexarray_set(back, boffset++, libxl__sprintf(gc, "%d", num));
-
- flexarray_set(front, foffset++, "backend-id");
- flexarray_set(front, foffset++, libxl__sprintf(gc, "%d", 0));
- flexarray_set(front, foffset++, "state");
- flexarray_set(front, foffset++, libxl__sprintf(gc, "%d", 1));
+ flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num),
+ "backend-id", libxl__sprintf(gc, "%d", 0),
+ "state", libxl__sprintf(gc, "%d", 1), NULL);
libxl__device_generic_add(ctx, &device,
- libxl__xs_kvs_of_flexarray(gc, back, boffset),
- libxl__xs_kvs_of_flexarray(gc, front, foffset));
+ libxl__xs_kvs_of_flexarray(gc, back, back->count),
+ libxl__xs_kvs_of_flexarray(gc, front,
front->count));
flexarray_free(back);
flexarray_free(front);
@@ -293,7 +280,6 @@ static int libxl_device_pci_add_xenstore
flexarray_t *back;
char *num_devs, *be_path;
int num = 0;
- unsigned int boffset = 0;
xs_transaction_t t;
be_path = libxl__sprintf(gc, "%s/backend/pci/%d/0",
libxl__xs_get_dompath(gc, 0), domid);
@@ -312,27 +298,24 @@ static int libxl_device_pci_add_xenstore
LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Adding new pci device to xenstore");
num = atoi(num_devs);
- flexarray_set(back, boffset++, libxl__sprintf(gc, "key-%d", num));
- flexarray_set(back, boffset++, libxl__sprintf(gc, PCI_BDF, pcidev->domain,
pcidev->bus, pcidev->dev, pcidev->func));
- flexarray_set(back, boffset++, libxl__sprintf(gc, "dev-%d", num));
- flexarray_set(back, boffset++, libxl__sprintf(gc, PCI_BDF, pcidev->domain,
pcidev->bus, pcidev->dev, pcidev->func));
+ flexarray_append(back, libxl__sprintf(gc, "key-%d", num));
+ flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain,
pcidev->bus, pcidev->dev, pcidev->func));
+ 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_set(back, boffset++, libxl__sprintf(gc, "vdevfn-%d", num));
- flexarray_set(back, boffset++, libxl__sprintf(gc, "%x",
pcidev->vdevfn));
+ flexarray_append(back, libxl__sprintf(gc, "vdevfn-%d", num));
+ flexarray_append(back, libxl__sprintf(gc, "%x", pcidev->vdevfn));
}
- flexarray_set(back, boffset++, libxl__sprintf(gc, "opts-%d", num));
- flexarray_set(back, boffset++, libxl__sprintf(gc,
"msitranslate=%d,power_mgmt=%d", pcidev->msitranslate, pcidev->power_mgmt));
- flexarray_set(back, boffset++, libxl__sprintf(gc, "state-%d", num));
- flexarray_set(back, boffset++, libxl__sprintf(gc, "%d", 1));
- flexarray_set(back, boffset++, "num_devs");
- flexarray_set(back, boffset++, libxl__sprintf(gc, "%d", num + 1));
- flexarray_set(back, boffset++, "state");
- flexarray_set(back, boffset++, libxl__sprintf(gc, "%d", 7));
+ 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_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num + 1),
NULL);
+ flexarray_vappend(back, "state", libxl__sprintf(gc, "%d", 7), NULL);
retry_transaction:
t = xs_transaction_start(ctx->xsh);
libxl__xs_writev(gc, t, be_path,
- libxl__xs_kvs_of_flexarray(gc, back, boffset));
+ libxl__xs_kvs_of_flexarray(gc, back, back->count));
if (!xs_transaction_end(ctx->xsh, t, 0))
if (errno == EAGAIN)
goto retry_transaction;
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|