[libvirt] [PATCH] Add directsync cache mode support for disk driver

Newer QEMU introduced cache=directsync for -drive, this patchset is to expose it in libvirt layer. * Introduced a new QEMU capability flag ($prefix_CACHE_DIRECTSYNC), As even $prefix_CACHE_V2 is set, we can't known if directsync is supported. --- docs/formatdomain.html.in | 2 +- docs/schemas/domain.rng | 1 + src/conf/domain_conf.c | 3 ++- src/conf/domain_conf.h | 1 + src/qemu/qemu_capabilities.c | 6 +++++- src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 29 ++++++++++++++++++++++------- tests/qemuargv2xmltest.c | 1 + tests/qemuxml2argvtest.c | 3 +++ tools/virsh.pod | 3 ++- 10 files changed, 39 insertions(+), 11 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index f46771d..6cb36d3 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -976,7 +976,7 @@ <li> The optional <code>cache</code> attribute controls the cache mechanism, possible values are "default", "none", - "writethrough" and "writeback". + "writethrough", "writeback", and "directsync". <span class="since">Since 0.6.0</span> </li> <li> diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng index dd8c41a..e43b17d 100644 --- a/docs/schemas/domain.rng +++ b/docs/schemas/domain.rng @@ -829,6 +829,7 @@ <value>none</value> <value>writeback</value> <value>writethrough</value> + <value>directsync</value> </choice> </attribute> </define> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 00212db..a2de8df 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -160,7 +160,8 @@ VIR_ENUM_IMPL(virDomainDiskCache, VIR_DOMAIN_DISK_CACHE_LAST, "default", "none", "writethrough", - "writeback") + "writeback", + "directsync") VIR_ENUM_IMPL(virDomainDiskErrorPolicy, VIR_DOMAIN_DISK_ERROR_POLICY_LAST, "default", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8382d28..0abb75e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -165,6 +165,7 @@ enum virDomainDiskCache { VIR_DOMAIN_DISK_CACHE_DISABLE, VIR_DOMAIN_DISK_CACHE_WRITETHRU, VIR_DOMAIN_DISK_CACHE_WRITEBACK, + VIR_DOMAIN_DISK_CACHE_DIRECTSYNC, VIR_DOMAIN_DISK_CACHE_LAST }; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f665de4..631d683 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -125,6 +125,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST, "sga", "virtio-blk-pci.event_idx", "virtio-net-pci.event_idx", + "cache-directsync", ); struct qemu_feature_flags { @@ -902,8 +903,11 @@ qemuCapsComputeCmdFlags(const char *help, if (strstr(help, "-drive")) { qemuCapsSet(flags, QEMU_CAPS_DRIVE); if (strstr(help, "cache=") && - !strstr(help, "cache=on|off")) + !strstr(help, "cache=on|off")) { qemuCapsSet(flags, QEMU_CAPS_DRIVE_CACHE_V2); + if (strstr(help, "directsync")) + qemuCapsSet(flags, QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC); + } if (strstr(help, "format=")) qemuCapsSet(flags, QEMU_CAPS_DRIVE_FORMAT); if (strstr(help, "readonly=")) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 13af0b9..c01d438 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -100,6 +100,7 @@ enum qemuCapsFlags { QEMU_CAPS_SGA = 62, /* Serial Graphics Adapter */ QEMU_CAPS_VIRTIO_BLK_EVENT_IDX = 63, /* virtio-blk-pci.event_idx */ QEMU_CAPS_VIRTIO_NET_EVENT_IDX = 64, /* virtio-net-pci.event_idx */ + QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC = 65, /* Is cache=directsync supported? */ QEMU_CAPS_LAST, /* this must always be the last item */ }; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 44a553b..fa52dc0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -64,14 +64,16 @@ VIR_ENUM_DECL(qemuDiskCacheV2) VIR_ENUM_IMPL(qemuDiskCacheV1, VIR_DOMAIN_DISK_CACHE_LAST, "default", "off", - "off", /* writethrough not supported, so for safety, disable */ - "on"); /* Old 'on' was equivalent to 'writeback' */ + "off", /* writethrough not supported, so for safety, disable */ + "on", /* Old 'on' was equivalent to 'writeback' */ + "off"); /* directsync not supported, for safety, disable */ VIR_ENUM_IMPL(qemuDiskCacheV2, VIR_DOMAIN_DISK_CACHE_LAST, "default", "none", "writethrough", - "writeback"); + "writeback", + "directsync"); VIR_ENUM_DECL(qemuVideo) @@ -1516,10 +1518,21 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk, } if (disk->cachemode) { - const char *mode = - qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_V2) ? - qemuDiskCacheV2TypeToString(disk->cachemode) : - qemuDiskCacheV1TypeToString(disk->cachemode); + const char *mode = NULL; + + if (qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_V2)) { + mode = qemuDiskCacheV2TypeToString(disk->cachemode); + + if (disk->cachemode == VIR_DOMAIN_DISK_CACHE_DIRECTSYNC && + !qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC)) { + qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("disk cache mode 'directsync' is not " + "supported by this QEMU")); + goto error; + } + } else { + mode = qemuDiskCacheV1TypeToString(disk->cachemode); + } virBufferAsprintf(&opt, ",cache=%s", mode); } else if (disk->shared && !disk->readonly) { @@ -5211,6 +5224,8 @@ qemuParseCommandLineDisk(virCapsPtr caps, def->cachemode = VIR_DOMAIN_DISK_CACHE_WRITEBACK; else if (STREQ(values[i], "writethrough")) def->cachemode = VIR_DOMAIN_DISK_CACHE_WRITETHRU; + else if (STREQ(values[i], "directsync")) + def->cachemode = VIR_DOMAIN_DISK_CACHE_DIRECTSYNC; } else if (STREQ(keywords[i], "werror") || STREQ(keywords[i], "rerror")) { if (STREQ(values[i], "stop")) diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index c2b6cf2..91f15af 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -168,6 +168,7 @@ mymain(void) DO_TEST("disk-drive-cache-v2-wt"); DO_TEST("disk-drive-cache-v2-wb"); DO_TEST("disk-drive-cache-v2-none"); + DO_TEST("disk-drive-cache-directsync"); DO_TEST("disk-drive-network-nbd"); DO_TEST("disk-drive-network-rbd"); DO_TEST("disk-drive-network-sheepdog"); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 6e8da5e..b009bf3 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -338,6 +338,9 @@ mymain(void) QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-cache-v2-none", false, QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2, QEMU_CAPS_DRIVE_FORMAT); + DO_TEST("disk-drive-cache-directsync", false, + QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2, + QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-network-nbd", false, QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-network-rbd", false, diff --git a/tools/virsh.pod b/tools/virsh.pod index b90c26e..5ac2c5c 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1099,7 +1099,8 @@ floppy device; consider using B<update-device> for this usage instead. I<mode> can specify the two specific mode I<readonly> or I<shareable>. I<persistent> indicates the changes will affect the next boot of the domain. I<sourcetype> can indicate the type of source (block|file) -I<cache> can be one of "default", "none", "writethrough" or "writeback". +I<cache> can be one of "default", "none", "writethrough", "writeback", or +"directsync". I<serial> is the serial of disk device. I<shareable> indicates the disk device is shareable between domains. I<address> is the address of disk device in the form of pci:domain.bus.slot.function, -- 1.7.6

