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 ++++++++++
4 files changed, 36 insertions(+)
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..b73b1241ad 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -604,6 +604,8 @@ struct _virDomainDiskDef {
virTristateBool rawio;
virDomainDeviceSGIO sgio;
virDomainDiskDiscard discard;
+ virTristateSwitch virtio_discard;
+ virTristateSwitch virtio_write_zeroes;
unsigned int iothread; /* unused = 0, > 0 specific thread # */
virDomainDiskDetectZeroes detect_zeroes;
virTristateSwitch discard_no_unref;
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>
--
2.38.5