[PATCH v2] conf: Move validation from virDomainDiskDefIotuneParse into the validation callback

Moteen Shah posted 1 patch 2 years ago
Failed in applying to current master (apply log)
src/conf/domain_conf.c     | 55 +++-----------------------------------
src/conf/domain_validate.c | 42 ++++++++++++++++++++++++++++-
2 files changed, 45 insertions(+), 52 deletions(-)
[PATCH v2] conf: Move validation from virDomainDiskDefIotuneParse into the validation callback
Posted by Moteen Shah 2 years ago
From: Moteen Shah <moteenshah.02@gmail.com>

all the option collision total and... error messages in
virDomainDiskDefIotuneParse shifted to validation callback

Signed-off-by: Moteen Shah <moteenshah.02@gmail.com>
---
 src/conf/domain_conf.c     | 55 +++-----------------------------------
 src/conf/domain_validate.c | 42 ++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 52 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f2480f37f6..48132c2f97 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1408,7 +1408,6 @@ VIR_ENUM_IMPL(virDomainSnapshotLocation,
               "no",
               "internal",
               "external",
-              "manual",
 );
 
 /* Internal mapping: subset of block job types that can be present in
@@ -6229,51 +6228,6 @@ virDomainDefPostParseCheckFailure(virDomainDef *def,
     return 0;
 }
 
-static int
-virDomainDefPostParseCheck(virDomainDiskDef *def)
-{
-    if ((def->blkdeviotune.total_bytes_sec &&
-         def->blkdeviotune.read_bytes_sec) ||
-        (def->blkdeviotune.total_bytes_sec &&
-         def->blkdeviotune.write_bytes_sec)) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("total and read/write bytes_sec "
-                         "cannot be set at the same time"));
-        return -1;
-    }
-
-    if ((def->blkdeviotune.total_iops_sec &&
-         def->blkdeviotune.read_iops_sec) ||
-        (def->blkdeviotune.total_iops_sec &&
-         def->blkdeviotune.write_iops_sec)) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("total and read/write iops_sec "
-                         "cannot be set at the same time"));
-        return -1;
-    }
-
-    if ((def->blkdeviotune.total_bytes_sec_max &&
-         def->blkdeviotune.read_bytes_sec_max) ||
-        (def->blkdeviotune.total_bytes_sec_max &&
-         def->blkdeviotune.write_bytes_sec_max)) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("total and read/write bytes_sec_max "
-                         "cannot be set at the same time"));
-        return -1;
-    }
-
-    if ((def->blkdeviotune.total_iops_sec_max &&
-         def->blkdeviotune.read_iops_sec_max) ||
-        (def->blkdeviotune.total_iops_sec_max &&
-         def->blkdeviotune.write_iops_sec_max)) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("total and read/write iops_sec_max "
-                         "cannot be set at the same time"));
-        return -1;
-    }
-    return 0;
-}
-
 int
 virDomainDefPostParse(virDomainDef *def,
                       unsigned int parseFlags,
@@ -8826,9 +8780,9 @@ virDomainDiskDefIotuneParse(virDomainDiskDef *def,
     PARSE_IOTUNE(write_iops_sec_max_length);
 
     def->blkdeviotune.group_name =
-        virXPathString("string(./iotune/group_name)", ctxt);
-
-    return virDomainDefPostParseCheck(def);
+    virXPathString("string(./iotune/group_name)", ctxt);
+    
+    return 0;
 }
 #undef PARSE_IOTUNE
 
@@ -9278,8 +9232,7 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
             return NULL;
     }
 
-    if (virDomainDiskDefIotuneParse(def, ctxt) < 0)
-        return NULL;
+    virDomainDiskDefIotuneParse(def, ctxt);
 
     def->domain_name = virXPathString("string(./backenddomain/@name)", ctxt);
     def->serial = virXPathString("string(./serial)", ctxt);
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index d6869e8fd8..4bdb95aa13 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -597,7 +597,6 @@ virDomainDiskDefSourceLUNValidate(const virStorageSource *src)
     return 0;
 }
 
-
 static int
 virDomainDiskDefValidate(const virDomainDef *def,
                          const virDomainDiskDef *disk)
@@ -651,6 +650,47 @@ virDomainDiskDefValidate(const virDomainDef *def,
         }
     }
 
+    /* Validate IotuneParse */
+    if ((disk->blkdeviotune.total_bytes_sec &&
+         disk->blkdeviotune.read_bytes_sec) ||
+        (disk->blkdeviotune.total_bytes_sec &&
+         disk->blkdeviotune.write_bytes_sec)) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("total and read/write bytes_sec "
+                         "cannot be set at the same time"));
+        return -1;
+    }
+
+    if ((disk->blkdeviotune.total_iops_sec &&
+         disk->blkdeviotune.read_iops_sec) ||
+        (disk->blkdeviotune.total_iops_sec &&
+         disk->blkdeviotune.write_iops_sec)) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("total and read/write iops_sec "
+                         "cannot be set at the same time"));
+        return -1;
+    }
+
+    if ((disk->blkdeviotune.total_bytes_sec_max &&
+         disk->blkdeviotune.read_bytes_sec_max) ||
+        (disk->blkdeviotune.total_bytes_sec_max &&
+         disk->blkdeviotune.write_bytes_sec_max)) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("total and read/write bytes_sec_max "
+                         "cannot be set at the same time"));
+        return -1;
+    }
+
+    if ((disk->blkdeviotune.total_iops_sec_max &&
+         disk->blkdeviotune.read_iops_sec_max) ||
+        (disk->blkdeviotune.total_iops_sec_max &&
+         disk->blkdeviotune.write_iops_sec_max)) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("total and read/write iops_sec_max "
+                         "cannot be set at the same time"));
+        return -1;
+    }
+
     /* Reject disks with a bus type that is not compatible with the
      * given address type. The function considers only buses that are
      * handled in common code. For other bus types it's not possible
-- 
2.35.1