introduce a cache options for PV disks
PATCH v2 1/1 introduce a cache options for PV disks
Document a per-disk cache option in the xl config file to allow users to select the cache mode that the backend should use to open the disk file or device.
Document a "cache" xenstore backend option, part of the vbd xenstore interface.
Add a reference to xen/include/public/io/blkif.h in docs/misc/vbd-interface.txt.
docs/misc/vbd-interface.txt +6 -0
@@ -125,3 +125,9 @@ because they directly map the bottom 8 bits of the xenstore integer directly to the Linux guest's device number and throw away the rest; they can crash due to minor number clashes. With these guests, the workaround is not to supply problematic combinations of devices. + + +Other frontend and backend options +---------------------------------- + +See xen/include/public/io/blkif.h for the full list of options.
docs/misc/xl-disk-configuration.txt +19 -0
@@ -178,6 +178,25 @@ information to be interpreted by the executable program <script>, These scripts are normally called "block-<script>". +cache=<cache> +------------- + +Description: Specifies what type of disk cache to use in the backend +Supported values: writeback, writethrough, none +Mandatory: No +Default value: depends on the backend type + +This does not affect the guest's view of the device. +Not all backends implement all cache modes: "phy" only supports "none", +"qdisk" supports all of them and defaults to "writeback". +It's important to note that if you are storing the VM disk on a network +filesystem or a network block device (NFS or ISCSI) it might not be safe +to use "none", see +http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html. +Otherwise using "none" is safe and gives you better performances. + + + ============================================ DEPRECATED PARAMETERS, PREFIXES AND SYNTAXES
xen/include/public/io/blkif.h +10 -0
@@ -97,6 +97,16 @@* * The type of the backing device/object. * +* +* cache +* Values: "none", "writeback", "writethrough" +* Optional +* +* The cache mode that the backend should use to open the backing +* device/object. The backend is not required to support all the +* possible cache modes. If an unsupported cache is requested, the +* backend is free to ignore it. +* *--------------------------------- Features --------------------------------- * * feature-barrier
Stefano Stabellini writes ("[PATCH v2] introduce a cache options for PV disks"):
Quoted 2 lines
+cache=<cache>
+-------------
Following a discussion with Stefano, we're going to rework this somewhat. The problem with this "cache=..." option is that it gives the impression that it should do a lot more than it actually does. For example, people might try to set cache=none because they know or suspect their guest is being loose with its barriers, or something. Or they might want to try to stop their host buffer cache being swamped by an unfriendly guest's IDE IO.
To avoid these problems we intend to rename this option and change the documentation accordingly. Probably, to "direct-io-safe" (both in Xenstore and the libxl API). The documentation will say that this option just disables any workaround where we avoid using direct IO because of bugs.
Ian.
Ian Jackson writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 5 lines
To avoid these problems we intend to rename this option and change the documentation accordingly. Probably, to "direct-io-safe" (both in Xenstore and the libxl API). The documentation will say that this option just disables any workaround where we avoid using direct IO because of bugs.
Here's an RFC version of the libxl part of this patch. It compiles but has not been tested.
For clarity the patch below doesn't include the rebuild of libxlu_disk_l.[ch].
Ian.
docs/misc/vbd-interface.txt +6 -0
@@ -125,3 +125,9 @@ because they directly map the bottom 8 bits of the xenstore integer directly to the Linux guest's device number and throw away the rest; they can crash due to minor number clashes. With these guests, the workaround is not to supply problematic combinations of devices. + + +Other frontend and backend options +---------------------------------- + +See xen/include/public/io/blkif.h for the full list of options.
docs/misc/xl-disk-configuration.txt +38 -0
@@ -178,6 +178,44 @@ information to be interpreted by the executable program <script>, These scripts are normally called "block-<script>". +direct-io-safe +-------------- + +Description: Disables non-O_DIRECT workaround +Supported values: absent, present +Mandatory: No +Default value: absent (workaround may be enabled) + +There is a memory lifetime bug in some driver domain (dom0) kernels +which can cause crashes when using O_DIRECT. The bug occurs due to a +mismatch between the backend-visible lifetime of pages used for the +Xen PV network protocol and that expected by the backend kernel's +networking subsystem. This can cause crashes when using certain +backends with certain underlying storage. + +See: + http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html + +For this reason, (this version of) the Xen libxl toolstack disables +O_DIRECT when using the qemu-based Xen PV backend ("qdisk"). + +However, this workaround has performance and scaling implications, and +it is only necessary if the underlying device is a network filesystem. +If the underlying device is not, then it is good to disable it; that +is what this option is for. + +This option simply requests that the workaround be disabled. (However, +not all backends versions which use the workaround understand this +option, so this is on a best effort basis.) + +It's important to note that if you are storing the VM disk on a +network filesystem or a network block device (NFS or ISCSI) it might +not be safe to use this option. Otherwise specifying it is safe and +can give better performances. + +If in the future the bug is fixed properly this option will then be +silently ignored. + ============================================ DEPRECATED PARAMETERS, PREFIXES AND SYNTAXES
tools/libxl/libxl.c +4 -0
@@ -2168,6 +2168,10 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,flexarray_append (back, disk->readwrite ?"w" :"r" );flexarray_append (back,"device-type" );flexarray_append (back, disk->is_cdrom ?"cdrom" :"disk" ); +if (disk->direct_io_safe) { +flexarray_append (back,"direct-io-safe" ); +flexarray_append (back,"1" ); + }flexarray_append (front,"backend-id" );flexarray_append (front,libxl__sprintf (gc,"%d" , disk->backend_domid));
tools/libxl/libxl_types.idl +1 -0
@@ -375,6 +375,7 @@ libxl_device_disk = Struct("device_disk", [ ("removable", integer), ("readwrite", integer), ("is_cdrom", integer), + ("direct_io_safe", bool), ]) libxl_device_nic = Struct("device_nic", [
tools/libxl/libxlu_disk_l.l +1 -0
@@ -173,6 +173,7 @@ 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; } /* the target magic parameter, eats the rest of the string */
xen/include/public/io/blkif.h +16 -0
@@ -97,6 +97,22 @@* * The type of the backing device/object. * +* +* direct-io-safe +* Values: 1 +* Optional +* +* The underlying storage is not affected by the direct IO memory +* lifetime bug. See: +* http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html +* +* So use of O_DIRECT is safe, in circumstances +* where we would normally have avoided it as a workaround for +* that bug. This option is not relevant for all backends, and +* even not necessarily supported for those for which it is +* relevant. A backend which knows that it is not affected by +* the bug can ignore this option. +* *--------------------------------- Features --------------------------------- * * feature-barrier
Quoted 100 lines · Ian Jackson
Ian Jackson writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 5 lines
To avoid these problems we intend to rename this option and change the documentation accordingly. Probably, to "direct-io-safe" (both in Xenstore and the libxl API). The documentation will say that this option just disables any workaround where we avoid using direct IO because of bugs.
Here's an RFC version of the libxl part of this patch. It compiles but has not been tested.
For clarity the patch below doesn't include the rebuild of libxlu_disk_l.[ch].
Ian.
Signed-off-by Ian Jackson <[email protected]>docs/misc/vbd-interface.txt +6
-0@@ -125,3 +125,9 @@ because they directly map the bottom 8 bits of the xenstore integer directly to the Linux guest's device number and throw away the rest; they can crash due to minor number clashes. With these guests, the workaround is not to supply problematic combinations of devices. + + +Other frontend and backend options +---------------------------------- + +See xen/include/public/io/blkif.h for the full list of options.docs/misc/xl-disk-configuration.txt +38
-0@@ -178,6 +178,44 @@ information to be interpreted by the executable program <script>, These scripts are normally called "block-<script>". +direct-io-safe +-------------- + +Description: Disables non-O_DIRECT workaround +Supported values: absent, present +Mandatory: No +Default value: absent (workaround may be enabled) + +There is a memory lifetime bug in some driver domain (dom0) kernels +which can cause crashes when using O_DIRECT. The bug occurs due to a +mismatch between the backend-visible lifetime of pages used for the +Xen PV network protocol and that expected by the backend kernel's +networking subsystem. This can cause crashes when using certain +backends with certain underlying storage. + +See: + http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html + +For this reason, (this version of) the Xen libxl toolstack disables +O_DIRECT when using the qemu-based Xen PV backend ("qdisk"). + +However, this workaround has performance and scaling implications, and +it is only necessary if the underlying device is a network filesystem. +If the underlying device is not, then it is good to disable it; that +is what this option is for. + +This option simply requests that the workaround be disabled. (However, +not all backends versions which use the workaround understand this +option, so this is on a best effort basis.) + +It's important to note that if you are storing the VM disk on a +network filesystem or a network block device (NFS or ISCSI) it might +not be safe to use this option. Otherwise specifying it is safe and +can give better performances. + +If in the future the bug is fixed properly this option will then be +silently ignored. + ============================================ DEPRECATED PARAMETERS, PREFIXES AND SYNTAXEStools/libxl/libxl.c +4
-0@@ -2168,6 +2168,10 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,flexarray_append (back, disk->readwrite ?"w" :"r" );flexarray_append (back,"device-type" );flexarray_append (back, disk->is_cdrom ?"cdrom" :"disk" ); +if (disk->direct_io_safe) { +flexarray_append (back,"direct-io-safe" ); +flexarray_append (back,"1" ); + }flexarray_append (front,"backend-id" );flexarray_append (front,libxl__sprintf (gc,"%d" , disk->backend_domid));tools/libxl/libxl_types.idl +0
-0
tools/libxl/libxl_types.idl libxl_device_disk = Struct("device_disk", [ · line 378
Quoted 4 lines
tools/libxl/libxl_types.idl +1
-0@@ -375,6 +375,7 @@ libxl_device_disk = Struct("device_disk", [ ("removable", integer), ("readwrite", integer), ("is_cdrom", integer), + ("direct_io_safe", bool),
You'll want a #define LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE (or something more wieldy) in libxl.h to enable people to write code which works against different versions of libxl.
Is this deliberately not a defbool?
Quoted 20 lines
tools/libxl/libxl_types.idl +0
-0]) libxl_device_nic = Struct("device_nic", [tools/libxl/libxlu_disk_l.l +1
-0@@ -173,6 +173,7 @@ 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; } /* the target magic parameter, eats the rest of the string */xen/include/public/io/blkif.h +0
-0
xen/include/public/io/blkif.h line 102
Quoted 6 lines
xen/include/public/io/blkif.h +3
-0@@ -97,6 +97,22 @@* * The type of the backing device/object. * +* +* direct-io-safe +* Values: 1
0 (==direct-io is unsafe) is explicitly not a valid value?
xen/include/public/io/blkif.h line 109
Quoted 7 lines
xen/include/public/io/blkif.h +7
-0+* Optional +* +* The underlying storage is not affected by the direct IO memory +* lifetime bug. See: +* http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html +* +* So use of O_DIRECT is safe, in circumstances
^Some ?
Otherwise I can't parse this sentence.
Quoted 9 lines
xen/include/public/io/blkif.h +6
-0+* where we would normally have avoided it as a workaround for +* that bug. This option is not relevant for all backends, and +* even not necessarily supported for those for which it is +* relevant. A backend which knows that it is not affected by +* the bug can ignore this option. +* *--------------------------------- Features --------------------------------- * * feature-barrier
Ian Campbell writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 6 lines · Ian Jackson
Quoted 5 lines
tools/libxl/libxl_types.idl +0
-0@@ -375,6 +375,7 @@ libxl_device_disk = Struct("device_disk", [
Quoted 8 lines
tools/libxl/libxl_types.idl libxl_device_disk = Struct("device_disk", [ · line 378
Quoted 4 lines
tools/libxl/libxl_types.idl +1
-0("removable", integer), ("readwrite", integer), ("is_cdrom", integer), + ("direct_io_safe", bool),You'll want a #define
LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE(or something more wieldy) inlibxl.hto enable people to write code which works against different versions of libxl.
Ah yes.
Quoted 1 line
Is this deliberately not a defbool?
Yes.
Quoted 5 lines
tools/libxl/libxl_types.idl libxl_device_disk = Struct("device_disk", [ · line 381
Quoted 3 lines
tools/libxl/libxl_types.idl +3
-0+ * + * direct-io-safe + * Values: 10 (==direct-io is unsafe) is explicitly not a valid value?
Yes. I could make it permitted. The obvious parsing code would understand it, obviously.
Quoted 5 lines
Quoted 1 line
+ * So use of
O_DIRECTis safe, in circumstances^Some ?Otherwise I can't parse this sentence.
Yes.
Do I take it you're happy with the general approach ?
Ian.
Ian Jackson writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 9 lines
Ian Campbell writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 6 lines · Ian Jackson
Quoted 1 line
+ * So use of
O_DIRECTis safe, in circumstances^Some ?Otherwise I can't parse this sentence.
Yes.
In, fact, no. How about:
* That is, if this option is enabled, use of O_DIRECT is safe, * in circumstances where we would normally have avoided it as a * workaround for that bug. This option is not relevant for ...
Ian.
Quoted 9 lines · Ian Jackson
Ian Jackson writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 8 lines
Ian Campbell writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 6 lines · Ian Jackson
Quoted 1 line
+ * So use of
O_DIRECTis safe, in circumstances^Some ?Otherwise I can't parse this sentence.
Quoted 7 lines
Quoted 1 line
Yes.
In, fact, no. How about:
* That is, if this option is enabled, use of O_DIRECT is safe, * in circumstances where we would normally have avoided it as a * workaround for that bug. This option is not relevant for ...
I think I can parse it now. It doesn't really say what the option does though. I'd expect it to say something about "disabling the workaround" or "the backend may use O_DIRECT".
Ian.
Ian Campbell writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 3 lines
I think I can parse it now. It doesn't really say what the option does though. I'd expect it to say something about "disabling the workaround" or "the backend may use
O_DIRECT".
How about:
* direct-io-safe
* Values: 0/1 (boolean) * Default Value: 0 * * The underlying storage is not affected by the direct IO memory * lifetime bug. See: * http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html * * Therefore this option gives the backend permission to use * O_DIRECT, notwithstanding that bug. * * That is, if this option is enabled, use of O_DIRECT is safe, * in circumstances where we would normally have avoided it as a * workaround for that bug. This option is not relevant for all * backends, and even not necessarily supported for those for * which it is relevant. A backend which knows that it is not * affected by the bug can ignore this option.
*
* This option doesn't require a backend to use O_DIRECT, so it
* should not be used to try to control the caching behaviour.
Ian.
Quoted 6 lines · Ian Jackson
Ian Campbell writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 3 lines
I think I can parse it now. It doesn't really say what the option does though. I'd expect it to say something about "disabling the workaround" or "the backend may use
O_DIRECT".How about:
Sounds good thanks.
Quoted 23 lines
* direct-io-safe
* Values: 0/1 (boolean) * Default Value: 0 * * The underlying storage is not affected by the direct IO memory * lifetime bug. See: * http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html * * Therefore this option gives the backend permission to use * O_DIRECT, notwithstanding that bug. * * That is, if this option is enabled, use of O_DIRECT is safe, * in circumstances where we would normally have avoided it as a * workaround for that bug. This option is not relevant for all * backends, and even not necessarily supported for those for * which it is relevant. A backend which knows that it is not * affected by the bug can ignore this option.*
* This option doesn't require a backend to useO_DIRECT, so it
* should not be used to try to control the caching behaviour.Ian.
Quoted 16 lines · Ian Jackson
Ian Campbell writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 6 lines · Ian Jackson
Quoted 5 lines
tools/libxl/libxl_types.idl +0
-0@@ -375,6 +375,7 @@ libxl_device_disk = Struct("device_disk", [Quoted 8 lines
tools/libxl/libxl_types.idl libxl_device_disk = Struct("device_disk", [ · line 378
Quoted 4 lines
tools/libxl/libxl_types.idl +1
-0("removable", integer), ("readwrite", integer), ("is_cdrom", integer), + ("direct_io_safe", bool),You'll want a #define
LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE(or something more wieldy) inlibxl.hto enable people to write code which works against different versions of libxl.
Quoted 5 lines
Ah yes.
Quoted 1 line
Is this deliberately not a defbool?
Yes.
OK.
Quoted 8 lines
Quoted 5 lines
tools/libxl/libxl_types.idl libxl_device_disk = Struct("device_disk", [ · line 381
Quoted 3 lines
tools/libxl/libxl_types.idl +3
-0+ * + * direct-io-safe + * Values: 10 (==direct-io is unsafe) is explicitly not a valid value?
Yes. I could make it permitted. The obvious parsing code would understand it, obviously.
The reason it occurred to me (other than most other similar keys supporting it) is that you were missing the "Default Value" documentation, which was only really relevant because I couldn't easily parse the description in terms of what happens when this option is absent (or actually present, but there's another subthread about that ;-)).
Quoted 1 line
Do I take it you're happy with the general approach ?
Yes.
Ian Campbell writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 6 lines · Ian Jackson
Quoted 5 lines
xen/include/public/io/blkif.h +0
-0@@ -97,6 +97,22 @@
Quoted 8 lines
xen/include/public/io/blkif.h line 102
Quoted 6 lines
xen/include/public/io/blkif.h +3
-0* * The type of the backing device/object. * +* +* direct-io-safe +* Values: 1 0 (==direct-io is unsafe) is explicitly not a valid value?
Looking around a bit, the other things in xenstore do this differently and it should be consistent. So I will change this to 0/1, defaulting to 0.
Ian.
Stefano Stabellini writes ("[PATCH v2] introduce a cache options for PV disks"):
Quoted 3 lines
Document a per-disk cache option in the xl config file to allow users to select the cache mode that the backend should use to open the disk file or device.
Here's an RFD revised version of the qemu patch. I haven't compiled it yet.
Ian.
hw/block/xen_disk.c +10 -0
@@ -93,6 +93,7 @@ struct XenBlkDev {char *type;char *dev;char *devtype; +bool directiosafe;const char *fileproto;const char *filename;int ring_ref;
@@ -701,6 +702,7 @@ static int blk_init(struct XenDevice *xendev) { struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);int info =0 ; + char *directiosafe == NULL;/* read xenstore entries */ if (blkdev->params ==NULL ) {
@@ -733,6 +735,8 @@ static int blk_init(struct XenDevice *xendev)if (blkdev->devtype ==NULL ) { blkdev->devtype =xenstore_read_be_str (&blkdev->xendev,"device-type" ); } + directiosafe =xenstore_read_be_str (&blkdev->xendev,"direct-io-safe" ); + blkdev->directiosafe = (directiosafe &&atoi (directiofsafe));/* do we have all we need? */ if (blkdev->params == NULL ||
@@ -760,6 +764,8 @@ static int blk_init(struct XenDevice *xendev)xenstore_write_be_int (&blkdev->xendev,"feature-flush-cache" ,1 );xenstore_write_be_int (&blkdev->xendev,"feature-persistent" ,1 );xenstore_write_be_int (&blkdev->xendev,"info" , info); + +g_free (directiosafe);return 0 ; out_error:
@@ -773,6 +779,7 @@ out_error: blkdev->dev =NULL ;g_free (blkdev->devtype); blkdev->devtype =NULL ; +g_free (directiosafe);return -1 ; }
@@ -784,6 +791,9 @@ static int blk_connect(struct XenDevice *xendev)/* read-only ? */ qflags =BDRV_O_CACHE_WB |BDRV_O_NATIVE_AIO ; +if (blkdev->directiosafe) { + qflags =BDRV_O_NOCACHE |BDRV_O_NATIVE_AIO ; + }if (strcmp (blkdev->mode,"w" ) ==0 ) { qflags |=BDRV_O_RDWR ; readonly = false;
Quoted 8 lines · Ian Jackson
Stefano Stabellini writes ("[PATCH v2] introduce a cache options for PV disks"):
Quoted 3 lines
Document a per-disk cache option in the xl config file to allow users to select the cache mode that the backend should use to open the disk file or device.
Here's an RFD revised version of the qemu patch. I haven't compiled it yet.
It's mostly OK, just few minor corrections for code readability
Quoted 13 lines
hw/block/xen_disk.c +1
-0@@ -93,6 +93,7 @@ struct XenBlkDev {char *type;char *dev;char *devtype; +bool directiosafe;const char *fileproto;const char *filename;int ring_ref;
hw/block/xen_disk.c static int blk_init(struct XenDevice *xendev) · line 705
Quoted 4 lines
hw/block/xen_disk.c +1
-0@@ -701,6 +702,7 @@ static int blk_init(struct XenDevice *xendev) { struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);int info =0 ; + char *directiosafe == NULL;
^ =
Quoted 21 lines
hw/block/xen_disk.c +4
-0/* read xenstore entries */ if (blkdev->params ==NULL ) {@@ -733,6 +735,8 @@ static int blk_init(struct XenDevice *xendev)if (blkdev->devtype ==NULL ) { blkdev->devtype =xenstore_read_be_str (&blkdev->xendev,"device-type" ); } + directiosafe =xenstore_read_be_str (&blkdev->xendev,"direct-io-safe" ); + blkdev->directiosafe = (directiosafe &&atoi (directiofsafe));/* do we have all we need? */ if (blkdev->params == NULL ||@@ -760,6 +764,8 @@ static int blk_init(struct XenDevice *xendev)xenstore_write_be_int (&blkdev->xendev,"feature-flush-cache" ,1 );xenstore_write_be_int (&blkdev->xendev,"feature-persistent" ,1 );xenstore_write_be_int (&blkdev->xendev,"info" , info); + +g_free (directiosafe);return 0 ; out_error:
hw/block/xen_disk.c out_error: · line 782
Quoted 4 lines
hw/block/xen_disk.c +1
-0@@ -773,6 +779,7 @@ out_error: blkdev->dev =NULL ;g_free (blkdev->devtype); blkdev->devtype =NULL ; +g_free (directiosafe);
maybe add
blkdev->directiosafe = false;
hw/block/xen_disk.c static int blk_connect(struct XenDevice *xendev) · line 796
Quoted 10 lines
hw/block/xen_disk.c +3
-0return -1 ; }@@ -784,6 +791,9 @@ static int blk_connect(struct XenDevice *xendev)/* read-only ? */ qflags =BDRV_O_CACHE_WB |BDRV_O_NATIVE_AIO ; +if (blkdev->directiosafe) { + qflags =BDRV_O_NOCACHE |BDRV_O_NATIVE_AIO ; + }
Please change this into:
if (blkdev->directiosafe) {
qflags = BDRV_O_NOCACHE | BDRV_O_NATIVE_AIO;
} else {
qflags = BDRV_O_CACHE_WB;
}Quoted 11 lines · Stefano Stabellini
Quoted 8 lines · Ian Jackson
Stefano Stabellini writes ("[PATCH v2] introduce a cache options for PV disks"):
Quoted 3 lines
Document a per-disk cache option in the xl config file to allow users to select the cache mode that the backend should use to open the disk file or device.
Here's an RFD revised version of the qemu patch. I haven't compiled it yet.
It's mostly OK, just few minor corrections for code readability
BTW are you going to follow up or do you want me to?
Quoted 70 lines
Quoted 14 lines
hw/block/xen_disk.c +1
-0@@ -93,6 +93,7 @@ struct XenBlkDev {char *type;char *dev;char *devtype; +bool directiosafe;const char *fileproto;const char *filename;int ring_ref;hw/block/xen_disk.c static int blk_init(struct XenDevice *xendev) · line 705
Quoted 4 lines
hw/block/xen_disk.c +1
-0@@ -701,6 +702,7 @@ static int blk_init(struct XenDevice *xendev) { struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);int info =0 ; + char *directiosafe == NULL;^ =Quoted 21 lines
hw/block/xen_disk.c +4
-0/* read xenstore entries */ if (blkdev->params ==NULL ) {@@ -733,6 +735,8 @@ static int blk_init(struct XenDevice *xendev)if (blkdev->devtype ==NULL ) { blkdev->devtype =xenstore_read_be_str (&blkdev->xendev,"device-type" ); } + directiosafe =xenstore_read_be_str (&blkdev->xendev,"direct-io-safe" ); + blkdev->directiosafe = (directiosafe &&atoi (directiofsafe));/* do we have all we need? */ if (blkdev->params == NULL ||@@ -760,6 +764,8 @@ static int blk_init(struct XenDevice *xendev)xenstore_write_be_int (&blkdev->xendev,"feature-flush-cache" ,1 );xenstore_write_be_int (&blkdev->xendev,"feature-persistent" ,1 );xenstore_write_be_int (&blkdev->xendev,"info" , info); + +g_free (directiosafe);return 0 ; out_error:hw/block/xen_disk.c out_error: · line 782
Quoted 4 lines
hw/block/xen_disk.c +1
-0@@ -773,6 +779,7 @@ out_error: blkdev->dev =NULL ;g_free (blkdev->devtype); blkdev->devtype =NULL ; +g_free (directiosafe);maybe add
blkdev->directiosafe= false;hw/block/xen_disk.c static int blk_connect(struct XenDevice *xendev) · line 796
Quoted 10 lines
hw/block/xen_disk.c +3
-0return -1 ; }@@ -784,6 +791,9 @@ static int blk_connect(struct XenDevice *xendev)/* read-only ? */ qflags =BDRV_O_CACHE_WB |BDRV_O_NATIVE_AIO ; +if (blkdev->directiosafe) { + qflags =BDRV_O_NOCACHE |BDRV_O_NATIVE_AIO ; + }Please change this into:
if (blkdev->directiosafe) { qflags = BDRV_O_NOCACHE | BDRV_O_NATIVE_AIO; } else { qflags = BDRV_O_CACHE_WB; }
Stefano Stabellini writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 1 line
It's mostly OK, just few minor corrections for code readability
Thanks.
Quoted 3 lines
Quoted 2 lines
int info = 0;+ char *directiosafe == NULL;
^ =
I did warn that I hadn't compiled it :-).
Quoted 10 lines
hw/block/xen_disk.c out_error: · line 782
Quoted 6 lines
out_error:hw/block/xen_disk.c +1
-0@@ -773,6 +779,7 @@ out_error: blkdev->dev =NULL ;g_free (blkdev->devtype); blkdev->devtype =NULL ; +g_free (directiosafe);maybe add
blkdev->directiosafe= false;
Sure, does no harm.
Quoted 11 lines
hw/block/xen_disk.c static int blk_connect(struct XenDevice *xendev) · line 796
Quoted 3 lines
hw/block/xen_disk.c +3
-0+if (blkdev->directiosafe) { + qflags =BDRV_O_NOCACHE |BDRV_O_NATIVE_AIO ; + }Please change this into:
if (blkdev->directiosafe) { qflags = BDRV_O_NOCACHE | BDRV_O_NATIVE_AIO; } else { qflags = BDRV_O_CACHE_WB; }
I don't think that can be right. The result would be that the value non-directiosafe value of qflags is changed. But I will break it apart as you suggest.
Ian.
Quoted 36 lines · Ian Jackson
Stefano Stabellini writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 1 line
It's mostly OK, just few minor corrections for code readability
Thanks.
Quoted 3 lines
Quoted 2 lines
int info = 0;+ char *directiosafe == NULL;
^ =I did warn that I hadn't compiled it :-).
Quoted 10 lines
hw/block/xen_disk.c out_error: · line 782
Quoted 6 lines
out_error:hw/block/xen_disk.c +1
-0@@ -773,6 +779,7 @@ out_error: blkdev->dev =NULL ;g_free (blkdev->devtype); blkdev->devtype =NULL ; +g_free (directiosafe);maybe add
blkdev->directiosafe= false;Sure, does no harm.
Quoted 11 lines
hw/block/xen_disk.c static int blk_connect(struct XenDevice *xendev) · line 796
Quoted 3 lines
hw/block/xen_disk.c +3
-0+if (blkdev->directiosafe) { + qflags =BDRV_O_NOCACHE |BDRV_O_NATIVE_AIO ; + }Please change this into:
if (blkdev->directiosafe) { qflags = BDRV_O_NOCACHE | BDRV_O_NATIVE_AIO; } else { qflags = BDRV_O_CACHE_WB; }
Quoted 3 lines
I don't think that can be right. The result would be that the value non-directiosafe value of qflags is changed. But I will break it apart as you suggest.
BDRV_O_NATIVE_AIO is ignored if BDRV_O_NOCACHE is not also set, so there would be not behavioural change. However the code would be clearer.
Stefano Stabellini writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 2 lines
BDRV_O_NATIVE_AIOis ignored ifBDRV_O_NOCACHEis not also set, so there would be not behavioural change. However the code would be clearer.
Right, OK.
Ian.
Here's the result. I took Anthony Ligouri's ack off it.
Ian.
commit 21538601f7d4f2de4d518b92ec9212c99be829e8
Author: Stefano Stabellini <[email protected]> Date: Thu Jun 27 14:20:51 2013 +0000
xen_disk: support "direct-io-safe" backend option
Support backend option "direct-io-safe". This is documented as follows in the Xen backend specification:
* direct-io-safe
* Values: 0/1 (boolean)
* Default Value: 0
*
* The underlying storage is not affected by the direct IO memory
* lifetime bug. See:
* http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html
*
* Therefore this option gives the backend permission to use
* O_DIRECT, notwithstanding that bug.
*
* That is, if this option is enabled, use of O_DIRECT is safe,
* in circumstances where we would normally have avoided it as a
* workaround for that bug. This option is not relevant for all
* backends, and even not necessarily supported for those for
* which it is relevant. A backend which knows that it is not
* affected by the bug can ignore this option.
*
* This option doesn't require a backend to use O_DIRECT, so it
* should not be used to try to control the caching behaviour.
Also, BDRV_O_NATIVE_AIO is ignored if BDRV_O_NOCACHE, so clarify the default flags passed to the qemu block layer.
hw/block/xen_disk.c +13 -1
@@ -93,6 +93,7 @@ struct XenBlkDev {char *type;char *dev;char *devtype; +bool directiosafe;const char *fileproto;const char *filename;int ring_ref;
@@ -701,6 +702,7 @@ static int blk_init(struct XenDevice *xendev) { struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);int info =0 ; +char *directiosafe =NULL ;/* read xenstore entries */ if (blkdev->params ==NULL ) {
@@ -733,6 +735,8 @@ static int blk_init(struct XenDevice *xendev)if (blkdev->devtype ==NULL ) { blkdev->devtype =xenstore_read_be_str (&blkdev->xendev,"device-type" ); } + directiosafe =xenstore_read_be_str (&blkdev->xendev,"direct-io-safe" ); + blkdev->directiosafe = (directiosafe &&atoi (directiofsafe));/* do we have all we need? */ if (blkdev->params == NULL ||
@@ -760,6 +764,8 @@ static int blk_init(struct XenDevice *xendev)xenstore_write_be_int (&blkdev->xendev,"feature-flush-cache" ,1 );xenstore_write_be_int (&blkdev->xendev,"feature-persistent" ,1 );xenstore_write_be_int (&blkdev->xendev,"info" , info); + +g_free (directiosafe);return 0 ; out_error:
@@ -773,6 +779,8 @@ out_error: blkdev->dev =NULL ;g_free (blkdev->devtype); blkdev->devtype =NULL ; +g_free (directiosafe); + blkdev->directiosafe = false;return -1 ; }
@@ -783,7 +791,11 @@ static int blk_connect(struct XenDevice *xendev)bool readonly = true;/* read-only ? */ - qflags =BDRV_O_CACHE_WB |BDRV_O_NATIVE_AIO ; +if (blkdev->directiosafe) { + qflags =BDRV_O_NOCACHE |BDRV_O_NATIVE_AIO ; + }else { + qflags =BDRV_O_CACHE_WB ; + }if (strcmp (blkdev->mode,"w" ) ==0 ) { qflags |=BDRV_O_RDWR ; readonly = false;
Ian Jackson writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 1 line
Here's the result. I took Anthony Ligouri's ack off it.
And the libxl half.
commit 98c0ba29e33ae875e8b854fa1ff58862ac09a530
Author: Stefano Stabellini <[email protected]> Date: Thu Jun 27 12:40:20 2013 +0100
libxl: introduce an option for disabling the non-O_DIRECT workaround
Document and implement a new option that permits disk backends which would otherwise have to avoid O_DIRECT (because of the network memory lifetime bug) to use it anyway. This is:
direct-io-safe in the xl domain disk config specification
direct_io_safe in the libxl disk API
direct-io-safe in the backend xenstore interface
Add a reference to xen/include/public/io/blkif.h in docs/misc/vbd-interface.txt.
docs/misc/vbd-interface.txt +6 -0
@@ -125,3 +125,9 @@ because they directly map the bottom 8 bits of the xenstore integer directly to the Linux guest's device number and throw away the rest; they can crash due to minor number clashes. With these guests, the workaround is not to supply problematic combinations of devices. + + +Other frontend and backend options +---------------------------------- + +See xen/include/public/io/blkif.h for the full list of options.
docs/misc/xl-disk-configuration.txt +38 -0
@@ -178,6 +178,44 @@ information to be interpreted by the executable program <script>, These scripts are normally called "block-<script>". +direct-io-safe +-------------- + +Description: Disables non-O_DIRECT workaround +Supported values: absent, present +Mandatory: No +Default value: absent (workaround may be enabled) + +There is a memory lifetime bug in some driver domain (dom0) kernels +which can cause crashes when using O_DIRECT. The bug occurs due to a +mismatch between the backend-visible lifetime of pages used for the +Xen PV network protocol and that expected by the backend kernel's +networking subsystem. This can cause crashes when using certain +backends with certain underlying storage. + +See: + http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html + +For this reason, (this version of) the Xen libxl toolstack disables +O_DIRECT when using the qemu-based Xen PV backend ("qdisk"). + +However, this workaround has performance and scaling implications, and +it is only necessary if the underlying device is a network filesystem. +If the underlying device is not, then it is good to disable it; that +is what this option is for. + +This option simply requests that the workaround be disabled. (However, +not all backends versions which use the workaround understand this +option, so this is on a best effort basis.) + +It's important to note that if you are storing the VM disk on a +network filesystem or a network block device (NFS or ISCSI) it might +not be safe to use this option. Otherwise specifying it is safe and +can give better performances. + +If in the future the bug is fixed properly this option will then be +silently ignored. + ============================================ DEPRECATED PARAMETERS, PREFIXES AND SYNTAXES
tools/libxl/libxl.c +4 -0
@@ -2168,6 +2168,10 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,flexarray_append (back, disk->readwrite ?"w" :"r" );flexarray_append (back,"device-type" );flexarray_append (back, disk->is_cdrom ?"cdrom" :"disk" ); +if (disk->direct_io_safe) { +flexarray_append (back,"direct-io-safe" ); +flexarray_append (back,"1" ); + }flexarray_append (front,"backend-id" );flexarray_append (front,libxl__sprintf (gc,"%d" , disk->backend_domid));
tools/libxl/libxl.h +7 -0
@@ -82,6 +82,13 @@#define LIBXL_HAVE_DOMAIN_NODEAFFINITY 1/* +* LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE indicates that a +* 'direct_io_safe' field (of boolean type) is present in +* libxl_device_disk. +*/ +#define LIBXL_HAVE_DEVICE_DISK_DIRECT_IO_SAFE 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility
tools/libxl/libxl_types.idl +1 -0
@@ -375,6 +375,7 @@ libxl_device_disk = Struct("device_disk", [ ("removable", integer), ("readwrite", integer), ("is_cdrom", integer), + ("direct_io_safe", bool), ]) libxl_device_nic = Struct("device_nic", [
tools/libxl/libxlu_disk_l.c +348 -333
864 lines not on this page · raw message
tools/libxl/libxlu_disk_l.h +1 -1
@@ -344,7 +344,7 @@ extern int xlu__disk_yylex (yyscan_t yyscanner);#undef YY_DECL#endif -#line 256 "libxlu_disk_l.l" +#line 257 "libxlu_disk_l.l"#line 350 "libxlu_disk_l.h"#undef xlu__disk_yyIN_HEADER
tools/libxl/libxlu_disk_l.l +1 -0
@@ -173,6 +173,7 @@ 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; } /* the target magic parameter, eats the rest of the string */
xen/include/public/io/blkif.h +22 -0
@@ -97,6 +97,28 @@* * The type of the backing device/object. * +* +* direct-io-safe +* Values: 0/1 (boolean) +* Default Value: 0 +* +* The underlying storage is not affected by the direct IO memory +* lifetime bug. See: +* http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html +* +* Therefore this option gives the backend permission to use +* O_DIRECT, notwithstanding that bug. +* +* That is, if this option is enabled, use of O_DIRECT is safe, +* in circumstances where we would normally have avoided it as a +* workaround for that bug. This option is not relevant for all +* backends, and even not necessarily supported for those for +* which it is relevant. A backend which knows that it is not +* affected by the bug can ignore this option. +* +* This option doesn't require a backend to use O_DIRECT, so it +* should not be used to try to control the caching behaviour. +* *--------------------------------- Features --------------------------------- * * feature-barrier
Ian Campbell
Acked-byQuoted 18 lines · Ian Jackson
Ian Jackson writes ("Re: [PATCH v2] introduce a cache options for PV disks"):
Quoted 1 line
Here's the result. I took Anthony Ligouri's ack off it.
And the libxl half.
commit
98c0ba29e33ae875e8b854fa1ff58862ac09a530Author: Stefano Stabellini <[email protected]> Date: Thu Jun 27 12:40:20 2013 +0100libxl: introduce an option for disabling the non-O_DIRECT workaround
Document and implement a new option that permits disk backends which would otherwise have to avoid
O_DIRECT(because of the network memory lifetime bug) to use it anyway. This is:
direct-io-safe in the xl domain disk config specification
direct_io_safein the libxl disk API
direct-io-safe in the backend xenstore interface
Quoted 5 lines
Add a reference to
xen/include/public/io/blkif.hindocs/misc/vbd-interface.txt.Signed-off-by Stefano Stabellini <[email protected]>Signed-off-by Ian Jackson <[email protected]>
I assume you will apply yourself. Since this mail is not git format-patch compliant I don't think I can feed it to git am without having to massage the commit message.
Quoted 34 lines · Ian Jackson
Here's the result. I took Anthony Ligouri's ack off it.
Ian.
commit
21538601f7d4f2de4d518b92ec9212c99be829e8Author: Stefano Stabellini <[email protected]> Date: Thu Jun 27 14:20:51 2013 +0000
xen_disk: support "direct-io-safe" backend optionSupport backend option "direct-io-safe". This is documented as follows in the Xen backend specification:
* direct-io-safe
* Values: 0/1 (boolean)
* Default Value: 0
*
* The underlying storage is not affected by the direct IO memory
* lifetime bug. See:
* http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html
*
* Therefore this option gives the backend permission to use
*O_DIRECT, notwithstanding that bug.
*
* That is, if this option is enabled, use ofO_DIRECTis safe,
* in circumstances where we would normally have avoided it as a
* workaround for that bug. This option is not relevant for all
* backends, and even not necessarily supported for those for
* which it is relevant. A backend which knows that it is not
* affected by the bug can ignore this option.
*
* This option doesn't require a backend to useO_DIRECT, so it
* should not be used to try to control the caching behaviour.
Quoted 4 lines
Also,
BDRV_O_NATIVE_AIOis ignored ifBDRV_O_NOCACHE, so clarify the default flags passed to the qemu block layer.Signed-off-by Stefano Stabellini <[email protected]>
I'll send to qemu-devel and add your signed-off-by if you are OK with that
Quoted 61 lines
hw/block/xen_disk.c +13
-1@@ -93,6 +93,7 @@ struct XenBlkDev {char *type;char *dev;char *devtype; +bool directiosafe;const char *fileproto;const char *filename;int ring_ref;@@ -701,6 +702,7 @@ static int blk_init(struct XenDevice *xendev) { struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);int info =0 ; +char *directiosafe =NULL ;/* read xenstore entries */ if (blkdev->params ==NULL ) {@@ -733,6 +735,8 @@ static int blk_init(struct XenDevice *xendev)if (blkdev->devtype ==NULL ) { blkdev->devtype =xenstore_read_be_str (&blkdev->xendev,"device-type" ); } + directiosafe =xenstore_read_be_str (&blkdev->xendev,"direct-io-safe" ); + blkdev->directiosafe = (directiosafe &&atoi (directiofsafe));/* do we have all we need? */ if (blkdev->params == NULL ||@@ -760,6 +764,8 @@ static int blk_init(struct XenDevice *xendev)xenstore_write_be_int (&blkdev->xendev,"feature-flush-cache" ,1 );xenstore_write_be_int (&blkdev->xendev,"feature-persistent" ,1 );xenstore_write_be_int (&blkdev->xendev,"info" , info); + +g_free (directiosafe);return 0 ; out_error:@@ -773,6 +779,8 @@ out_error: blkdev->dev =NULL ;g_free (blkdev->devtype); blkdev->devtype =NULL ; +g_free (directiosafe); + blkdev->directiosafe = false;return -1 ; }@@ -783,7 +791,11 @@ static int blk_connect(struct XenDevice *xendev)bool readonly = true;/* read-only ? */ - qflags =BDRV_O_CACHE_WB |BDRV_O_NATIVE_AIO ; +if (blkdev->directiosafe) { + qflags =BDRV_O_NOCACHE |BDRV_O_NATIVE_AIO ; + }else { + qflags =BDRV_O_CACHE_WB ; + }if (strcmp (blkdev->mode,"w" ) ==0 ) { qflags |=BDRV_O_RDWR ; readonly = false;