mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-26 15:45:28 +00:00
maint: prefer enum over int for virstoragefile structs
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>
This commit is contained in:
parent
ab5178188f
commit
b279e52f7b
@ -4972,7 +4972,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
|
|||||||
|
|
||||||
memset(&host, 0, sizeof(host));
|
memset(&host, 0, sizeof(host));
|
||||||
|
|
||||||
switch ((virStorageType)src->type) {
|
switch (src->type) {
|
||||||
case VIR_STORAGE_TYPE_FILE:
|
case VIR_STORAGE_TYPE_FILE:
|
||||||
src->path = virXMLPropString(node, "file");
|
src->path = virXMLPropString(node, "file");
|
||||||
break;
|
break;
|
||||||
@ -14847,7 +14847,7 @@ virDomainDiskSourceFormat(virBufferPtr buf,
|
|||||||
startupPolicy = virDomainStartupPolicyTypeToString(policy);
|
startupPolicy = virDomainStartupPolicyTypeToString(policy);
|
||||||
|
|
||||||
if (src->path || src->nhosts > 0 || src->srcpool || startupPolicy) {
|
if (src->path || src->nhosts > 0 || src->srcpool || startupPolicy) {
|
||||||
switch ((virStorageType)src->type) {
|
switch (src->type) {
|
||||||
case VIR_STORAGE_TYPE_FILE:
|
case VIR_STORAGE_TYPE_FILE:
|
||||||
virBufferAddLit(buf, "<source");
|
virBufferAddLit(buf, "<source");
|
||||||
virBufferEscapeString(buf, " file='%s'", src->path);
|
virBufferEscapeString(buf, " file='%s'", src->path);
|
||||||
|
@ -11065,6 +11065,14 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12368,7 +12368,7 @@ qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case VIR_STORAGE_TYPE_NETWORK:
|
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_NBD:
|
||||||
case VIR_STORAGE_NET_PROTOCOL_RBD:
|
case VIR_STORAGE_NET_PROTOCOL_RBD:
|
||||||
case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
|
case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
|
||||||
@ -12430,7 +12430,7 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case VIR_STORAGE_TYPE_NETWORK:
|
case VIR_STORAGE_TYPE_NETWORK:
|
||||||
switch ((virStorageNetProtocol) disk->src.protocol) {
|
switch (disk->src.protocol) {
|
||||||
case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
|
case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -12575,7 +12575,7 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case VIR_STORAGE_TYPE_NETWORK:
|
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_NBD:
|
||||||
case VIR_STORAGE_NET_PROTOCOL_RBD:
|
case VIR_STORAGE_NET_PROTOCOL_RBD:
|
||||||
case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
|
case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
|
||||||
@ -12801,7 +12801,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
|
|||||||
VIR_STRDUP(persistSource, snap->src.path) < 0)
|
VIR_STRDUP(persistSource, snap->src.path) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
switch ((virStorageType)snap->src.type) {
|
switch (snap->src.type) {
|
||||||
case VIR_STORAGE_TYPE_BLOCK:
|
case VIR_STORAGE_TYPE_BLOCK:
|
||||||
reuse = true;
|
reuse = true;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
@ -150,7 +150,7 @@ typedef virStorageNetHostDef *virStorageNetHostDefPtr;
|
|||||||
struct _virStorageNetHostDef {
|
struct _virStorageNetHostDef {
|
||||||
char *name;
|
char *name;
|
||||||
char *port;
|
char *port;
|
||||||
int transport; /* virStorageNetHostTransport */
|
virStorageNetHostTransport transport;
|
||||||
char *socket; /* path to unix socket */
|
char *socket; /* path to unix socket */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -182,10 +182,10 @@ typedef struct _virStorageSourcePoolDef virStorageSourcePoolDef;
|
|||||||
struct _virStorageSourcePoolDef {
|
struct _virStorageSourcePoolDef {
|
||||||
char *pool; /* pool name */
|
char *pool; /* pool name */
|
||||||
char *volume; /* volume name */
|
char *volume; /* volume name */
|
||||||
int voltype; /* virStorageVolType, internal only */
|
virStorageVolType voltype; /* internal only */
|
||||||
int pooltype; /* virStoragePoolType, internal only */
|
int pooltype; /* virStoragePoolType from storage_conf.h, internal only */
|
||||||
int actualtype; /* virStorageType, internal only */
|
virStorageType actualtype; /* internal only */
|
||||||
int mode; /* virStorageSourcePoolMode */
|
virStorageSourcePoolMode mode;
|
||||||
};
|
};
|
||||||
typedef virStorageSourcePoolDef *virStorageSourcePoolDefPtr;
|
typedef virStorageSourcePoolDef *virStorageSourcePoolDefPtr;
|
||||||
|
|
||||||
@ -208,15 +208,15 @@ typedef virStorageSource *virStorageSourcePtr;
|
|||||||
* backing chains, multiple source disks join to form a single guest
|
* backing chains, multiple source disks join to form a single guest
|
||||||
* view. */
|
* view. */
|
||||||
struct _virStorageSource {
|
struct _virStorageSource {
|
||||||
int type; /* virStorageType */
|
virStorageType type;
|
||||||
char *path;
|
char *path;
|
||||||
int protocol; /* virStorageNetProtocol */
|
virStorageNetProtocol protocol;
|
||||||
size_t nhosts;
|
size_t nhosts;
|
||||||
virStorageNetHostDefPtr hosts;
|
virStorageNetHostDefPtr hosts;
|
||||||
virStorageSourcePoolDefPtr srcpool;
|
virStorageSourcePoolDefPtr srcpool;
|
||||||
struct {
|
struct {
|
||||||
char *username;
|
char *username;
|
||||||
int secretType; /* virStorageSecretType */
|
virStorageSecretType secretType;
|
||||||
union {
|
union {
|
||||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||||
char *usage;
|
char *usage;
|
||||||
@ -225,7 +225,8 @@ struct _virStorageSource {
|
|||||||
virStorageEncryptionPtr encryption;
|
virStorageEncryptionPtr encryption;
|
||||||
|
|
||||||
char *driverName;
|
char *driverName;
|
||||||
int format; /* virStorageFileFormat */
|
int format; /* virStorageFileFormat in domain backing chains, but
|
||||||
|
* pool-specific enum for storage volumes */
|
||||||
virBitmapPtr features;
|
virBitmapPtr features;
|
||||||
char *compat;
|
char *compat;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user