You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by wi...@apache.org on 2013/08/14 13:29:13 UTC

[1/2] git commit: updated refs/heads/master to d7f738f

Updated Branches:
  refs/heads/4.2 9e7983ac1 -> 5d9ce82f7
  refs/heads/master 21d898248 -> d7f738fb6


rbd: When the template is a RAW image, do not use a temp file when deploying


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d7f738fb
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d7f738fb
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d7f738fb

Branch: refs/heads/master
Commit: d7f738fb647f392ea5c43ecc0a556272ddd6df9d
Parents: 21d8982
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Tue Aug 13 17:22:22 2013 +0200
Committer: Wido den Hollander <wi...@widodh.nl>
Committed: Wed Aug 14 13:28:08 2013 +0200

----------------------------------------------------------------------
 .../kvm/storage/LibvirtStorageAdaptor.java      | 32 +++++++++++++-------
 1 file changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d7f738fb/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
index 41df310..f93eb37 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
@@ -1022,13 +1022,21 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
               * A HUGE performance gain can be achieved here if QCOW2 -> RBD format 2 can be done in one step
               */
             s_logger.debug("The source image is not RBD, but the destination is. We will convert into RBD format 2");
-            String tmpFile = "/tmp/" + name;
+            String sourceFile;
+            boolean useTmpFile = false;
 
             try {
-                srcFile = new QemuImgFile(sourcePath, sourceFormat);
-                destFile = new QemuImgFile(tmpFile);
-                s_logger.debug("Converting " + srcFile.getFileName() +  " to " + tmpFile +  " as a temporary file for RBD conversion");
-                qemu.convert(srcFile, destFile);
+                if (sourceFormat != destFormat) {
+                    srcFile = new QemuImgFile(sourcePath, sourceFormat);
+                    destFile = new QemuImgFile("/tmp/" + name);
+                    s_logger.debug("Converting " + srcFile.getFileName() +  " to " + destFile.getFileName() +  " as a temporary file for RBD conversion");
+                    qemu.convert(srcFile, destFile);
+                    sourceFile = destFile.getFileName();
+                    useTmpFile = true;
+                } else {
+                    // Source file is RAW, we can write directly to RBD
+                    sourceFile = sourcePath;
+                }
 
                 // We now convert the temporary file to a RBD image with format 2
                 Rados r = new Rados(destPool.getAuthUserName());
@@ -1045,13 +1053,12 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
 
                 RbdImage image = rbd.open(name);
 
-                // We now read the temporary file and write it to the RBD image
-                File fh = new File(tmpFile);
+                File fh = new File(sourceFile);
                 BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fh));
 
                 int chunkSize = 4194304;
                 long offset = 0;
-                s_logger.debug("Reading temporary file " + tmpFile + " (" + fh.length() + " bytes) into RBD image " + name + " in chunks of " + chunkSize + " bytes");
+                s_logger.debug("Reading file " + sourceFile + " (" + fh.length() + " bytes) into RBD image " + name + " in chunks of " + chunkSize + " bytes");
                 while(true) {
                     byte[] buf = new byte[chunkSize];
 
@@ -1062,10 +1069,13 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
                     image.write(buf, offset, bytes);
                     offset += bytes;
                 }
-                s_logger.debug("Completed writing " + tmpFile + " to RBD image " + name + ". Bytes written: " + offset);
+                s_logger.debug("Completed writing " + sourceFile + " to RBD image " + name + ". Bytes written: " + offset);
                 bis.close();
-                s_logger.debug("Removing temporary file " + tmpFile);
-                fh.delete();
+
+                if (useTmpFile) {
+                    s_logger.debug("Removing temporary file " + sourceFile);
+                    fh.delete();
+                }
 
                 /* Snapshot the image and protect that snapshot so we can clone (layer) from it */
                 s_logger.debug("Creating RBD snapshot " + this.rbdTemplateSnapName + " on image " + name);


[2/2] git commit: updated refs/heads/4.2 to 5d9ce82

Posted by wi...@apache.org.
rbd: When the template is a RAW image, do not use a temp file when deploying


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5d9ce82f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5d9ce82f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5d9ce82f

Branch: refs/heads/4.2
Commit: 5d9ce82f7dd3b60887d7819a73b12bae362364ee
Parents: 9e7983a
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Tue Aug 13 17:22:22 2013 +0200
Committer: Wido den Hollander <wi...@widodh.nl>
Committed: Wed Aug 14 13:28:21 2013 +0200

----------------------------------------------------------------------
 .../kvm/storage/LibvirtStorageAdaptor.java      | 32 +++++++++++++-------
 1 file changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5d9ce82f/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
index 41df310..f93eb37 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
@@ -1022,13 +1022,21 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
               * A HUGE performance gain can be achieved here if QCOW2 -> RBD format 2 can be done in one step
               */
             s_logger.debug("The source image is not RBD, but the destination is. We will convert into RBD format 2");
-            String tmpFile = "/tmp/" + name;
+            String sourceFile;
+            boolean useTmpFile = false;
 
             try {
-                srcFile = new QemuImgFile(sourcePath, sourceFormat);
-                destFile = new QemuImgFile(tmpFile);
-                s_logger.debug("Converting " + srcFile.getFileName() +  " to " + tmpFile +  " as a temporary file for RBD conversion");
-                qemu.convert(srcFile, destFile);
+                if (sourceFormat != destFormat) {
+                    srcFile = new QemuImgFile(sourcePath, sourceFormat);
+                    destFile = new QemuImgFile("/tmp/" + name);
+                    s_logger.debug("Converting " + srcFile.getFileName() +  " to " + destFile.getFileName() +  " as a temporary file for RBD conversion");
+                    qemu.convert(srcFile, destFile);
+                    sourceFile = destFile.getFileName();
+                    useTmpFile = true;
+                } else {
+                    // Source file is RAW, we can write directly to RBD
+                    sourceFile = sourcePath;
+                }
 
                 // We now convert the temporary file to a RBD image with format 2
                 Rados r = new Rados(destPool.getAuthUserName());
@@ -1045,13 +1053,12 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
 
                 RbdImage image = rbd.open(name);
 
-                // We now read the temporary file and write it to the RBD image
-                File fh = new File(tmpFile);
+                File fh = new File(sourceFile);
                 BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fh));
 
                 int chunkSize = 4194304;
                 long offset = 0;
-                s_logger.debug("Reading temporary file " + tmpFile + " (" + fh.length() + " bytes) into RBD image " + name + " in chunks of " + chunkSize + " bytes");
+                s_logger.debug("Reading file " + sourceFile + " (" + fh.length() + " bytes) into RBD image " + name + " in chunks of " + chunkSize + " bytes");
                 while(true) {
                     byte[] buf = new byte[chunkSize];
 
@@ -1062,10 +1069,13 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
                     image.write(buf, offset, bytes);
                     offset += bytes;
                 }
-                s_logger.debug("Completed writing " + tmpFile + " to RBD image " + name + ". Bytes written: " + offset);
+                s_logger.debug("Completed writing " + sourceFile + " to RBD image " + name + ". Bytes written: " + offset);
                 bis.close();
-                s_logger.debug("Removing temporary file " + tmpFile);
-                fh.delete();
+
+                if (useTmpFile) {
+                    s_logger.debug("Removing temporary file " + sourceFile);
+                    fh.delete();
+                }
 
                 /* Snapshot the image and protect that snapshot so we can clone (layer) from it */
                 s_logger.debug("Creating RBD snapshot " + this.rbdTemplateSnapName + " on image " + name);