debuggers.hg

diff tools/libxl/libxl.c @ 22726:03718b569d97

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@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Gianni Tedesco <gianni.tedesco@citrix.com>
date Fri Jan 07 18:53:50 2011 +0000 (2011-01-07)
parents e1392f5327ce
children ca75ceb02221
line diff
     1.1 --- a/tools/libxl/libxl.c	Fri Jan 07 18:24:54 2011 +0000
     1.2 +++ b/tools/libxl/libxl.c	Fri Jan 07 18:53:50 2011 +0000
     1.3 @@ -1075,8 +1075,6 @@ int libxl_device_disk_add(libxl_ctx *ctx
     1.4      flexarray_t *front;
     1.5      flexarray_t *back;
     1.6      char *backend_type;
     1.7 -    unsigned int boffset = 0;
     1.8 -    unsigned int foffset = 0;
     1.9      int devid;
    1.10      libxl__device device;
    1.11      int major, minor, rc;
    1.12 @@ -1111,11 +1109,11 @@ int libxl_device_disk_add(libxl_ctx *ctx
    1.13          case PHYSTYPE_PHY: {
    1.14  
    1.15              libxl__device_physdisk_major_minor(disk->physpath, &major, &minor);
    1.16 -            flexarray_set(back, boffset++, "physical-device");
    1.17 -            flexarray_set(back, boffset++, libxl__sprintf(&gc, "%x:%x", major, minor));
    1.18 -
    1.19 -            flexarray_set(back, boffset++, "params");
    1.20 -            flexarray_set(back, boffset++, disk->physpath);
    1.21 +            flexarray_append(back, "physical-device");
    1.22 +            flexarray_append(back, libxl__sprintf(&gc, "%x:%x", major, minor));
    1.23 +
    1.24 +            flexarray_append(back, "params");
    1.25 +            flexarray_append(back, disk->physpath);
    1.26  
    1.27              device.backend_kind = DEVICE_VBD;
    1.28              break;
    1.29 @@ -1134,20 +1132,20 @@ int libxl_device_disk_add(libxl_ctx *ctx
    1.30                      rc = ERROR_FAIL;
    1.31                      goto out_free;
    1.32                  }
    1.33 -                flexarray_set(back, boffset++, "tapdisk-params");
    1.34 -                flexarray_set(back, boffset++, libxl__sprintf(&gc, "%s:%s", libxl__device_disk_string_of_phystype(disk->phystype), disk->physpath));
    1.35 -                flexarray_set(back, boffset++, "params");
    1.36 -                flexarray_set(back, boffset++, libxl__strdup(&gc, dev));
    1.37 +                flexarray_append(back, "tapdisk-params");
    1.38 +                flexarray_append(back, libxl__sprintf(&gc, "%s:%s", libxl__device_disk_string_of_phystype(disk->phystype), disk->physpath));
    1.39 +                flexarray_append(back, "params");
    1.40 +                flexarray_append(back, libxl__strdup(&gc, dev));
    1.41                  backend_type = "phy";
    1.42                  libxl__device_physdisk_major_minor(dev, &major, &minor);
    1.43 -                flexarray_set(back, boffset++, "physical-device");
    1.44 -                flexarray_set(back, boffset++, libxl__sprintf(&gc, "%x:%x", major, minor));
    1.45 +                flexarray_append(back, "physical-device");
    1.46 +                flexarray_append(back, libxl__sprintf(&gc, "%x:%x", major, minor));
    1.47                  device.backend_kind = DEVICE_VBD;
    1.48  
    1.49                  break;
    1.50              }
    1.51 -            flexarray_set(back, boffset++, "params");
    1.52 -            flexarray_set(back, boffset++, libxl__sprintf(&gc, "%s:%s",
    1.53 +            flexarray_append(back, "params");
    1.54 +            flexarray_append(back, libxl__sprintf(&gc, "%s:%s",
    1.55                            libxl__device_disk_string_of_phystype(disk->phystype), disk->physpath));
    1.56  
    1.57              if (libxl__blktap_enabled(&gc))
    1.58 @@ -1162,40 +1160,40 @@ int libxl_device_disk_add(libxl_ctx *ctx
    1.59              goto out_free;
    1.60      }
    1.61  
    1.62 -    flexarray_set(back, boffset++, "frontend-id");
    1.63 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", disk->domid));
    1.64 -    flexarray_set(back, boffset++, "online");
    1.65 -    flexarray_set(back, boffset++, "1");
    1.66 -    flexarray_set(back, boffset++, "removable");
    1.67 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", (disk->unpluggable) ? 1 : 0));
    1.68 -    flexarray_set(back, boffset++, "bootable");
    1.69 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
    1.70 -    flexarray_set(back, boffset++, "state");
    1.71 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
    1.72 -    flexarray_set(back, boffset++, "dev");
    1.73 -    flexarray_set(back, boffset++, disk->virtpath);
    1.74 -    flexarray_set(back, boffset++, "type");
    1.75 -    flexarray_set(back, boffset++, backend_type);
    1.76 -    flexarray_set(back, boffset++, "mode");
    1.77 -    flexarray_set(back, boffset++, disk->readwrite ? "w" : "r");
    1.78 -
    1.79 -    flexarray_set(front, foffset++, "backend-id");
    1.80 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", disk->backend_domid));
    1.81 -    flexarray_set(front, foffset++, "state");
    1.82 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1));
    1.83 -    flexarray_set(front, foffset++, "virtual-device");
    1.84 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", devid));
    1.85 -    flexarray_set(front, foffset++, "device-type");
    1.86 -    flexarray_set(front, foffset++, disk->is_cdrom ? "cdrom" : "disk");
    1.87 +    flexarray_append(back, "frontend-id");
    1.88 +    flexarray_append(back, libxl__sprintf(&gc, "%d", disk->domid));
    1.89 +    flexarray_append(back, "online");
    1.90 +    flexarray_append(back, "1");
    1.91 +    flexarray_append(back, "removable");
    1.92 +    flexarray_append(back, libxl__sprintf(&gc, "%d", (disk->unpluggable) ? 1 : 0));
    1.93 +    flexarray_append(back, "bootable");
    1.94 +    flexarray_append(back, libxl__sprintf(&gc, "%d", 1));
    1.95 +    flexarray_append(back, "state");
    1.96 +    flexarray_append(back, libxl__sprintf(&gc, "%d", 1));
    1.97 +    flexarray_append(back, "dev");
    1.98 +    flexarray_append(back, disk->virtpath);
    1.99 +    flexarray_append(back, "type");
   1.100 +    flexarray_append(back, backend_type);
   1.101 +    flexarray_append(back, "mode");
   1.102 +    flexarray_append(back, disk->readwrite ? "w" : "r");
   1.103 +
   1.104 +    flexarray_append(front, "backend-id");
   1.105 +    flexarray_append(front, libxl__sprintf(&gc, "%d", disk->backend_domid));
   1.106 +    flexarray_append(front, "state");
   1.107 +    flexarray_append(front, libxl__sprintf(&gc, "%d", 1));
   1.108 +    flexarray_append(front, "virtual-device");
   1.109 +    flexarray_append(front, libxl__sprintf(&gc, "%d", devid));
   1.110 +    flexarray_append(front, "device-type");
   1.111 +    flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
   1.112  
   1.113      if (0 /* protocol != native*/) {
   1.114 -        flexarray_set(front, foffset++, "protocol");
   1.115 -        flexarray_set(front, foffset++, "x86_32-abi"); /* hardcoded ! */
   1.116 +        flexarray_append(front, "protocol");
   1.117 +        flexarray_append(front, "x86_32-abi"); /* hardcoded ! */
   1.118      }
   1.119  
   1.120      libxl__device_generic_add(ctx, &device,
   1.121 -                             libxl__xs_kvs_of_flexarray(&gc, back, boffset),
   1.122 -                             libxl__xs_kvs_of_flexarray(&gc, front, foffset));
   1.123 +                             libxl__xs_kvs_of_flexarray(&gc, back, back->count),
   1.124 +                             libxl__xs_kvs_of_flexarray(&gc, front, front->count));
   1.125  
   1.126      rc = 0;
   1.127  
   1.128 @@ -1274,8 +1272,6 @@ int libxl_device_nic_add(libxl_ctx *ctx,
   1.129      libxl__gc gc = LIBXL_INIT_GC(ctx);
   1.130      flexarray_t *front;
   1.131      flexarray_t *back;
   1.132 -    unsigned int boffset = 0;
   1.133 -    unsigned int foffset = 0;
   1.134      libxl__device device;
   1.135      char *dompath, **l;
   1.136      unsigned int nb, rc;
   1.137 @@ -1311,41 +1307,41 @@ int libxl_device_nic_add(libxl_ctx *ctx,
   1.138      device.domid = nic->domid;
   1.139      device.kind = DEVICE_VIF;
   1.140  
   1.141 -    flexarray_set(back, boffset++, "frontend-id");
   1.142 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", nic->domid));
   1.143 -    flexarray_set(back, boffset++, "online");
   1.144 -    flexarray_set(back, boffset++, "1");
   1.145 -    flexarray_set(back, boffset++, "state");
   1.146 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
   1.147 -    flexarray_set(back, boffset++, "script");
   1.148 -    flexarray_set(back, boffset++, nic->script);
   1.149 -    flexarray_set(back, boffset++, "mac");
   1.150 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.151 +    flexarray_append(back, "frontend-id");
   1.152 +    flexarray_append(back, libxl__sprintf(&gc, "%d", nic->domid));
   1.153 +    flexarray_append(back, "online");
   1.154 +    flexarray_append(back, "1");
   1.155 +    flexarray_append(back, "state");
   1.156 +    flexarray_append(back, libxl__sprintf(&gc, "%d", 1));
   1.157 +    flexarray_append(back, "script");
   1.158 +    flexarray_append(back, nic->script);
   1.159 +    flexarray_append(back, "mac");
   1.160 +    flexarray_append(back, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.161                                                   nic->mac[0], nic->mac[1], nic->mac[2],
   1.162                                                   nic->mac[3], nic->mac[4], nic->mac[5]));
   1.163 -    flexarray_set(back, boffset++, "bridge");
   1.164 -    flexarray_set(back, boffset++, libxl__strdup(&gc, nic->bridge));
   1.165 -    flexarray_set(back, boffset++, "handle");
   1.166 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", nic->devid));
   1.167 -
   1.168 -    flexarray_set(front, foffset++, "backend-id");
   1.169 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", nic->backend_domid));
   1.170 -    flexarray_set(front, foffset++, "state");
   1.171 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1));
   1.172 -    flexarray_set(front, foffset++, "handle");
   1.173 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", nic->devid));
   1.174 -    flexarray_set(front, foffset++, "mac");
   1.175 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.176 +    flexarray_append(back, "bridge");
   1.177 +    flexarray_append(back, libxl__strdup(&gc, nic->bridge));
   1.178 +    flexarray_append(back, "handle");
   1.179 +    flexarray_append(back, libxl__sprintf(&gc, "%d", nic->devid));
   1.180 +
   1.181 +    flexarray_append(front, "backend-id");
   1.182 +    flexarray_append(front, libxl__sprintf(&gc, "%d", nic->backend_domid));
   1.183 +    flexarray_append(front, "state");
   1.184 +    flexarray_append(front, libxl__sprintf(&gc, "%d", 1));
   1.185 +    flexarray_append(front, "handle");
   1.186 +    flexarray_append(front, libxl__sprintf(&gc, "%d", nic->devid));
   1.187 +    flexarray_append(front, "mac");
   1.188 +    flexarray_append(front, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.189                                                    nic->mac[0], nic->mac[1], nic->mac[2],
   1.190                                                    nic->mac[3], nic->mac[4], nic->mac[5]));
   1.191      if (0 /* protocol != native*/) {
   1.192 -        flexarray_set(front, foffset++, "protocol");
   1.193 -        flexarray_set(front, foffset++, "x86_32-abi"); /* hardcoded ! */
   1.194 +        flexarray_append(front, "protocol");
   1.195 +        flexarray_append(front, "x86_32-abi"); /* hardcoded ! */
   1.196      }
   1.197  
   1.198      libxl__device_generic_add(ctx, &device,
   1.199 -                             libxl__xs_kvs_of_flexarray(&gc, back, boffset),
   1.200 -                             libxl__xs_kvs_of_flexarray(&gc, front, foffset));
   1.201 +                             libxl__xs_kvs_of_flexarray(&gc, back, back->count),
   1.202 +                             libxl__xs_kvs_of_flexarray(&gc, front, front->count));
   1.203  
   1.204      /* FIXME: wait for plug */
   1.205      rc = 0;
   1.206 @@ -1433,7 +1429,6 @@ int libxl_device_net2_add(libxl_ctx *ctx
   1.207  {
   1.208      libxl__gc gc = LIBXL_INIT_GC(ctx);
   1.209      flexarray_t *front, *back;
   1.210 -    unsigned int boffset = 0, foffset = 0;
   1.211      libxl__device device;
   1.212      char *dompath, *dom, **l;
   1.213      unsigned int nb;
   1.214 @@ -1472,65 +1467,65 @@ int libxl_device_net2_add(libxl_ctx *ctx
   1.215      device.domid = net2->domid;
   1.216      device.kind = DEVICE_VIF2;
   1.217  
   1.218 -    flexarray_set(back, boffset++, "domain");
   1.219 -    flexarray_set(back, boffset++, dom);
   1.220 -    flexarray_set(back, boffset++, "frontend-id");
   1.221 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", net2->domid));
   1.222 -
   1.223 -    flexarray_set(back, boffset++, "local-trusted");
   1.224 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", net2->back_trusted));
   1.225 -    flexarray_set(back, boffset++, "mac");
   1.226 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.227 +    flexarray_append(back, "domain");
   1.228 +    flexarray_append(back, dom);
   1.229 +    flexarray_append(back, "frontend-id");
   1.230 +    flexarray_append(back, libxl__sprintf(&gc, "%d", net2->domid));
   1.231 +
   1.232 +    flexarray_append(back, "local-trusted");
   1.233 +    flexarray_append(back, libxl__sprintf(&gc, "%d", net2->back_trusted));
   1.234 +    flexarray_append(back, "mac");
   1.235 +    flexarray_append(back, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.236                                                   net2->back_mac[0], net2->back_mac[1],
   1.237                                                   net2->back_mac[2], net2->back_mac[3],
   1.238                                                   net2->back_mac[4], net2->back_mac[5]));
   1.239  
   1.240 -    flexarray_set(back, boffset++, "remote-trusted");
   1.241 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", net2->trusted));
   1.242 -    flexarray_set(back, boffset++, "remote-mac");
   1.243 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.244 +    flexarray_append(back, "remote-trusted");
   1.245 +    flexarray_append(back, libxl__sprintf(&gc, "%d", net2->trusted));
   1.246 +    flexarray_append(back, "remote-mac");
   1.247 +    flexarray_append(back, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.248                                                   net2->front_mac[0], net2->front_mac[1],
   1.249                                                   net2->front_mac[2], net2->front_mac[3],
   1.250                                                   net2->front_mac[4], net2->front_mac[5]));
   1.251  
   1.252 -    flexarray_set(back, boffset++, "max-bypasses");
   1.253 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", net2->max_bypasses));
   1.254 -    flexarray_set(back, boffset++, "filter-mac");
   1.255 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", !!(net2->filter_mac)));
   1.256 -    flexarray_set(back, boffset++, "handle");
   1.257 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", net2->devid));
   1.258 -    flexarray_set(back, boffset++, "online");
   1.259 -    flexarray_set(back, boffset++, "1");
   1.260 -    flexarray_set(back, boffset++, "state");
   1.261 -    flexarray_set(back, boffset++, "1");
   1.262 -
   1.263 -    flexarray_set(front, foffset++, "backend-id");
   1.264 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", net2->backend_domid));
   1.265 -
   1.266 -    flexarray_set(front, foffset++, "local-trusted");
   1.267 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", net2->trusted));
   1.268 -    flexarray_set(front, foffset++, "mac");
   1.269 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.270 +    flexarray_append(back, "max-bypasses");
   1.271 +    flexarray_append(back, libxl__sprintf(&gc, "%d", net2->max_bypasses));
   1.272 +    flexarray_append(back, "filter-mac");
   1.273 +    flexarray_append(back, libxl__sprintf(&gc, "%d", !!(net2->filter_mac)));
   1.274 +    flexarray_append(back, "handle");
   1.275 +    flexarray_append(back, libxl__sprintf(&gc, "%d", net2->devid));
   1.276 +    flexarray_append(back, "online");
   1.277 +    flexarray_append(back, "1");
   1.278 +    flexarray_append(back, "state");
   1.279 +    flexarray_append(back, "1");
   1.280 +
   1.281 +    flexarray_append(front, "backend-id");
   1.282 +    flexarray_append(front, libxl__sprintf(&gc, "%d", net2->backend_domid));
   1.283 +
   1.284 +    flexarray_append(front, "local-trusted");
   1.285 +    flexarray_append(front, libxl__sprintf(&gc, "%d", net2->trusted));
   1.286 +    flexarray_append(front, "mac");
   1.287 +    flexarray_append(front, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.288                                                    net2->front_mac[0], net2->front_mac[1],
   1.289                                                    net2->front_mac[2], net2->front_mac[3],
   1.290                                                    net2->front_mac[4], net2->front_mac[5]));
   1.291  
   1.292 -    flexarray_set(front, foffset++, "remote-trusted");
   1.293 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", net2->back_trusted));
   1.294 -    flexarray_set(front, foffset++, "remote-mac");
   1.295 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.296 +    flexarray_append(front, "remote-trusted");
   1.297 +    flexarray_append(front, libxl__sprintf(&gc, "%d", net2->back_trusted));
   1.298 +    flexarray_append(front, "remote-mac");
   1.299 +    flexarray_append(front, libxl__sprintf(&gc, "%02x:%02x:%02x:%02x:%02x:%02x",
   1.300                                                    net2->back_mac[0], net2->back_mac[1],
   1.301                                                    net2->back_mac[2], net2->back_mac[3],
   1.302                                                    net2->back_mac[4], net2->back_mac[5]));
   1.303  
   1.304 -    flexarray_set(front, foffset++, "filter-mac");
   1.305 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", !!(net2->filter_mac)));
   1.306 -    flexarray_set(front, foffset++, "state");
   1.307 -    flexarray_set(front, foffset++, "1");
   1.308 +    flexarray_append(front, "filter-mac");
   1.309 +    flexarray_append(front, libxl__sprintf(&gc, "%d", !!(net2->filter_mac)));
   1.310 +    flexarray_append(front, "state");
   1.311 +    flexarray_append(front, "1");
   1.312  
   1.313      libxl__device_generic_add(ctx, &device,
   1.314 -                             libxl__xs_kvs_of_flexarray(&gc, back, boffset),
   1.315 -                             libxl__xs_kvs_of_flexarray(&gc, front, foffset));
   1.316 +                             libxl__xs_kvs_of_flexarray(&gc, back, back->count),
   1.317 +                             libxl__xs_kvs_of_flexarray(&gc, front, front->count));
   1.318  
   1.319      /* FIXME: wait for plug */
   1.320      rc = 0;
   1.321 @@ -1624,8 +1619,6 @@ int libxl_device_console_add(libxl_ctx *
   1.322      libxl__gc gc = LIBXL_INIT_GC(ctx);
   1.323      flexarray_t *front;
   1.324      flexarray_t *back;
   1.325 -    unsigned int boffset = 0;
   1.326 -    unsigned int foffset = 0;
   1.327      libxl__device device;
   1.328      int rc;
   1.329  
   1.330 @@ -1647,48 +1640,48 @@ int libxl_device_console_add(libxl_ctx *
   1.331      device.domid = console->domid;
   1.332      device.kind = DEVICE_CONSOLE;
   1.333  
   1.334 -    flexarray_set(back, boffset++, "frontend-id");
   1.335 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", console->domid));
   1.336 -    flexarray_set(back, boffset++, "online");
   1.337 -    flexarray_set(back, boffset++, "1");
   1.338 -    flexarray_set(back, boffset++, "state");
   1.339 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
   1.340 -    flexarray_set(back, boffset++, "domain");
   1.341 -    flexarray_set(back, boffset++, libxl__domid_to_name(&gc, domid));
   1.342 -    flexarray_set(back, boffset++, "protocol");
   1.343 -    flexarray_set(back, boffset++, LIBXL_XENCONSOLE_PROTOCOL);
   1.344 -
   1.345 -    flexarray_set(front, foffset++, "backend-id");
   1.346 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", console->backend_domid));
   1.347 -    flexarray_set(front, foffset++, "limit");
   1.348 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", LIBXL_XENCONSOLE_LIMIT));
   1.349 -    flexarray_set(front, foffset++, "type");
   1.350 +    flexarray_append(back, "frontend-id");
   1.351 +    flexarray_append(back, libxl__sprintf(&gc, "%d", console->domid));
   1.352 +    flexarray_append(back, "online");
   1.353 +    flexarray_append(back, "1");
   1.354 +    flexarray_append(back, "state");
   1.355 +    flexarray_append(back, libxl__sprintf(&gc, "%d", 1));
   1.356 +    flexarray_append(back, "domain");
   1.357 +    flexarray_append(back, libxl__domid_to_name(&gc, domid));
   1.358 +    flexarray_append(back, "protocol");
   1.359 +    flexarray_append(back, LIBXL_XENCONSOLE_PROTOCOL);
   1.360 +
   1.361 +    flexarray_append(front, "backend-id");
   1.362 +    flexarray_append(front, libxl__sprintf(&gc, "%d", console->backend_domid));
   1.363 +    flexarray_append(front, "limit");
   1.364 +    flexarray_append(front, libxl__sprintf(&gc, "%d", LIBXL_XENCONSOLE_LIMIT));
   1.365 +    flexarray_append(front, "type");
   1.366      if (console->consback == LIBXL_CONSBACK_XENCONSOLED)
   1.367 -        flexarray_set(front, foffset++, "xenconsoled");
   1.368 +        flexarray_append(front, "xenconsoled");
   1.369      else
   1.370 -        flexarray_set(front, foffset++, "ioemu");
   1.371 -    flexarray_set(front, foffset++, "output");
   1.372 -    flexarray_set(front, foffset++, console->output);
   1.373 +        flexarray_append(front, "ioemu");
   1.374 +    flexarray_append(front, "output");
   1.375 +    flexarray_append(front, console->output);
   1.376  
   1.377      if (device.devid == 0) {
   1.378          if (console->build_state == NULL) {
   1.379              rc = ERROR_INVAL;
   1.380              goto out_free;
   1.381          }
   1.382 -        flexarray_set(front, foffset++, "port");
   1.383 -        flexarray_set(front, foffset++, libxl__sprintf(&gc, "%"PRIu32, console->build_state->console_port));
   1.384 -        flexarray_set(front, foffset++, "ring-ref");
   1.385 -        flexarray_set(front, foffset++, libxl__sprintf(&gc, "%lu", console->build_state->console_mfn));
   1.386 +        flexarray_append(front, "port");
   1.387 +        flexarray_append(front, libxl__sprintf(&gc, "%"PRIu32, console->build_state->console_port));
   1.388 +        flexarray_append(front, "ring-ref");
   1.389 +        flexarray_append(front, libxl__sprintf(&gc, "%lu", console->build_state->console_mfn));
   1.390      } else {
   1.391 -        flexarray_set(front, foffset++, "state");
   1.392 -        flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1));
   1.393 -        flexarray_set(front, foffset++, "protocol");
   1.394 -        flexarray_set(front, foffset++, LIBXL_XENCONSOLE_PROTOCOL);
   1.395 +        flexarray_append(front, "state");
   1.396 +        flexarray_append(front, libxl__sprintf(&gc, "%d", 1));
   1.397 +        flexarray_append(front, "protocol");
   1.398 +        flexarray_append(front, LIBXL_XENCONSOLE_PROTOCOL);
   1.399      }
   1.400  
   1.401      libxl__device_generic_add(ctx, &device,
   1.402 -                             libxl__xs_kvs_of_flexarray(&gc, back, boffset),
   1.403 -                             libxl__xs_kvs_of_flexarray(&gc, front, foffset));
   1.404 +                             libxl__xs_kvs_of_flexarray(&gc, back, back->count),
   1.405 +                             libxl__xs_kvs_of_flexarray(&gc, front, front->count));
   1.406      rc = 0;
   1.407  out_free:
   1.408      flexarray_free(back);
   1.409 @@ -1704,8 +1697,6 @@ int libxl_device_vkb_add(libxl_ctx *ctx,
   1.410      libxl__gc gc = LIBXL_INIT_GC(ctx);
   1.411      flexarray_t *front;
   1.412      flexarray_t *back;
   1.413 -    unsigned int boffset = 0;
   1.414 -    unsigned int foffset = 0;
   1.415      libxl__device device;
   1.416      int rc;
   1.417  
   1.418 @@ -1727,23 +1718,23 @@ int libxl_device_vkb_add(libxl_ctx *ctx,
   1.419      device.domid = vkb->domid;
   1.420      device.kind = DEVICE_VKBD;
   1.421  
   1.422 -    flexarray_set(back, boffset++, "frontend-id");
   1.423 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vkb->domid));
   1.424 -    flexarray_set(back, boffset++, "online");
   1.425 -    flexarray_set(back, boffset++, "1");
   1.426 -    flexarray_set(back, boffset++, "state");
   1.427 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
   1.428 -    flexarray_set(back, boffset++, "domain");
   1.429 -    flexarray_set(back, boffset++, libxl__domid_to_name(&gc, domid));
   1.430 -
   1.431 -    flexarray_set(front, foffset++, "backend-id");
   1.432 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", vkb->backend_domid));
   1.433 -    flexarray_set(front, foffset++, "state");
   1.434 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1));
   1.435 +    flexarray_append(back, "frontend-id");
   1.436 +    flexarray_append(back, libxl__sprintf(&gc, "%d", vkb->domid));
   1.437 +    flexarray_append(back, "online");
   1.438 +    flexarray_append(back, "1");
   1.439 +    flexarray_append(back, "state");
   1.440 +    flexarray_append(back, libxl__sprintf(&gc, "%d", 1));
   1.441 +    flexarray_append(back, "domain");
   1.442 +    flexarray_append(back, libxl__domid_to_name(&gc, domid));
   1.443 +
   1.444 +    flexarray_append(front, "backend-id");
   1.445 +    flexarray_append(front, libxl__sprintf(&gc, "%d", vkb->backend_domid));
   1.446 +    flexarray_append(front, "state");
   1.447 +    flexarray_append(front, libxl__sprintf(&gc, "%d", 1));
   1.448  
   1.449      libxl__device_generic_add(ctx, &device,
   1.450 -                             libxl__xs_kvs_of_flexarray(&gc, back, boffset),
   1.451 -                             libxl__xs_kvs_of_flexarray(&gc, front, foffset));
   1.452 +                             libxl__xs_kvs_of_flexarray(&gc, back, back->count),
   1.453 +                             libxl__xs_kvs_of_flexarray(&gc, front, front->count));
   1.454      rc = 0;
   1.455  out_free:
   1.456      flexarray_free(back);
   1.457 @@ -1904,8 +1895,6 @@ int libxl_device_vfb_add(libxl_ctx *ctx,
   1.458      libxl__gc gc = LIBXL_INIT_GC(ctx);
   1.459      flexarray_t *front;
   1.460      flexarray_t *back;
   1.461 -    unsigned int boffset = 0;
   1.462 -    unsigned int foffset = 0;
   1.463      libxl__device device;
   1.464      int rc;
   1.465  
   1.466 @@ -1927,45 +1916,31 @@ int libxl_device_vfb_add(libxl_ctx *ctx,
   1.467      device.domid = vfb->domid;
   1.468      device.kind = DEVICE_VFB;
   1.469  
   1.470 -    flexarray_set(back, boffset++, "frontend-id");
   1.471 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->domid));
   1.472 -    flexarray_set(back, boffset++, "online");
   1.473 -    flexarray_set(back, boffset++, "1");
   1.474 -    flexarray_set(back, boffset++, "state");
   1.475 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", 1));
   1.476 -    flexarray_set(back, boffset++, "domain");
   1.477 -    flexarray_set(back, boffset++, libxl__domid_to_name(&gc, domid));
   1.478 -    flexarray_set(back, boffset++, "vnc");
   1.479 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->vnc));
   1.480 -    flexarray_set(back, boffset++, "vnclisten");
   1.481 -    flexarray_set(back, boffset++, vfb->vnclisten);
   1.482 -    flexarray_set(back, boffset++, "vncpasswd");
   1.483 -    flexarray_set(back, boffset++, vfb->vncpasswd);
   1.484 -    flexarray_set(back, boffset++, "vncdisplay");
   1.485 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->vncdisplay));
   1.486 -    flexarray_set(back, boffset++, "vncunused");
   1.487 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->vncunused));
   1.488 -    flexarray_set(back, boffset++, "sdl");
   1.489 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->sdl));
   1.490 -    flexarray_set(back, boffset++, "opengl");
   1.491 -    flexarray_set(back, boffset++, libxl__sprintf(&gc, "%d", vfb->opengl));
   1.492 +    flexarray_vappend(back, "frontend-id", libxl__sprintf(&gc, "%d", vfb->domid), NULL);
   1.493 +    flexarray_vappend(back, "online", "1", NULL);
   1.494 +    flexarray_vappend(back, "state", libxl__sprintf(&gc, "%d", 1), NULL);
   1.495 +    flexarray_vappend(back, "domain", libxl__domid_to_name(&gc, domid), NULL);
   1.496 +    flexarray_vappend(back, "vnc", libxl__sprintf(&gc, "%d", vfb->vnc), NULL);
   1.497 +    flexarray_vappend(back, "vnclisten", vfb->vnclisten, NULL);
   1.498 +    flexarray_append(back, "vncpasswd");
   1.499 +    flexarray_append(back, vfb->vncpasswd);
   1.500 +    flexarray_vappend(back, "vncdisplay", libxl__sprintf(&gc, "%d", vfb->vncdisplay), NULL);
   1.501 +    flexarray_vappend(back, "vncunused", libxl__sprintf(&gc, "%d", vfb->vncunused), NULL);
   1.502 +    flexarray_vappend(back, "sdl", libxl__sprintf(&gc, "%d", vfb->sdl), NULL);
   1.503 +    flexarray_vappend(back, "opengl", libxl__sprintf(&gc, "%d", vfb->opengl), NULL);
   1.504      if (vfb->xauthority) {
   1.505 -        flexarray_set(back, boffset++, "xauthority");
   1.506 -        flexarray_set(back, boffset++, vfb->xauthority);
   1.507 +        flexarray_vappend(back, "xauthority", vfb->xauthority, NULL);
   1.508      }
   1.509      if (vfb->display) {
   1.510 -        flexarray_set(back, boffset++, "display");
   1.511 -        flexarray_set(back, boffset++, vfb->display);
   1.512 +        flexarray_vappend(back, "display", vfb->display, NULL);
   1.513      }
   1.514  
   1.515 -    flexarray_set(front, foffset++, "backend-id");
   1.516 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", vfb->backend_domid));
   1.517 -    flexarray_set(front, foffset++, "state");
   1.518 -    flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1));
   1.519 +    flexarray_vappend(front, "backend-id", libxl__sprintf(&gc, "%d", vfb->backend_domid), NULL);
   1.520 +    flexarray_vappend(front, "state", libxl__sprintf(&gc, "%d", 1), NULL);
   1.521  
   1.522      libxl__device_generic_add(ctx, &device,
   1.523 -                             libxl__xs_kvs_of_flexarray(&gc, back, boffset),
   1.524 -                             libxl__xs_kvs_of_flexarray(&gc, front, foffset));
   1.525 +                             libxl__xs_kvs_of_flexarray(&gc, back, back->count),
   1.526 +                             libxl__xs_kvs_of_flexarray(&gc, front, front->count));
   1.527      rc = 0;
   1.528  out_free:
   1.529      flexarray_free(front);