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

@ -1242,7 +1242,13 @@ public class VirtualMachineMO extends BaseMO {
out.close();
// 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);
command.setWorkDir(exportDir);
command.add("-cf", exportName + ".ova");
@ -1250,13 +1256,16 @@ public class VirtualMachineMO extends BaseMO {
for(String name: fileNames) {
command.add((new File(name).getName()));
}
String result = command.execute();
if(result == null) {
success = true;
s_logger.info("Package OVA with commmand: " + command.toString());
command.execute();
// to be safe, physically test existence of the target OVA file
if((new File(exportDir + File.separator + exportName + ".ova")).exists()) {
success = true;
} else {
s_logger.error("failed to execute command: " + command.toString());
}
s_logger.error(exportDir + File.separator + exportName + ".ova is not created as expected");
}
}
}
} catch(Throwable e) {
@ -1270,10 +1279,8 @@ public class VirtualMachineMO extends BaseMO {
}
}
if(!success) {
new File(exportDir + File.separator + exportName + ".ova").delete();
if(!success)
throw new Exception("Unable to finish the whole process to package as a OVA file");
}
}
}
} finally {