# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1318941402 -3600
# Node ID 7357a4c2c0113afb971a074f4b21b5c67eb5140b
# Parent ae1e145bdac024835980370473bc82269c9f9c67
libxl: convert disk handling to device API
Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
---
diff -r ae1e145bdac0 -r 7357a4c2c011 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/libxl.c Tue Oct 18 13:36:42 2011 +0100
@@ -916,13 +916,58 @@
/******************************************************************************/
+int libxl_device_disk_init(libxl_ctx *ctx, libxl_device_disk *disk)
+{
+ memset(disk, 0x00, sizeof(libxl_device_disk));
+ return 0;
+}
+
+static int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
+ libxl_device_disk *disk,
+ libxl__device *device)
+{
+ libxl_ctx *ctx = libxl__gc_owner(gc);
+ int devid;
+
+ devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
+ if (devid==-1) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
+ " virtual disk identifier %s", disk->vdev);
+ return ERROR_INVAL;
+ }
+
+ device->backend_domid = disk->backend_domid;
+ device->backend_devid = devid;
+
+ switch (disk->backend) {
+ case LIBXL_DISK_BACKEND_PHY:
+ device->backend_kind = LIBXL__DEVICE_KIND_VBD;
+ break;
+ case LIBXL_DISK_BACKEND_TAP:
+ device->backend_kind = LIBXL__DEVICE_KIND_VBD;
+ break;
+ case LIBXL_DISK_BACKEND_QDISK:
+ device->backend_kind = LIBXL__DEVICE_KIND_QDISK;
+ break;
+ default:
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type:
%d\n",
+ disk->backend);
+ return ERROR_INVAL;
+ }
+
+ device->domid = domid;
+ device->devid = devid;
+ device->kind = LIBXL__DEVICE_KIND_VBD;
+
+ return 0;
+}
+
int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk
*disk)
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
flexarray_t *front;
flexarray_t *back;
char *dev;
- int devid;
libxl__device device;
int major, minor, rc;
@@ -950,20 +995,13 @@
goto out_free;
}
- devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
- if (devid==-1) {
+ rc = libxl__device_from_disk(&gc, domid, disk, &device);
+ if (rc != 0) {
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
" virtual disk identifier %s", disk->vdev);
- rc = ERROR_INVAL;
goto out_free;
}
- device.backend_devid = devid;
- device.backend_domid = disk->backend_domid;
- device.devid = devid;
- device.domid = domid;
- device.kind = LIBXL__DEVICE_KIND_VBD;
-
switch (disk->backend) {
case LIBXL_DISK_BACKEND_PHY:
dev = disk->pdev_path;
@@ -975,7 +1013,7 @@
flexarray_append(back, "params");
flexarray_append(back, dev);
- device.backend_kind = LIBXL__DEVICE_KIND_VBD;
+ assert(device.backend_kind == LIBXL__DEVICE_KIND_VBD);
break;
case LIBXL_DISK_BACKEND_TAP:
dev = libxl__blktap_devpath(&gc, disk->pdev_path, disk->format);
@@ -994,7 +1032,7 @@
flexarray_append(back, "params");
flexarray_append(back, libxl__sprintf(&gc, "%s:%s",
libxl__device_disk_string_of_format(disk->format),
disk->pdev_path));
- device.backend_kind = LIBXL__DEVICE_KIND_QDISK;
+ assert(device.backend_kind == LIBXL__DEVICE_KIND_QDISK);
break;
default:
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type:
%d\n", disk->backend);
@@ -1026,7 +1064,7 @@
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, libxl__sprintf(&gc, "%d", device.devid));
flexarray_append(front, "device-type");
flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
@@ -1044,45 +1082,37 @@
return rc;
}
-int libxl_device_disk_del(libxl_ctx *ctx, uint32_t domid,
- libxl_device_disk *disk, int wait)
+int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid,
+ libxl_device_disk *disk)
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
libxl__device device;
- int devid, rc;
-
- devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
- device.backend_domid = disk->backend_domid;
- device.backend_devid = devid;
-
- switch (disk->backend) {
- case LIBXL_DISK_BACKEND_PHY:
- device.backend_kind = LIBXL__DEVICE_KIND_VBD;
- break;
- case LIBXL_DISK_BACKEND_TAP:
- device.backend_kind = LIBXL__DEVICE_KIND_VBD;
- break;
- case LIBXL_DISK_BACKEND_QDISK:
- device.backend_kind = LIBXL__DEVICE_KIND_QDISK;
- break;
- default:
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type:
%d\n",
- disk->backend);
- rc = ERROR_INVAL;
- goto out_free;
- }
- device.domid = domid;
- device.devid = devid;
- device.kind = LIBXL__DEVICE_KIND_VBD;
- if (wait)
- rc = libxl__device_remove(&gc, &device, wait);
- else
- rc = libxl__device_destroy(&gc, &device);
-out_free:
+ int rc;
+
+ rc = libxl__device_from_disk(&gc, domid, disk, &device);
+ if (rc != 0) goto out;
+
+ rc = libxl__device_remove(&gc, &device, 1);
+out:
libxl__free_all(&gc);
return rc;
}
+int libxl_device_disk_destroy(libxl_ctx *ctx, uint32_t domid,
+ libxl_device_disk *disk)
+{
+ libxl__gc gc = LIBXL_INIT_GC(ctx);
+ libxl__device device;
+ int rc;
+
+ rc = libxl__device_from_disk(&gc, domid, disk, &device);
+ if (rc != 0) goto out;
+
+ rc = libxl__device_destroy(&gc, &device);
+out:
+ libxl__free_all(&gc);
+ return rc;
+}
char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk)
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
@@ -1626,7 +1656,7 @@
unsigned int len;
char *tmp;
- memset(disk, 0, sizeof(*disk));
+ libxl_device_disk_init(ctx, disk);
tmp = xs_read(ctx->xsh, XBT_NULL,
libxl__sprintf(gc, "%s/params", be_path), &len);
@@ -1670,7 +1700,8 @@
char *dompath, *path;
int rc = ERROR_FAIL;
- memset(disk, 0, sizeof (libxl_device_disk));
+ libxl_device_disk_init(ctx, disk);
+
dompath = libxl__xs_get_dompath(&gc, domid);
if (!dompath) {
goto out;
@@ -1812,11 +1843,11 @@
ret = 0;
- libxl_device_disk_del(ctx, domid, disks + i, 1);
+ libxl_device_disk_remove(ctx, domid, disks + i);
libxl_device_disk_add(ctx, domid, disk);
stubdomid = libxl_get_stubdom_id(ctx, domid);
if (stubdomid) {
- libxl_device_disk_del(ctx, stubdomid, disks + i, 1);
+ libxl_device_disk_remove(ctx, stubdomid, disks + i);
libxl_device_disk_add(ctx, stubdomid, disk);
}
out:
diff -r ae1e145bdac0 -r 7357a4c2c011 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/libxl.h Tue Oct 18 13:36:42 2011 +0100
@@ -438,15 +438,27 @@
* This function does not interact with the guest and therefore
* cannot block on the guest.
*/
+
+/* Disks */
+int libxl_device_disk_init(libxl_ctx *ctx, libxl_device_disk *disk);
int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk
*disk);
-int libxl_device_disk_del(libxl_ctx *ctx, uint32_t domid, libxl_device_disk
*disk, int wait);
+int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_disk
*disk);
+int libxl_device_disk_destroy(libxl_ctx *ctx, uint32_t domid,
+ libxl_device_disk *disk);
+
libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int
*num);
int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
libxl_device_disk *disk, libxl_diskinfo
*diskinfo);
+
+/*
+ * Insert a CD-ROM device. A device corresponding to disk must already
+ * be attached to the guest.
+ */
int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk
*disk);
/*
- * Make a disk available in this domain. Returns path to a device.
+ * Make a disk available in this (the control) domain. Returns path to
+ * a device.
*/
char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk);
int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk);
diff -r ae1e145bdac0 -r 7357a4c2c011 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c Tue Oct 18 13:36:42 2011 +0100
@@ -494,7 +494,7 @@
{
int e;
- memset(disk, 0, sizeof(*disk));
+ libxl_device_disk_init(ctx, disk);
if (!*config) {
*config = xlu_cfg_init(stderr, "command line");
@@ -1893,6 +1893,8 @@
disk.backend_domid = 0;
libxl_cdrom_insert(ctx, domid, &disk);
+
+ libxl_device_disk_dispose(&disk);
free(buf);
}
@@ -4182,8 +4184,8 @@
fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]);
return 1;
}
- if (libxl_device_disk_del(ctx, domid, &disk, 1)) {
- fprintf(stderr, "libxl_device_disk_del failed.\n");
+ if (libxl_device_disk_remove(ctx, domid, &disk)) {
+ fprintf(stderr, "libxl_device_disk_remove failed.\n");
}
return 0;
}
diff -r ae1e145bdac0 -r 7357a4c2c011 tools/ocaml/libs/xl/genwrap.py
--- a/tools/ocaml/libs/xl/genwrap.py Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/ocaml/libs/xl/genwrap.py Tue Oct 18 13:36:42 2011 +0100
@@ -16,6 +16,11 @@
"libxl_hwcap": ("int32 array", None,
"Val_hwcap(&%(c)s)"),
}
+DEVICE_FUNCTIONS = [ ("add", ["t", "domid", "unit"]),
+ ("remove", ["t", "domid", "unit"]),
+ ("destroy", ["t", "domid", "unit"]),
+ ]
+
functions = { # ( name , [type1,type2,....] )
"device_vfb": [ ("add", ["t", "domid", "unit"]),
("clean_shutdown", ["domid", "unit"]),
@@ -27,9 +32,7 @@
],
"device_console": [ ("add", ["t", "domid", "unit"]),
],
- "device_disk": [ ("add", ["t", "domid", "unit"]),
- ("del", ["t", "domid", "unit"]),
- ],
+ "device_disk": DEVICE_FUNCTIONS,
"device_nic": [ ("add", ["t", "domid", "unit"]),
("del", ["t", "domid", "unit"]),
],
diff -r ae1e145bdac0 -r 7357a4c2c011 tools/ocaml/libs/xl/xenlight_stubs.c
--- a/tools/ocaml/libs/xl/xenlight_stubs.c Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/ocaml/libs/xl/xenlight_stubs.c Tue Oct 18 13:36:42 2011 +0100
@@ -247,7 +247,7 @@
device_disk_val(&gc, &lg, &c_info, info);
INIT_CTX();
- ret = libxl_device_disk_del(ctx, Int_val(domid), &c_info, 0);
+ ret = libxl_device_disk_remove(ctx, Int_val(domid), &c_info);
if (ret != 0)
failwith_xl("disk_del", &lg);
FREE_CTX();
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|