render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
9119d9
From 3266c173fd4fab80e0fbd80c66cb99fb92c10b73 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <3266c173fd4fab80e0fbd80c66cb99fb92c10b73@dist-git>
9119d9
From: Peter Krempa <pkrempa@redhat.com>
9119d9
Date: Wed, 24 Sep 2014 11:01:26 +0200
9119d9
Subject: [PATCH] util: Add function to check if a virStorageSource is "empty"
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1138231
9119d9
9119d9
To express empty drive we historically use storage source with empty
9119d9
path. Unfortunately NBD disks may be declared without a path.
9119d9
9119d9
Add a helper to wrap this logic.
9119d9
9119d9
(cherry picked from commit 5e3e9919288511964afb0a7937bd1dcc497b8c17)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/libvirt_private.syms  |  1 +
9119d9
 src/util/virstoragefile.c | 21 +++++++++++++++++++++
9119d9
 src/util/virstoragefile.h |  1 +
9119d9
 3 files changed, 23 insertions(+)
9119d9
9119d9
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
9119d9
index 55fff46..ab81ba2 100644
9119d9
--- a/src/libvirt_private.syms
9119d9
+++ b/src/libvirt_private.syms
9119d9
@@ -1941,6 +1941,7 @@ virStorageSourceFree;
9119d9
 virStorageSourceGetActualType;
9119d9
 virStorageSourceGetSecurityLabelDef;
9119d9
 virStorageSourceInitChainElement;
9119d9
+virStorageSourceIsEmpty;
9119d9
 virStorageSourceIsLocalStorage;
9119d9
 virStorageSourceNewFromBacking;
9119d9
 virStorageSourcePoolDefFree;
9119d9
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
9119d9
index 79f4adb..fdf14c0 100644
9119d9
--- a/src/util/virstoragefile.c
9119d9
+++ b/src/util/virstoragefile.c
9119d9
@@ -1965,6 +1965,27 @@ virStorageSourceIsLocalStorage(virStorageSourcePtr src)
9119d9
 
9119d9
 
9119d9
 /**
9119d9
+ * virStorageSourceIsEmpty:
9119d9
+ *
9119d9
+ * @src: disk source to check
9119d9
+ *
9119d9
+ * Returns true if the guest disk has no associated host storage source
9119d9
+ * (such as an empty cdrom drive).
9119d9
+ */
9119d9
+bool
9119d9
+virStorageSourceIsEmpty(virStorageSourcePtr src)
9119d9
+{
9119d9
+    if (virStorageSourceIsLocalStorage(src) && !src->path)
9119d9
+        return true;
9119d9
+
9119d9
+    if (src->type == VIR_STORAGE_TYPE_NONE)
9119d9
+        return true;
9119d9
+
9119d9
+    return false;
9119d9
+}
9119d9
+
9119d9
+
9119d9
+/**
9119d9
  * virStorageSourceBackingStoreClear:
9119d9
  *
9119d9
  * @src: disk source to clear
9119d9
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
9119d9
index eccbf4e..2583e10 100644
9119d9
--- a/src/util/virstoragefile.h
9119d9
+++ b/src/util/virstoragefile.h
9119d9
@@ -353,6 +353,7 @@ void virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def);
9119d9
 void virStorageSourceClear(virStorageSourcePtr def);
9119d9
 int virStorageSourceGetActualType(virStorageSourcePtr def);
9119d9
 bool virStorageSourceIsLocalStorage(virStorageSourcePtr src);
9119d9
+bool virStorageSourceIsEmpty(virStorageSourcePtr src);
9119d9
 void virStorageSourceFree(virStorageSourcePtr def);
9119d9
 void virStorageSourceBackingStoreClear(virStorageSourcePtr def);
9119d9
 virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr parent);
9119d9
-- 
9119d9
2.1.1
9119d9