bug 10363 : cleanup vhd in secondary storage if copy_vhd_to_secondarystorage fails

This commit is contained in:
anthony 2012-01-10 15:03:05 -08:00
parent fb596aa003
commit 924953220b
2 changed files with 21 additions and 11 deletions

View File

@ -2218,20 +2218,22 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
private String copy_vhd_to_secondarystorage(Connection conn, String mountpoint, String vdiuuid, String sruuid, int wait) {
String results = callHostPluginAsync(conn, "vmopspremium", "copy_vhd_to_secondarystorage",
wait, "mountpoint", mountpoint, "vdiuuid", vdiuuid, "sruuid", sruuid);
String errMsg = null;
if (results == null || results.isEmpty()) {
String msg = "copy_vhd_to_secondarystorage return null";
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
String[] tmp = results.split("#");
String status = tmp[0];
if (status.equals("0")) {
return tmp[1];
errMsg = "copy_vhd_to_secondarystorage return null";
} else {
s_logger.warn(tmp[1]);
throw new CloudRuntimeException(tmp[1]);
String[] tmp = results.split("#");
String status = tmp[0];
if (status.equals("0")) {
return tmp[1];
} else {
errMsg = tmp[1];
}
}
String source = vdiuuid + ".vhd";
killCopyProcess(conn, source);
s_logger.warn(errMsg);
throw new CloudRuntimeException(errMsg);
}
String upgradeSnapshot(Connection conn, String templatePath, String snapshotPath) {

View File

@ -67,6 +67,7 @@ vhdfile=$localmp/${vdiuuid}.vhd
if [ $type == "nfs" -o $type == "ext" ]; then
dd if=/var/run/sr-mount/$sruuid/${vdiuuid}.vhd of=$vhdfile bs=2M
if [ $? -ne 0 ]; then
rm -f $vhdfile
echo "8#failed to copy /var/run/sr-mount/$sruuid/${vdiuuid}.vhd to secondarystorage"
cleanup
exit 0
@ -88,10 +89,17 @@ elif [ $type == "lvmoiscsi" -o $type == "lvm" -o $type == "lvmohba" ]; then
size=$((size>>21))
size=$((size+1))
dd if=/dev/VG_XenStorage-$sruuid/VHD-$vdiuuid of=$vhdfile bs=2M count=$size
if [ $? -ne 0 ]; then
rm -f $vhdfile
echo "8#failed to copy /dev/VG_XenStorage-$sruuid/VHD-$vdiuuid to secondarystorage"
cleanup
exit 0
fi
#in byte unit
size=$((size<<21))
vhd-util modify -s $size -n $vhdfile
if [ $? -ne 0 ]; then
rm -f $vhdfile
echo "11#failed to change $vhdfile physical size"
cleanup
exit 0