mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 18:43:26 +01:00
bug 10363 : cleanup vhd in secondary storage if backsnapshot fails
Conflicts: core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
This commit is contained in:
parent
3c49258d0e
commit
fb8364ad0c
@ -3075,35 +3075,37 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||||||
|
|
||||||
// Each argument is put in a separate line for readability.
|
// Each argument is put in a separate line for readability.
|
||||||
// Using more lines does not harm the environment.
|
// Using more lines does not harm the environment.
|
||||||
|
String backupUuid = UUID.randomUUID().toString();
|
||||||
String results = callHostPluginAsync(conn, "vmopsSnapshot", "backupSnapshot", wait,
|
String results = callHostPluginAsync(conn, "vmopsSnapshot", "backupSnapshot", wait,
|
||||||
"primaryStorageSRUuid", primaryStorageSRUuid, "dcId", dcId.toString(), "accountId", accountId
|
"primaryStorageSRUuid", primaryStorageSRUuid, "dcId", dcId.toString(), "accountId", accountId.toString(),
|
||||||
.toString(), "volumeId", volumeId.toString(), "secondaryStorageMountPath",
|
"volumeId", volumeId.toString(), "secondaryStorageMountPath", secondaryStorageMountPath,
|
||||||
secondaryStorageMountPath, "snapshotUuid", snapshotUuid, "prevBackupUuid", prevBackupUuid, "isISCSI",
|
"snapshotUuid", snapshotUuid, "prevBackupUuid", prevBackupUuid, "backupUuid", backupUuid, "isISCSI", isISCSI.toString());
|
||||||
isISCSI.toString());
|
String errMsg = null;
|
||||||
|
|
||||||
if (results == null || results.isEmpty()) {
|
if (results == null || results.isEmpty()) {
|
||||||
// errString is already logged.
|
errMsg = "Could not copy backupUuid: " + backupSnapshotUuid + " of volumeId: " + volumeId
|
||||||
return null;
|
+ " from primary storage " + primaryStorageSRUuid + " to secondary storage "
|
||||||
}
|
+ secondaryStorageMountPath + " due to null";
|
||||||
|
} else {
|
||||||
|
|
||||||
String[] tmp = results.split("#");
|
String[] tmp = results.split("#");
|
||||||
String status = tmp[0];
|
String status = tmp[0];
|
||||||
backupSnapshotUuid = tmp[1];
|
backupSnapshotUuid = tmp[1];
|
||||||
|
|
||||||
// status == "1" if and only if backupSnapshotUuid != null
|
// status == "1" if and only if backupSnapshotUuid != null
|
||||||
// So we don't rely on status value but return backupSnapshotUuid as an
|
// So we don't rely on status value but return backupSnapshotUuid as an
|
||||||
// indicator of success.
|
// indicator of success.
|
||||||
String failureString = "Could not copy backupUuid: " + backupSnapshotUuid + " of volumeId: " + volumeId
|
|
||||||
+ " from primary storage " + primaryStorageSRUuid + " to secondary storage "
|
|
||||||
+ secondaryStorageMountPath;
|
|
||||||
if (status != null && status.equalsIgnoreCase("1") && backupSnapshotUuid != null) {
|
if (status != null && status.equalsIgnoreCase("1") && backupSnapshotUuid != null) {
|
||||||
s_logger.debug("Successfully copied backupUuid: " + backupSnapshotUuid + " of volumeId: " + volumeId
|
s_logger.debug("Successfully copied backupUuid: " + backupSnapshotUuid + " of volumeId: " + volumeId
|
||||||
+ " to secondary storage");
|
+ " to secondary storage");
|
||||||
} else {
|
|
||||||
s_logger.debug(failureString + ". Failed with status: " + status);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return backupSnapshotUuid;
|
return backupSnapshotUuid;
|
||||||
|
} else {
|
||||||
|
errMsg = "Could not copy backupUuid: " + backupSnapshotUuid + " of volumeId: " + volumeId
|
||||||
|
+ " from primary storage " + primaryStorageSRUuid + " to secondary storage "
|
||||||
|
+ secondaryStorageMountPath + " due to " + tmp[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s_logger.warn(errMsg);
|
||||||
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String callHostPluginAsync(Connection conn, String plugin, String cmd, int wait, String... params) {
|
protected String callHostPluginAsync(Connection conn, String plugin, String cmd, int wait, String... params) {
|
||||||
|
|||||||
@ -175,21 +175,16 @@ def isfile(path, isISCSI):
|
|||||||
def copyfile(fromFile, toFile, isISCSI):
|
def copyfile(fromFile, toFile, isISCSI):
|
||||||
util.SMlog("Starting to copy " + fromFile + " to " + toFile)
|
util.SMlog("Starting to copy " + fromFile + " to " + toFile)
|
||||||
errMsg = ''
|
errMsg = ''
|
||||||
if isISCSI:
|
|
||||||
try:
|
try:
|
||||||
cmd = ['dd', 'if=' + fromFile, 'of=' + toFile, 'bs=1M']
|
cmd = ['dd', 'if=' + fromFile, 'of=' + toFile, 'bs=4M']
|
||||||
txt = util.pread2(cmd)
|
txt = util.pread2(cmd)
|
||||||
except:
|
except:
|
||||||
txt = ''
|
|
||||||
errMsg = "Error while copying " + fromFile + " to " + toFile + " in ISCSI mode"
|
|
||||||
util.SMlog(errMsg)
|
|
||||||
raise xs_errors.XenError(errMsg)
|
|
||||||
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
shutil.copy2(fromFile, toFile)
|
os.system("rm -f " + toFile)
|
||||||
except OSError, (errno, strerror):
|
except:
|
||||||
errMsg = "Error while copying " + fromFile + " to " + toFile + " with errno: " + str(errno) + " and strerr: " + strerror
|
|
||||||
|
txt = ''
|
||||||
|
errMsg = "Error while copying " + fromFile + " to " + toFile + " in secondary storage"
|
||||||
util.SMlog(errMsg)
|
util.SMlog(errMsg)
|
||||||
raise xs_errors.XenError(errMsg)
|
raise xs_errors.XenError(errMsg)
|
||||||
|
|
||||||
@ -469,6 +464,7 @@ def backupSnapshot(session, args):
|
|||||||
secondaryStorageMountPath = args['secondaryStorageMountPath']
|
secondaryStorageMountPath = args['secondaryStorageMountPath']
|
||||||
snapshotUuid = args['snapshotUuid']
|
snapshotUuid = args['snapshotUuid']
|
||||||
prevBackupUuid = args['prevBackupUuid']
|
prevBackupUuid = args['prevBackupUuid']
|
||||||
|
backupUuid = args['backupUuid']
|
||||||
isISCSI = getIsTrueString(args['isISCSI'])
|
isISCSI = getIsTrueString(args['isISCSI'])
|
||||||
|
|
||||||
primarySRPath = getPrimarySRPath(primaryStorageSRUuid, isISCSI)
|
primarySRPath = getPrimarySRPath(primaryStorageSRUuid, isISCSI)
|
||||||
@ -488,8 +484,13 @@ def backupSnapshot(session, args):
|
|||||||
|
|
||||||
# Check existence of snapshot on primary storage
|
# Check existence of snapshot on primary storage
|
||||||
isfile(baseCopyPath, isISCSI)
|
isfile(baseCopyPath, isISCSI)
|
||||||
|
if prevBackupUuid:
|
||||||
|
# Check existence of prevBackupFile
|
||||||
|
prevBackupVHD = getBackupVHD(prevBackupUuid)
|
||||||
|
prevBackupFile = os.path.join(backupsDir, prevBackupVHD)
|
||||||
|
isfile(prevBackupFile, False)
|
||||||
|
|
||||||
# copy baseCopyPath to backupsDir with new uuid
|
# copy baseCopyPath to backupsDir with new uuid
|
||||||
backupUuid = util.gen_uuid()
|
|
||||||
backupVHD = getBackupVHD(backupUuid)
|
backupVHD = getBackupVHD(backupUuid)
|
||||||
backupFile = os.path.join(backupsDir, backupVHD)
|
backupFile = os.path.join(backupsDir, backupVHD)
|
||||||
util.SMlog("Back up " + baseCopyUuid + " to Secondary Storage as " + backupUuid)
|
util.SMlog("Back up " + baseCopyUuid + " to Secondary Storage as " + backupUuid)
|
||||||
@ -501,8 +502,6 @@ def backupSnapshot(session, args):
|
|||||||
# So set the parent of the current baseCopyVHD to prevBackupVHD
|
# So set the parent of the current baseCopyVHD to prevBackupVHD
|
||||||
if prevBackupUuid:
|
if prevBackupUuid:
|
||||||
# If there was a previous snapshot
|
# If there was a previous snapshot
|
||||||
prevBackupVHD = getBackupVHD(prevBackupUuid)
|
|
||||||
prevBackupFile = os.path.join(backupsDir, prevBackupVHD)
|
|
||||||
setParent(prevBackupFile, backupFile)
|
setParent(prevBackupFile, backupFile)
|
||||||
|
|
||||||
txt = "1#" + backupUuid
|
txt = "1#" + backupUuid
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user