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);
|
virStoragePoolDefFree(pooldef);
|
||||||
return ret;
|
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 virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def);
|
||||||
|
|
||||||
|
int
|
||||||
|
virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard discard,
|
||||||
|
virDomainDiskDetectZeroes detect_zeroes);
|
||||||
|
|
||||||
#endif /* __DOMAIN_CONF_H */
|
#endif /* __DOMAIN_CONF_H */
|
||||||
|
@ -326,6 +326,7 @@ virDomainDiskErrorPolicyTypeToString;
|
|||||||
virDomainDiskFindByBusAndDst;
|
virDomainDiskFindByBusAndDst;
|
||||||
virDomainDiskGeometryTransTypeFromString;
|
virDomainDiskGeometryTransTypeFromString;
|
||||||
virDomainDiskGeometryTransTypeToString;
|
virDomainDiskGeometryTransTypeToString;
|
||||||
|
virDomainDiskGetDetectZeroesMode;
|
||||||
virDomainDiskGetDriver;
|
virDomainDiskGetDriver;
|
||||||
virDomainDiskGetFormat;
|
virDomainDiskGetFormat;
|
||||||
virDomainDiskGetSource;
|
virDomainDiskGetSource;
|
||||||
|
@ -1729,6 +1729,8 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
|
|||||||
virQEMUCapsPtr qemuCaps)
|
virQEMUCapsPtr qemuCaps)
|
||||||
{
|
{
|
||||||
virBuffer opt = VIR_BUFFER_INITIALIZER;
|
virBuffer opt = VIR_BUFFER_INITIALIZER;
|
||||||
|
int detect_zeroes = virDomainDiskGetDetectZeroesMode(disk->discard,
|
||||||
|
disk->detect_zeroes);
|
||||||
|
|
||||||
if (qemuBuildDriveSourceStr(disk, qemuCaps, &opt) < 0)
|
if (qemuBuildDriveSourceStr(disk, qemuCaps, &opt) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -1808,20 +1810,7 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
|
|||||||
virDomainDiskDiscardTypeToString(disk->discard));
|
virDomainDiskDiscardTypeToString(disk->discard));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disk->detect_zeroes) {
|
if (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;
|
|
||||||
|
|
||||||
virBufferAsprintf(&opt, ",detect-zeroes=%s",
|
virBufferAsprintf(&opt, ",detect-zeroes=%s",
|
||||||
virDomainDiskDetectZeroesTypeToString(detect_zeroes));
|
virDomainDiskDetectZeroesTypeToString(detect_zeroes));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user