]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Turn 'protocol' field of virStorageSource into proper enum type
authorPeter Krempa <pkrempa@redhat.com>
Fri, 11 Nov 2022 12:05:33 +0000 (13:05 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 23 Jul 2025 12:47:24 +0000 (14:47 +0200)
Convert the member to the appropriate type, fix few offending parse
calls and remove explicit typecasts in switch().

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c
src/conf/domain_validate.c
src/conf/storage_source_conf.h
src/libxl/libxl_conf.c
src/libxl/xen_xl.c
src/qemu/qemu_block.c
src/qemu/qemu_domain.c
src/qemu/qemu_snapshot.c
src/storage_file/storage_source_backingstore.c

index 4f2045c21306443f4affdaee52221d6071103403..0342d6eae7f83ebfe5437363f4c801c05e977c4f 100644 (file)
@@ -7357,15 +7357,12 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
                                 virStorageSource *src,
                                 unsigned int flags)
 {
-    virStorageNetProtocol protocol;
     xmlNodePtr tmpnode;
 
     if (virXMLPropEnum(node, "protocol", virStorageNetProtocolTypeFromString,
-                       VIR_XML_PROP_REQUIRED, &protocol) < 0)
+                       VIR_XML_PROP_REQUIRED, &src->protocol) < 0)
         return -1;
 
-    src->protocol = protocol;
-
     if (!(src->path = virXMLPropString(node, "name")) &&
         src->protocol != VIR_STORAGE_NET_PROTOCOL_NBD) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
index 8f7259a0e1eddabc1e86e97ca6e9188d6ef551f1..c7afdbf7fd13b092d3c9aee223484626e5612081 100644 (file)
@@ -494,7 +494,7 @@ virDomainDiskDefValidateSourceChainOne(const virStorageSource *src)
             return -1;
         }
 
