Move the code into 'virDomainDiskDefValidateStartupPolicy' which will be
later reused in the qemu driver.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_validate.c | 45 ++++++++++++++++++++++++--------------
src/conf/domain_validate.h | 2 ++
src/libvirt_private.syms | 1 +
3 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 3e11e00ee4..70e9167eac 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -632,6 +632,32 @@ virDomainDiskDefSourceLUNValidate(const virStorageSource *src)
}
+int
+virDomainDiskDefValidateStartupPolicy(const virDomainDiskDef *disk)
+{
+ if (disk->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_DEFAULT)
+ return 0;
+
+ if (disk->src->type == VIR_STORAGE_TYPE_NETWORK) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("disk startupPolicy '%s' is not allowed for disk of
'%s' type"),
+ virDomainStartupPolicyTypeToString(disk->startupPolicy),
+ virStorageTypeToString(disk->src->type));
+ return -1;
+ }
+
+ if (disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM &&
+ disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
+ disk->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_REQUISITE) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("disk startupPolicy 'requisite' is allowed only for
cdrom or floppy"));
+ return -1;
+ }
+
+ return 0;
+}
+
+
static int
virDomainDiskDefValidate(const virDomainDef *def,
const virDomainDiskDef *disk)
@@ -852,23 +878,8 @@ virDomainDiskDefValidate(const virDomainDef *def,
return -1;
}
- if (disk->startupPolicy != VIR_DOMAIN_STARTUP_POLICY_DEFAULT) {
- if (disk->src->type == VIR_STORAGE_TYPE_NETWORK) {
- virReportError(VIR_ERR_XML_ERROR,
- _("disk startupPolicy '%s' is not allowed for
disk of '%s' type"),
- virDomainStartupPolicyTypeToString(disk->startupPolicy),
- virStorageTypeToString(disk->src->type));
- return -1;
- }
-
- if (disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM &&
- disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
- disk->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_REQUISITE) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("disk startupPolicy 'requisite' is allowed only
for cdrom or floppy"));
- return -1;
- }
- }
+ if (virDomainDiskDefValidateStartupPolicy(disk) < 0)
+ return -1;
if (disk->wwn && !virValidateWWN(disk->wwn))
return -1;
diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h
index 430d61fd3c..07b99195e3 100644
--- a/src/conf/domain_validate.h
+++ b/src/conf/domain_validate.h
@@ -41,4 +41,6 @@ int virDomainDeviceDefValidate(const virDomainDeviceDef *dev,
int virDomainDiskDefValidateSource(const virStorageSource *src);
+int virDomainDiskDefValidateStartupPolicy(const virDomainDiskDef *disk);
+
int virDomainDiskDefSourceLUNValidate(const virStorageSource *src);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 770dfe459a..76bcc64eb0 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -779,6 +779,7 @@ virDomainActualNetDefValidate;
virDomainDefValidate;
virDomainDeviceValidateAliasForHotplug;
virDomainDiskDefSourceLUNValidate;
+virDomainDiskDefValidateStartupPolicy;
# conf/interface_conf.h
--
2.36.1