cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [2/2] git commit: updated refs/heads/4.2 to d019388
Date Wed, 21 Aug 2013 15:33:32 GMT
CLOUDSTACK-4249: Do not assume KVM snapshots are in QCOW2 format

RBD snapshots are in RAW format and are stored as such on Secondary Storage.

When creating a template from such a snapshot, honor the image format passed
down by the management server and act on that.

The old code simply assumed it always was QCOW2.


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

Branch: refs/heads/4.2
Commit: d019388bf53a15ba8a5c121885929f587d564d41
Parents: b3921e5
Author: Wido den Hollander <wido@widodh.nl>
Authored: Wed Aug 21 17:10:06 2013 +0200
Committer: Wido den Hollander <wido@widodh.nl>
Committed: Wed Aug 21 17:33:07 2013 +0200

----------------------------------------------------------------------
 .../resource/NfsSecondaryStorageResource.java   | 41 +++++++++++++++-----
 1 file changed, 32 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d019388b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index f79bae8..8b9de39 100755
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -407,10 +407,14 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
         } else if (srcData.getHypervisorType() == HypervisorType.KVM) {
             File srcFile = getFile(srcData.getPath(), srcDataStore.getUrl());
             File destFile = getFile(destData.getPath(), destDataStore.getUrl());
+
+            ImageFormat srcFormat = srcData.getVolume().getFormat();
+
             // get snapshot file name
             String templateName = srcFile.getName();
-            // add kvm file extension for copied template name
-            String destFileFullPath = destFile.getAbsolutePath() + File.separator + templateName
+ "." + ImageFormat.QCOW2.getFileExtension();
+            // add kvm file extension for copied template name    
+            String fileName = templateName + "." + srcFormat.getFileExtension();
+            String destFileFullPath = destFile.getAbsolutePath() + File.separator + fileName;
             s_logger.debug("copy snapshot " + srcFile.getAbsolutePath() + " to template "
+ destFileFullPath);
             Script.runSimpleBashScript("cp " + srcFile.getAbsolutePath() + " " + destFileFullPath);
             try {
@@ -422,18 +426,30 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
                 BufferedWriter bufferWriter = new BufferedWriter(writer);
                 bufferWriter.write("uniquename=" + destData.getName());
                 bufferWriter.write("\n");
-                bufferWriter.write("filename=" + templateName + "." + ImageFormat.QCOW2.getFileExtension());
+                bufferWriter.write("filename=" + fileName);
                 bufferWriter.write("\n");
                 long size = this._storage.getSize(destFileFullPath);
                 bufferWriter.write("size=" + size);
                 bufferWriter.close();
                 writer.close();
-                // template post processing
-                QCOW2Processor processor = new QCOW2Processor();
+
+
+                /**
+                 * Snapshots might be in either QCOW2 or RAW image format
+                 *
+                 * For example RBD snapshots are in RAW format
+                 */
+                Processor processor = null;
+                if (srcFormat == ImageFormat.QCOW2) {
+                    processor = new QCOW2Processor();
+                } else if (srcFormat == ImageFormat.RAW) {
+                    processor = new RawImageProcessor();
+                }
+
                 Map<String, Object> params = new HashMap<String, Object>();
                 params.put(StorageLayer.InstanceConfigKey, _storage);
 
-                processor.configure("qcow2 processor", params);
+                processor.configure("template processor", params);
                 String destPath = destFile.getAbsolutePath();
 
                 FormatInfo info = processor.process(destPath, null, templateName);
@@ -441,12 +457,14 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
                 loc.create(1, true, srcFile.getName());
                 loc.addFormat(info);
                 loc.save();
+
                 TemplateProp prop = loc.getTemplateInfo();
                 TemplateObjectTO newTemplate = new TemplateObjectTO();
-                newTemplate.setPath(destData.getPath() + File.separator + templateName +
"." + ImageFormat.QCOW2.getFileExtension());
-                newTemplate.setFormat(ImageFormat.QCOW2);
+                newTemplate.setPath(destData.getPath() + File.separator + fileName);
+                newTemplate.setFormat(srcFormat);
                 newTemplate.setSize(prop.getSize());
                 newTemplate.setPhysicalSize(prop.getPhysicalSize());
+
                 return new CopyCmdAnswer(newTemplate);
             } catch (ConfigurationException e) {
                 s_logger.debug("Failed to create template:" + e.toString());
@@ -454,6 +472,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
             } catch (IOException e) {
                 s_logger.debug("Failed to create template:" + e.toString());
                 return new CopyCmdAnswer(e.toString());
+            } catch (InternalErrorException e) {
+                s_logger.debug("Failed to create template:" + e.toString());
+                return new CopyCmdAnswer(e.toString());
             }
         }
 
@@ -711,7 +732,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
                 return ImageFormat.OVA;
             } else if (ext.equalsIgnoreCase("tar")) {
                 return ImageFormat.TAR;
-            } else if (ext.equalsIgnoreCase("img")) {
+            } else if (ext.equalsIgnoreCase("img") || ext.equalsIgnoreCase("raw")) {
                 return ImageFormat.RAW;
             }
         }
@@ -731,6 +752,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
                 processor = new VmdkProcessor();
             } else if (format == ImageFormat.VHD) {
                 processor = new VhdProcessor();
+            } else if (format == ImageFormat.RAW) {
+                processor = new RawImageProcessor();
             }
 
             if (processor == null) {


Mime
View raw message