From: Hyman Huang(黄勇) <yong.huang(a)smartx.com>
Add 'virtio_discard' and 'virtio_write_zeroes' attribute to control
whether discard and write-zeroes requests are handled by the
virtio-blk device.
To distinguish the attributes in block drive layer, use the 'virtio'
prefix to indicate that these attributes are specific for virtio-blk.
Signed-off-by: Hyman Huang(黄勇) <yong.huang(a)smartx.com>
---
docs/formatdomain.rst | 8 ++++++++
src/conf/domain_conf.c | 16 ++++++++++++++++
src/conf/domain_conf.h | 2 ++
src/conf/schemas/domaincommon.rng | 10 ++++++++++
src/conf/storage_source_conf.c | 2 ++
src/conf/storage_source_conf.h | 2 ++
src/qemu/qemu_domain.c | 2 ++
src/qemu/qemu_driver.c | 4 +++-
src/vz/vz_utils.c | 12 ++++++++++++
9 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index 4af0b82569..7be12ff08e 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -3259,6 +3259,14 @@ paravirtualized driver is specified via the ``disk`` element.
value can be either "unmap" (allow the discard request to be passed) or
"ignore" (ignore the discard request). :since:`Since 1.0.6 (QEMU and KVM
only)`
+ - The optional ``virtio_discard`` and ``virtio_write_zeroes`` are attributes
+ that control whether discard and write-zeroes requests are handled by the
+ virtio-blk device. The feature is based on DISCARD and WRITE_ZEROES
+ commands introduced in virtio-blk protocol to improve performance when
+ using SSD backend. The value can be either 'on' or 'off'. Note
that
+ ``discard`` and ``write_zeroes`` implementations in the block drive layer
+ are parts of the feature logically and should be turned on when enabling
+ the feature. :since:`Since 9.6.0 (QEMU and KVM only)`
- The optional ``detect_zeroes`` attribute controls whether to detect zero
write requests. The value can be "off", "on" or
"unmap". First two values
turn the detection off and on, respectively. The third value ("unmap")
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5ac5c0b771..0f82b489f4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7813,6 +7813,14 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def,
VIR_XML_PROP_NONZERO, &def->discard) < 0)
return -1;
+ if (virXMLPropTristateSwitch(cur, "virtio_discard", VIR_XML_PROP_NONE,
+ &def->virtio_discard) < 0)
+ return -1;
+
+ if (virXMLPropTristateSwitch(cur, "virtio_write_zeroes",
VIR_XML_PROP_NONE,
+ &def->virtio_write_zeroes) < 0)
+ return -1;
+
if (virXMLPropUInt(cur, "iothread", 10, VIR_XML_PROP_NONZERO,
&def->iothread) < 0)
return -1;
@@ -22514,6 +22522,14 @@ virDomainDiskDefFormatDriver(virBuffer *buf,
virBufferAsprintf(&attrBuf, " discard='%s'",
virDomainDiskDiscardTypeToString(disk->discard));
+ if (disk->virtio_discard)
+ virBufferAsprintf(&attrBuf, " virtio_discard='%s'",
+ virTristateSwitchTypeToString(disk->virtio_discard));
+
+ if (disk->virtio_write_zeroes)
+ virBufferAsprintf(&attrBuf, " virtio_write_zeroes='%s'",
+ virTristateSwitchTypeToString(disk->virtio_write_zeroes));
+
if (disk->iothread)
virBufferAsprintf(&attrBuf, " iothread='%u'",
disk->iothread);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c857ba556f..86e955333e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -607,6 +607,8 @@ struct _virDomainDiskDef {
unsigned int iothread; /* unused = 0, > 0 specific thread # */
virDomainDiskDetectZeroes detect_zeroes;
virTristateSwitch discard_no_unref;
+ virTristateSwitch virtio_discard;
+ virTristateSwitch virtio_write_zeroes;
char *domain_name; /* backend domain name */
unsigned int queues;
unsigned int queue_size;
diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng
index c2f56b0490..c3a59aeb15 100644
--- a/src/conf/schemas/domaincommon.rng
+++ b/src/conf/schemas/domaincommon.rng
@@ -2510,6 +2510,16 @@
<optional>
<ref name="discard"/>
</optional>
+ <optional>
+ <attribute name="virtio_discard">
+ <ref name="virOnOff"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="virtio_write_zeroes">
+ <ref name="virOnOff"/>
+ </attribute>
+ </optional>
<optional>
<ref name="driverIOThread"/>
</optional>
diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c
index dcac3a8ff6..c2fee652f3 100644
--- a/src/conf/storage_source_conf.c
+++ b/src/conf/storage_source_conf.c
@@ -810,6 +810,8 @@ virStorageSourceCopy(const virStorageSource *src,
def->discard = src->discard;
def->detect_zeroes = src->detect_zeroes;
def->discard_no_unref = src->discard_no_unref;
+ def->virtio_discard = src->virtio_discard;
+ def->virtio_write_zeroes = src->virtio_write_zeroes;
def->sslverify = src->sslverify;
def->readahead = src->readahead;
def->timeout = src->timeout;
diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h
index f13e7c756a..5e7f093fc0 100644
--- a/src/conf/storage_source_conf.h
+++ b/src/conf/storage_source_conf.h
@@ -400,6 +400,8 @@ struct _virStorageSource {
int discard; /* enum virDomainDiskDiscard */
int detect_zeroes; /* enum virDomainDiskDetectZeroes */
virTristateSwitch discard_no_unref;
+ virTristateSwitch virtio_discard;
+ virTristateSwitch virtio_write_zeroes;
bool floppyimg; /* set to true if the storage source is going to be used
as a source for floppy drive */
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3700b3e711..634d8699d0 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11031,6 +11031,8 @@ qemuDomainPrepareDiskSourceData(virDomainDiskDef *disk,
src->cachemode = disk->cachemode;
src->discard = disk->discard;
src->discard_no_unref = disk->discard_no_unref;
+ src->virtio_discard = disk->virtio_discard;
+ src->virtio_write_zeroes = disk->virtio_write_zeroes;
if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
src->floppyimg = true;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f20544590d..43e157da68 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14243,9 +14243,11 @@ qemuDomainBlockCopyCommon(virDomainObj *vm,
* Since 'mirror' has the ambition to replace it we need to propagate
* it into the mirror too. We do it directly as otherwise we'd need
* to modify all callers of 'qemuDomainPrepareStorageSourceBlockdev'
- * Same for discard_no_unref */
+ * Same for discard_no_unref,virtio_discard and virtio_write_zeroes */
mirror->detect_zeroes = disk->detect_zeroes;
mirror->discard_no_unref = disk->discard_no_unref;
+ mirror->virtio_discard = disk->virtio_discard;
+ mirror->virtio_write_zeroes = disk->virtio_write_zeroes;
/* If reusing an external image that includes a backing file but the user
* did not enumerate the chain in the XML we need to detect the chain */
diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c
index 7db7dbd419..1d824a9d2b 100644
--- a/src/vz/vz_utils.c
+++ b/src/vz/vz_utils.c
@@ -353,6 +353,18 @@ vzCheckDiskUnsupportedParams(virDomainDiskDef *disk)
return -1;
}
+ if (disk->virtio_discard) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Disk virtio_discard is not supported by vz
driver."));
+ return -1;
+ }
+
+ if (disk->virtio_write_zeroes) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Disk virtio_write_zeroes is not supported by vz
driver."));
+ return -1;
+ }
+
if (disk->startupPolicy != VIR_DOMAIN_STARTUP_POLICY_DEFAULT) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Setting up disk startup policy is not "
--
2.38.5