Blame SOURCES/libvirt-storage-Add-helper-to-retrieve-the-backing-store-string-of-a-storage-volume.patch

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