From bf83efcf4bd2c8ac5aacaf948826331ebb96b993 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Fri, 6 Sep 2013 14:33:34 -0700 Subject: [PATCH] CLOUDSTACK-4190:[Object_store_refactor] volume should be deleted from staging storage after successfule volume migration, specially handle DeleteVolume command for Vmware volume structure in secondary storage. --- .../resource/NfsSecondaryStorageResource.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index cf4369c9e44..3e19b641256 100755 --- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -1775,7 +1775,15 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S parent += File.separator; } String absoluteVolumePath = parent + relativeVolumePath; - File tmpltParent = new File(absoluteVolumePath).getParentFile(); + File volPath = new File(absoluteVolumePath); + File tmpltParent = null; + if (volPath.exists() && volPath.isDirectory()) { + // for vmware, absoluteVolumePath represents a directory where volume files are located. + tmpltParent = volPath; + } else{ + // for other hypervisors, the volume .vhd or .qcow2 file path is passed + tmpltParent = new File(absoluteVolumePath).getParentFile(); + } String details = null; if (!tmpltParent.exists()) { details = "volume parent directory " + tmpltParent.getName() + " doesn't exist"; @@ -1806,7 +1814,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S if (!f.delete()) { return new Answer(cmd, false, "Unable to delete file " + f.getName() + " under Volume path " - + relativeVolumePath); + + tmpltParent.getPath()); } } if (!found) { @@ -1816,7 +1824,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S } if (!tmpltParent.delete()) { details = "Unable to delete directory " + tmpltParent.getName() + " under Volume path " - + relativeVolumePath; + + tmpltParent.getPath(); s_logger.debug(details); return new Answer(cmd, false, details); }