WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 17 of 23] libxl: convert disk handling to device API

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 17 of 23] libxl: convert disk handling to device API
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Fri, 30 Sep 2011 14:33:30 +0100
Cc: Jim Fehlig <jfehlig@xxxxxxxxxx>, Mike McClurg <mike.mcclurg@xxxxxxxxxx>, Dave Scott <Dave.Scott@xxxxxxxxxxxxx>, Jonathan Ludlam <Jonathan.Ludlam@xxxxxxxxxxxxx>
Delivery-date: Fri, 30 Sep 2011 06:51:40 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1317389593@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1317389593@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1317389248 -3600
# Node ID 1892dad72518f5253af2282db650cdd70c56a218
# Parent  b3e80fe9f014f03700ca4846dde58d3473236223
libxl: convert disk handling to device API

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r b3e80fe9f014 -r 1892dad72518 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.c       Fri Sep 30 14:27:28 2011 +0100
@@ -916,13 +916,58 @@ int libxl_vncviewer_exec(libxl_ctx *ctx,
 
 
/******************************************************************************/
 
+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;
 
@@ -947,20 +992,13 @@ int libxl_device_disk_add(libxl_ctx *ctx
         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;
@@ -972,7 +1010,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
             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);
@@ -991,7 +1029,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
             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);
@@ -1023,7 +1061,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
     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");
 
@@ -1041,45 +1079,37 @@ out:
     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_force_remove(&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_force_remove(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_force_remove(&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);
@@ -1623,7 +1653,7 @@ static void libxl__device_disk_from_xs_b
     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);
@@ -1667,7 +1697,8 @@ int libxl_devid_to_device_disk(libxl_ctx
     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;
@@ -1809,11 +1840,11 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
 
     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 b3e80fe9f014 -r 1892dad72518 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.h       Fri Sep 30 14:27:28 2011 +0100
@@ -451,15 +451,27 @@ libxl_vminfo * libxl_list_vm(libxl_ctx *
  * is used to free the members of the libxl_device_<type> data
  * type. It has no impact on the devices attached to any domain.
  */
+
+/* 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_force_remove(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 b3e80fe9f014 -r 1892dad72518 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Fri Sep 30 14:27:28 2011 +0100
@@ -554,7 +554,7 @@ static void parse_disk_config_multistrin
 {
     int e;
 
-    memset(disk, 0, sizeof(*disk));
+    libxl_device_disk_init(ctx, disk);
 
     if (!*config) {
         *config = xlu_cfg_init(stderr, "command line");
@@ -1953,6 +1953,8 @@ static void cd_insert(const char *dom, c
     disk.backend_domid = 0;
 
     libxl_cdrom_insert(ctx, domid, &disk);
+
+    libxl_device_disk_destroy(&disk);
     free(buf);
 }
 
@@ -4242,8 +4244,8 @@ int main_blockdetach(int argc, char **ar
         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;
 }

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>