]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Add helper to retrieve the backing store string of a storage volume
authorPeter Krempa <pkrempa@redhat.com>
Mon, 19 Jun 2017 16:16:30 +0000 (18:16 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 20 Jun 2017 11:25:55 +0000 (13:25 +0200)
It is necessary for some parts of the code to refresh just data
based on the based on the backing store string. Add a convenience
function that will retrieve this data.

src/storage/storage_driver.c
src/storage/storage_driver.h

index 967776698f05225f7bc31dfb10105846777f7960..ab1dc8f3648d14b3e2ff108f471e2d671b2c400d 100644 (file)
@@ -3263,6 +3263,50 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
 }
 
 
+/**
+ * virStorageFileGetBackingStoreStr:
+ * @src: storage object
+ *
+ * Extracts the backing store string as stored in the storage volume described
+ * by @src and returns it to the user. Caller is responsible for freeing it.
+ * In case when the string can't be retrieved or does not exist NULL is
+ * returned.
+ */
+char *
+virStorageFileGetBackingStoreStr(virStorageSourcePtr src)
+{
+    virStorageSourcePtr tmp = NULL;
+    char *buf = NULL;
+    ssize_t headerLen;
+    char *ret = NULL;
+
+    /* exit if we can't load information about the current image */
+    if (!virStorageFileSupportsBackingChainTraversal(src))
+        return NULL;
+
+    if (virStorageFileAccess(src, F_OK) < 0)
+        return NULL;
+
+    if ((headerLen = virStorageFileReadHeader(src, VIR_STORAGE_MAX_HEADER,
+                                              &buf)) < 0)
+        return NULL;
+
+    if (!(tmp = virStorageSourceCopy(src, false)))
+        goto cleanup;
+
+    if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0)
+        goto cleanup;
+
+    VIR_STEAL_PTR(ret, tmp->backingStoreRaw);
+
+ cleanup:
+    VIR_FREE(buf);
+    virStorageSourceFree(tmp);
+
+    return ret;
+}
+
+
 static int
 virStorageAddISCSIPoolSourceHost(virDomainDiskDefPtr def,
                                  virStoragePoolDefPtr pooldef)
index 530bc338806c9b5d15bb2c43e9a120c0f3c9c08f..ade05f7156f7420b1d3bd2be3038dbcd12034c59 100644 (file)
@@ -54,6 +54,9 @@ int virStorageFileGetMetadata(virStorageSourcePtr src,
                               bool report_broken)
     ATTRIBUTE_NONNULL(1);
 
+char *virStorageFileGetBackingStoreStr(virStorageSourcePtr src)
+    ATTRIBUTE_NONNULL(1);
+
 int virStorageTranslateDiskSourcePool(virConnectPtr conn,
                                       virDomainDiskDefPtr def);