Skip to contentSkip to conversation

libxl: add option for discard support to xl disk configuration

PATCH Superseded Olaf Hering 3 participants 5 messages May 5, 2014 – May 9, 2014

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 libxl: add option for discard support to xl disk configuration

Handle new option discard=on|off 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 is a boolean and 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.

v4:
rebase ontop of commit 6ec48cf4 (direct_io_safe)
rebase ontop of fixup commit for 6ec48cf4 (direct_io_safe)
add testcases to tools/libxl/check-xl-disk-parse
v3:
enable discard unconditionally by always writing discard-enable=1 to xenstore fix typos in xl-disk-configuration.txt
update description in blkif.h, property should be ignored if unsupported v2:
rename xenstore property from discard_enable to discard-enable update description in xl-disk-configuration.txt
use libxl_defbool as type for discard_enable
update check-xl-disk-parse to use "<default>"
add LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE to libxl.h

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
---
 docs/misc/xl-disk-configuration.txt | 15 +++++++
 tools/libxl/check-xl-disk-parse     | 80 +++++++++++++++++++++++++++++++++----
 tools/libxl/libxl.c                 |  2 +
 tools/libxl/libxl.h                 |  5 +++
 tools/libxl/libxl_types.idl         |  1 +
 tools/libxl/libxlu_disk.c           |  2 +
 tools/libxl/libxlu_disk_l.l         |  4 ++
 xen/include/public/io/blkif.h       | 10 +++++
 8 files changed, 112 insertions(+), 7 deletions(-)
docs/misc/xl-disk-configuration.txt +15 -0
index 11fee9a..e2a56f3 100644
@@ -217,6 +217,21 @@ If in the future the bug is fixed properly this option will then be
 silently ignored.
 
 
+discard=<boolean>
+---------------
+
+Description:           Instruct backend to advertise discard support to frontend
+Supported values:      on, off, 0, 1
+Mandatory:             No
+Default value:         on
+
+This option is an advisory setting for the backend driver, depending on the
+value, 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 allows
+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
 ============================================
tools/libxl/check-xl-disk-parse +73 -7

126 lines not on this page · raw message

tools/libxl/libxl.c +2 -0
index d59ce0c..2b7352c 100644
@@ -2209,6 +2209,8 @@ 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));
tools/libxl/libxl.h +5 -0
index 84f9c0e..c7aa817 100644
@@ -102,6 +102,11 @@
 #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
  *
  * The only guarantee which libxl makes regarding ABI compatibility
tools/libxl/libxl_types.idl +1 -0
index 8944686..52f1aa9 100644
@@ -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", [
tools/libxl/libxlu_disk.c +2 -0
index 18fe386..5827025 100644
@@ -79,6 +79,8 @@ int xlu_disk_parse(XLU_Config *cfg,
         if (!disk->pdev_path || !strcmp(disk->pdev_path, ""))
             disk->format = LIBXL_DISK_FORMAT_EMPTY;
     }
