]> xenbits.xensource.com Git - people/julieng/xen-unstable.git/commitdiff
libxl: add option for discard support to xl disk configuration
authorOlaf Hering <olaf@aepfle.de>
Mon, 19 May 2014 09:50:19 +0000 (11:50 +0200)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 19 May 2014 11:50:27 +0000 (12:50 +0100)
Handle new boolean option discard/no-discard for disk configuration. It
is supposed to disable discard support if file based backing storage was
intentionally created non-sparse to avoid fragmentation of the file.

The option intended for the backend driver. A new boolean property
"discard-enable" is written to the backend node. An upcoming patch for
qemu will make use of this property. The kernel blkback driver may be
updated as well to disable discard for phy based backing storage.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
docs/misc/xl-disk-configuration.txt
tools/libxl/check-xl-disk-parse
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/libxl_types.idl
tools/libxl/libxlu_disk.c
tools/libxl/libxlu_disk_l.l
xen/include/public/io/blkif.h

index 11fee9a9b86e460ecf814b9fc537bb09d224a601..6a2118dfc4e4d449e2611770bdcb3a4f01368c0d 100644 (file)
@@ -217,6 +217,23 @@ If in the future the bug is fixed properly this option will then be
 silently ignored.
 
 
+discard / no-discard
+---------------
+
+Description:           Request that backend advertise discard support to frontend
+Supported values:      discard
+                       no-discard
+Mandatory:             No
+Default value:         discard
+
+An advisory setting for the backend driver, specifying whether to
+advertise discard support (TRIM, UNMAP) to the frontend.  The real
+benefit of this option is to be able to force it off rather than on.  It
+can be used to disable "hole punching" for file based backends which
+were intentionally created non-sparse to avoid fragmentation of the
+file.
+
+
 ============================================
 DEPRECATED PARAMETERS, PREFIXES AND SYNTAXES
 ============================================
index 0698586cf2e132ee080c83d3ffcabf7d7dd14980..1bec4ca9df7dc81a514072698c3d111c65a14cf6 100755 (executable)
@@ -62,7 +62,8 @@ disk: {
     "removable": 0,
     "readwrite": 1,
     "is_cdrom": 0,
-    "direct_io_safe": false
+    "direct_io_safe": false,
+    "discard_enable": "True"
 }
 
 END
@@ -84,7 +85,8 @@ disk: {
     "removable": 1,
     "readwrite": 0,
     "is_cdrom": 1,
-    "direct_io_safe": false
+    "direct_io_safe": false,
+    "discard_enable": "False"
 }
 
 END
@@ -107,7 +109,8 @@ disk: {
     "removable": 0,
     "readwrite": 1,
     "is_cdrom": 0,
-    "direct_io_safe": false
+    "direct_io_safe": false,
+    "discard_enable": "True"
 }
 
 EOF
@@ -125,7 +128,8 @@ disk: {
     "removable": 1,
     "readwrite": 0,
     "is_cdrom": 1,
-    "direct_io_safe": false
+    "direct_io_safe": false,
+    "discard_enable": "False"
 }
 
 EOF
@@ -147,7 +151,8 @@ disk: {
     "removable": 1,
     "readwrite": 0,
     "is_cdrom": 1,
-    "direct_io_safe": false
+    "direct_io_safe": false,
+    "discard_enable": "False"
 }
 
 EOF
@@ -166,7 +171,8 @@ disk: {
     "removable": 0,
     "readwrite": 1,
     "is_cdrom": 0,
-    "direct_io_safe": false
+    "direct_io_safe": false,
+    "discard_enable": "True"
 }
 
 EOF
@@ -187,7 +193,8 @@ disk: {
     "removable": 0,
     "readwrite": 1,
     "is_cdrom": 0,
-    "direct_io_safe": false
+    "direct_io_safe": false,
+    "discard_enable": "True"
 }
 
 EOF
@@ -196,4 +203,63 @@ EOF
 # http://www.drbd.org/users-guide-emb/s-xen-configure-domu.html
 one 0 drbd:app01,hda,w
 
