diff mbox series

[17/30] storagefile: Split out virStorageSourceNewFromChild

Message ID 024031653c027c12a7cc627493aa93c83eceb87d.1570482718.git.crobinso@redhat.com
State Accepted
Commit 8863c03d7d38a2ad133aa055f0ed7a262b9088c5
Headers show
Series storagefile, security: qcow2 data_file support | expand

Commit Message

Cole Robinson Oct. 7, 2019, 9:49 p.m. UTC
Future patches will use this for external data file handling

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 src/util/virstoragefile.c | 47 ++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 16 deletions(-)

-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Comments

Daniel Henrique Barboza Oct. 10, 2019, 2:40 p.m. UTC | #1
On 10/7/19 6:49 PM, Cole Robinson wrote:
> Future patches will use this for external data file handling

>

> Signed-off-by: Cole Robinson <crobinso@redhat.com>

> ---


Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>


>   src/util/virstoragefile.c | 47 ++++++++++++++++++++++++++-------------

>   1 file changed, 31 insertions(+), 16 deletions(-)

>

> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c

> index c47df6c200..7ae6719dd6 100644

> --- a/src/util/virstoragefile.c

> +++ b/src/util/virstoragefile.c

> @@ -3716,38 +3716,38 @@ virStorageSourceNewFromBackingAbsolute(const char *path,

>   

>   

>   /**

> - * virStorageSourceNewFromBacking:

> + * virStorageSourceNewFromChild:

>    * @parent: storage source parent

> - * @backing: returned backing store definition

> + * @child: returned child/backing store definition

> + * @parentRaw: raw child string (backingStoreRaw)

>    *

>    * Creates a storage source which describes the backing image of @parent and

> - * fills it into @backing depending on the 'backingStoreRaw' property of @parent

> + * fills it into @backing depending on the passed parentRaw (backingStoreRaw)

>    * and other data. Note that for local storage this function accesses the file

> - * to update the actual type of the backing store.

> + * to update the actual type of the child store.

>    *

> - * Returns 0 on success, 1 if we could parse all location data but the backinig

> + * Returns 0 on success, 1 if we could parse all location data but the child

>    * store specification contained other data unrepresentable by libvirt (e.g.

>    * inline authentication).

>    * In both cases @src is filled. On error -1 is returned @src is NULL and an

>    * error is reported.

>    */

> -int

> -virStorageSourceNewFromBacking(virStorageSourcePtr parent,

> -                               virStorageSourcePtr *backing)

> +static int

> +virStorageSourceNewFromChild(virStorageSourcePtr parent,

> +                             const char *parentRaw,

> +                             virStorageSourcePtr *child)

>   {

>       struct stat st;

>       VIR_AUTOUNREF(virStorageSourcePtr) def = NULL;

>       int rc = 0;

>   

> -    *backing = NULL;

> +    *child = NULL;

>   

> -    if (virStorageIsRelative(parent->backingStoreRaw)) {

> -        if (!(def = virStorageSourceNewFromBackingRelative(parent,

> -                                                           parent->backingStoreRaw)))

> +    if (virStorageIsRelative(parentRaw)) {

> +        if (!(def = virStorageSourceNewFromBackingRelative(parent, parentRaw)))

>               return -1;

>       } else {

> -        if ((rc = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw,

> -                                                         &def)) < 0)

> +        if ((rc = virStorageSourceNewFromBackingAbsolute(parentRaw, &def)) < 0)

>               return -1;

>       }

>   

> @@ -3767,10 +3767,25 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent,

>       if (virStorageSourceInitChainElement(def, parent, true) < 0)

>           return -1;

>   

> -    def->readonly = true;

>       def->detected = true;

>   

> -    VIR_STEAL_PTR(*backing, def);

> +    VIR_STEAL_PTR(*child, def);

> +    return rc;

> +}

> +

> +

> +int

> +virStorageSourceNewFromBacking(virStorageSourcePtr parent,

> +                               virStorageSourcePtr *backing)

> +{

> +    int rc;

> +

> +    if ((rc = virStorageSourceNewFromChild(parent,

> +                                           parent->backingStoreRaw,

> +                                           backing)) < 0)

> +        return rc;

> +

> +    (*backing)->readonly = true;

>       return rc;

>   }

>   


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index c47df6c200..7ae6719dd6 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -3716,38 +3716,38 @@  virStorageSourceNewFromBackingAbsolute(const char *path,
 
 
 /**
- * virStorageSourceNewFromBacking:
+ * virStorageSourceNewFromChild:
  * @parent: storage source parent
- * @backing: returned backing store definition
+ * @child: returned child/backing store definition
+ * @parentRaw: raw child string (backingStoreRaw)
  *
  * Creates a storage source which describes the backing image of @parent and
- * fills it into @backing depending on the 'backingStoreRaw' property of @parent
+ * fills it into @backing depending on the passed parentRaw (backingStoreRaw)
  * and other data. Note that for local storage this function accesses the file
- * to update the actual type of the backing store.
+ * to update the actual type of the child store.
  *
- * Returns 0 on success, 1 if we could parse all location data but the backinig
+ * Returns 0 on success, 1 if we could parse all location data but the child
  * store specification contained other data unrepresentable by libvirt (e.g.
  * inline authentication).
  * In both cases @src is filled. On error -1 is returned @src is NULL and an
  * error is reported.
  */
-int
-virStorageSourceNewFromBacking(virStorageSourcePtr parent,
-                               virStorageSourcePtr *backing)
+static int
+virStorageSourceNewFromChild(virStorageSourcePtr parent,
+                             const char *parentRaw,
+                             virStorageSourcePtr *child)
 {
     struct stat st;
     VIR_AUTOUNREF(virStorageSourcePtr) def = NULL;
     int rc = 0;
 
-    *backing = NULL;
+    *child = NULL;
 
-    if (virStorageIsRelative(parent->backingStoreRaw)) {
-        if (!(def = virStorageSourceNewFromBackingRelative(parent,
-                                                           parent->backingStoreRaw)))
+    if (virStorageIsRelative(parentRaw)) {
+        if (!(def = virStorageSourceNewFromBackingRelative(parent, parentRaw)))
             return -1;
     } else {
-        if ((rc = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw,
-                                                         &def)) < 0)
+        if ((rc = virStorageSourceNewFromBackingAbsolute(parentRaw, &def)) < 0)
             return -1;
     }
 
@@ -3767,10 +3767,25 @@  virStorageSourceNewFromBacking(virStorageSourcePtr parent,
     if (virStorageSourceInitChainElement(def, parent, true) < 0)
         return -1;
 
-    def->readonly = true;
     def->detected = true;
 
-    VIR_STEAL_PTR(*backing, def);
+    VIR_STEAL_PTR(*child, def);
+    return rc;
+}
+
+
+int
+virStorageSourceNewFromBacking(virStorageSourcePtr parent,
+                               virStorageSourcePtr *backing)
+{
+    int rc;
+
+    if ((rc = virStorageSourceNewFromChild(parent,
+                                           parent->backingStoreRaw,
+                                           backing)) < 0)
+        return rc;
+
+    (*backing)->readonly = true;
     return rc;
 }