cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [1/2] git commit: updated refs/heads/master to 227509b
Date Tue, 13 Aug 2013 14:25:38 GMT
Updated Branches:
  refs/heads/master 4d48d9603 -> 227509be4


CLOUDSTACK-4114: Use RAW disk images for RBD instead of QCOW2


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

Branch: refs/heads/master
Commit: 04f378bcff90c9a3ab3bb3c92c5ec1145aab45c4
Parents: 4d48d96
Author: Wido den Hollander <wido@widodh.nl>
Authored: Tue Aug 6 16:25:55 2013 +0200
Committer: Wido den Hollander <wido@widodh.nl>
Committed: Tue Aug 13 16:14:45 2013 +0200

----------------------------------------------------------------------
 .../com/cloud/upgrade/dao/Upgrade410to420.java  | 11 ++++++
 .../cloudstack/storage/image/format/RAW.java    | 32 +++++++++++++++
 .../cloudstack/storage/volume/VolumeObject.java |  6 +++
 .../kvm/storage/KVMStorageProcessor.java        | 41 +++++++++++++++++++-
 .../kvm/storage/LibvirtStorageAdaptor.java      |  1 +
 5 files changed, 90 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04f378bc/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index 7ab7ab7..fd4f2a7 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -105,6 +105,7 @@ public class Upgrade410to420 implements DbUpgrade {
         fixRouterKeys(conn);
         encryptSite2SitePSK(conn);
         migrateDatafromIsoIdInVolumesTable(conn);
+        setRAWformatForRBDVolumes(conn);
     }
 
     private void fixBaremetalForeignKeys(Connection conn) {
@@ -2180,6 +2181,16 @@ public class Upgrade410to420 implements DbUpgrade {
         }catch (SQLException e) {
             //implies iso_id1 is not present, so do nothing.
         }
+    }
 