+    if (libxl_defbool_is_default(disk->discard_enable))
+        libxl_defbool_setdefault(&disk->discard_enable, !!disk->readwrite);
 
     if (!disk->vdev) {
         xlu__disk_err(&dpc,0, "no vdev specified");
tools/libxl/libxlu_disk_l.l +4 -0
index ba8577c..7fb378a 100644
@@ -174,6 +174,10 @@ 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=on,?	{ libxl_defbool_set(&DPC->disk->discard_enable, true); }
+discard=1,?	{ libxl_defbool_set(&DPC->disk->discard_enable, true); }
+discard=off,?	{ libxl_defbool_set(&DPC->disk->discard_enable, false); }
+discard=0,?	{ libxl_defbool_set(&DPC->disk->discard_enable, false); }
 
  /* the target magic parameter, eats the rest of the string */
 
xen/include/public/io/blkif.h +10 -0
index 1e7cea9..27a88ba 100644
@@ -197,6 +197,16 @@
  *
  *------------------------- 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. The
+ *      backend driver should ignore the property if the property is set but
+ *      the backing storage does not support the feature.
+ *
  * discard-alignment
  *      Values:         <uint32_t>
  *      Default Value:  0
#1 lore raw
Quoted 263 lines · Olaf Hering

Handle new option discard=on|off 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 is a boolean and 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.

v4:
rebase ontop of commit 6ec48cf4 (direct_io_safe)
rebase ontop of fixup commit for 6ec48cf4 (direct_io_safe)
add testcases to tools/libxl/check-xl-disk-parse
v3:
enable discard unconditionally by always writing discard-enable=1 to xenstore fix typos in xl-disk-configuration.txt
update description in blkif.h, property should be ignored if unsupported v2:
rename xenstore property from discard_enable to discard-enable update description in xl-disk-configuration.txt
use libxl_defbool as type for discard_enable
update check-xl-disk-parse to use "<default>"
add LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE to libxl.h

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
---
 docs/misc/xl-disk-configuration.txt | 15 +++++++
 tools/libxl/check-xl-disk-parse     | 80 +++++++++++++++++++++++++++++++++----
 tools/libxl/libxl.c                 |  2 +
 tools/libxl/libxl.h                 |  5 +++
 tools/libxl/libxl_types.idl         |  1 +
 tools/libxl/libxlu_disk.c           |  2 +
 tools/libxl/libxlu_disk_l.l         |  4 ++
 xen/include/public/io/blkif.h       | 10 +++++
 8 files changed, 112 insertions(+), 7 deletions(-)
docs/misc/xl-disk-configuration.txt +15 -0
index 11fee9a..e2a56f3 100644
@@ -217,6 +217,21 @@ If in the future the bug is fixed properly this option will then be
 silently ignored.
 
 
+discard=<boolean>
+---------------
+
+Description:           Instruct backend to advertise discard support to frontend
+Supported values:      on, off, 0, 1
+Mandatory:             No
+Default value:         on
+
+This option is an advisory setting for the backend driver, depending on the
+value, 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 allows
+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
 ============================================
tools/libxl/check-xl-disk-parse +73 -7
index 0698586..c564e01 100755
@@ -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=off vdev=hda target=/some/disk/image.raw
+one 0  discard=0   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 discard=off vdev=hda target=/some/disk/image.iso
+
 complete
tools/libxl/libxl.c +2 -0
index d59ce0c..2b7352c 100644
@@ -2209,6 +2209,8 @@ 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));
tools/libxl/libxl.h +5 -0
index 84f9c0e..c7aa817 100644
@@ -102,6 +102,11 @@
 #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
  *
  * The only guarantee which libxl makes regarding ABI compatibility
tools/libxl/libxl_types.idl +1 -0
index 8944686..52f1aa9 100644
@@ -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", [
tools/libxl/libxlu_disk.c +2 -0
index 18fe386..5827025 100644
@@ -79,6 +79,8 @@ int xlu_disk_parse(XLU_Config *cfg,
         if (!disk->pdev_path || !strcmp(disk->pdev_path, ""))
             disk->format = LIBXL_DISK_FORMAT_EMPTY;
     }
