summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Krempa <pkrempa@redhat.com>2016-05-02 13:42:32 +0200
committerPeter Krempa <pkrempa@redhat.com>2016-05-09 12:36:52 +0200
commit3ec7bb354a94c343c3c0da8b799c24d2144e7871 (patch)
tree1376ad1024f2bce91975fbb33bafb70e3bd78802 /src
parente85d3e1bbe0b0762920f999b8bbfc127bf86d701 (diff)
downloadlibvirt-3ec7bb354a94c343c3c0da8b799c24d2144e7871.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/libvirt_private.syms1
-rw-r--r--src/lxc/lxc_cgroup.c3
-rw-r--r--src/qemu/qemu_conf.c10
-rw-r--r--src/util/virstoragefile.c16
-rw-r--r--src/util/virstoragefile.h3
5 files changed, 27 insertions, 6 deletions
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c445d9faed..9ad473dde4 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2279,6 +2279,7 @@ virStorageSourceFree;
virStorageSourceGetActualType;
virStorageSourceGetSecurityLabelDef;
virStorageSourceInitChainElement;
+virStorageSourceIsBlockLocal;
virStorageSourceIsEmpty;
virStorageSourceIsLocalStorage;
virStorageSourceNewFromBacking;
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 4afe7e229e..ea86d3603a 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -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,
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 5ed5776a45..e00ddcaa57 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -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);
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 05ac2546bd..4f44e05de5 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -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;
@@ -2012,6 +2012,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:
*
* @src: disk source to clear
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index b98fe25871..17e12779c1 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -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,