render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
3e5111
From a4d89750b7d61aa561b9b9956bf354e39f434b01 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <a4d89750b7d61aa561b9b9956bf354e39f434b01@dist-git>
3e5111
From: Peter Krempa <pkrempa@redhat.com>
3e5111
Date: Tue, 20 Jun 2017 14:45:37 +0200
3e5111
Subject: [PATCH] storage: Add helper to retrieve the backing store string of a
3e5111
 storage volume
3e5111
3e5111
It is necessary for some parts of the code to refresh just data
3e5111
based on the based on the backing store string. Add a convenience
3e5111
function that will retrieve this data.
3e5111
3e5111
(cherry picked from commit d97cfdc891f262e1b0cd3ed05f7ca2bb7ef7de1c)
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1461303
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3e5111
---
3e5111
 src/storage/storage_driver.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
3e5111
 src/storage/storage_driver.h |  3 +++
3e5111
 2 files changed, 47 insertions(+)
3e5111
3e5111
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
3e5111
index 61c5e7eff1..21af949170 100644
3e5111
--- a/src/storage/storage_driver.c
3e5111
+++ b/src/storage/storage_driver.c
3e5111
@@ -3370,6 +3370,50 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
3e5111
 }
3e5111
 
3e5111
 
3e5111
+/**
3e5111
+ * virStorageFileGetBackingStoreStr:
3e5111
+ * @src: storage object
3e5111
+ *
3e5111
+ * Extracts the backing store string as stored in the storage volume described
3e5111
+ * by @src and returns it to the user. Caller is responsible for freeing it.
3e5111
+ * In case when the string can't be retrieved or does not exist NULL is
3e5111
+ * returned.
3e5111
+ */
3e5111
+char *
3e5111
+virStorageFileGetBackingStoreStr(virStorageSourcePtr src)
3e5111
+{
3e5111
+    virStorageSourcePtr tmp = NULL;
3e5111
+    char *buf = NULL;
3e5111
+    ssize_t headerLen;
3e5111
+    char *ret = NULL;
3e5111
+
3e5111
+    /* exit if we can't load information about the current image */
3e5111
+    if (!virStorageFileSupportsBackingChainTraversal(src))
3e5111
+        return NULL;
3e5111
+
3e5111
+    if (virStorageFileAccess(src, F_OK) < 0)
3e5111
+        return NULL;
3e5111
+
3e5111
+    if ((headerLen = virStorageFileReadHeader(src, VIR_STORAGE_MAX_HEADER,
3e5111
+                                              &buf)) < 0)
3e5111
+        return NULL;
3e5111
+
3e5111
+    if (!(tmp = virStorageSourceCopy(src, false)))
3e5111
+        goto cleanup;
3e5111
+
3e5111
+    if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0)
3e5111
+        goto cleanup;
3e5111
+
3e5111
+    VIR_STEAL_PTR(ret, tmp->backingStoreRaw);
3e5111
+
3e5111
+ cleanup:
3e5111
+    VIR_FREE(buf);
3e5111
+    virStorageSourceFree(tmp);
3e5111
+
3e5111
+    return ret;
3e5111
+}
3e5111
+
3e5111
+
3e5111
 static int
3e5111
 virStorageAddISCSIPoolSourceHost(virDomainDiskDefPtr def,
3e5111
                                  virStoragePoolDefPtr pooldef)
3e5111
diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h
3e5111
index 530bc33880..ade05f7156 100644
3e5111
--- a/src/storage/storage_driver.h
3e5111
+++ b/src/storage/storage_driver.h
3e5111
@@ -54,6 +54,9 @@ int virStorageFileGetMetadata(virStorageSourcePtr src,
3e5111
                               bool report_broken)
3e5111
     ATTRIBUTE_NONNULL(1);
3e5111
 
3e5111
+char *virStorageFileGetBackingStoreStr(virStorageSourcePtr src)
3e5111
+    ATTRIBUTE_NONNULL(1);
3e5111
+
3e5111
 int virStorageTranslateDiskSourcePool(virConnectPtr conn,
3e5111
                                       virDomainDiskDefPtr def);
3e5111
 
3e5111
-- 
3e5111
2.13.1
3e5111