[PATCH 11/21] domain_conf.c: move vendor, product and tray checks to post parse

Daniel Henrique Barboza danielhb413 at gmail.com
Tue Nov 24 19:20:25 UTC 2020


The 'tray' check isn't a XML parse specific code and can be pushed
to post, in virDomainDiskDefPostParse().

'vendor' and 'product' string sizes are already checked by the
domaincommon.rng schema, but can be of use in post parse time since
not all scenarios will go through the XML parsing.

Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---
 src/conf/domain_conf.c | 47 ++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e21f353595..6623abad73 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5253,6 +5253,9 @@ virDomainDiskExpandGroupIoTune(virDomainDiskDefPtr disk,
 }
 
 
+#define VENDOR_LEN  8
+#define PRODUCT_LEN 16
+
 static int
 virDomainDiskDefPostParse(virDomainDiskDefPtr disk,
                           const virDomainDef *def,
@@ -5277,6 +5280,28 @@ virDomainDiskDefPostParse(virDomainDiskDefPtr disk,
         }
     }
 
+    if (disk->tray_status &&
+        disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
+        disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("tray is only valid for cdrom and floppy"));
+        return -1;
+    }
+
+    if (disk->vendor && strlen(disk->vendor) > VENDOR_LEN) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("disk vendor is more than %d characters"),
+                       VENDOR_LEN);
+        return -1;
+    }
+
+    if (disk->product && strlen(disk->product) > PRODUCT_LEN) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("disk product is more than %d characters"),
+                       PRODUCT_LEN);
+        return -1;
+    }
+
     if (disk->src->type == VIR_STORAGE_TYPE_NETWORK &&
         disk->src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI) {
         virDomainPostParseCheckISCSIPath(&disk->src->path);
@@ -10513,9 +10538,6 @@ virDomainDiskDefParsePrivateData(xmlXPathContextPtr ctxt,
 }
 
 
-#define VENDOR_LEN  8
-#define PRODUCT_LEN 16
-
 static virDomainDiskDefPtr
 virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
                          xmlNodePtr node,
@@ -10690,12 +10712,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
             if (!(vendor = virXMLNodeContentString(cur)))
                 return NULL;
 
-            if (strlen(vendor) > VENDOR_LEN) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("disk vendor is more than 8 characters"));
-                return NULL;
-            }
-
             if (!virStringIsPrintable(vendor)) {
                 virReportError(VIR_ERR_XML_ERROR, "%s",
                                _("disk vendor is not printable string"));
@@ -10706,12 +10722,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
             if (!(product = virXMLNodeContentString(cur)))
                 return NULL;
 
-            if (strlen(product) > PRODUCT_LEN) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("disk product is more than 16 characters"));
-                return NULL;
-            }
-
             if (!virStringIsPrintable(product)) {
                 virReportError(VIR_ERR_XML_ERROR, "%s",
                                _("disk product is not printable string"));
@@ -10842,13 +10852,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
                            _("unknown disk tray status '%s'"), tray);
             return NULL;
         }
-
-        if (def->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
-            def->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("tray is only valid for cdrom and floppy"));
-            return NULL;
-        }
     }
 
     if (removable) {
-- 
2.26.2




More information about the libvir-list mailing list