virStorageSourceGetActualType: Change type of retval

The virStorageSourceGetActualType() function returns either
virStorageSource->type (which is of type virStorageType), or
virStorageSourcePoolDef->type, which really stores a value of the
same enum. Thus, the latter struct can be changed so that the
virStorageSourceGetActualType() function can return correct type
instead of generic int.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
This commit is contained in:
Michal Privoznik 2022-01-23 12:10:35 +01:00
parent 2307f06cb2
commit 215b2466cd
13 changed files with 33 additions and 33 deletions

View File

@ -1004,7 +1004,7 @@ virStorageSourcePoolDefFree(virStorageSourcePoolDef *def)
* and virDomainDiskTranslateSourcePool was called on @def the actual type * and virDomainDiskTranslateSourcePool was called on @def the actual type
* of the storage volume is returned rather than VIR_STORAGE_TYPE_VOLUME. * of the storage volume is returned rather than VIR_STORAGE_TYPE_VOLUME.
*/ */
int virStorageType
virStorageSourceGetActualType(const virStorageSource *def) virStorageSourceGetActualType(const virStorageSource *def)
{ {
if (def->type == VIR_STORAGE_TYPE_VOLUME && if (def->type == VIR_STORAGE_TYPE_VOLUME &&

View File

@ -199,7 +199,7 @@ struct _virStorageSourcePoolDef {
char *volume; /* volume name */ char *volume; /* volume name */
int voltype; /* virStorageVolType, internal only */ int voltype; /* virStorageVolType, internal only */
int pooltype; /* virStoragePoolType from storage_conf.h, internal only */ int pooltype; /* virStoragePoolType from storage_conf.h, internal only */
int actualtype; /* virStorageType, internal only */ virStorageType actualtype; /* internal only */
int mode; /* virStorageSourcePoolMode, currently makes sense only for iscsi pool */ int mode; /* virStorageSourcePoolMode, currently makes sense only for iscsi pool */
}; };
@ -469,7 +469,7 @@ virStorageSourcePoolDefFree(virStorageSourcePoolDef *def);
void void
virStorageSourceClear(virStorageSource *def); virStorageSourceClear(virStorageSource *def);
int virStorageType
virStorageSourceGetActualType(const virStorageSource *def); virStorageSourceGetActualType(const virStorageSource *def);
bool bool

View File

@ -1067,7 +1067,7 @@ libxlMakeDisk(virDomainDiskDef *l_disk, libxl_device_disk *x_disk)
{ {
const char *driver = virDomainDiskGetDriver(l_disk); const char *driver = virDomainDiskGetDriver(l_disk);
int format = virDomainDiskGetFormat(l_disk); int format = virDomainDiskGetFormat(l_disk);
int actual_type = virStorageSourceGetActualType(l_disk->src); virStorageType actual_type = virStorageSourceGetActualType(l_disk->src);
if (actual_type == VIR_STORAGE_TYPE_NETWORK) { if (actual_type == VIR_STORAGE_TYPE_NETWORK) {
if (STRNEQ_NULLABLE(driver, "qemu")) { if (STRNEQ_NULLABLE(driver, "qemu")) {

View File

@ -330,7 +330,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDef *dev,
if (dev->type == VIR_DOMAIN_DEVICE_DISK) { if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
virDomainDiskDef *disk = dev->data.disk; virDomainDiskDef *disk = dev->data.disk;
int actual_type = virStorageSourceGetActualType(disk->src); virStorageType actual_type = virStorageSourceGetActualType(disk->src);
int format = virDomainDiskGetFormat(disk); int format = virDomainDiskGetFormat(disk);
/* for network-based disks, set 'qemu' as the default driver */ /* for network-based disks, set 'qemu' as the default driver */

View File

@ -1489,14 +1489,14 @@ xenFormatXLDiskSrcNet(virStorageSource *src)
static int static int
xenFormatXLDiskSrc(virStorageSource *src, char **srcstr) xenFormatXLDiskSrc(virStorageSource *src, char **srcstr)
{ {
int actualType = virStorageSourceGetActualType(src); virStorageType actualType = virStorageSourceGetActualType(src);
*srcstr = NULL; *srcstr = NULL;
if (virStorageSourceIsEmpty(src)) if (virStorageSourceIsEmpty(src))
return 0; return 0;
switch ((virStorageType)actualType) { switch (actualType) {
case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_BLOCK:
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
case VIR_STORAGE_TYPE_DIR: case VIR_STORAGE_TYPE_DIR:

View File

@ -72,7 +72,7 @@ static int virDomainLockManagerAddImage(virLockManager *lock,
virStorageSource *src) virStorageSource *src)
{ {
unsigned int diskFlags = 0; unsigned int diskFlags = 0;
int type = virStorageSourceGetActualType(src); virStorageType type = virStorageSourceGetActualType(src);
if (!src->path) if (!src->path)
return 0; return 0;

View File

@ -1128,7 +1128,7 @@ virJSONValue *
qemuBlockStorageSourceGetBackendProps(virStorageSource *src, qemuBlockStorageSourceGetBackendProps(virStorageSource *src,
unsigned int flags) unsigned int flags)
{ {
int actualType = virStorageSourceGetActualType(src); virStorageType actualType = virStorageSourceGetActualType(src);
g_autoptr(virJSONValue) fileprops = NULL; g_autoptr(virJSONValue) fileprops = NULL;
const char *driver = NULL; const char *driver = NULL;
virTristateBool aro = VIR_TRISTATE_BOOL_ABSENT; virTristateBool aro = VIR_TRISTATE_BOOL_ABSENT;
@ -1145,7 +1145,7 @@ qemuBlockStorageSourceGetBackendProps(virStorageSource *src,
ro = VIR_TRISTATE_BOOL_NO; ro = VIR_TRISTATE_BOOL_NO;
} }
switch ((virStorageType)actualType) { switch (actualType) {
case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_BLOCK:
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
if (virStorageSourceIsBlockLocal(src)) { if (virStorageSourceIsBlockLocal(src)) {
@ -2200,7 +2200,7 @@ char *
qemuBlockGetBackingStoreString(virStorageSource *src, qemuBlockGetBackingStoreString(virStorageSource *src,
bool pretty) bool pretty)
{ {
int actualType = virStorageSourceGetActualType(src); virStorageType actualType = virStorageSourceGetActualType(src);
g_autoptr(virJSONValue) backingProps = NULL; g_autoptr(virJSONValue) backingProps = NULL;
g_autoptr(virJSONValue) sliceProps = NULL; g_autoptr(virJSONValue) sliceProps = NULL;
virJSONValue *props = NULL; virJSONValue *props = NULL;
@ -2599,12 +2599,12 @@ int
qemuBlockStorageSourceCreateGetStorageProps(virStorageSource *src, qemuBlockStorageSourceCreateGetStorageProps(virStorageSource *src,
virJSONValue **props) virJSONValue **props)
{ {
int actualType = virStorageSourceGetActualType(src); virStorageType actualType = virStorageSourceGetActualType(src);
g_autoptr(virJSONValue) location = NULL; g_autoptr(virJSONValue) location = NULL;
const char *driver = NULL; const char *driver = NULL;
const char *filename = NULL; const char *filename = NULL;
switch ((virStorageType) actualType) { switch (actualType) {
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
driver = "file"; driver = "file";
filename = src->path; filename = src->path;
@ -2745,7 +2745,7 @@ qemuBlockStorageSourceCreateStorage(virDomainObj *vm,
virStorageSource *chain, virStorageSource *chain,
virDomainAsyncJob asyncJob) virDomainAsyncJob asyncJob)
{ {
int actualType = virStorageSourceGetActualType(src); virStorageType actualType = virStorageSourceGetActualType(src);
g_autoptr(virJSONValue) createstorageprops = NULL; g_autoptr(virJSONValue) createstorageprops = NULL;
int ret; int ret;

View File

@ -1736,7 +1736,7 @@ qemuGetDriveSourceString(virStorageSource *src,
qemuDomainSecretInfo *secinfo, qemuDomainSecretInfo *secinfo,
char **source) char **source)
{ {
int actualType = virStorageSourceGetActualType(src); virStorageType actualType = virStorageSourceGetActualType(src);
*source = NULL; *source = NULL;
@ -1744,7 +1744,7 @@ qemuGetDriveSourceString(virStorageSource *src,
if (virStorageSourceIsEmpty(src)) if (virStorageSourceIsEmpty(src))
return 1; return 1;
switch ((virStorageType)actualType) { switch (actualType) {
case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_BLOCK:
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
case VIR_STORAGE_TYPE_DIR: case VIR_STORAGE_TYPE_DIR:
@ -1803,7 +1803,7 @@ qemuDiskBusIsSD(int bus)
static bool static bool
qemuDiskSourceNeedsProps(virStorageSource *src) qemuDiskSourceNeedsProps(virStorageSource *src)
{ {
int actualType = virStorageSourceGetActualType(src); virStorageType actualType = virStorageSourceGetActualType(src);
if (actualType == VIR_STORAGE_TYPE_NETWORK && if (actualType == VIR_STORAGE_TYPE_NETWORK &&
src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER && src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER &&
@ -1879,7 +1879,7 @@ static int
qemuBuildDriveSourceStr(virDomainDiskDef *disk, qemuBuildDriveSourceStr(virDomainDiskDef *disk,
virBuffer *buf) virBuffer *buf)
{ {
int actualType = virStorageSourceGetActualType(disk->src); virStorageType actualType = virStorageSourceGetActualType(disk->src);
qemuDomainStorageSourcePrivate *srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src); qemuDomainStorageSourcePrivate *srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src);
qemuDomainSecretInfo *secinfo = NULL; qemuDomainSecretInfo *secinfo = NULL;
qemuDomainSecretInfo *encinfo = NULL; qemuDomainSecretInfo *encinfo = NULL;

View File

@ -4809,7 +4809,7 @@ qemuDomainValidateStorageSource(virStorageSource *src,
virQEMUCaps *qemuCaps, virQEMUCaps *qemuCaps,
bool maskBlockdev) bool maskBlockdev)
{ {
int actualType = virStorageSourceGetActualType(src); virStorageType actualType = virStorageSourceGetActualType(src);
bool blockdev = virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV); bool blockdev = virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV);
if (maskBlockdev) if (maskBlockdev)
@ -10932,7 +10932,7 @@ qemuDomainPrepareDiskSource(virDomainDiskDef *disk,
/* set default format for storage pool based disks */ /* set default format for storage pool based disks */
if (disk->src->type == VIR_STORAGE_TYPE_VOLUME && if (disk->src->type == VIR_STORAGE_TYPE_VOLUME &&
disk->src->format <= VIR_STORAGE_FILE_NONE) { disk->src->format <= VIR_STORAGE_FILE_NONE) {
int actualType = virStorageSourceGetActualType(disk->src); virStorageType actualType = virStorageSourceGetActualType(disk->src);
if (actualType == VIR_STORAGE_TYPE_DIR) if (actualType == VIR_STORAGE_TYPE_DIR)
disk->src->format = VIR_STORAGE_FILE_FAT; disk->src->format = VIR_STORAGE_FILE_FAT;

View File

@ -14790,7 +14790,7 @@ qemuDomainBlockCopyValidateMirror(virStorageSource *mirror,
const char *dst, const char *dst,
bool *reuse) bool *reuse)
{ {
int desttype = virStorageSourceGetActualType(mirror); virStorageType desttype = virStorageSourceGetActualType(mirror);
struct stat st; struct stat st;
if (!virStorageSourceIsLocalStorage(mirror)) if (!virStorageSourceIsLocalStorage(mirror))

View File

@ -1504,7 +1504,7 @@ qemuMigrationSrcIsSafe(virDomainDef *def,
for (i = 0; i < def->ndisks; i++) { for (i = 0; i < def->ndisks; i++) {
virDomainDiskDef *disk = def->disks[i]; virDomainDiskDef *disk = def->disks[i];
const char *src = virDomainDiskGetSource(disk); const char *src = virDomainDiskGetSource(disk);
int actualType = virStorageSourceGetActualType(disk->src); virStorageType actualType = virStorageSourceGetActualType(disk->src);
bool unsafe = false; bool unsafe = false;
/* Disks without any source (i.e. floppies and CD-ROMs) /* Disks without any source (i.e. floppies and CD-ROMs)
@ -1519,7 +1519,7 @@ qemuMigrationSrcIsSafe(virDomainDef *def,
continue; continue;
/* However, disks on local FS (e.g. ext4) are not safe. */ /* However, disks on local FS (e.g. ext4) are not safe. */
switch ((virStorageType) actualType) { switch (actualType) {
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
if ((rc = virFileIsSharedFS(src)) < 0) { if ((rc = virFileIsSharedFS(src)) < 0) {
return false; return false;

View File

@ -380,10 +380,10 @@ static int
qemuSnapshotPrepareDiskExternalInactive(virDomainSnapshotDiskDef *snapdisk, qemuSnapshotPrepareDiskExternalInactive(virDomainSnapshotDiskDef *snapdisk,
virDomainDiskDef *domdisk) virDomainDiskDef *domdisk)
{ {
int domDiskType = virStorageSourceGetActualType(domdisk->src); virStorageType domDiskType = virStorageSourceGetActualType(domdisk->src);
int snapDiskType = virStorageSourceGetActualType(snapdisk->src); virStorageType snapDiskType = virStorageSourceGetActualType(snapdisk->src);
switch ((virStorageType)domDiskType) { switch (domDiskType) {
case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_BLOCK:
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
break; break;
@ -425,7 +425,7 @@ qemuSnapshotPrepareDiskExternalInactive(virDomainSnapshotDiskDef *snapdisk,
return -1; return -1;
} }
switch ((virStorageType)snapDiskType) { switch (snapDiskType) {
case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_BLOCK:
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
break; break;
@ -456,7 +456,7 @@ qemuSnapshotPrepareDiskExternalActive(virDomainObj *vm,
virDomainDiskDef *domdisk, virDomainDiskDef *domdisk,
bool blockdev) bool blockdev)
{ {
int actualType = virStorageSourceGetActualType(snapdisk->src); virStorageType actualType = virStorageSourceGetActualType(snapdisk->src);
if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_MANUAL) if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_MANUAL)
return 0; return 0;
@ -471,7 +471,7 @@ qemuSnapshotPrepareDiskExternalActive(virDomainObj *vm,
if (!qemuDomainDiskBlockJobIsSupported(vm, domdisk)) if (!qemuDomainDiskBlockJobIsSupported(vm, domdisk))
return -1; return -1;
switch ((virStorageType)actualType) { switch (actualType) {
case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_BLOCK:
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
break; break;
@ -620,7 +620,7 @@ static int
qemuSnapshotPrepareDiskInternal(virDomainDiskDef *disk, qemuSnapshotPrepareDiskInternal(virDomainDiskDef *disk,
bool active) bool active)
{ {
int actualType; virStorageType actualType;
/* active disks are handled by qemu itself so no need to worry about those */ /* active disks are handled by qemu itself so no need to worry about those */
if (active) if (active)
@ -631,7 +631,7 @@ qemuSnapshotPrepareDiskInternal(virDomainDiskDef *disk,
actualType = virStorageSourceGetActualType(disk->src); actualType = virStorageSourceGetActualType(disk->src);
switch ((virStorageType)actualType) { switch (actualType) {
case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_BLOCK:
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
return 0; return 0;

View File

@ -807,7 +807,7 @@ static int
virStorageSourceGetBackendForSupportCheck(const virStorageSource *src, virStorageSourceGetBackendForSupportCheck(const virStorageSource *src,
virStorageFileBackend **backend) virStorageFileBackend **backend)
{ {
int actualType; virStorageType actualType;
if (!src) { if (!src) {
@ -944,7 +944,7 @@ int
virStorageSourceInitAs(virStorageSource *src, virStorageSourceInitAs(virStorageSource *src,
uid_t uid, gid_t gid) uid_t uid, gid_t gid)
{ {
int actualType = virStorageSourceGetActualType(src); virStorageType actualType = virStorageSourceGetActualType(src);
virStorageDriverData *drv = g_new0(virStorageDriverData, 1); virStorageDriverData *drv = g_new0(virStorageDriverData, 1);
src->drv = drv; src->drv = drv;