]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: storage: Modify return value of virStorageSourceNewFromBacking
authorPeter Krempa <pkrempa@redhat.com>
Thu, 15 Aug 2019 12:49:49 +0000 (14:49 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 26 Aug 2019 11:49:16 +0000 (13:49 +0200)
Return the storage source definition via a pointer in the arguments and
document the returned values. This will simplify the possibility to
ignore certain backing store types which are not representable by
libvirt.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/storage/storage_util.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index 3dc5ad2969774b1beaf95c759fdb5865287b0969..6165dd43b20b90bc5854849471fa252408046bb8 100644 (file)
@@ -3391,7 +3391,7 @@ storageBackendProbeTarget(virStorageSourcePtr target,
         return -1;
 
     if (meta->backingStoreRaw) {
-        if (!(target->backingStore = virStorageSourceNewFromBacking(meta)))
+        if (virStorageSourceNewFromBacking(meta, &target->backingStore) < 0)
             return -1;
 
         target->backingStore->format = backingStoreFormat;
index 86d75f44039bcf68bcd425ffbdcd0d9a6f508392..5e02ea7bf53187f20a6bf6e017d8503f628330ed 100644 (file)
@@ -3681,42 +3681,57 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
 }
 
 
-virStorageSourcePtr
-virStorageSourceNewFromBacking(virStorageSourcePtr parent)
+/**
+ * virStorageSourceNewFromBacking:
+ * @parent: storage source parent
+ * @backing: returned backing store definition
+ *
+ * Creates a storage source which describes the backing image of @parent and
+ * fills it into @backing depending on the 'backingStoreRaw' property of @parent
+ * and other data. Note that for local storage this function accesses the file
+ * to update the actual type of the backing store.
+ *
+ * Returns 0 and fills @backing, or -1 on error (with appropriate error reported).
+ */
+int
+virStorageSourceNewFromBacking(virStorageSourcePtr parent,
+                               virStorageSourcePtr *backing)
 {
     struct stat st;
-    virStorageSourcePtr ret = NULL;
     VIR_AUTOUNREF(virStorageSourcePtr) def = NULL;
 
+    *backing = NULL;
+
     if (virStorageIsRelative(parent->backingStoreRaw))
         def = virStorageSourceNewFromBackingRelative(parent,
                                                      parent->backingStoreRaw);
     else
         def = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw);
 
-    if (def) {
-        /* possibly update local type */
-        if (def->type == VIR_STORAGE_TYPE_FILE) {
-            if (stat(def->path, &st) == 0) {
-                if (S_ISDIR(st.st_mode)) {
-                    def->type = VIR_STORAGE_TYPE_DIR;
-                    def->format = VIR_STORAGE_FILE_DIR;
-                } else if (S_ISBLK(st.st_mode)) {
-                    def->type = VIR_STORAGE_TYPE_BLOCK;
-                }
+    if (!def)
+        return -1;
+
+    /* possibly update local type */
+    if (def->type == VIR_STORAGE_TYPE_FILE) {
+        if (stat(def->path, &st) == 0) {
+            if (S_ISDIR(st.st_mode)) {
+                def->type = VIR_STORAGE_TYPE_DIR;
+                def->format = VIR_STORAGE_FILE_DIR;
+            } else if (S_ISBLK(st.st_mode)) {
+                def->type = VIR_STORAGE_TYPE_BLOCK;
             }
         }
+    }
 
-        /* copy parent's labelling and other top level stuff */
-        if (virStorageSourceInitChainElement(def, parent, true) < 0)
-            return NULL;
+    /* copy parent's labelling and other top level stuff */
+    if (virStorageSourceInitChainElement(def, parent, true) < 0)
+        return -1;
 
-        def->readonly = true;
-        def->detected = true;
-    }
+    def->readonly = true;
+    def->detected = true;
 
-    VIR_STEAL_PTR(ret, def);
-    return ret;
+    VIR_STEAL_PTR(*backing, def);
+    return 0;
 }
 
 
@@ -4893,7 +4908,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
         goto cleanup;
 
     if (src->backingStoreRaw) {
-        if (!(backingStore = virStorageSourceNewFromBacking(src)))
+        if (virStorageSourceNewFromBacking(src, &backingStore) < 0)
             goto cleanup;
 
         if (backingFormat == VIR_STORAGE_FILE_AUTO)
index b65cd4c38279c6601b8c2696c4fa87fa9348feef..c43d87a160be55b22d87621644a3e1c7c60fbefa 100644 (file)
@@ -444,7 +444,9 @@ int virStorageSourceUpdateCapacity(virStorageSourcePtr src,
                                    char *buf, ssize_t len,
                                    bool probe);
 
-virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr parent);
+int virStorageSourceNewFromBacking(virStorageSourcePtr parent,
+                                   virStorageSourcePtr *backing);
+
 virStorageSourcePtr virStorageSourceCopy(const virStorageSource *src,
                                          bool backingChain)
     ATTRIBUTE_NONNULL(1);