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(); out.close();
// 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");
@ -1250,13 +1256,16 @@ public class VirtualMachineMO extends BaseMO {
for(String name: fileNames) { for(String name: fileNames) {
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();
success = true;
// to be safe, physically test existence of the target OVA file
if((new File(exportDir + File.separator + exportName + ".ova")).exists()) {
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");
} }
} }
} }
} catch(Throwable e) { } catch(Throwable e) {
@ -1270,10 +1279,8 @@ 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 {