mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
conf: Extract logic for updating 'detect_zeroes' mode
For some reason we've decided to silently translate the disk detect_zeroes mode if it would be invalid. Extract the logic so that it does not need to be copypasta'd across the code base. Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
1cb7f41568
commit
8fc5e5bfdc
@ -29362,3 +29362,25 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
|
||||
virStoragePoolDefFree(pooldef);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virDomainDiskGetDetectZeroesMode:
|
||||
* @discard: disk/image sector discard setting
|
||||
* @detect_zeroes: disk/image zero sector detection mode
|
||||
*
|
||||
* As a convenience syntax, if discards are ignored and zero detection is set
|
||||
* to 'unmap', then simply behave like zero detection is set to 'on'. But
|
||||
* don't change it in the XML for easier adjustments. This behaviour is
|
||||
* documented.
|
||||
*/
|
||||
int
|
||||
virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard discard,
|
||||
virDomainDiskDetectZeroes detect_zeroes)
|
||||
{
|
||||
if (discard != VIR_DOMAIN_DISK_DISCARD_UNMAP &&
|
||||
detect_zeroes == VIR_DOMAIN_DISK_DETECT_ZEROES_UNMAP)
|
||||
return VIR_DOMAIN_DISK_DETECT_ZEROES_ON;
|
||||
|
||||
return detect_zeroes;
|
||||
}
|
||||
|
@ -3528,5 +3528,8 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface)
|
||||
|
||||
int virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def);
|
||||
|
||||
int
|
||||
virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard discard,
|
||||
virDomainDiskDetectZeroes detect_zeroes);
|
||||
|
||||
#endif /* __DOMAIN_CONF_H */
|
||||
|
@ -326,6 +326,7 @@ virDomainDiskErrorPolicyTypeToString;
|
||||
virDomainDiskFindByBusAndDst;
|
||||
virDomainDiskGeometryTransTypeFromString;
|
||||
virDomainDiskGeometryTransTypeToString;
|
||||
virDomainDiskGetDetectZeroesMode;
|
||||
virDomainDiskGetDriver;
|
||||
virDomainDiskGetFormat;
|
||||
virDomainDiskGetSource;
|
||||
|
@ -1729,6 +1729,8 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
|
||||
virQEMUCapsPtr qemuCaps)
|
||||
{
|
||||
virBuffer opt = VIR_BUFFER_INITIALIZER;
|
||||
int detect_zeroes = virDomainDiskGetDetectZeroesMode(disk->discard,
|
||||
disk->detect_zeroes);
|
||||
|
||||
if (qemuBuildDriveSourceStr(disk, qemuCaps, &opt) < 0)
|
||||
goto error;
|
||||
@ -1808,20 +1810,7 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
|
||||
virDomainDiskDiscardTypeToString(disk->discard));
|
||||
}
|
||||
|
||||
if (disk->detect_zeroes) {
|
||||
int detect_zeroes = disk->detect_zeroes;
|
||||
|
||||
/*
|
||||
* As a convenience syntax, if discards are ignored and
|
||||
* zero detection is set to 'unmap', then simply behave
|
||||
* like zero detection is set to 'on'. But don't change
|
||||
* it in the XML for easier adjustments. This behaviour
|
||||
* is documented.
|
||||
*/
|
||||
if (disk->discard != VIR_DOMAIN_DISK_DISCARD_UNMAP &&
|
||||
detect_zeroes == VIR_DOMAIN_DISK_DETECT_ZEROES_UNMAP)
|
||||
detect_zeroes = VIR_DOMAIN_DISK_DETECT_ZEROES_ON;
|
||||
|
||||
if (detect_zeroes) {
|
||||
virBufferAsprintf(&opt, ",detect-zeroes=%s",
|
||||
virDomainDiskDetectZeroesTypeToString(detect_zeroes));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user