From ba0493e2f0572ad44428e4d00f518b2eafd2bc0f Mon Sep 17 00:00:00 2001 From: edison Date: Tue, 7 Sep 2010 16:42:58 -0700 Subject: [PATCH] fix delete snapshot --- .../computing/LibvirtComputingResource.java | 7 +++--- scripts/storage/qcow2/createtmplt.sh | 6 ++--- scripts/storage/qcow2/managesnapshot.sh | 23 +++++++++++++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java index c776001560e..f1d2d36e29b 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java @@ -1311,7 +1311,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { StoragePool secondaryStoragePool = getNfsSPbyURI(_conn, new URI(secondaryStoragePoolURL)); String ssPmountPath = _mountPoint + File.separator + secondaryStoragePool.getUUIDString(); - snapshotDestPath = ssPmountPath + File.separator + dcId + File.separator + "snapshots" + File.separator + accountId + File.separator + volumeId; + snapshotDestPath = ssPmountPath + File.separator + "snapshots" + File.separator + dcId + File.separator + accountId + File.separator + volumeId; Script command = new Script(_manageSnapshotPath, _timeout, s_logger); command.add("-b", snapshotPath); command.add("-n", snapshotName); @@ -1367,7 +1367,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { StoragePool secondaryStoragePool = getNfsSPbyURI(_conn, new URI(cmd.getSecondaryStoragePoolURL())); String ssPmountPath = _mountPoint + File.separator + secondaryStoragePool.getUUIDString(); - String snapshotDestPath = ssPmountPath + File.separator + dcId + File.separator + "snapshots" + File.separator + accountId + File.separator + volumeId; + String snapshotDestPath = ssPmountPath + File.separator + "snapshots" + File.separator + dcId + File.separator + accountId + File.separator + volumeId; final Script command = new Script(_manageSnapshotPath, _timeout, s_logger); command.add("-d", snapshotDestPath); @@ -1389,11 +1389,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { StoragePool secondaryStoragePool = getNfsSPbyURI(_conn, new URI(cmd.getSecondaryStoragePoolURL())); String ssPmountPath = _mountPoint + File.separator + secondaryStoragePool.getUUIDString(); - String snapshotDestPath = ssPmountPath + File.separator + dcId + File.separator + "snapshots" + File.separator + accountId + File.separator + volumeId; + String snapshotDestPath = ssPmountPath + File.separator + "snapshots" + File.separator + dcId + File.separator + accountId + File.separator + volumeId; final Script command = new Script(_manageSnapshotPath, _timeout, s_logger); command.add("-d", snapshotDestPath); command.add("-n", cmd.getSnapshotName()); + command.add("-f"); command.execute(); } catch (LibvirtException e) { return new Answer(cmd, false, e.toString()); diff --git a/scripts/storage/qcow2/createtmplt.sh b/scripts/storage/qcow2/createtmplt.sh index 84b081ce408..f9c72b7219b 100755 --- a/scripts/storage/qcow2/createtmplt.sh +++ b/scripts/storage/qcow2/createtmplt.sh @@ -78,7 +78,7 @@ create_from_file() { then rm -f $tmpltimg fi - chmod +r /$tmpltfs/$tmpltname + chmod a+r /$tmpltfs/$tmpltname } create_from_snapshot() { @@ -94,7 +94,7 @@ create_from_snapshot() { exit 2 fi - chmod +r /$tmpltfs/$tmpltname + chmod a+r /$tmpltfs/$tmpltname } tflag= @@ -168,7 +168,7 @@ else fi touch /$tmpltfs/template.properties -chmod +r /$tmpltfs/template.properties +chmod a+r /$tmpltfs/template.properties echo -n "" > /$tmpltfs/template.properties today=$(date '+%m_%d_%Y') diff --git a/scripts/storage/qcow2/managesnapshot.sh b/scripts/storage/qcow2/managesnapshot.sh index d9b339267a0..80db8febec1 100755 --- a/scripts/storage/qcow2/managesnapshot.sh +++ b/scripts/storage/qcow2/managesnapshot.sh @@ -43,8 +43,24 @@ create_snapshot() { destroy_snapshot() { local disk=$1 local snapshotname=$2 + local deleteDir=$3 local failed=0 + if [ -d $disk ] + then + if [ -f $disk/$snapshotname ] + then + rm -rf $disk/$snapshotname >& /dev/null + fi + + if [ "$deleteDir" == "1" ] + then + rm -rf %disk >& /dev/null + fi + + return $failed + fi + if [ ! -f $disk ] then failed=1 @@ -119,8 +135,9 @@ nflag= pathval= snapshot= tmplName= +deleteDir= -while getopts 'c:d:r:n:b:p:t:' OPTION +while getopts 'c:d:r:n:b:p:t:f' OPTION do case $OPTION in c) cflag=1 @@ -142,6 +159,8 @@ do ;; t) tmplName="$OPTARG" ;; + f) deleteDir=1 + ;; ?) usage ;; esac @@ -154,7 +173,7 @@ then exit $? elif [ "$dflag" == "1" ] then - destroy_snapshot $pathval $snapshot + destroy_snapshot $pathval $snapshot $deleteDir exit $? elif [ "$bflag" == "1" ] then