+expected <<END
+disk: {
+    "backend_domid": 0,
+    "backend_domname": null,
+    "pdev_path": "/some/disk/image.raw",
+    "vdev": "hda",
+    "backend": "unknown",
+    "format": "raw",
+    "script": null,
+    "removable": 0,
+    "readwrite": 1,
+    "is_cdrom": 0,
+    "direct_io_safe": false,
+    "discard_enable": "True"
+}
+
+END
+one 0  discard=on  vdev=hda target=/some/disk/image.raw
+one 0  discard=1   vdev=hda target=/some/disk/image.raw
+
+expected <<END
+disk: {
+    "backend_domid": 0,
+    "backend_domname": null,
+    "pdev_path": "/some/disk/image.raw",
+    "vdev": "hda",
+    "backend": "unknown",
+    "format": "raw",
+    "script": null,
+    "removable": 0,
+    "readwrite": 1,
+    "is_cdrom": 0,
+    "direct_io_safe": false,
+    "discard_enable": "False"
+}
+
+END
+one 0  discard vdev=hda target=/some/disk/image.raw
+one 0  discard vdev=hda target=/some/disk/image.raw
+
+expected <<END
+disk: {
+    "backend_domid": 0,
+    "backend_domname": null,
+    "pdev_path": "/some/disk/image.iso",
+    "vdev": "hda",
+    "backend": "unknown",
+    "format": "raw",
+    "script": null,
+    "removable": 1,
+    "readwrite": 0,
+    "is_cdrom": 1,
+    "direct_io_safe": false,
+    "discard_enable": "False"
+}
+
+END
+one 0  cdrom no-discard vdev=hda target=/some/disk/image.iso
+
 complete
index d59ce0c28804827f2dc228282cc76883729e6d3f..4ea7abbad46c0a206d7669c0fbee7c2bd979f57d 100644 (file)
@@ -2209,6 +2209,9 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
             flexarray_append(back, "direct-io-safe");
             flexarray_append(back, "1");
         }
+        flexarray_append_pair(back, "discard-enable",
+                              libxl_defbool_val(disk->discard_enable) ?
+                              "1" : "0");
 
         flexarray_append(front, "backend-id");
         flexarray_append(front, libxl__sprintf(gc, "%d", disk->backend_domid));
index 84f9c0eea82fe14779fa5d2ff260bb7a3664eff8..c7aa8177622294bf4a1ff8d045e50b6afa7f10a5 100644 (file)
  */
 #define LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE 1
 
+/*
+ * The libxl_device_disk has the discard_enable field.
+ */
+#define LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE 1
+
 /*
  * libxl ABI compatibility
  *
index 8944686b8ae77b6ee80b1e7275e352edfef792ee..52f1aa9f21398675b312a77609e480dbd083dbf5 100644 (file)
@@ -417,6 +417,7 @@ libxl_device_disk = Struct("device_disk", [
     ("readwrite", integer),
     ("is_cdrom", integer),
     ("direct_io_safe", bool),
+    ("discard_enable", libxl_defbool),
     ])
 
 libxl_device_nic = Struct("device_nic", [
index 18fe386dbe2f0adff504af5863c2e30d4c09975d..752a2c7cdc08ff42849156ad0e75f31b8bcc3726 100644 (file)
@@ -79,6 +79,7 @@ int xlu_disk_parse(XLU_Config *cfg,
         if (!disk->pdev_path || !strcmp(disk->pdev_path, ""))
             disk->format = LIBXL_DISK_FORMAT_EMPTY;
     }
+    libxl_defbool_setdefault(&disk->discard_enable, !!disk->readwrite);
 
     if (!disk->vdev) {
         xlu__disk_err(&dpc,0, "no vdev specified");
index ba8577cc0c31c4f14757bfa8d0e632eb6fbca56c..1a5deb5be6698b2b86d107dbdb2ffda948c3b9d0 100644 (file)
@@ -174,6 +174,8 @@ backendtype=[^,]*,? { STRIP(','); setbackendtype(DPC,FROMEQUALS); }
 vdev=[^,]*,?   { STRIP(','); SAVESTRING("vdev", vdev, FROMEQUALS); }
 script=[^,]*,? { STRIP(','); SAVESTRING("script", script, FROMEQUALS); }
 direct-io-safe,? { DPC->disk->direct_io_safe = 1; }
+discard,?      { libxl_defbool_set(&DPC->disk->discard_enable, true); }
+no-discard,?   { libxl_defbool_set(&DPC->disk->discard_enable, false); }
 
  /* the target magic parameter, eats the rest of the string */
 
index 1e7cea948edf5546c5a2b05392425d0cff939e3e..6baf7fb5191bf870803f38fb8860641e1cfbd788 100644 (file)
  *
  *------------------------- Backend Device Properties -------------------------
  *
+ * discard-enable
+ *      Values:         0/1 (boolean)
+ *      Default Value:  1
+ *
+ *      This optional property, set by the toolstack, instructs the backend
+ *      to offer discard to the frontend. If the property is missing the
+ *      backend should offer discard if the backing storage actually supports
+ *      it. This optional property, set by the toolstack, requests that the
+ *      backend offer, or not offer, discard to the frontend.
+ *
  * discard-alignment
  *      Values:         <uint32_t>
  *      Default Value:  0