Updated Branches: refs/heads/master 823c72552 -> cd6853cc1
CLOUDSTACK-732 Add disk snapshot for KVM 6.3, add the flag in CS. Signed-off-by: Edison Su <[email protected]> Conflicts: engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/cd6853cc Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/cd6853cc Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/cd6853cc Branch: refs/heads/master Commit: cd6853cc1a16a033717707e8567c55a406935961 Parents: 823c725 Author: Edison Su <[email protected]> Authored: Fri Jul 19 13:26:19 2013 -0700 Committer: Edison Su <[email protected]> Committed: Fri Jul 19 13:26:19 2013 -0700 ---------------------------------------------------------------------- .../com/cloud/upgrade/dao/Upgrade410to420.java | 44 ++++++++++++++++++-- server/src/com/cloud/configuration/Config.java | 1 + .../storage/snapshot/SnapshotManagerImpl.java | 6 +++ 3 files changed, 48 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cd6853cc/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 0cf6b5b..d4b7b6d 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -90,6 +90,7 @@ public class Upgrade410to420 implements DbUpgrade { correctExternalNetworkDevicesSetup(conn); removeFirewallServiceFromSharedNetworkOfferingWithSGService(conn); fix22xKVMSnapshots(conn); + setKVMSnapshotFlag(conn); addIndexForAlert(conn); fixBaremetalForeignKeys(conn); // storage refactor related migration @@ -297,9 +298,46 @@ public class Upgrade410to420 implements DbUpgrade { */ } - private void updatePrimaryStore(Connection conn) { - PreparedStatement sql = null; - PreparedStatement sql2 = null; + //KVM snapshot flag: only turn on if Customers is using snapshot; + private void setKVMSnapshotFlag(Connection conn) { + s_logger.debug("Verify and set the KVM snapshot flag if snapshot was used. "); + PreparedStatement pstmt = null; + ResultSet rs = null; + try { + int numRows = 0; + pstmt = conn.prepareStatement("select count(*) from `cloud`.`snapshots` where hypervisor_type = 'KVM'"); + rs = pstmt.executeQuery(); + if(rs.next()){ + numRows = rs.getInt(1); + } + rs.close(); + pstmt.close(); + if (numRows > 0){ + //Add the configuration flag + pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = 'KVM.snapshot.enabled'"); + pstmt.setString(1, "true"); + pstmt.executeUpdate(); + } + } catch (SQLException e) { + throw new CloudRuntimeException("Failed to read the snapshot table for KVM upgrade. ", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + s_logger.debug("Done set KVM snapshot flag. "); + } + + private void updatePrimaryStore(Connection conn) { + PreparedStatement sql = null; + PreparedStatement sql2 = null; try { sql = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type = 'Filesystem' or pool_type = 'LVM'"); sql.setString(1, DataStoreProvider.DEFAULT_PRIMARY); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cd6853cc/server/src/com/cloud/configuration/Config.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index bb0237c..8153dd6 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -145,6 +145,7 @@ public enum Config { SnapshotPollInterval("Snapshots", SnapshotManager.class, Integer.class, "snapshot.poll.interval", "300", "The time interval in seconds when the management server polls for snapshots to be scheduled.", null), SnapshotDeltaMax("Snapshots", SnapshotManager.class, Integer.class, "snapshot.delta.max", "16", "max delta snapshots between two full snapshots.", null), BackupSnapshotAferTakingSnapshot("Snapshots", SnapshotManager.class, Boolean.class, "snapshot.backup.rightafter", "true", "backup snapshot right after snapshot is taken", null), + KVMSnapshotEnabled("Snapshots", SnapshotManager.class, Boolean.class, "KVM.snapshot.enabled", "false", "whether snapshot is enabled for KVM hosts", null), // Advanced JobExpireMinutes("Advanced", ManagementServer.class, String.class, "job.expire.minutes", "1440", "Time (in minutes) for async-jobs to be kept in system", null), http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cd6853cc/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index d766f7a..123c595 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -910,6 +910,12 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, if (host.getHypervisorType() != HypervisorType.KVM) { return true; } + + //Turn off snapshot by default for KVM, unless it is set in the global flag + boolean snapshotEnabled = Boolean.parseBoolean(_configDao.getValue("KVM.snapshot.enabled")); + if (!snapshotEnabled) { + return false; + } // Determine host capabilities String caps = host.getCapabilities();