-        switch ((virStorageNetProtocol) src->protocol) {
+        switch (src->protocol) {
         case VIR_STORAGE_NET_PROTOCOL_ISCSI:
         case VIR_STORAGE_NET_PROTOCOL_HTTP:
         case VIR_STORAGE_NET_PROTOCOL_HTTPS:
index a0d5acdb09fc9711b4fce2e49cd9ca1dd2ce0d30..48d576e83d1797a93f1d80d133c4017b6b811b9e 100644 (file)
@@ -301,7 +301,7 @@ struct _virStorageSource {
     virStorageType type;
     char *path;
     char *fdgroup; /* name of group of file descriptors the user wishes to use instead of 'path' */
-    int protocol; /* virStorageNetProtocol */
+    virStorageNetProtocol protocol;
     char *volume; /* volume name for remote storage */
     char *snapshot; /* for storage systems supporting internal snapshots */
     char *configFile; /* some storage systems use config file as part of
index bdd30dd65a90f0adbaabc45e964fa1a594ca78a8..36fba4a55572e08bae25d29ff29bef08ece5e111 100644 (file)
@@ -1068,7 +1068,7 @@ libxlMakeNetworkDiskSrcStr(virStorageSource *src,
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     size_t i;
 
-    switch ((virStorageNetProtocol) src->protocol) {
+    switch (src->protocol) {
     case VIR_STORAGE_NET_PROTOCOL_NBD:
     case VIR_STORAGE_NET_PROTOCOL_HTTP:
     case VIR_STORAGE_NET_PROTOCOL_HTTPS:
index ec8de30c018c2e719d8533152086a38bd82ede2b..b83ed45c46da889d8c351f6933d3bd75fb666c50 100644 (file)
@@ -1448,7 +1448,7 @@ xenFormatXLDiskSrcNet(virStorageSource *src)
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     size_t i;
 
-    switch ((virStorageNetProtocol) src->protocol) {
+    switch (src->protocol) {
     case VIR_STORAGE_NET_PROTOCOL_NBD:
     case VIR_STORAGE_NET_PROTOCOL_HTTP:
     case VIR_STORAGE_NET_PROTOCOL_HTTPS:
index 32568d4ae6ce93adc72b93458ddf438cbd3b18b2..a59c0a0a0337084fec5b5cf3cec9c7d41929b6ad 100644 (file)
@@ -1046,14 +1046,13 @@ qemuBlockStorageSourceGetBackendProps(virStorageSource *src,
             break;
         }
 
-        switch ((virStorageNetProtocol) src->protocol) {
+        switch (src->protocol) {
         case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
             driver = "gluster";
             if (!(fileprops = qemuBlockStorageSourceGetGlusterProps(src, onlytarget)))
                 return NULL;
             break;
 
-
         case VIR_STORAGE_NET_PROTOCOL_HTTP:
         case VIR_STORAGE_NET_PROTOCOL_HTTPS:
         case VIR_STORAGE_NET_PROTOCOL_FTP:
@@ -1969,7 +1968,7 @@ qemuBlockGetBackingStoreString(virStorageSource *src,
             src->readahead == 0 &&
             src->reconnectDelay == 0) {
 
-            switch ((virStorageNetProtocol) src->protocol) {
+            switch (src->protocol) {
             case VIR_STORAGE_NET_PROTOCOL_NBD:
             case VIR_STORAGE_NET_PROTOCOL_HTTP:
             case VIR_STORAGE_NET_PROTOCOL_HTTPS:
@@ -2352,7 +2351,7 @@ qemuBlockStorageSourceCreateGetStorageProps(virStorageSource *src,
         break;
 
     case VIR_STORAGE_TYPE_NETWORK:
-        switch ((virStorageNetProtocol) src->protocol) {
+        switch (src->protocol) {
         case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
             driver = "gluster";
             if (!(location = qemuBlockStorageSourceGetGlusterProps(src, false)))
index d580c3165370c124fd33e3568a2456e6a0034a56..a2c7c88a7e3557b0e65bf4e9809a6be74972a1b8 100644 (file)
@@ -8952,7 +8952,7 @@ qemuDomainPrepareStorageSourceTLS(virStorageSource *src,
     if (virStorageSourceGetActualType(src) != VIR_STORAGE_TYPE_NETWORK)
         return 0;
 
-    switch ((virStorageNetProtocol) src->protocol) {
+    switch (src->protocol) {
     case VIR_STORAGE_NET_PROTOCOL_VXHS:
         /* vxhs is no longer supported */
         break;
index 8128154749f519292fde01e2aa9b9e212d271689..764aafda4d80821141481e9e8779aa08abc20046 100644 (file)
@@ -658,7 +658,7 @@ qemuSnapshotPrepareDiskExternalInactive(virDomainSnapshotDiskDef *snapdisk,
         break;
 
     case VIR_STORAGE_TYPE_NETWORK:
-        switch ((virStorageNetProtocol) domdisk->src->protocol) {
+        switch (domdisk->src->protocol) {
         case VIR_STORAGE_NET_PROTOCOL_NONE:
         case VIR_STORAGE_NET_PROTOCOL_NBD:
         case VIR_STORAGE_NET_PROTOCOL_RBD:
@@ -883,7 +883,7 @@ qemuSnapshotPrepareDiskInternal(virDomainDiskDef *disk,
         return 0;
 
     case VIR_STORAGE_TYPE_NETWORK:
-        switch ((virStorageNetProtocol) disk->src->protocol) {
+        switch (disk->src->protocol) {
         case VIR_STORAGE_NET_PROTOCOL_NONE:
         case VIR_STORAGE_NET_PROTOCOL_NBD:
         case VIR_STORAGE_NET_PROTOCOL_RBD:
index 80681924eae5953e45a123d3c6ab13d74030cc10..4a273fe46ca4452e7fc7506efdecf82b5e549773 100644 (file)
@@ -44,6 +44,7 @@ virStorageSourceParseBackingURI(virStorageSource *src,
     const char *path = NULL;
     int transport = 0;
     g_auto(GStrv) scheme = NULL;
+    int protocol;
 
     if (!(uri = virURIParse(uristr))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -59,12 +60,13 @@ virStorageSourceParseBackingURI(virStorageSource *src,
         return -1;
 
     if (!scheme[0] ||
-        (src->protocol = virStorageNetProtocolTypeFromString(scheme[0])) < 0) {
+        (protocol = virStorageNetProtocolTypeFromString(scheme[0])) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("invalid backing protocol '%1$s'"),
                        NULLSTR(scheme[0]));
         return -1;
     }
+    src->protocol = protocol;
 
     if (scheme[1]) {
         if ((transport = virStorageNetHostTransportTypeFromString(scheme[1])) < 0) {
@@ -370,7 +372,8 @@ virStorageSourceParseBackingColon(virStorageSource *src,
                                   const char *path)
 {
     const char *p;
-    g_autofree char *protocol = NULL;
+    g_autofree char *protocol_str = NULL;
+    int protocol;
 
     if (!(p = strchr(path, ':'))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -379,16 +382,18 @@ virStorageSourceParseBackingColon(virStorageSource *src,
         return -1;
     }
 
-    protocol = g_strndup(path, p - path);
+    protocol_str = g_strndup(path, p - path);
 
-    if ((src->protocol = virStorageNetProtocolTypeFromString(protocol)) < 0) {
+    if ((protocol = virStorageNetProtocolTypeFromString(protocol_str)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("invalid backing protocol '%1$s'"),
-                       protocol);
+                       protocol_str);
         return -1;
     }
 
-    switch ((virStorageNetProtocol) src->protocol) {
+    src->protocol = protocol;
+
+    switch (src->protocol) {
     case VIR_STORAGE_NET_PROTOCOL_NBD:
         if (virStorageSourceParseNBDColonString(path, src) < 0)
             return -1;
@@ -404,7 +409,7 @@ virStorageSourceParseBackingColon(virStorageSource *src,
     case VIR_STORAGE_NET_PROTOCOL_NONE:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("backing store parser is not implemented for protocol %1$s"),
-                       protocol);
+                       protocol_str);
         return -1;
 
     case VIR_STORAGE_NET_PROTOCOL_HTTP:
@@ -419,7 +424,7 @@ virStorageSourceParseBackingColon(virStorageSource *src,
     case VIR_STORAGE_NET_PROTOCOL_NFS:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("malformed backing store path for protocol %1$s"),
-                       protocol);
+                       protocol_str);
         return -1;
     }