+    if (libxl_defbool_is_default(disk->discard_enable))
+        libxl_defbool_setdefault(&disk->discard_enable, !!disk->readwrite);
 
     if (!disk->vdev) {
         xlu__disk_err(&dpc,0, "no vdev specified");
tools/libxl/libxlu_disk_l.l +0 -0
index ba8577c..7fb378a 100644

tools/libxl/libxlu_disk_l.l backendtype=[^,]*,? { STRIP(','); setbackendtype(DPC,FROMEQUALS); } · line 180

Quoted 7 lines
tools/libxl/libxlu_disk_l.l +4 -0
@@ -174,6 +174,10 @@ 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=on,?	{ libxl_defbool_set(&DPC->disk->discard_enable, true); }
+discard=1,?	{ libxl_defbool_set(&DPC->disk->discard_enable, true); }
+discard=off,?	{ libxl_defbool_set(&DPC->disk->discard_enable, false); }
+discard=0,?	{ libxl_defbool_set(&DPC->disk->discard_enable, false); }

I think this automatically generated?

Quoted 12 lines
tools/libxl/libxlu_disk_l.l +0 -0
  /* the target magic parameter, eats the rest of the string */
 
xen/include/public/io/blkif.h +1 -0
index 1e7cea9..27a88ba 100644
@@ -197,6 +197,16 @@
  *
  *------------------------- Backend Device Properties -------------------------
  *
+ * discard-enable

xen/include/public/io/blkif.h line 210

Quoted 10 lines
xen/include/public/io/blkif.h +8 -0
+ *      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. The
 
 
+ *      backend driver should ignore the property if the property is set but
+ *      the backing storage does not support the feature.

? I think you want to say: "The backend driver should ignore the propery if the backing storage does not expose this functionality."

Quoted 9 lines
xen/include/public/io/blkif.h +1 -0
+ *
  * discard-alignment
  *      Values:         <uint32_t>
  *      Default Value:  0

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 11 lines · Konrad Rzeszutek Wilk

tools/libxl/libxlu_disk_l.l backendtype=[^,]*,? { STRIP(','); setbackendtype(DPC,FROMEQUALS); } · line 180

Quoted 9 lines

+++ b/tools/libxl/libxlu_disk_l.l

tools/libxl/libxlu_disk_l.l +4 -0
@@ -174,6 +174,10 @@ 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=on,?	{ libxl_defbool_set(&DPC->disk->discard_enable, true); }
+discard=1,?	{ libxl_defbool_set(&DPC->disk->discard_enable, true); }
+discard=off,?	{ libxl_defbool_set(&DPC->disk->discard_enable, false); }
+discard=0,?	{ libxl_defbool_set(&DPC->disk->discard_enable, false); }

I think this automatically generated?

Yes, bison/flex should be rerun after applying this change.

Quoted 4 lines

xen/include/public/io/blkif.h line 208

Quoted 2 lines
xen/include/public/io/blkif.h +2 -0
+ *      backend driver should ignore the property if the property is set but
+ *      the backing storage does not support the feature.

? I think you want to say: "The backend driver should ignore the propery if the backing storage does not expose this functionality."

That would be ok as well, if your version is better english anyway.

Olaf

#3 lore raw
In reply to Olaf Hering

Olaf Hering writes ("[PATCH v4] libxl: add option for discard support to xl disk configuration"):

Quoted 9 lines

Handle new option discard=on|off 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 is a boolean and 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.

Thanks. This is pretty good, but I have some minor comments and questions:

Quoted 1 line

+++ b/docs/misc/xl-disk-configuration.txt

...

docs/misc/xl-disk-configuration.txt If in the future the bug is fixed properly this option will then be · line 223

Quoted 4 lines
docs/misc/xl-disk-configuration.txt +4 -0
+discard=<boolean>
+---------------
+
+Description:           Instruct backend to advertise discard support to frontend

I think you mean "Request" rather than "Instruct". Since the request may or may not be honoured.

docs/misc/xl-disk-configuration.txt If in the future the bug is fixed properly this option will then be · line 226

Quoted 3 lines
docs/misc/xl-disk-configuration.txt +3 -0
+Supported values:      on, off, 0, 1
+Mandatory:             No
+Default value:         on

We have two other roughly boolean configuration parameters, and neither of them use "thing=0" or "thing=on":
disk->is_cdrom is set by simply saying "cdrom". disk->direct_io_safe is set by simply saying "direct-io-safe".

I think we should follow this pattern.

This new option needs a negative, though, since the default is on. I suggest:
discard
no-discard
?

Review

Quoted 6 lines
(quoted diff) +6 -0
+This option is an advisory setting for the backend driver,
+depending on the value, 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 allows to disable "hole punching"
+for file based backends which were intentionally created non-sparse
+to avoid fragmentation of the file.

This reads rather oddly to a native speaker. Let me rephrase for you:

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.

Quoted 1 line

+++ b/tools/libxl/libxl.c

...

tools/libxl/libxl.c static void device_disk_add(libxl__egc *egc, uint32_t domid, · line 2213

Quoted 2 lines
tools/libxl/libxl.c +2 -0
+        flexarray_append_pair(back, "discard-enable",
+                              libxl_defbool_val(disk->discard_enable) ? "1" : "0");

This line needs to be wrapped.

Quoted 1 line

+++ b/tools/libxl/libxl.h

...

tools/libxl/libxlu_disk.c int xlu_disk_parse(XLU_Config *cfg, · line 83

Quoted 2 lines
tools/libxl/libxlu_disk.c +2 -0
+    if (libxl_defbool_is_default(disk->discard_enable))
+        libxl_defbool_setdefault(&disk->discard_enable, !!disk->readwrite);

You can call setdefault unconditionally.

Quoted 5 lines

+ * discard-enable

+ *      Values:         0/1 (boolean)
+ *      Default Value:  1

+ *
+ * This optional property, set by the toolstack, instructs the backend\

to

Quoted 1 line

+ * offer discard to the frontend. If the property is missing the backe\

nd

Quoted 1 line

+ * should offer discard if the backing storage actually supports it. T\

he

Quoted 1 line

+ * backend driver should ignore the property if the property is set bu\

t

Quoted 1 line

+ * the backing storage does not support the feature.

I think it would be helpful to wrap this a bit tighter. You can see the wrap damage.

I agree with Konrad's comments about the last sentence.

I think here you want to say "request" again rather than "instruct". Also, you need to make it go both ways. I would suggest

This optional property, set by the toolstack, requests that the backend offer, or not offer, discard to the frontend.

Thanks,
Ian.

#4 lore raw
Quoted 5 lines · Ian Jackson

Olaf Hering writes ("[PATCH v4] libxl: add option for discard support to xl disk configuration"):

Quoted 4 lines

Handle new option discard=on|off 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.

Quoted 8 lines
Quoted 5 lines

The option is a boolean and 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.

Thanks. This is pretty good, but I have some minor comments and questions:

Thanks for the review. I sent v5, which contains this change compared to v4.

Olaf

 docs/misc/xl-disk-configuration.txt | 22 ++++++++++++----------
 tools/libxl/check-xl-disk-parse     |  6 +++---
 tools/libxl/libxl.c                 |  3 ++-
 tools/libxl/libxlu_disk.c           |  3 +--
 tools/libxl/libxlu_disk_l.l         |  6 ++----
 xen/include/public/io/blkif.h       | 10 +++++-----
 6 files changed, 25 insertions(+), 25 deletions(-)
docs/misc/xl-disk-configuration.txt +12 -10
index e2a56f3..8421e8a 100644
@@ -217,19 +217,21 @@ If in the future the bug is fixed properly this option will then be
 silently ignored.
 
 
-discard=<boolean>
+discard / no-discard
 ---------------
 
-Description:           Instruct backend to advertise discard support to frontend
-Supported values:      on, off, 0, 1
+Description:           Request backend to advertise discard support to frontend
+Supported values:      discard
+                       no-discard
 Mandatory:             No
-Default value:         on
-
-This option is an advisory setting for the backend driver, depending on the
-value, 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 allows
-to disable "hole punching" for file based backends which were intentionally
-created non-sparse to avoid fragmentation of the file.
+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.
 
 
 ============================================
tools/libxl/check-xl-disk-parse +3 -3
index c564e01..1bec4ca 100755
@@ -240,8 +240,8 @@ disk: {
 }
 
 END
-one 0  discard=off vdev=hda target=/some/disk/image.raw
-one 0  discard=0   vdev=hda target=/some/disk/image.raw
+one 0  discard vdev=hda target=/some/disk/image.raw
+one 0  discard vdev=hda target=/some/disk/image.raw
 
 expected <<END
 disk: {
@@ -260,6 +260,6 @@ disk: {
 }
 
 END
-one 0  cdrom discard=off vdev=hda target=/some/disk/image.iso
+one 0  cdrom no-discard vdev=hda target=/some/disk/image.iso
 
 complete
tools/libxl/libxl.c +2 -1
index 1b76a25..c3a9236 100644
@@ -2477,7 +2477,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
             flexarray_append(back, "1");
         }
         flexarray_append_pair(back, "discard-enable",
-                              libxl_defbool_val(disk->discard_enable) ? "1" : "0");
+                              libxl_defbool_val(disk->discard_enable) ?
+                              "1" : "0");
 
         flexarray_append(front, "backend-id");
         flexarray_append(front, libxl__sprintf(gc, "%d", disk->backend_domid));
tools/libxl/libxlu_disk.c +1 -2
index 5827025..752a2c7 100644
@@ -79,8 +79,7 @@ int xlu_disk_parse(XLU_Config *cfg,
         if (!disk->pdev_path || !strcmp(disk->pdev_path, ""))
             disk->format = LIBXL_DISK_FORMAT_EMPTY;
     }
-    if (libxl_defbool_is_default(disk->discard_enable))
-        libxl_defbool_setdefault(&disk->discard_enable, !!disk->readwrite);
+    libxl_defbool_setdefault(&disk->discard_enable, !!disk->readwrite);
 
     if (!disk->vdev) {
         xlu__disk_err(&dpc,0, "no vdev specified");
tools/libxl/libxlu_disk_l.l +2 -4
index 7fb378a..1a5deb5 100644
@@ -174,10 +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=on,?	{ libxl_defbool_set(&DPC->disk->discard_enable, true); }
-discard=1,?	{ libxl_defbool_set(&DPC->disk->discard_enable, true); }
-discard=off,?	{ libxl_defbool_set(&DPC->disk->discard_enable, false); }
-discard=0,?	{ libxl_defbool_set(&DPC->disk->discard_enable, false); }
+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 */
 
xen/include/public/io/blkif.h +5 -5
index 27a88ba..6baf7fb 100644
@@ -201,11 +201,11 @@
  *      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. The
- *      backend driver should ignore the property if the property is set but
- *      the backing storage does not support the feature.
+ *      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>