render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
459f93
From 296343c5a950668d790f9cd5ebd7b466e8156d03 Mon Sep 17 00:00:00 2001
459f93
Message-Id: <296343c5a950668d790f9cd5ebd7b466e8156d03@dist-git>
459f93
From: Peter Krempa <pkrempa@redhat.com>
459f93
Date: Tue, 14 Jun 2022 13:23:29 +0200
459f93
Subject: [PATCH] domain_validate: Split out validation of disk startup policy
459f93
MIME-Version: 1.0
459f93
Content-Type: text/plain; charset=UTF-8
459f93
Content-Transfer-Encoding: 8bit
459f93
459f93
Move the code into 'virDomainDiskDefValidateStartupPolicy' which will be
459f93
later reused in the qemu driver.
459f93
459f93
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
459f93
Reviewed-by: Ján Tomko <jtomko@redhat.com>
459f93
(cherry picked from commit 3603a18bcec18842cedecbd8329723062b87795c)
459f93
https://bugzilla.redhat.com/show_bug.cgi?id=2095758
459f93
---
459f93
 src/conf/domain_validate.c | 45 ++++++++++++++++++++++++--------------
459f93
 src/conf/domain_validate.h |  2 ++
459f93
 src/libvirt_private.syms   |  1 +
459f93
 3 files changed, 31 insertions(+), 17 deletions(-)
459f93
459f93
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
459f93
index 452742e67c..bfff7339ef 100644
459f93
--- a/src/conf/domain_validate.c
459f93
+++ b/src/conf/domain_validate.c
459f93
@@ -598,6 +598,32 @@ virDomainDiskDefSourceLUNValidate(const virStorageSource *src)
459f93
 }
459f93
 
459f93
 
459f93
+int
459f93
+virDomainDiskDefValidateStartupPolicy(const virDomainDiskDef *disk)
459f93
+{
459f93
+    if (disk->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_DEFAULT)
459f93
+        return 0;
459f93
+
459f93
+    if (disk->src->type == VIR_STORAGE_TYPE_NETWORK) {
459f93
+        virReportError(VIR_ERR_XML_ERROR,
459f93
+                       _("disk startupPolicy '%s' is not allowed for disk of '%s' type"),
459f93
+                       virDomainStartupPolicyTypeToString(disk->startupPolicy),
459f93
+                       virStorageTypeToString(disk->src->type));
459f93
+        return -1;
459f93
+    }
459f93
+
459f93
+    if (disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM &&
459f93
+        disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
459f93
+        disk->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_REQUISITE) {
459f93
+        virReportError(VIR_ERR_XML_ERROR, "%s",
459f93
+                       _("disk startupPolicy 'requisite' is allowed only for cdrom or floppy"));
459f93
+        return -1;
459f93
+    }
459f93
+
459f93
+    return 0;
459f93
+}
459f93
+
459f93
+
459f93
 static int
459f93
 virDomainDiskDefValidate(const virDomainDef *def,
459f93
                          const virDomainDiskDef *disk)
459f93
@@ -775,23 +801,8 @@ virDomainDiskDefValidate(const virDomainDef *def,
459f93
         return -1;
459f93
     }
459f93
 
459f93
-    if (disk->startupPolicy != VIR_DOMAIN_STARTUP_POLICY_DEFAULT) {
459f93
-        if (disk->src->type == VIR_STORAGE_TYPE_NETWORK) {
459f93
-            virReportError(VIR_ERR_XML_ERROR,
459f93
-                           _("disk startupPolicy '%s' is not allowed for disk of '%s' type"),
459f93
-                           virDomainStartupPolicyTypeToString(disk->startupPolicy),
459f93
-                           virStorageTypeToString(disk->src->type));
459f93
-            return -1;
459f93
-        }
459f93
-
459f93
-        if (disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM &&
459f93
-            disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
459f93
-            disk->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_REQUISITE) {
459f93
-            virReportError(VIR_ERR_XML_ERROR, "%s",
459f93
-                           _("disk startupPolicy 'requisite' is allowed only for cdrom or floppy"));
459f93
-            return -1;
459f93
-        }
459f93
-    }
459f93
+    if (virDomainDiskDefValidateStartupPolicy(disk) < 0)
459f93
+        return -1;
459f93
 
459f93
     if (disk->wwn && !virValidateWWN(disk->wwn))
459f93
         return -1;
459f93
diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h
459f93
index 430d61fd3c..07b99195e3 100644
459f93
--- a/src/conf/domain_validate.h
459f93
+++ b/src/conf/domain_validate.h
459f93
@@ -41,4 +41,6 @@ int virDomainDeviceDefValidate(const virDomainDeviceDef *dev,
459f93
 
459f93
 int virDomainDiskDefValidateSource(const virStorageSource *src);
459f93
 
459f93
+int virDomainDiskDefValidateStartupPolicy(const virDomainDiskDef *disk);
459f93
+
459f93
 int virDomainDiskDefSourceLUNValidate(const virStorageSource *src);
459f93
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
459f93
index 2c42e2a5e8..5b7a056151 100644
459f93
--- a/src/libvirt_private.syms
459f93
+++ b/src/libvirt_private.syms
459f93
@@ -777,6 +777,7 @@ virDomainActualNetDefValidate;
459f93
 virDomainDefValidate;
459f93
 virDomainDeviceValidateAliasForHotplug;
459f93
 virDomainDiskDefSourceLUNValidate;
459f93
+virDomainDiskDefValidateStartupPolicy;
459f93
 
459f93
 
459f93
 # conf/interface_conf.h
459f93
-- 
459f93
2.35.1
459f93