[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH 5/6] libxl: introduce libxl__alloc_vdev
On Tue, 2012-03-27 at 14:59 +0100, Stefano Stabellini wrote: > Introduce libxl__alloc_vdev: find a spare virtual block device in the > domain passed as argument. > > Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> > --- > tools/libxl/libxl.c | 60 > +++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 60 insertions(+), 0 deletions(-) > > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c > index fe63fd5..fa7898a 100644 > --- a/tools/libxl/libxl.c > +++ b/tools/libxl/libxl.c > @@ -1228,6 +1228,13 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t > domid, int autopass) > > > /******************************************************************************/ > > +static int libxl__append_disk_list_of_type(libxl__gc *gc, > + uint32_t domid, > + xs_transaction_t t, > + const char *type, > + libxl_device_disk **disks, > + int *ndisks); > + > int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk) > { > int rc; > @@ -1278,6 +1285,59 @@ static int libxl__device_from_disk(libxl__gc *gc, > uint32_t domid, > return 0; > } > > +static int libxl__vdev_to_index(libxl__gc *gc, char *vdev) > +{ > + if (vdev == NULL) > + return 0; > + if (strlen(vdev) > 4 || strlen(vdev) < 4) > + return 0; > + /* assume xvdz is the last one available */ > + if (vdev[3] >= 'z') > + return -1; > + return vdev[3] - 'a'; > +} > + > +static char* libxl__index_to_vdev(libxl__gc *gc, int idx) > +{ > + if (idx < 0) > + return NULL; > + return libxl__sprintf(gc, "xvd%c", 'a' + idx); > +} > + > +static char * libxl__alloc_vdev(libxl__gc *gc, uint32_t domid, > xs_transaction_t t, > + libxl_device_disk *disk) > +{ > + int rc = 0; > + libxl_device_disk *disks = NULL; > + int num = 0, idx = -1, max_idx = -1, i = 0; > + > + rc = libxl__append_disk_list_of_type(gc, domid, t, "vbd", &disks, &num); > + if (rc) goto out; > + > + rc = libxl__append_disk_list_of_type(gc, domid, t, "tap", &disks, &num); > + if (rc) goto out; > + > + rc = libxl__append_disk_list_of_type(gc, domid, t, "qdisk", &disks, > &num); > + if (rc) goto out; This is basically an open-coded version of libxl_disk_list, isn't it? For this use though wouldn't it be as easy to simply iterate over idx checking if a frontend dir exists? > + > + for (i = 0; i < num; i++) { > + idx = libxl__vdev_to_index(gc, disks[i].vdev); > + if (idx < 0) { > + max_idx = -1; > + goto out; > + } > + if (idx > max_idx) > + max_idx = idx; > + } > + max_idx++; > +out: > + while (disks && num) { > + num--; > + libxl_device_disk_dispose(&disks[num]); > + } > + free(disks); > + return libxl__index_to_vdev(gc, max_idx); > +} > > static int libxl__device_disk_add_t(libxl__gc *gc, uint32_t domid, > xs_transaction_t t, > libxl_device_disk *disk) _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |