]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: storagefile: Modify arguments of virStorageSourceNewFromBackingAbsolue
authorPeter Krempa <pkrempa@redhat.com>
Thu, 15 Aug 2019 14:43:40 +0000 (16:43 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 26 Aug 2019 11:49:17 +0000 (13:49 +0200)
Return the parsed storage source via an pointer in arguments and return
an integer from the function. Describe the semantics with a comment for
the function and adjust callers to the new semantics.

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

index 56e7e5fc9e98baa6cd6c48929d4bd0ee16cce2b8..561de5ddb14ae9545f601ef4fe0f1ed048fbcfa5 100644 (file)
@@ -3635,22 +3635,32 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src,
 }
 
 
-virStorageSourcePtr
-virStorageSourceNewFromBackingAbsolute(const char *path)
+/**
+ * virStorageSourceNewFromBackingAbsolute
+ * @path: string representing absolute location of a storage source
+ * @src: filled with virStorageSource object representing @path
+ *
+ * Returns 0 on success and fills @src or -1 on error and reports appropriate
+ * error.
+ */
+int
+virStorageSourceNewFromBackingAbsolute(const char *path,
+                                       virStorageSourcePtr *src)
 {
     const char *json;
-    virStorageSourcePtr ret = NULL;
     int rc;
     VIR_AUTOUNREF(virStorageSourcePtr) def = NULL;
 
+    *src = NULL;
+
     if (!(def = virStorageSourceNew()))
-        return NULL;
+        return -1;
 
     if (virStorageIsFile(path)) {
         def->type = VIR_STORAGE_TYPE_FILE;
 
         if (VIR_STRDUP(def->path, path) < 0)
-            return NULL;
+            return -1;
     } else {
         def->type = VIR_STORAGE_TYPE_NETWORK;
 
@@ -3665,7 +3675,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
             rc = virStorageSourceParseBackingColon(def, path);
 
         if (rc < 0)
-            return NULL;
+            return -1;
 
         virStorageSourceNetworkAssignDefaultPorts(def);
 
@@ -3678,8 +3688,8 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
         }
     }
 
-    VIR_STEAL_PTR(ret, def);
-    return ret;
+    VIR_STEAL_PTR(*src, def);
+    return 0;
 }
 
 
@@ -3704,14 +3714,15 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent,
 
     *backing = NULL;
 
-    if (virStorageIsRelative(parent->backingStoreRaw))
-        def = virStorageSourceNewFromBackingRelative(parent,
-                                                     parent->backingStoreRaw);
-    else
-        def = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw);
-
-    if (!def)
-        return -1;
+    if (virStorageIsRelative(parent->backingStoreRaw)) {
+        if (!(def = virStorageSourceNewFromBackingRelative(parent,
+                                                           parent->backingStoreRaw)))
+            return -1;
+    } else {
+        if (virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw,
+                                                   &def) < 0)
+            return -1;
+    }
 
     /* possibly update local type */
     if (def->type == VIR_STORAGE_TYPE_FILE) {
index c43d87a160be55b22d87621644a3e1c7c60fbefa..81b83a53ef624c5be8f9a0c097766ea7fa9ff2e3 100644 (file)
@@ -473,7 +473,8 @@ int virStorageFileGetRelativeBackingPath(virStorageSourcePtr from,
 
 int virStorageFileCheckCompat(const char *compat);
 
-virStorageSourcePtr virStorageSourceNewFromBackingAbsolute(const char *path);
+int virStorageSourceNewFromBackingAbsolute(const char *path,
+                                           virStorageSourcePtr *src);
 
 bool virStorageSourceIsRelative(virStorageSourcePtr src);
 
index 9321531f6ce729cc02937fde139df08503418062..e5d77c423c1a95059c1be81425a7431678ed9994 100644 (file)
@@ -85,7 +85,8 @@ testBackingXMLjsonXML(const void *args)
     if (virAsprintf(&protocolwrapper, "json:%s", propsstr) < 0)
         return -1;
 
-    if (!(jsonsrc = virStorageSourceNewFromBackingAbsolute(protocolwrapper))) {
+    if (virStorageSourceNewFromBackingAbsolute(protocolwrapper,
+                                               &jsonsrc) < 0) {
         fprintf(stderr, "failed to parse disk json\n");
         return -1;
     }
index a65491737fa9f24ed7ab80d677fdf1bc0e45c050..25985bc73284167607bf020121e6f58a52b2bdca 100644 (file)
@@ -613,7 +613,7 @@ testBackingParse(const void *args)
     VIR_AUTOFREE(char *) xml = NULL;
     VIR_AUTOUNREF(virStorageSourcePtr) src = NULL;
 
-    if (!(src = virStorageSourceNewFromBackingAbsolute(data->backing))) {
+    if (virStorageSourceNewFromBackingAbsolute(data->backing, &src) < 0) {
         if (!data->expect)
             return 0;
         else