bug 13777: propagate snapshot packaging failures up. Reviewed-By: Anthony

tar command random failure may occur due to linux kernal bug (or feature) that tar can't handle well. The failuar happens when tar wants to package a newly created file before file system has fully synced
This commit is contained in:
Kelven Yang 2012-02-17 14:50:10 -08:00
parent 8f273b0fac
commit bd9a250e12

View File

@ -1243,6 +1243,12 @@ public class VirtualMachineMO extends BaseMO {
// tar files into OVA // tar files into OVA
if(packToOva) { if(packToOva) {
// Important! we need to sync file system before we can safely use tar to work around a linux kernal bug(or feature)
s_logger.info("Sync file system before we package OVA...");
Script commandSync = new Script(true, "sync", 0, s_logger);
commandSync.execute();
Script command = new Script(false, "tar", 0, s_logger); Script command = new Script(false, "tar", 0, s_logger);
command.setWorkDir(exportDir); command.setWorkDir(exportDir);
command.add("-cf", exportName + ".ova"); command.add("-cf", exportName + ".ova");
@ -1251,11 +1257,14 @@ public class VirtualMachineMO extends BaseMO {
command.add((new File(name).getName())); command.add((new File(name).getName()));
} }
String result = command.execute(); s_logger.info("Package OVA with commmand: " + command.toString());
if(result == null) { command.execute();
// to be safe, physically test existence of the target OVA file
if((new File(exportDir + File.separator + exportName + ".ova")).exists()) {
success = true; success = true;
} else { } else {
s_logger.error("failed to execute command: " + command.toString()); s_logger.error(exportDir + File.separator + exportName + ".ova is not created as expected");
} }
} }
} }
@ -1270,12 +1279,10 @@ public class VirtualMachineMO extends BaseMO {
} }
} }
if(!success) { if(!success)
new File(exportDir + File.separator + exportName + ".ova").delete();
throw new Exception("Unable to finish the whole process to package as a OVA file"); throw new Exception("Unable to finish the whole process to package as a OVA file");
} }
} }
}
} finally { } finally {
leaseMo.updateLeaseProgress(100); leaseMo.updateLeaseProgress(100);
leaseMo.completeLease(); leaseMo.completeLease();