diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java index 382d1eb8cb0..227054169f8 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java @@ -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 {