]> xenbits.xensource.com Git - libvirt.git/commitdiff
maint: prefer enum over int for virstoragefile structs
authorEric Blake <eblake@redhat.com>
Wed, 14 May 2014 22:40:33 +0000 (16:40 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 16 May 2014 06:22:18 +0000 (00:22 -0600)
For internal structs, we might as well be type-safe and let the
compiler help us with less typing required on our part (getting
rid of casts is always nice).  In trying to use enums directly,
I noticed two problems in virstoragefile.h that can't be fixed
without more invasive refactoring: virStorageSource.format is
used as more of a union of multiple enums in storage volume
code (so it has to remain an int), and virStorageSourcePoolDef
refers to pooltype whose enum is declared in src/conf, but where
src/util can't pull in headers from src/conf.

* src/util/virstoragefile.h (virStorageNetHostDef)
(virStorageSourcePoolDef, virStorageSource): Use enums instead of
int for fields of internal types.
* src/qemu/qemu_command.c (qemuParseCommandLine): Cover all values.
* src/conf/domain_conf.c (virDomainDiskSourceParse)
(virDomainDiskSourceFormat): Simplify clients.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskInternal): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/conf/domain_conf.c
src/qemu/qemu_command.c
src/qemu/qemu_driver.c
src/util/virstoragefile.h

index e65b62b45674f7405be9355e82bf53eb7ceb2a07..e5ae7c6ba03f4ebd85e97fa4b6202fb52d48c7d8 100644 (file)
@@ -4972,7 +4972,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
 
     memset(&host, 0, sizeof(host));
 
-    switch ((virStorageType)src->type) {
+    switch (src->type) {
     case VIR_STORAGE_TYPE_FILE:
         src->path = virXMLPropString(node, "file");
         break;
@@ -14847,7 +14847,7 @@ virDomainDiskSourceFormat(virBufferPtr buf,
         startupPolicy = virDomainStartupPolicyTypeToString(policy);
 
     if (src->path || src->nhosts > 0 || src->srcpool || startupPolicy) {
-        switch ((virStorageType)src->type) {
+        switch (src->type) {
         case VIR_STORAGE_TYPE_FILE:
             virBufferAddLit(buf, "<source");
             virBufferEscapeString(buf, " file='%s'", src->path);
index cfd1bcfaea97e135ac9f20824cc5845cd204703e..9ae1a968f3a5f61ef9a37725a6b0d41783a3aaa8 100644 (file)
@@ -11065,6 +11065,14 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
                         goto error;
 
                     break;
+                case VIR_STORAGE_NET_PROTOCOL_HTTP:
+                case VIR_STORAGE_NET_PROTOCOL_HTTPS:
+                case VIR_STORAGE_NET_PROTOCOL_FTP:
+                case VIR_STORAGE_NET_PROTOCOL_FTPS:
+                case VIR_STORAGE_NET_PROTOCOL_TFTP:
+                case VIR_STORAGE_NET_PROTOCOL_LAST:
+                    /* ignored for now */
+                    break;
                 }
             }
 
index cab653b5d6d0b48da096e098ba2758f99cf855f0..55b47552f8e9a0b7df394035795f554179d7fb34 100644 (file)
@@ -12368,7 +12368,7 @@ qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk)
         return 0;
 
     case VIR_STORAGE_TYPE_NETWORK:
-        switch ((virStorageNetProtocol) disk->src.protocol) {
+        switch (disk->src.protocol) {
         case VIR_STORAGE_NET_PROTOCOL_NBD:
         case VIR_STORAGE_NET_PROTOCOL_RBD:
         case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
@@ -12430,7 +12430,7 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d
         return 0;
 
     case VIR_STORAGE_TYPE_NETWORK:
-        switch ((virStorageNetProtocol) disk->src.protocol) {
+        switch (disk->src.protocol) {
         case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
             return 0;
 
@@ -12575,7 +12575,7 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn,
         return 0;
 
     case VIR_STORAGE_TYPE_NETWORK:
-        switch ((virStorageNetProtocol) disk->src.protocol) {
+        switch (disk->src.protocol) {
         case VIR_STORAGE_NET_PROTOCOL_NBD:
         case VIR_STORAGE_NET_PROTOCOL_RBD:
         case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
@@ -12801,7 +12801,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
         VIR_STRDUP(persistSource, snap->src.path) < 0)
         goto cleanup;
 
-    switch ((virStorageType)snap->src.type) {
+    switch (snap->src.type) {
     case VIR_STORAGE_TYPE_BLOCK:
         reuse = true;
         /* fallthrough */
index e32389e36fc2eb52eb724b063da42675bafe4c1d..0a1960311a89cc3877d0e0ae12e6b1f27fd904eb 100644 (file)
@@ -150,7 +150,7 @@ typedef virStorageNetHostDef *virStorageNetHostDefPtr;
 struct _virStorageNetHostDef {
     char *name;
     char *port;
-    int transport; /* virStorageNetHostTransport */
+    virStorageNetHostTransport transport;
     char *socket;  /* path to unix socket */
 };
 
@@ -182,10 +182,10 @@ typedef struct _virStorageSourcePoolDef virStorageSourcePoolDef;
 struct _virStorageSourcePoolDef {
     char *pool; /* pool name */
     char *volume; /* volume name */
-    int voltype; /* virStorageVolType, internal only */
-    int pooltype; /* virStoragePoolType, internal only */
-    int actualtype; /* virStorageType, internal only */
-    int mode; /* virStorageSourcePoolMode */
+    virStorageVolType voltype; /* internal only */
+    int pooltype; /* virStoragePoolType from storage_conf.h, internal only */
+    virStorageType actualtype; /* internal only */
+    virStorageSourcePoolMode mode;
 };
 typedef virStorageSourcePoolDef *virStorageSourcePoolDefPtr;
 
@@ -208,15 +208,15 @@ typedef virStorageSource *virStorageSourcePtr;
  * backing chains, multiple source disks join to form a single guest
  * view.  */
 struct _virStorageSource {
-    int type; /* virStorageType */
+    virStorageType type;
     char *path;
-    int protocol; /* virStorageNetProtocol */
+    virStorageNetProtocol protocol;
     size_t nhosts;
     virStorageNetHostDefPtr hosts;
     virStorageSourcePoolDefPtr srcpool;
     struct {
         char *username;
-        int secretType; /* virStorageSecretType */
+        virStorageSecretType secretType;
         union {
             unsigned char uuid[VIR_UUID_BUFLEN];
             char *usage;
@@ -225,7 +225,8 @@ struct _virStorageSource {
     virStorageEncryptionPtr encryption;
 
     char *driverName;
-    int format; /* virStorageFileFormat */
+    int format; /* virStorageFileFormat in domain backing chains, but
+                 * pool-specific enum for storage volumes */
     virBitmapPtr features;
     char *compat;