From 003b0e4a236741c3c30875eed7cd839900d05004 Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 3 Nov 2010 19:04:08 -0700 Subject: [PATCH] merge from 2.1.x 86d02eaa155cfdbb0a8cf31c8eae47711fbf5c2b delete all snapshut which has been backed up to secondary storage change dd block size from 512 to 1M, make taking snapstho faster for iscsi primary storage --- .../xen/resource/CitrixResourceBase.java | 37 ++++++++++++++++++- scripts/vm/hypervisor/xenserver/vmopsSnapshot | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 9a0e64117c8..32a29bfec07 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -5544,6 +5544,39 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR } return new CreatePrivateTemplateAnswer(cmd, result, details); } + + private boolean destroySnapshotOnPrimaryStorageExceptThis(String volumeUuid, String avoidSnapshotUuid){ + try { + Connection conn = getConnection(); + VDI volume = getVDIbyUuid(volumeUuid); + if (volume == null) { + throw new InternalErrorException("Could not destroy snapshot on volume " + volumeUuid + " due to can not find it"); + } + Set snapshots = volume.getSnapshots(conn); + for( VDI snapshot : snapshots ) { + try { + if(! snapshot.getUuid(conn).equals(avoidSnapshotUuid)) { + snapshot.destroy(conn); + } + } catch (Exception e) { + String msg = "Destroying snapshot: " + snapshot+ " on primary storage failed due to " + e.toString(); + s_logger.warn(msg, e); + } + } + s_logger.debug("Successfully destroyed snapshot on volume: " + volumeUuid + " execept this current snapshot "+ avoidSnapshotUuid ); + return true; + } catch (XenAPIException e) { + String msg = "Destroying snapshot on volume: " + volumeUuid + " execept this current snapshot "+ avoidSnapshotUuid + " failed due to " + e.toString(); + s_logger.error(msg, e); + } catch (Exception e) { + String msg = "Destroying snapshot on volume: " + volumeUuid + " execept this current snapshot "+ avoidSnapshotUuid + " failed due to " + e.toString(); + s_logger.warn(msg, e); + } + + return false; + } + + protected BackupSnapshotAnswer execute(final BackupSnapshotCommand cmd) { String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel(); @@ -5617,7 +5650,9 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR // new one // and muddle the vhd chain on the secondary storage. - destroySnapshotOnPrimaryStorage(prevSnapshotUuid); + String volumeUuid = cmd.getVolumePath(); + destroySnapshotOnPrimaryStorageExceptThis(volumeUuid, snapshotUuid); + } } diff --git a/scripts/vm/hypervisor/xenserver/vmopsSnapshot b/scripts/vm/hypervisor/xenserver/vmopsSnapshot index 34e06342aa3..802556a6028 100755 --- a/scripts/vm/hypervisor/xenserver/vmopsSnapshot +++ b/scripts/vm/hypervisor/xenserver/vmopsSnapshot @@ -171,7 +171,7 @@ def copyfile(fromFile, toFile, isISCSI): errMsg = '' if isISCSI: try: - cmd = ['dd', 'if=' + fromFile, 'of=' + toFile] + cmd = ['dd', 'if=' + fromFile, 'of=' + toFile, 'bs=1M'] txt = util.pread2(cmd) except: txt = ''