+    protected void setRAWformatForRBDVolumes(Connection conn) {
+        PreparedStatement pstmt = null;
+        try {
+            s_logger.debug("Setting format to RAW for all volumes on RBD primary storage
pools");
+            pstmt = conn.prepareStatement("UPDATE volumes SET format = 'RAW' WHERE pool_id
IN(SELECT id FROM storage_pool WHERE pool_type = 'RBD')");
+            pstmt.executeQuery();
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Failed to update volume format to RAW for volumes
on RBD pools");
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04f378bc/engine/storage/src/org/apache/cloudstack/storage/image/format/RAW.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/RAW.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/RAW.java
new file mode 100644
index 0000000..84adff2
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/RAW.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.image.format;
+
+import org.apache.cloudstack.storage.BaseType;
+import org.springframework.stereotype.Component;
+
+@Component("imageformat_raw")
+public class RAW extends BaseType implements ImageFormat {
+    private final String type = "RAW";
+
+    @Override
+    public String toString() {
+        return type;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04f378bc/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
index 5058dba..b24b715 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
@@ -474,6 +474,9 @@ public class VolumeObject implements VolumeInfo {
                     if (newVol.getSize() != null) {
                         vol.setSize(newVol.getSize());
                     }
+                    if (newVol.getFormat() != null) {
+                        vol.setFormat(newVol.getFormat());
+                    }
                     vol.setPoolId(this.getDataStore().getId());
                     volumeDao.update(vol.getId(), vol);
                 } else if (answer instanceof CreateObjectAnswer) {
@@ -485,6 +488,9 @@ public class VolumeObject implements VolumeInfo {
                         vol.setSize(newVol.getSize());
                     }
                     vol.setPoolId(this.getDataStore().getId());
+                    if (newVol.getFormat() != null) {
+                        vol.setFormat(newVol.getFormat());
+                    }
                     volumeDao.update(vol.getId(), vol);
                 }
             } else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04f378bc/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
index d813eb9..8f46c22 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
@@ -199,7 +199,16 @@ public class KVMStorageProcessor implements StorageProcessor {
 
             TemplateObjectTO newTemplate = new TemplateObjectTO();
             newTemplate.setPath(primaryVol.getName());
-            newTemplate.setFormat(ImageFormat.QCOW2);
+
+            /**
+             * Force the ImageFormat for RBD templates to RAW
+             *
+             */
+            if (primaryPool.getType() == StoragePoolType.RBD) {
+                newTemplate.setFormat(ImageFormat.RAW);
+            } else {
+                newTemplate.setFormat(ImageFormat.QCOW2);
+            }
             return new CopyCmdAnswer(newTemplate);
         } catch (CloudRuntimeException e) {
             return new CopyCmdAnswer(e.toString());
@@ -291,6 +300,12 @@ public class KVMStorageProcessor implements StorageProcessor {
             newVol.setPath(vol.getName());
             newVol.setSize(volume.getSize());
 
+            if (vol.getFormat() == PhysicalDiskFormat.RAW) {
+                newVol.setFormat(ImageFormat.RAW);
+            } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) {
+                newVol.setFormat(ImageFormat.QCOW2);
+            }
+
             return new CopyCmdAnswer(newVol);
         } catch (CloudRuntimeException e) {
             s_logger.debug("Failed to create volume: " + e.toString());
@@ -985,6 +1000,15 @@ public class KVMStorageProcessor implements StorageProcessor {
             VolumeObjectTO newVol = new VolumeObjectTO();
             newVol.setPath(vol.getName());
             newVol.setSize(volume.getSize());
+
+            /**
+             * Volumes on RBD are always in RAW format
+             * Hardcode this to RAW since there is no other way right now
+             */
+            if (primaryPool.getType() == StoragePoolType.RBD) {
+                newVol.setFormat(ImageFormat.RAW);
+            }
+
             return new CreateObjectAnswer(newVol);
         } catch (Exception e) {
             s_logger.debug("Failed to create volume: " + e.toString());
@@ -1120,6 +1144,7 @@ public class KVMStorageProcessor implements StorageProcessor {
             DataTO destData = cmd.getDestTO();
             PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore();
             DataStoreTO imageStore = srcData.getDataStore();
+            VolumeObjectTO volume = snapshot.getVolume();
 
             if (!(imageStore instanceof NfsTO)) {
                 return new CopyCmdAnswer("unsupported protocol");
@@ -1135,6 +1160,12 @@ public class KVMStorageProcessor implements StorageProcessor {
                     + snapshotPath);
             KVMPhysicalDisk snapshotDisk = secondaryPool.getPhysicalDisk(snapshotName);
 
+            if (volume.getFormat() == ImageFormat.RAW) {
+                snapshotDisk.setFormat(PhysicalDiskFormat.RAW);
+            } else if (volume.getFormat() == ImageFormat.QCOW2) {
+                snapshotDisk.setFormat(PhysicalDiskFormat.QCOW2);
+            }
+
             String primaryUuid = pool.getUuid();
             KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(pool.getPoolType(),
primaryUuid);
             String volUuid = UUID.randomUUID().toString();
@@ -1142,6 +1173,14 @@ public class KVMStorageProcessor implements StorageProcessor {
             VolumeObjectTO newVol = new VolumeObjectTO();
             newVol.setPath(disk.getName());
             newVol.setSize(disk.getVirtualSize());
+
+            /**
+             * We have to force the format of RBD volumes to RAW
+             */
+            if (primaryPool.getType() == StoragePoolType.RBD) {
+                newVol.setFormat(ImageFormat.RAW);
+            }
+
             return new CopyCmdAnswer(newVol);
         } catch (CloudRuntimeException e) {
             return new CopyCmdAnswer(e.toString());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04f378bc/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 262343a..28cfd42 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
@@ -787,6 +787,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
                     qemu.convert(sourceFile, destFile);
                 }
             } else {
+                format = PhysicalDiskFormat.RAW;
                 disk = new KVMPhysicalDisk(destPool.getSourceDir() + "/" + newUuid, newUuid,
destPool);
                 disk.setFormat(format);
                 disk.setSize(template.getVirtualSize());


Mime
View raw message