提交 b279e52f 编写于 作者: E Eric Blake

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: NEric Blake <eblake@redhat.com>
上级 ab517818
......@@ -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);
......
......@@ -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;
}
}
......
......@@ -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 */
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册