[PATCH 3/5] storage: add new function virStorageBackendConvertImage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



virStorageBackendConvertImage can be used to convert image from one
format to another.
---
 src/storage/storage_backend.c | 22 ++++++++++++++++++++++
 src/storage/storage_backend.h |  5 +++++
 2 files changed, 27 insertions(+)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index efb5ce5..8fe5b8b 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -2194,3 +2194,25 @@ virStorageBackendFindGlusterPoolSources(const char *host ATTRIBUTE_UNUSED,
     return 0;
 }
 #endif /* #ifdef GLUSTER_CLI */
+
+int virStorageBackendConvertImage(const char* inputPath, virStorageFileFormat inputFormat,
+                                  const char* path, virStorageFileFormat format,
+                                  uid_t uid, gid_t gid, mode_t mode)
+{
+    const char* inFmt = NULL;
+    const char* outFmt = NULL;
+    char* tool = NULL;
+    virCommandPtr cmd = NULL;
+    int ret = -1;
+
+    if (virStorageBackendFindQemuImgTool(&tool) < 0 ||
+        (inFmt = virStorageFileFormatTypeToString(inputFormat)) == NULL ||
+        (outFmt = virStorageFileFormatTypeToString(format)) == NULL)
+        return -1;
+
+    cmd = virCommandNewArgList(tool, "convert", "-f", inFmt, "-O", outFmt,
+                               inputPath, path, NULL);
+    ret = virStorageBackendCreateExec(cmd, path, uid, gid, mode);
+    virCommandFree(cmd);
+    return ret;
+}
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index 96b5f39..8e6b2d7 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -214,6 +214,11 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
                                          const char *create_tool,
                                          int imgformat);
 
+int virStorageBackendConvertImage(const char* inputPath,
+                                  virStorageFileFormat inputFormat,
+                                  const char* path,
+                                  virStorageFileFormat format,
+                                  uid_t uid, gid_t gid, mode_t mode);
 /* ------- virStorageFile backends ------------ */
 typedef struct _virStorageFileBackend virStorageFileBackend;
 typedef virStorageFileBackend *virStorageFileBackendPtr;
-- 
1.8.3.1

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]