util: Replace virDomainDiskSourceIsBlockType with a new helper

For disks sources described by a libvirt volume we don't need to do a
complicated check since virStorageTranslateDiskSourcePool already
correctly determines the actual disk type.

Replace the checks using a new accessor that does not open-code the
whole logic.
This commit is contained in:
Peter Krempa 2016-05-02 13:42:32 +02:00
parent e85d3e1bbe
commit 3ec7bb354a
5 changed files with 27 additions and 6 deletions

View File

@ -2279,6 +2279,7 @@ virStorageSourceFree;
virStorageSourceGetActualType;
virStorageSourceGetSecurityLabelDef;
virStorageSourceInitChainElement;
virStorageSourceIsBlockLocal;
virStorageSourceIsEmpty;
virStorageSourceIsLocalStorage;
virStorageSourceNewFromBacking;

View File

@ -393,7 +393,8 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
VIR_DEBUG("Allowing any disk block devs");
for (i = 0; i < def->ndisks; i++) {
if (!virDomainDiskSourceIsBlockType(def->disks[i]->src, false))
if (virStorageSourceIsEmpty(def->disks[i]->src) ||
!virStorageSourceIsBlockLocal(def->disks[i]->src))
continue;
if (virCgroupAllowDevicePath(cgroup,

View File

@ -1243,7 +1243,9 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
char *key = NULL;
int ret = -1;
if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src, false))
if (virStorageSourceIsEmpty(disk->src) ||
!disk->src->shared ||
!virStorageSourceIsBlockLocal(disk->src))
return 0;
qemuDriverLock(driver);
@ -1388,7 +1390,9 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver,
char *key = NULL;
int ret = -1;
if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src, false))
if (virStorageSourceIsEmpty(disk->src) ||
!disk->src->shared ||
!virStorageSourceIsBlockLocal(disk->src))
return 0;
qemuDriverLock(driver);
@ -1476,7 +1480,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
disk = dev->data.disk;
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
!virDomainDiskSourceIsBlockType(disk->src, false))
!virStorageSourceIsBlockLocal(disk->src))
return 0;
path = virDomainDiskGetSource(disk);

View File

@ -1955,7 +1955,7 @@ virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def)
int
virStorageSourceGetActualType(virStorageSourcePtr def)
virStorageSourceGetActualType(const virStorageSource *def)
{
if (def->type == VIR_STORAGE_TYPE_VOLUME && def->srcpool)
return def->srcpool->actualtype;
@ -2011,6 +2011,20 @@ virStorageSourceIsEmpty(virStorageSourcePtr src)
}
/**
* virStorageSourceIsBlockLocal:
* @src: disk source definition
*
* Returns true if @src describes a locally accessible block storage source.
* This includes block devices and host-mapped iSCSI volumes.
*/
bool
virStorageSourceIsBlockLocal(const virStorageSource *src)
{
return virStorageSourceGetActualType(src) == VIR_STORAGE_TYPE_BLOCK;
}
/**
* virStorageSourceBackingStoreClear:
*

View File

@ -357,9 +357,10 @@ int virStorageSourceInitChainElement(virStorageSourcePtr newelem,
bool force);
void virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def);
void virStorageSourceClear(virStorageSourcePtr def);
int virStorageSourceGetActualType(virStorageSourcePtr def);
int virStorageSourceGetActualType(const virStorageSource *def);
bool virStorageSourceIsLocalStorage(virStorageSourcePtr src);
bool virStorageSourceIsEmpty(virStorageSourcePtr src);
bool virStorageSourceIsBlockLocal(const virStorageSource *src);
void virStorageSourceFree(virStorageSourcePtr def);
void virStorageSourceBackingStoreClear(virStorageSourcePtr def);
int virStorageSourceUpdateBlockPhysicalSize(virStorageSourcePtr src,