]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Add function to check if a virStorageSource is "empty"
authorPeter Krempa <pkrempa@redhat.com>
Thu, 11 Sep 2014 17:43:53 +0000 (19:43 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 12 Sep 2014 07:37:37 +0000 (09:37 +0200)
To express empty drive we historically use storage source with empty
path. Unfortunately NBD disks may be declared without a path.

Add a helper to wrap this logic.

src/libvirt_private.syms
src/util/virstoragefile.c
src/util/virstoragefile.h

index fdf454870045e7e357aa4cf0e8fdc5ef5a115ec8..e819049496c8f4cfabd486797af83ae94fcbbf48 100644 (file)
@@ -1941,6 +1941,7 @@ virStorageSourceFree;
 virStorageSourceGetActualType;
 virStorageSourceGetSecurityLabelDef;
 virStorageSourceInitChainElement;
+virStorageSourceIsEmpty;
 virStorageSourceIsLocalStorage;
 virStorageSourceNewFromBacking;
 virStorageSourcePoolDefFree;
index 299edcd48e2282042e71efa2376b1d0faf995d58..5db918489818014cec28b6a1fe8c4e35da388320 100644 (file)
@@ -1975,6 +1975,27 @@ virStorageSourceIsLocalStorage(virStorageSourcePtr src)
 }
 
 
+/**
+ * virStorageSourceIsEmpty:
+ *
+ * @src: disk source to check
+ *
+ * Returns true if the guest disk has no associated host storage source
+ * (such as an empty cdrom drive).
+ */
+bool
+virStorageSourceIsEmpty(virStorageSourcePtr src)
+{
+    if (virStorageSourceIsLocalStorage(src) && !src->path)
+        return true;
+
+    if (src->type == VIR_STORAGE_TYPE_NONE)
+        return true;
+
+    return false;
+}
+
+
 /**
  * virStorageSourceBackingStoreClear:
  *
index eccbf4e4664476a81816867569f7beabcf67588c..2583e107a6cc4b0645cf58fe2348368a8d791219 100644 (file)
@@ -353,6 +353,7 @@ void virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def);
 void virStorageSourceClear(virStorageSourcePtr def);
 int virStorageSourceGetActualType(virStorageSourcePtr def);
 bool virStorageSourceIsLocalStorage(virStorageSourcePtr src);
+bool virStorageSourceIsEmpty(virStorageSourcePtr src);
 void virStorageSourceFree(virStorageSourcePtr def);
 void virStorageSourceBackingStoreClear(virStorageSourcePtr def);
 virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr parent);