提交 8fc5e5bf 编写于 作者: P Peter Krempa

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: NPeter Krempa <pkrempa@redhat.com>
上级 1cb7f415
......@@ -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));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册