Create a shim that will allow other backends to make use of qemu-img
functionality to create or possibly modify the volume.

Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/storage/storage_util.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 src/storage/storage_util.h |  8 ++++++++
 2 files changed, 50 insertions(+)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 5252e429fd..e9bafd3b15 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -1409,6 +1409,48 @@ storageBackendCreateQemuImg(virConnectPtr conn,
     return ret;
 }
 
+
+/**
+ * virStorageBackendCreateVolUsingQemuImg
+ * @conn: Connection pointer
+ * @pool: Storage Pool Object
+ * @vol: Volume definition
+ * @inputvol: Volume to use for creation
+ * @flags: Flags for creation options
+ *
+ * A shim to storageBackendCreateQemuImg to allow other backends to
+ * utilize qemu-img processing in order to create or alter the volume.
+ *
+ * NB: If a volume target format is not supplied (per usual for some
+ * backends), temporarily adjust the format to be RAW. Once completed,
+ * reset the format back to NONE.
+ *
+ * Returns: 0 on success, -1 on failure.
+ */
+int
+virStorageBackendCreateVolUsingQemuImg(virConnectPtr conn,
+                                       virStoragePoolObjPtr pool,
+                                       virStorageVolDefPtr vol,
+                                       virStorageVolDefPtr inputvol,
+                                       unsigned int flags)
+{
+    int ret = -1;
+    bool changeFormat = false;
+
+    if (vol->target.format == VIR_STORAGE_FILE_NONE) {
+        vol->target.format = VIR_STORAGE_FILE_RAW;
+        changeFormat = true;
+    }
+
+    ret = storageBackendCreateQemuImg(conn, pool, vol, inputvol, flags);
+
+    if (changeFormat)
+        vol->target.format = VIR_STORAGE_FILE_NONE;
+
+    return ret;
+}
+
+
 virStorageBackendBuildVolFrom
 virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
                                          virStorageVolDefPtr inputvol)
diff --git a/src/storage/storage_util.h b/src/storage/storage_util.h
index 00793ff3a4..dc7e62517b 100644
--- a/src/storage/storage_util.h
+++ b/src/storage/storage_util.h
@@ -27,6 +27,14 @@
 # include "storage_backend.h"
 
 /* File creation/cloning functions used for cloning between backends */
+
+int
+virStorageBackendCreateVolUsingQemuImg(virConnectPtr conn,
+                                       virStoragePoolObjPtr pool,
+                                       virStorageVolDefPtr vol,
+                                       virStorageVolDefPtr inputvol,
+                                       unsigned int flags);
+
 virStorageBackendBuildVolFrom
 virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
                                          virStorageVolDefPtr inputvol);
-- 
2.13.6

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

Reply via email to