conf: add support for discard_granularity

This introduces the ability to set the discard granularity option
for a disk.  It defines the smallest amount of data that can be
discarded in a single operation (useful for managing and
optimizing storage).

However, most hypervisors automatically set the proper discard
granularity and users usually do not need to change the default
setting.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Kristina Hanicova 2023-08-25 14:50:31 +02:00 committed by Peter Krempa
parent c3934b2b6b
commit 96d8ee2cff
7 changed files with 36 additions and 4 deletions

View File

@ -2588,7 +2588,7 @@ paravirtualized driver is specified via the ``disk`` element.
<driver name='qemu' type='raw'/> <driver name='qemu' type='raw'/>
<source dev='/dev/sda'/> <source dev='/dev/sda'/>
<geometry cyls='16383' heads='16' secs='63' trans='lba'/> <geometry cyls='16383' heads='16' secs='63' trans='lba'/>
<blockio logical_block_size='512' physical_block_size='4096'/> <blockio logical_block_size='512' physical_block_size='4096' discard_granularity='4096'/>
<target dev='hdj' bus='ide'/> <target dev='hdj' bus='ide'/>
</disk> </disk>
<disk type='volume' device='disk'> <disk type='volume' device='disk'>
@ -3453,6 +3453,11 @@ paravirtualized driver is specified via the ``disk`` element.
this would be the value returned by the BLKPBSZGET ioctl and describes the this would be the value returned by the BLKPBSZGET ioctl and describes the
disk's hardware sector size which can be relevant for the alignment of disk's hardware sector size which can be relevant for the alignment of
disk data. disk data.
``discard_granularity``
The smallest amount of data that can be discarded in a single operation.
It impacts the unmap operations and it must be a multiple of a
``logical_block_size``. This is usually properly configured by the
hypervisor.
Filesystems Filesystems
~~~~~~~~~~~ ~~~~~~~~~~~

View File

@ -8073,6 +8073,10 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
if (virXMLPropUInt(blockioNode, "physical_block_size", 10, VIR_XML_PROP_NONE, if (virXMLPropUInt(blockioNode, "physical_block_size", 10, VIR_XML_PROP_NONE,
&def->blockio.physical_block_size) < 0) &def->blockio.physical_block_size) < 0)
return NULL; return NULL;
if (virXMLPropUInt(blockioNode, "discard_granularity", 10, VIR_XML_PROP_NONE,
&def->blockio.discard_granularity) < 0)
return NULL;
} }
if ((driverNode = virXPathNode("./driver", ctxt))) { if ((driverNode = virXPathNode("./driver", ctxt))) {
@ -19836,6 +19840,13 @@ virDomainDiskBlockIoCheckABIStability(virDomainDiskDef *src,
dst->blockio.physical_block_size, src->blockio.physical_block_size); dst->blockio.physical_block_size, src->blockio.physical_block_size);
return false; return false;
} }
if (src->blockio.discard_granularity != dst->blockio.discard_granularity) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target disk discard_granularity %1$u does not match source %2$u"),
dst->blockio.discard_granularity, src->blockio.discard_granularity);
return false;
}
return true; return true;
} }
@ -22132,7 +22143,8 @@ virDomainDiskBlockIoDefFormat(virBuffer *buf,
virDomainDiskDef *def) virDomainDiskDef *def)
{ {
if (def->blockio.logical_block_size > 0 || if (def->blockio.logical_block_size > 0 ||
def->blockio.physical_block_size > 0) { def->blockio.physical_block_size > 0 ||
def->blockio.discard_granularity > 0) {
virBufferAddLit(buf, "<blockio"); virBufferAddLit(buf, "<blockio");
if (def->blockio.logical_block_size > 0) { if (def->blockio.logical_block_size > 0) {
virBufferAsprintf(buf, virBufferAsprintf(buf,
@ -22144,6 +22156,11 @@ virDomainDiskBlockIoDefFormat(virBuffer *buf,
" physical_block_size='%u'", " physical_block_size='%u'",
def->blockio.physical_block_size); def->blockio.physical_block_size);
} }
if (def->blockio.discard_granularity > 0) {
virBufferAsprintf(buf,
" discard_granularity='%u'",
def->blockio.discard_granularity);
}
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} }
} }

View File

@ -579,6 +579,7 @@ struct _virDomainDiskDef {
struct { struct {
unsigned int logical_block_size; unsigned int logical_block_size;
unsigned int physical_block_size; unsigned int physical_block_size;
unsigned int discard_granularity;
} blockio; } blockio;
virDomainBlockIoTuneInfo blkdeviotune; virDomainBlockIoTuneInfo blkdeviotune;

View File

@ -466,7 +466,8 @@ virDomainDiskVhostUserValidate(const virDomainDiskDef *disk)
} }
if (disk->blockio.logical_block_size > 0 || if (disk->blockio.logical_block_size > 0 ||
disk->blockio.physical_block_size > 0) { disk->blockio.physical_block_size > 0 ||
disk->blockio.discard_granularity > 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("blockio is not supported with vhostuser disk")); _("blockio is not supported with vhostuser disk"));
return -1; return -1;

View File

@ -2461,6 +2461,11 @@
<data type="integer"/> <data type="integer"/>
</attribute> </attribute>
</optional> </optional>
<optional>
<attribute name="discard_granularity">
<data type="integer"/>
</attribute>
</optional>
</element> </element>
</define> </define>
<!-- <!--

View File

@ -8426,6 +8426,8 @@ qemuDomainDiskChangeSupported(virDomainDiskDef *disk,
"blockio logical_block_size", false); "blockio logical_block_size", false);
CHECK_EQ(blockio.physical_block_size, CHECK_EQ(blockio.physical_block_size,
"blockio physical_block_size", false); "blockio physical_block_size", false);
CHECK_EQ(blockio.discard_granularity,
"blockio discard_granularity", false);
CHECK_EQ(blkdeviotune.total_bytes_sec, CHECK_EQ(blkdeviotune.total_bytes_sec,
"blkdeviotune total_bytes_sec", "blkdeviotune total_bytes_sec",

View File

@ -279,7 +279,8 @@ vzCheckDiskUnsupportedParams(virDomainDiskDef *disk)
} }
if (disk->blockio.logical_block_size || if (disk->blockio.logical_block_size ||
disk->blockio.physical_block_size) { disk->blockio.physical_block_size ||
disk->blockio.discard_granularity) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Setting disk block sizes is not " _("Setting disk block sizes is not "
"supported by vz driver.")); "supported by vz driver."));