On Fri, Sep 02, 2011 at 03:38:38PM +0800, Osier Yang wrote:
Newer QEMU introduced cache=directsync for -drive, this patchset is to expose it in libvirt layer.
* Introduced a new QEMU capability flag ($prefix_CACHE_DIRECTSYNC), As even $prefix_CACHE_V2 is set, we can't known if directsync is supported. --- docs/formatdomain.html.in | 2 +- docs/schemas/domain.rng | 1 + src/conf/domain_conf.c | 3 ++- src/conf/domain_conf.h | 1 + src/qemu/qemu_capabilities.c | 6 +++++- src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 29 ++++++++++++++++++++++------- tests/qemuargv2xmltest.c | 1 + tests/qemuxml2argvtest.c | 3 +++ tools/virsh.pod | 3 ++- 10 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index f46771d..6cb36d3 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -976,7 +976,7 @@ <li> The optional <code>cache</code> attribute controls the cache mechanism, possible values are "default", "none", - "writethrough" and "writeback". + "writethrough", "writeback", and "directsync". <span class="since">Since 0.6.0</span> </li> <li> diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng index dd8c41a..e43b17d 100644 --- a/docs/schemas/domain.rng +++ b/docs/schemas/domain.rng @@ -829,6 +829,7 @@ <value>none</value> <value>writeback</value> <value>writethrough</value> + <value>directsync</value> </choice> </attribute> </define> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 00212db..a2de8df 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -160,7 +160,8 @@ VIR_ENUM_IMPL(virDomainDiskCache, VIR_DOMAIN_DISK_CACHE_LAST, "default", "none", "writethrough", - "writeback") + "writeback", + "directsync")
VIR_ENUM_IMPL(virDomainDiskErrorPolicy, VIR_DOMAIN_DISK_ERROR_POLICY_LAST, "default", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8382d28..0abb75e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -165,6 +165,7 @@ enum virDomainDiskCache { VIR_DOMAIN_DISK_CACHE_DISABLE, VIR_DOMAIN_DISK_CACHE_WRITETHRU, VIR_DOMAIN_DISK_CACHE_WRITEBACK, + VIR_DOMAIN_DISK_CACHE_DIRECTSYNC,
VIR_DOMAIN_DISK_CACHE_LAST }; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f665de4..631d683 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -125,6 +125,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST, "sga", "virtio-blk-pci.event_idx", "virtio-net-pci.event_idx", + "cache-directsync", );
struct qemu_feature_flags { @@ -902,8 +903,11 @@ qemuCapsComputeCmdFlags(const char *help, if (strstr(help, "-drive")) { qemuCapsSet(flags, QEMU_CAPS_DRIVE); if (strstr(help, "cache=") && - !strstr(help, "cache=on|off")) + !strstr(help, "cache=on|off")) { qemuCapsSet(flags, QEMU_CAPS_DRIVE_CACHE_V2); + if (strstr(help, "directsync")) + qemuCapsSet(flags, QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC); + } if (strstr(help, "format=")) qemuCapsSet(flags, QEMU_CAPS_DRIVE_FORMAT); if (strstr(help, "readonly=")) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 13af0b9..c01d438 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -100,6 +100,7 @@ enum qemuCapsFlags { QEMU_CAPS_SGA = 62, /* Serial Graphics Adapter */ QEMU_CAPS_VIRTIO_BLK_EVENT_IDX = 63, /* virtio-blk-pci.event_idx */ QEMU_CAPS_VIRTIO_NET_EVENT_IDX = 64, /* virtio-net-pci.event_idx */ + QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC = 65, /* Is cache=directsync supported? */
QEMU_CAPS_LAST, /* this must always be the last item */ }; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 44a553b..fa52dc0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -64,14 +64,16 @@ VIR_ENUM_DECL(qemuDiskCacheV2) VIR_ENUM_IMPL(qemuDiskCacheV1, VIR_DOMAIN_DISK_CACHE_LAST, "default", "off", - "off", /* writethrough not supported, so for safety, disable */ - "on"); /* Old 'on' was equivalent to 'writeback' */ + "off", /* writethrough not supported, so for safety, disable */ + "on", /* Old 'on' was equivalent to 'writeback' */ + "off"); /* directsync not supported, for safety, disable */
VIR_ENUM_IMPL(qemuDiskCacheV2, VIR_DOMAIN_DISK_CACHE_LAST, "default", "none", "writethrough", - "writeback"); + "writeback", + "directsync");
VIR_ENUM_DECL(qemuVideo)
@@ -1516,10 +1518,21 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk, }
if (disk->cachemode) { - const char *mode = - qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_V2) ? - qemuDiskCacheV2TypeToString(disk->cachemode) : - qemuDiskCacheV1TypeToString(disk->cachemode); + const char *mode = NULL; + + if (qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_V2)) { + mode = qemuDiskCacheV2TypeToString(disk->cachemode); + + if (disk->cachemode == VIR_DOMAIN_DISK_CACHE_DIRECTSYNC && + !qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC)) { + qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("disk cache mode 'directsync' is not " + "supported by this QEMU")); + goto error; + } + } else { + mode = qemuDiskCacheV1TypeToString(disk->cachemode); + }
virBufferAsprintf(&opt, ",cache=%s", mode); } else if (disk->shared && !disk->readonly) { @@ -5211,6 +5224,8 @@ qemuParseCommandLineDisk(virCapsPtr caps, def->cachemode = VIR_DOMAIN_DISK_CACHE_WRITEBACK; else if (STREQ(values[i], "writethrough")) def->cachemode = VIR_DOMAIN_DISK_CACHE_WRITETHRU; + else if (STREQ(values[i], "directsync")) + def->cachemode = VIR_DOMAIN_DISK_CACHE_DIRECTSYNC; } else if (STREQ(keywords[i], "werror") || STREQ(keywords[i], "rerror")) { if (STREQ(values[i], "stop")) diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index c2b6cf2..91f15af 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -168,6 +168,7 @@ mymain(void) DO_TEST("disk-drive-cache-v2-wt"); DO_TEST("disk-drive-cache-v2-wb"); DO_TEST("disk-drive-cache-v2-none"); + DO_TEST("disk-drive-cache-directsync"); DO_TEST("disk-drive-network-nbd"); DO_TEST("disk-drive-network-rbd"); DO_TEST("disk-drive-network-sheepdog"); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 6e8da5e..b009bf3 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -338,6 +338,9 @@ mymain(void) QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-cache-v2-none", false, QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2, QEMU_CAPS_DRIVE_FORMAT); + DO_TEST("disk-drive-cache-directsync", false, + QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2, + QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-network-nbd", false, QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-network-rbd", false, diff --git a/tools/virsh.pod b/tools/virsh.pod index b90c26e..5ac2c5c 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1099,7 +1099,8 @@ floppy device; consider using B<update-device> for this usage instead. I<mode> can specify the two specific mode I<readonly> or I<shareable>. I<persistent> indicates the changes will affect the next boot of the domain. I<sourcetype> can indicate the type of source (block|file) -I<cache> can be one of "default", "none", "writethrough" or "writeback". +I<cache> can be one of "default", "none", "writethrough", "writeback", or +"directsync". I<serial> is the serial of disk device. I<shareable> indicates the disk device is shareable between domains. I<address> is the address of disk device in the form of pci:domain.bus.slot.function,
ACK, though I would prefer if docs/formatdomain.html.in was expanded to explain the semantic of that new flag ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

于 2011年09月02日 18:04, Daniel Veillard 写道:
On Fri, Sep 02, 2011 at 03:38:38PM +0800, Osier Yang wrote:
Newer QEMU introduced cache=directsync for -drive, this patchset is to expose it in libvirt layer.
* Introduced a new QEMU capability flag ($prefix_CACHE_DIRECTSYNC), As even $prefix_CACHE_V2 is set, we can't known if directsync is supported. --- docs/formatdomain.html.in | 2 +- docs/schemas/domain.rng | 1 + src/conf/domain_conf.c | 3 ++- src/conf/domain_conf.h | 1 + src/qemu/qemu_capabilities.c | 6 +++++- src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 29 ++++++++++++++++++++++------- tests/qemuargv2xmltest.c | 1 + tests/qemuxml2argvtest.c | 3 +++ tools/virsh.pod | 3 ++- 10 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index f46771d..6cb36d3 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -976,7 +976,7 @@ <li> The optional<code>cache</code> attribute controls the cache mechanism, possible values are "default", "none", - "writethrough" and "writeback". + "writethrough", "writeback", and "directsync". <span class="since">Since 0.6.0</span> </li> <li> diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng index dd8c41a..e43b17d 100644 --- a/docs/schemas/domain.rng +++ b/docs/schemas/domain.rng @@ -829,6 +829,7 @@ <value>none</value> <value>writeback</value> <value>writethrough</value> +<value>directsync</value> </choice> </attribute> </define> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 00212db..a2de8df 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -160,7 +160,8 @@ VIR_ENUM_IMPL(virDomainDiskCache, VIR_DOMAIN_DISK_CACHE_LAST, "default", "none", "writethrough", - "writeback") + "writeback", + "directsync")
VIR_ENUM_IMPL(virDomainDiskErrorPolicy, VIR_DOMAIN_DISK_ERROR_POLICY_LAST, "default", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8382d28..0abb75e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -165,6 +165,7 @@ enum virDomainDiskCache { VIR_DOMAIN_DISK_CACHE_DISABLE, VIR_DOMAIN_DISK_CACHE_WRITETHRU, VIR_DOMAIN_DISK_CACHE_WRITEBACK, + VIR_DOMAIN_DISK_CACHE_DIRECTSYNC,
VIR_DOMAIN_DISK_CACHE_LAST }; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f665de4..631d683 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -125,6 +125,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST, "sga", "virtio-blk-pci.event_idx", "virtio-net-pci.event_idx", + "cache-directsync", );
struct qemu_feature_flags { @@ -902,8 +903,11 @@ qemuCapsComputeCmdFlags(const char *help, if (strstr(help, "-drive")) { qemuCapsSet(flags, QEMU_CAPS_DRIVE); if (strstr(help, "cache=")&& - !strstr(help, "cache=on|off")) + !strstr(help, "cache=on|off")) { qemuCapsSet(flags, QEMU_CAPS_DRIVE_CACHE_V2); + if (strstr(help, "directsync")) + qemuCapsSet(flags, QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC); + } if (strstr(help, "format=")) qemuCapsSet(flags, QEMU_CAPS_DRIVE_FORMAT); if (strstr(help, "readonly=")) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 13af0b9..c01d438 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -100,6 +100,7 @@ enum qemuCapsFlags { QEMU_CAPS_SGA = 62, /* Serial Graphics Adapter */ QEMU_CAPS_VIRTIO_BLK_EVENT_IDX = 63, /* virtio-blk-pci.event_idx */ QEMU_CAPS_VIRTIO_NET_EVENT_IDX = 64, /* virtio-net-pci.event_idx */ + QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC = 65, /* Is cache=directsync supported? */
QEMU_CAPS_LAST, /* this must always be the last item */ }; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 44a553b..fa52dc0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -64,14 +64,16 @@ VIR_ENUM_DECL(qemuDiskCacheV2) VIR_ENUM_IMPL(qemuDiskCacheV1, VIR_DOMAIN_DISK_CACHE_LAST, "default", "off", - "off", /* writethrough not supported, so for safety, disable */ - "on"); /* Old 'on' was equivalent to 'writeback' */ + "off", /* writethrough not supported, so for safety, disable */ + "on", /* Old 'on' was equivalent to 'writeback' */ + "off"); /* directsync not supported, for safety, disable */
VIR_ENUM_IMPL(qemuDiskCacheV2, VIR_DOMAIN_DISK_CACHE_LAST, "default", "none", "writethrough", - "writeback"); + "writeback", + "directsync");
VIR_ENUM_DECL(qemuVideo)
@@ -1516,10 +1518,21 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk, }
if (disk->cachemode) { - const char *mode = - qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_V2) ? - qemuDiskCacheV2TypeToString(disk->cachemode) : - qemuDiskCacheV1TypeToString(disk->cachemode); + const char *mode = NULL; + + if (qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_V2)) { + mode = qemuDiskCacheV2TypeToString(disk->cachemode); + + if (disk->cachemode == VIR_DOMAIN_DISK_CACHE_DIRECTSYNC&& + !qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC)) { + qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("disk cache mode 'directsync' is not " + "supported by this QEMU")); + goto error; + } + } else { + mode = qemuDiskCacheV1TypeToString(disk->cachemode); + }
virBufferAsprintf(&opt, ",cache=%s", mode); } else if (disk->shared&& !disk->readonly) { @@ -5211,6 +5224,8 @@ qemuParseCommandLineDisk(virCapsPtr caps, def->cachemode = VIR_DOMAIN_DISK_CACHE_WRITEBACK; else if (STREQ(values[i], "writethrough")) def->cachemode = VIR_DOMAIN_DISK_CACHE_WRITETHRU; + else if (STREQ(values[i], "directsync")) + def->cachemode = VIR_DOMAIN_DISK_CACHE_DIRECTSYNC; } else if (STREQ(keywords[i], "werror") || STREQ(keywords[i], "rerror")) { if (STREQ(values[i], "stop")) diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index c2b6cf2..91f15af 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -168,6 +168,7 @@ mymain(void) DO_TEST("disk-drive-cache-v2-wt"); DO_TEST("disk-drive-cache-v2-wb"); DO_TEST("disk-drive-cache-v2-none"); + DO_TEST("disk-drive-cache-directsync"); DO_TEST("disk-drive-network-nbd"); DO_TEST("disk-drive-network-rbd"); DO_TEST("disk-drive-network-sheepdog"); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 6e8da5e..b009bf3 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -338,6 +338,9 @@ mymain(void) QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-cache-v2-none", false, QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2, QEMU_CAPS_DRIVE_FORMAT); + DO_TEST("disk-drive-cache-directsync", false, + QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2, + QEMU_CAPS_DRIVE_CACHE_DIRECTSYNC, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-network-nbd", false, QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT); DO_TEST("disk-drive-network-rbd", false, diff --git a/tools/virsh.pod b/tools/virsh.pod index b90c26e..5ac2c5c 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1099,7 +1099,8 @@ floppy device; consider using B<update-device> for this usage instead. I<mode> can specify the two specific mode I<readonly> or I<shareable>. I<persistent> indicates the changes will affect the next boot of the domain. I<sourcetype> can indicate the type of source (block|file) -I<cache> can be one of "default", "none", "writethrough" or "writeback". +I<cache> can be one of "default", "none", "writethrough", "writeback", or +"directsync". I<serial> is the serial of disk device. I<shareable> indicates the disk device is shareable between domains. I<address> is the address of disk device in the form of pci:domain.bus.slot.function, ACK, though I would prefer if docs/formatdomain.html.in was expanded to explain the semantic of that new flag !
Daniel
I pushed with document: "directsync" is like "writethrough", but it bypasses the host page cache. Regards, Osier

On 09/02/2011 01:38 AM, Osier Yang wrote:
Newer QEMU introduced cache=directsync for -drive, this patchset is to expose it in libvirt layer.
* Introduced a new QEMU capability flag ($prefix_CACHE_DIRECTSYNC), As even $prefix_CACHE_V2 is set, we can't known if directsync is supported. --- docs/formatdomain.html.in | 2 +- docs/schemas/domain.rng | 1 + src/conf/domain_conf.c | 3 ++- src/conf/domain_conf.h | 1 + src/qemu/qemu_capabilities.c | 6 +++++- src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 29 ++++++++++++++++++++++------- tests/qemuargv2xmltest.c | 1 + tests/qemuxml2argvtest.c | 3 +++
Missing new files in tests/qemuxml2argdata. :( I can guess at what they were, but it's breaking 'make check', and I'd rather have the version that you forgot to 'git add' on your end. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Created by copying from qemuxml2argv-disk-drive-v2-wb.*, then s/writeback/directsync/. Hopefully this matches Osier's intentions. * tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.args: * tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.xml: Add missing files needed by 'make check'. --- Pushing under the build-breaker rule. Osier, if this conflicts with the files you have locally, then feel free to update the test to use the version you tested. .../qemuxml2argv-disk-drive-cache-directsync.args | 5 +++ .../qemuxml2argv-disk-drive-cache-directsync.xml | 33 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 0 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.xml diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.args new file mode 100644 index 0000000..3e78726 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.args @@ -0,0 +1,5 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ +pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi -boot c -drive file=/dev/HostVG/QEMUGuest1,if=ide,bus=0,unit=0,\ +format=qcow2,cache=directsync -drive file=/dev/HostVG/QEMUGuest2,if=ide,\ +media=cdrom,bus=1,unit=0,format=raw -net none -serial none -parallel none -usb diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.xml new file mode 100644 index 0000000..17d7c1c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.xml @@ -0,0 +1,33 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219136</memory> + <currentMemory>219136</currentMemory> + <vcpu>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <driver name='qemu' type='qcow2' cache='directsync'/> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' unit='0'/> + </disk> + <disk type='block' device='cdrom'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest2'/> + <target dev='hdc' bus='ide'/> + <readonly/> + <address type='drive' controller='0' bus='1' unit='0'/> + </disk> + <controller type='ide' index='0'/> + <memballoon model='virtio'/> + </devices> +</domain> -- 1.7.4.4

于 2011年09月02日 22:44, Eric Blake 写道:
Created by copying from qemuxml2argv-disk-drive-v2-wb.*, then s/writeback/directsync/. Hopefully this matches Osier's intentions.
* tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.args: * tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.xml: Add missing files needed by 'make check'. ---
Pushing under the build-breaker rule. Osier, if this conflicts with the files you have locally, then feel free to update the test to use the version you tested.
It's same with what I created, thanks.
.../qemuxml2argv-disk-drive-cache-directsync.args | 5 +++ .../qemuxml2argv-disk-drive-cache-directsync.xml | 33 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 0 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.xml
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.args new file mode 100644 index 0000000..3e78726 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.args @@ -0,0 +1,5 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ +pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi -boot c -drive file=/dev/HostVG/QEMUGuest1,if=ide,bus=0,unit=0,\ +format=qcow2,cache=directsync -drive file=/dev/HostVG/QEMUGuest2,if=ide,\ +media=cdrom,bus=1,unit=0,format=raw -net none -serial none -parallel none -usb diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.xml new file mode 100644 index 0000000..17d7c1c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-cache-directsync.xml @@ -0,0 +1,33 @@ +<domain type='qemu'> +<name>QEMUGuest1</name> +<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> +<memory>219136</memory> +<currentMemory>219136</currentMemory> +<vcpu>1</vcpu> +<os> +<type arch='i686' machine='pc'>hvm</type> +<boot dev='hd'/> +</os> +<clock offset='utc'/> +<on_poweroff>destroy</on_poweroff> +<on_reboot>restart</on_reboot> +<on_crash>destroy</on_crash> +<devices> +<emulator>/usr/bin/qemu</emulator> +<disk type='block' device='disk'> +<driver name='qemu' type='qcow2' cache='directsync'/> +<source dev='/dev/HostVG/QEMUGuest1'/> +<target dev='hda' bus='ide'/> +<address type='drive' controller='0' bus='0' unit='0'/> +</disk> +<disk type='block' device='cdrom'> +<driver name='qemu' type='raw'/> +<source dev='/dev/HostVG/QEMUGuest2'/> +<target dev='hdc' bus='ide'/> +<readonly/> +<address type='drive' controller='0' bus='1' unit='0'/> +</disk> +<controller type='ide' index='0'/> +<memballoon model='virtio'/> +</devices> +</domain>

于 2011年09月02日 22:38, Eric Blake 写道:
On 09/02/2011 01:38 AM, Osier Yang wrote:
Newer QEMU introduced cache=directsync for -drive, this patchset is to expose it in libvirt layer.
* Introduced a new QEMU capability flag ($prefix_CACHE_DIRECTSYNC), As even $prefix_CACHE_V2 is set, we can't known if directsync is supported. --- docs/formatdomain.html.in | 2 +- docs/schemas/domain.rng | 1 + src/conf/domain_conf.c | 3 ++- src/conf/domain_conf.h | 1 + src/qemu/qemu_capabilities.c | 6 +++++- src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 29 ++++++++++++++++++++++------- tests/qemuargv2xmltest.c | 1 + tests/qemuxml2argvtest.c | 3 +++
Missing new files in tests/qemuxml2argdata. :( I can guess at what they were, but it's breaking 'make check', and I'd rather have the version that you forgot to 'git add' on your end.
Argh, thanks for committing the missing files. Regards, Osier
participants (3)
-
Daniel Veillard
-
Eric Blake
-
Osier Yang