cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raf...@apache.org
Subject [01/11] git commit: updated refs/heads/master to d705d85
Date Wed, 24 Feb 2016 20:24:32 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 8df8094a0 -> d705d8527


CLOUDSTACK-9252: Remove duplicates getNfsVersion, refactor


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/76dc2705
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/76dc2705
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/76dc2705

Branch: refs/heads/master
Commit: 76dc2705b7873f52b35c07ae742190c3515f4245
Parents: e524f65
Author: nvazquez <nicolas.m.vazquez@gmail.com>
Authored: Thu Jan 28 17:57:33 2016 -0200
Committer: nvazquez <nicolas.m.vazquez@gmail.com>
Committed: Mon Feb 1 12:50:58 2016 -0800

----------------------------------------------------------------------
 .../cloud/agent/api/BackupSnapshotCommand.java  |  9 +++
 ...reatePrivateTemplateFromSnapshotCommand.java |  9 +++
 .../CreatePrivateTemplateFromVolumeCommand.java |  9 +++
 .../api/CreateVolumeFromSnapshotCommand.java    | 10 +++
 .../agent/api/storage/CopyVolumeCommand.java    |  9 +++
 .../storage/PrimaryStorageDownloadCommand.java  |  9 +++
 .../TemplateOrVolumePostUploadCommand.java      | 10 +++
 .../storage/image/TemplateServiceImpl.java      | 17 +----
 .../MockLocalNfsSecondaryStorageResource.java   |  2 +-
 .../vmware/manager/VmwareManagerImpl.java       | 12 +---
 .../manager/VmwareStorageManagerImpl.java       | 65 +++++++++++---------
 .../resource/VmwareStorageProcessor.java        | 54 ++++++++--------
 .../VmwareStorageSubsystemCommandHandler.java   |  9 +--
 server/src/com/cloud/server/StatsCollector.java | 14 +----
 .../cloud/storage/ImageStoreDetailsUtil.java    | 59 ++++++++++++++++++
 .../SecondaryStorageManagerImpl.java            | 18 +-----
 .../resource/NfsSecondaryStorageResource.java   | 48 ++++++++-------
 .../storage/template/DownloadManagerImpl.java   |  3 +-
 18 files changed, 231 insertions(+), 135 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/core/src/com/cloud/agent/api/BackupSnapshotCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/BackupSnapshotCommand.java b/core/src/com/cloud/agent/api/BackupSnapshotCommand.java
index 2a46610..d93c32f 100644
--- a/core/src/com/cloud/agent/api/BackupSnapshotCommand.java
+++ b/core/src/com/cloud/agent/api/BackupSnapshotCommand.java
@@ -39,6 +39,7 @@ public class BackupSnapshotCommand extends SnapshotCommand {
     private S3TO s3;
     StorageFilerTO pool;
     private Long secHostId;
+    private String nfsVersion;
 
     protected BackupSnapshotCommand() {
 
@@ -107,4 +108,12 @@ public class BackupSnapshotCommand extends SnapshotCommand {
     public Long getSecHostId() {
         return secHostId;
     }
+
+    public String getNfsVersion() {
+        return nfsVersion;
+    }
+
+    public void setNfsVersion(String nfsVersion) {
+        this.nfsVersion = nfsVersion;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/core/src/com/cloud/agent/api/CreatePrivateTemplateFromSnapshotCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/CreatePrivateTemplateFromSnapshotCommand.java b/core/src/com/cloud/agent/api/CreatePrivateTemplateFromSnapshotCommand.java
index 7ac2dde..5a09994 100644
--- a/core/src/com/cloud/agent/api/CreatePrivateTemplateFromSnapshotCommand.java
+++ b/core/src/com/cloud/agent/api/CreatePrivateTemplateFromSnapshotCommand.java
@@ -28,6 +28,7 @@ public class CreatePrivateTemplateFromSnapshotCommand extends SnapshotCommand {
     private String origTemplateInstallPath;
     private Long newTemplateId;
     private String templateName;
+    private String nfsVersion;
 
     protected CreatePrivateTemplateFromSnapshotCommand() {
 
@@ -72,4 +73,12 @@ public class CreatePrivateTemplateFromSnapshotCommand extends SnapshotCommand {
     public String getTemplateName() {
         return templateName;
     }
+
+    public String getNfsVersion() {
+        return nfsVersion;
+    }
+
+    public void setNfsVersion(String nfsVersion) {
+        this.nfsVersion = nfsVersion;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/core/src/com/cloud/agent/api/CreatePrivateTemplateFromVolumeCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/CreatePrivateTemplateFromVolumeCommand.java b/core/src/com/cloud/agent/api/CreatePrivateTemplateFromVolumeCommand.java
index 3025147..b6cc6ac 100644
--- a/core/src/com/cloud/agent/api/CreatePrivateTemplateFromVolumeCommand.java
+++ b/core/src/com/cloud/agent/api/CreatePrivateTemplateFromVolumeCommand.java
@@ -32,6 +32,7 @@ public class CreatePrivateTemplateFromVolumeCommand extends SnapshotCommand {
     StorageFilerTO _primaryPool;
     // For XenServer
     private String _secondaryStorageUrl;
+    private String nfsVersion;
 
     public CreatePrivateTemplateFromVolumeCommand() {
     }
@@ -99,4 +100,12 @@ public class CreatePrivateTemplateFromVolumeCommand extends SnapshotCommand {
     public void setTemplateId(long templateId) {
         _templateId = templateId;
     }
+
+    public String getNfsVersion() {
+        return nfsVersion;
+    }
+
+    public void setNfsVersion(String nfsVersion) {
+        this.nfsVersion = nfsVersion;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/core/src/com/cloud/agent/api/CreateVolumeFromSnapshotCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/CreateVolumeFromSnapshotCommand.java b/core/src/com/cloud/agent/api/CreateVolumeFromSnapshotCommand.java
index fa9a4d5..933be03 100644
--- a/core/src/com/cloud/agent/api/CreateVolumeFromSnapshotCommand.java
+++ b/core/src/com/cloud/agent/api/CreateVolumeFromSnapshotCommand.java
@@ -26,6 +26,8 @@ import com.cloud.storage.StoragePool;
  */
 public class CreateVolumeFromSnapshotCommand extends SnapshotCommand {
 
+    private String nfsVersion;
+
     protected CreateVolumeFromSnapshotCommand() {
 
     }
@@ -50,4 +52,12 @@ public class CreateVolumeFromSnapshotCommand extends SnapshotCommand {
         super(pool, secondaryStoragePoolURL, backedUpSnapshotUuid, backedUpSnapshotName, dcId, accountId, volumeId);
         setWait(wait);
     }
+
+    public String getNfsVersion() {
+        return nfsVersion;
+    }
+
+    public void setNfsVersion(String nfsVersion) {
+        this.nfsVersion = nfsVersion;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/core/src/com/cloud/agent/api/storage/CopyVolumeCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/storage/CopyVolumeCommand.java b/core/src/com/cloud/agent/api/storage/CopyVolumeCommand.java
index 43c84ee..7ab822c 100644
--- a/core/src/com/cloud/agent/api/storage/CopyVolumeCommand.java
+++ b/core/src/com/cloud/agent/api/storage/CopyVolumeCommand.java
@@ -32,6 +32,7 @@ public class CopyVolumeCommand extends Command {
     boolean toSecondaryStorage;
     String vmName;
     boolean executeInSequence = false;
+    String nfsVersion;
 
     public CopyVolumeCommand() {
     }
@@ -75,4 +76,12 @@ public class CopyVolumeCommand extends Command {
     public String getVmName() {
         return vmName;
     }
+
+    public String getNfsVersion() {
+        return nfsVersion;
+    }
+
+    public void setNfsVersion(String nfsVersion) {
+        this.nfsVersion = nfsVersion;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java b/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
index ce8ed21..9dae513 100644
--- a/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
+++ b/core/src/com/cloud/agent/api/storage/PrimaryStorageDownloadCommand.java
@@ -35,6 +35,7 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand {
 
     String secondaryStorageUrl;
     String primaryStorageUrl;
+    String nfsVersion;
 
     protected PrimaryStorageDownloadCommand() {
     }
@@ -87,4 +88,12 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand {
     public boolean executeInSequence() {
         return true;
     }
+
+    public String getNfsVersion() {
+        return nfsVersion;
+    }
+
+    public void setNfsVersion(String nfsVersion) {
+        this.nfsVersion = nfsVersion;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java
----------------------------------------------------------------------
diff --git a/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java b/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java
index 5d1e56b..bfcd9ae 100644
--- a/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java
+++ b/core/src/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java
@@ -53,6 +53,8 @@ public class TemplateOrVolumePostUploadCommand {
 
     private long accountId;
 
+    private String nfsVersion;
+
     public TemplateOrVolumePostUploadCommand(long entityId, String entityUUID, String absolutePath, String checksum, String type, String name, String imageFormat, String dataTo,
             String dataToRole) {
         this.entityId = entityId;
@@ -196,4 +198,12 @@ public class TemplateOrVolumePostUploadCommand {
     public long getAccountId() {
         return accountId;
     }
+
+    public String getNfsVersion() {
+        return nfsVersion;
+    }
+
+    public void setNfsVersion(String nfsVersion) {
+        this.nfsVersion = nfsVersion;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
index cbfcb42..2a6159e 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
@@ -56,7 +56,6 @@ import org.apache.cloudstack.storage.command.CommandResult;
 import org.apache.cloudstack.storage.command.DeleteCommand;
 import org.apache.cloudstack.storage.datastore.DataObjectManager;
 import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
-import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
@@ -74,6 +73,7 @@ import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.ImageStoreDetailsUtil;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.TemplateType;
 import com.cloud.storage.StoragePool;
@@ -136,8 +136,6 @@ public class TemplateServiceImpl implements TemplateService {
     ConfigurationDao _configDao;
     @Inject
     StorageCacheManager _cacheMgr;
-    @Inject
-    ImageStoreDetailsDao _imageStoreDetailsDao;
 
     class TemplateOpContext<T> extends AsyncRpcContext<T> {
         final TemplateObject template;
@@ -567,7 +565,7 @@ public class TemplateServiceImpl implements TemplateService {
     }
 
     private Map<String, TemplateProp> listTemplate(DataStore ssStore) {
-        ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO(), getNfsVersion(ssStore.getId()));
+        ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO(), ImageStoreDetailsUtil.getNfsVersion(ssStore.getId()));
         EndPoint ep = _epSelector.select(ssStore);
         Answer answer = null;
         if (ep == null) {
@@ -589,17 +587,6 @@ public class TemplateServiceImpl implements TemplateService {
         return null;
     }
 
-    private String getNfsVersion(long storeId) {
-        String nfsVersion = null;
-        if (_imageStoreDetailsDao.getDetails(storeId) != null){
-            Map<String, String> storeDetails = _imageStoreDetailsDao.getDetails(storeId);
-            if (storeDetails != null && storeDetails.containsKey("nfs.version")){
-                nfsVersion = storeDetails.get("nfs.version");
-            }
-        }
-        return nfsVersion;
-    }
-
     protected Void createTemplateCallback(AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> callback, TemplateOpContext<TemplateApiResult> context) {
         TemplateObject template = context.getTemplate();
         AsyncCompletionCallback<TemplateApiResult> parentCallback = context.getParentCallback();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java
index 8963428..5c41dca 100644
--- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java
+++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java
@@ -51,7 +51,7 @@ public class MockLocalNfsSecondaryStorageResource extends NfsSecondaryStorageRes
     }
 
     @Override
-    public String getRootDir(String secUrl) {
+    public String getRootDir(String secUrl, String nfsVersion) {
         return "/mnt";
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 602a544..d51d96f 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -106,6 +106,7 @@ import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
 import com.cloud.org.Cluster.ClusterType;
 import com.cloud.secstorage.CommandExecLogDao;
 import com.cloud.server.ConfigurationServer;
+import com.cloud.storage.ImageStoreDetailsUtil;
 import com.cloud.storage.JavaStorageLayer;
 import com.cloud.storage.StorageLayer;
 import com.cloud.utils.FileUtil;
@@ -553,16 +554,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
 
     @Override
     public void prepareSecondaryStorageStore(String storageUrl, Long storeId) {
-        String nfsVersion = null;
-        if (storeId != null){
-            Map<String, String> details = _imageDetailsStoreDao.getDetails(storeId);
-            for (String detailKey : details.keySet()) {
-                if (detailKey.equals("nfs.version")){
-                    nfsVersion = details.get(detailKey);
-                }
-            }
-        }
-        String mountPoint = getMountPoint(storageUrl, nfsVersion);
+        String mountPoint = getMountPoint(storageUrl, ImageStoreDetailsUtil.getNfsVersion(storeId));
 
         GlobalLock lock = GlobalLock.getInternLock("prepare.systemvm");
         try {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
index f87fe6c..b41a147 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
@@ -77,6 +77,7 @@ import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
 import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
 import com.cloud.hypervisor.vmware.util.VmwareContext;
 import com.cloud.hypervisor.vmware.util.VmwareHelper;
+import com.cloud.storage.ImageStoreDetailsUtil;
 import com.cloud.storage.JavaStorageLayer;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.StorageLayer;
@@ -156,7 +157,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
         String secStorageUrl = nfsStore.getUrl();
         assert (secStorageUrl != null);
         String installPath = template.getPath();
-        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
+        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, ImageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
         String installFullPath = secondaryMountPoint + "/" + installPath;
         try {
             if (installFullPath.endsWith(".ova")) {
@@ -194,7 +195,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
         String installPath = volume.getPath();
         int index = installPath.lastIndexOf(File.separator);
         String volumeUuid = installPath.substring(index + 1);
-        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
+        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, ImageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
         //The real volume path
         String volumePath = installPath + File.separator + volumeUuid + ".ova";
         String installFullPath = secondaryMountPoint + "/" + installPath;
@@ -271,7 +272,8 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
                 assert (morDs != null);
                 DatastoreMO primaryStorageDatastoreMo = new DatastoreMO(context, morDs);
 
-                copyTemplateFromSecondaryToPrimary(hyperHost, primaryStorageDatastoreMo, secondaryStorageUrl, mountPoint, templateName, templateUuidName);
+                copyTemplateFromSecondaryToPrimary(hyperHost, primaryStorageDatastoreMo, secondaryStorageUrl, mountPoint, templateName, templateUuidName,
+                        cmd.getNfsVersion());
             } else {
                 s_logger.info("Template " + templateName + " has already been setup, skip the template setup process in primary storage");
             }
@@ -345,7 +347,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
 
                 snapshotBackupUuid =
                         backupSnapshotToSecondaryStorage(vmMo, accountId, volumeId, cmd.getVolumePath(), snapshotUuid, secondaryStorageUrl, prevSnapshotUuid, prevBackupUuid,
-                                hostService.getWorkerName(context, cmd, 1));
+                                hostService.getWorkerName(context, cmd, 1), cmd.getNfsVersion());
 
                 success = (snapshotBackupUuid != null);
                 if (success) {
@@ -413,7 +415,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
 
             Ternary<String, Long, Long> result =
                     createTemplateFromVolume(vmMo, accountId, templateId, cmd.getUniqueName(), secondaryStoragePoolURL, volumePath,
-                            hostService.getWorkerName(context, cmd, 0));
+                            hostService.getWorkerName(context, cmd, 0), cmd.getNfsVersion());
 
             return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), cmd.getUniqueName(), ImageFormat.OVA);
 
@@ -441,7 +443,8 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
 
         VmwareContext context = hostService.getServiceContext(cmd);
         try {
-            Ternary<String, Long, Long> result = createTemplateFromSnapshot(accountId, newTemplateId, uniqeName, secondaryStorageUrl, volumeId, backedUpSnapshotUuid);
+            Ternary<String, Long, Long> result = createTemplateFromSnapshot(accountId, newTemplateId, uniqeName, secondaryStorageUrl, volumeId, backedUpSnapshotUuid,
+                    cmd.getNfsVersion());
 
             return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), uniqeName, ImageFormat.OVA);
         } catch (Throwable e) {
@@ -471,7 +474,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
             if (cmd.toSecondaryStorage()) {
                 result =
                         copyVolumeToSecStorage(hostService, hyperHost, cmd, vmName, volumeId, cmd.getPool().getUuid(), volumePath, secondaryStorageURL,
-                                hostService.getWorkerName(context, cmd, 0));
+                                hostService.getWorkerName(context, cmd, 0), cmd.getNfsVersion());
             } else {
                 StorageFilerTO poolTO = cmd.getPool();
 
@@ -484,8 +487,9 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
                     }
                 }
 
-                result = copyVolumeFromSecStorage(hyperHost, volumeId, new DatastoreMO(context, morDatastore), secondaryStorageURL, volumePath);
-                deleteVolumeDirOnSecondaryStorage(volumeId, secondaryStorageURL);
+                result = copyVolumeFromSecStorage(hyperHost, volumeId, new DatastoreMO(context, morDatastore), secondaryStorageURL, volumePath,
+                        cmd.getNfsVersion());
+                deleteVolumeDirOnSecondaryStorage(volumeId, secondaryStorageURL, cmd.getNfsVersion());
             }
             return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second());
         } catch (Throwable e) {
@@ -523,7 +527,8 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
             }
 
             DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
-            details = createVolumeFromSnapshot(hyperHost, primaryDsMo, newVolumeName, accountId, volumeId, secondaryStorageUrl, backedUpSnapshotUuid);
+            details = createVolumeFromSnapshot(hyperHost, primaryDsMo, newVolumeName, accountId, volumeId, secondaryStorageUrl, backedUpSnapshotUuid,
+                    cmd.getNfsVersion());
             if (details == null) {
                 success = true;
             }
@@ -542,12 +547,12 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
     // templateName: name in secondary storage
     // templateUuid: will be used at hypervisor layer
     private void copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, DatastoreMO datastoreMo, String secondaryStorageUrl,
-            String templatePathAtSecondaryStorage, String templateName, String templateUuid) throws Exception {
+            String templatePathAtSecondaryStorage, String templateName, String templateUuid, String nfsVersion) throws Exception {
 
         s_logger.info("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " +
                 templatePathAtSecondaryStorage + ", templateName: " + templateName);
 
-        String secondaryMountPoint = _mountService.getMountPoint(secondaryStorageUrl, null);
+        String secondaryMountPoint = _mountService.getMountPoint(secondaryStorageUrl, nfsVersion);
         s_logger.info("Secondary storage mount point: " + secondaryMountPoint);
 
         String srcOVAFileName = secondaryMountPoint + "/" + templatePathAtSecondaryStorage + templateName + "." + ImageFormat.OVA.getFileExtension();
@@ -598,9 +603,9 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
     }
 
     private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vmMo, long accountId, long templateId, String templateUniqueName, String secStorageUrl,
-            String volumePath, String workerVmName) throws Exception {
+            String volumePath, String workerVmName, String nfsVersion) throws Exception {
 
-        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
+        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, nfsVersion);
         String installPath = getTemplateRelativeDirInSecStorage(accountId, templateId);
         String installFullPath = secondaryMountPoint + "/" + installPath;
         synchronized (installPath.intern()) {
@@ -663,9 +668,9 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
     }
 
     private Ternary<String, Long, Long> createTemplateFromSnapshot(long accountId, long templateId, String templateUniqueName, String secStorageUrl, long volumeId,
-            String backedUpSnapshotUuid) throws Exception {
+            String backedUpSnapshotUuid, String nfsVersion) throws Exception {
 
-        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
+        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, nfsVersion);
         String installPath = getTemplateRelativeDirInSecStorage(accountId, templateId);
         String installFullPath = secondaryMountPoint + "/" + installPath;
         String installFullOVAName = installFullPath + "/" + templateUniqueName + ".ova";  //Note: volss for tmpl
@@ -847,16 +852,16 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
     }
 
     private String createVolumeFromSnapshot(VmwareHypervisorHost hyperHost, DatastoreMO primaryDsMo, String newVolumeName, long accountId, long volumeId,
-            String secStorageUrl, String snapshotBackupUuid) throws Exception {
+            String secStorageUrl, String snapshotBackupUuid, String nfsVersion) throws Exception {
 
-        restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secStorageUrl, getSnapshotRelativeDirInSecStorage(accountId, volumeId), snapshotBackupUuid);
+        restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secStorageUrl, getSnapshotRelativeDirInSecStorage(accountId, volumeId), snapshotBackupUuid, nfsVersion);
         return null;
     }
 
     private void restoreVolumeFromSecStorage(VmwareHypervisorHost hyperHost, DatastoreMO primaryDsMo, String newVolumeName, String secStorageUrl, String secStorageDir,
-            String backupName) throws Exception {
+            String backupName, String nfsVersion) throws Exception {
 
-        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
+        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, nfsVersion);
         String srcOVAFileName = secondaryMountPoint + "/" + secStorageDir + "/" + backupName + "." + ImageFormat.OVA.getFileExtension();
         String snapshotDir = "";
         if (backupName.contains("/")) {
@@ -914,17 +919,17 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
     }
 
     private String backupSnapshotToSecondaryStorage(VirtualMachineMO vmMo, long accountId, long volumeId, String volumePath, String snapshotUuid, String secStorageUrl,
-            String prevSnapshotUuid, String prevBackupUuid, String workerVmName) throws Exception {
+            String prevSnapshotUuid, String prevBackupUuid, String workerVmName, String nfsVersion) throws Exception {
 
         String backupUuid = UUID.randomUUID().toString();
-        exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, getSnapshotRelativeDirInSecStorage(accountId, volumeId), backupUuid, workerVmName);
+        exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, getSnapshotRelativeDirInSecStorage(accountId, volumeId), backupUuid, workerVmName, nfsVersion);
         return backupUuid + "/" + backupUuid;
     }
 
     private void exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volumePath, String secStorageUrl, String secStorageDir, String exportName,
-            String workerVmName) throws Exception {
+            String workerVmName, String nfsVersion) throws Exception {
 
-        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
+        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, nfsVersion);
         String exportPath = secondaryMountPoint + "/" + secStorageDir + "/" + exportName;
 
         synchronized (exportPath.intern()) {
@@ -967,7 +972,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
     }
 
     private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostService, VmwareHypervisorHost hyperHost, CopyVolumeCommand cmd, String vmName,
-            long volumeId, String poolId, String volumePath, String secStorageUrl, String workerVmName) throws Exception {
+            long volumeId, String poolId, String volumePath, String secStorageUrl, String workerVmName, String nfsVersion) throws Exception {
 
         String volumeFolder = String.valueOf(volumeId) + "/";
         VirtualMachineMO workerVm = null;
@@ -1004,7 +1009,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
             vmMo.createSnapshot(exportName, "Temporary snapshot for copy-volume command", false, false);
 
             exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, "volumes/" + volumeFolder, exportName,
-                    hostService.getWorkerName(hyperHost.getContext(), cmd, 1));
+                    hostService.getWorkerName(hyperHost.getContext(), cmd, 1), nfsVersion);
             return new Pair<String, String>(volumeFolder, exportName);
 
         } finally {
@@ -1025,12 +1030,12 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
         return datastoreVolumePath;
     }
 
-    private Pair<String, String> copyVolumeFromSecStorage(VmwareHypervisorHost hyperHost, long volumeId, DatastoreMO dsMo, String secStorageUrl, String exportName)
+    private Pair<String, String> copyVolumeFromSecStorage(VmwareHypervisorHost hyperHost, long volumeId, DatastoreMO dsMo, String secStorageUrl, String exportName, String nfsVersion)
             throws Exception {
 
         String volumeFolder = String.valueOf(volumeId) + "/";
         String newVolume = UUID.randomUUID().toString().replaceAll("-", "");
-        restoreVolumeFromSecStorage(hyperHost, dsMo, newVolume, secStorageUrl, "volumes/" + volumeFolder, exportName);
+        restoreVolumeFromSecStorage(hyperHost, dsMo, newVolume, secStorageUrl, "volumes/" + volumeFolder, exportName, nfsVersion);
 
         return new Pair<String, String>(volumeFolder, newVolume);
     }
@@ -1445,8 +1450,8 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
         }
     }
 
-    private String deleteVolumeDirOnSecondaryStorage(long volumeId, String secStorageUrl) throws Exception {
-        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
+    private String deleteVolumeDirOnSecondaryStorage(long volumeId, String secStorageUrl, String nfsVersion) throws Exception {
+        String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, nfsVersion);
         String volumeMountRoot = secondaryMountPoint + "/" + getVolumeRelativeDirInSecStroage(volumeId);
 
         return deleteDir(volumeMountRoot);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
index 35e775f..2163324 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
@@ -96,6 +96,7 @@ import com.cloud.hypervisor.vmware.util.VmwareContext;
 import com.cloud.hypervisor.vmware.util.VmwareHelper;
 import com.cloud.serializer.GsonHelper;
 import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.ImageStoreDetailsUtil;
 import com.cloud.storage.JavaStorageLayer;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.StorageLayer;
@@ -155,12 +156,12 @@ public class VmwareStorageProcessor implements StorageProcessor {
     }
 
     private VirtualMachineMO copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, DatastoreMO datastoreMo, String secondaryStorageUrl,
-            String templatePathAtSecondaryStorage, String templateName, String templateUuid, boolean createSnapshot) throws Exception {
+            String templatePathAtSecondaryStorage, String templateName, String templateUuid, boolean createSnapshot, String nfsVersion) throws Exception {
 
         s_logger.info("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " +
                 templatePathAtSecondaryStorage + ", templateName: " + templateName);
 
-        String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl, null);
+        String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl, nfsVersion);
         s_logger.info("Secondary storage mount point: " + secondaryMountPoint);
 
         String srcOVAFileName =
@@ -316,7 +317,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
 
                 if (managed) {
                     VirtualMachineMO vmMo = copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, templateInfo.first(), templateInfo.second(),
-                            managedStoragePoolRootVolumeName, false);
+                            managedStoragePoolRootVolumeName, false, ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
 
                     vmMo.unregisterVm();
 
@@ -333,7 +334,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
                 }
                 else {
                     copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, templateInfo.first(), templateInfo.second(),
-                            templateUuidName, true);
+                            templateUuidName, true, ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
                 }
             } else {
                 s_logger.info("Template " + templateInfo.second() + " has already been setup, skip the template setup process in primary storage");
@@ -518,7 +519,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
         }
     }
 
-    private Pair<String, String> copyVolumeFromSecStorage(VmwareHypervisorHost hyperHost, String srcVolumePath, DatastoreMO dsMo, String secStorageUrl, long wait) throws Exception {
+    private Pair<String, String> copyVolumeFromSecStorage(VmwareHypervisorHost hyperHost, String srcVolumePath, DatastoreMO dsMo, String secStorageUrl, long wait, String nfsVersion) throws Exception {
 
         String volumeFolder = null;
         String volumeName = null;
@@ -533,13 +534,13 @@ public class VmwareStorageProcessor implements StorageProcessor {
         }
 
         String newVolume = VmwareHelper.getVCenterSafeUuid();
-        restoreVolumeFromSecStorage(hyperHost, dsMo, newVolume, secStorageUrl, volumeFolder, volumeName, wait);
+        restoreVolumeFromSecStorage(hyperHost, dsMo, newVolume, secStorageUrl, volumeFolder, volumeName, wait, nfsVersion);
 
         return new Pair<String, String>(volumeFolder, newVolume);
     }
 
-    private String deleteVolumeDirOnSecondaryStorage(String volumeDir, String secStorageUrl) throws Exception {
-        String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, null);
+    private String deleteVolumeDirOnSecondaryStorage(String volumeDir, String secStorageUrl, String nfsVersion) throws Exception {
+        String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, nfsVersion);
         String volumeMountRoot = secondaryMountPoint + File.separator + volumeDir;
 
         return deleteDir(volumeMountRoot);
@@ -578,8 +579,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
                 }
             }
 
-            Pair<String, String> result = copyVolumeFromSecStorage(hyperHost, srcVolume.getPath(), new DatastoreMO(context, morDatastore), srcStore.getUrl(), (long)cmd.getWait() * 1000);
-            deleteVolumeDirOnSecondaryStorage(result.first(), srcStore.getUrl());
+            Pair<String, String> result = copyVolumeFromSecStorage(hyperHost, srcVolume.getPath(), new DatastoreMO(context, morDatastore), srcStore.getUrl(), (long)cmd.getWait() * 1000, ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
+            deleteVolumeDirOnSecondaryStorage(result.first(), srcStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(uuid));
             VolumeObjectTO newVolume = new VolumeObjectTO();
             newVolume.setPath(result.second());
             return new CopyCmdAnswer(newVolume);
@@ -636,7 +637,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
 
             vmMo.createSnapshot(exportName, "Temporary snapshot for copy-volume command", false, false);
 
-            exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, destVolumePath, exportName, hostService.getWorkerName(hyperHost.getContext(), cmd, 1));
+            exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, destVolumePath, exportName, hostService.getWorkerName(hyperHost.getContext(), cmd, 1),
+                   ImageStoreDetailsUtil.getNfsVersionByUuid(cmd.getDestTO().getDataStore().getUuid()));
             return new Pair<String, String>(destVolumePath, exportName);
 
         } finally {
@@ -720,9 +722,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
     }
 
     private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vmMo, String installPath, long templateId, String templateUniqueName,
-            String secStorageUrl, String volumePath, String workerVmName) throws Exception {
+            String secStorageUrl, String volumePath, String workerVmName, String nfsVersion) throws Exception {
 
-        String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, null);
+        String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, nfsVersion);
         String installFullPath = secondaryMountPoint + "/" + installPath;
         synchronized (installPath.intern()) {
             Script command = new Script(false, "mkdir", _timeout, s_logger);
@@ -838,7 +840,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
 
             Ternary<String, Long, Long> result =
                     createTemplateFromVolume(vmMo, template.getPath(), template.getId(), template.getName(), secondaryStoragePoolURL, volumePath,
-                            hostService.getWorkerName(context, cmd, 0));
+                            hostService.getWorkerName(context, cmd, 0), ImageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
 
             TemplateObjectTO newTemplate = new TemplateObjectTO();
             newTemplate.setPath(result.first());
@@ -885,7 +887,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
     }
 
     private Ternary<String, Long, Long> createTemplateFromSnapshot(String installPath, String templateUniqueName, String secStorageUrl, String snapshotPath,
-            Long templateId, long wait) throws Exception {
+            Long templateId, long wait, String nfsVersion) throws Exception {
         //Snapshot path is decoded in this form: /snapshots/account/volumeId/uuid/uuid
         String backupSSUuid;
         String snapshotFolder;
@@ -899,7 +901,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
             snapshotFolder = StringUtils.join(tokens, File.separator, 0, tokens.length - 1);
         }
 
-        String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, null);
+        String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, nfsVersion);
         String installFullPath = secondaryMountPoint + "/" + installPath;
         String installFullOVAName = installFullPath + "/" + templateUniqueName + ".ova";  //Note: volss for tmpl
         String snapshotRoot = secondaryMountPoint + "/" + snapshotFolder;
@@ -1029,7 +1031,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
             }
 
             NfsTO nfsSvr = (NfsTO)imageStore;
-            Ternary<String, Long, Long> result = createTemplateFromSnapshot(template.getPath(), uniqeName, nfsSvr.getUrl(), snapshot.getPath(), template.getId(), (long)cmd.getWait() * 1000);
+            Ternary<String, Long, Long> result = createTemplateFromSnapshot(template.getPath(), uniqeName, nfsSvr.getUrl(), snapshot.getPath(), template.getId(), (long)cmd.getWait() * 1000,
+                    ImageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
 
             TemplateObjectTO newTemplate = new TemplateObjectTO();
             newTemplate.setPath(result.first());
@@ -1052,9 +1055,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
 
     // return Pair<String(divice bus name), String[](disk chain)>
     private Pair<String, String[]> exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volumePath, String secStorageUrl, String secStorageDir,
-            String exportName, String workerVmName) throws Exception {
+            String exportName, String workerVmName, String nfsVersion) throws Exception {
 
-        String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, null);
+        String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, nfsVersion);
         String exportPath = secondaryMountPoint + "/" + secStorageDir + "/" + exportName;
 
         synchronized (exportPath.intern()) {
@@ -1096,10 +1099,10 @@ public class VmwareStorageProcessor implements StorageProcessor {
 
     // Ternary<String(backup uuid in secondary storage), String(device bus name), String[](original disk chain in the snapshot)>
     private Ternary<String, String, String[]> backupSnapshotToSecondaryStorage(VirtualMachineMO vmMo, String installPath, String volumePath, String snapshotUuid,
-            String secStorageUrl, String prevSnapshotUuid, String prevBackupUuid, String workerVmName) throws Exception {
+            String secStorageUrl, String prevSnapshotUuid, String prevBackupUuid, String workerVmName, String nfsVersion) throws Exception {
 
         String backupUuid = UUID.randomUUID().toString();
-        Pair<String, String[]> snapshotInfo = exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, installPath, backupUuid, workerVmName);
+        Pair<String, String[]> snapshotInfo = exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, installPath, backupUuid, workerVmName, nfsVersion);
         return new Ternary<String, String, String[]>(backupUuid, snapshotInfo.first(), snapshotInfo.second());
     }
 
@@ -1172,9 +1175,10 @@ public class VmwareStorageProcessor implements StorageProcessor {
                     throw new Exception("Failed to take snapshot " + srcSnapshot.getName() + " on vm: " + vmName);
                 }
 
+                String nfsVersion = ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid());
                 backupResult =
                         backupSnapshotToSecondaryStorage(vmMo, destSnapshot.getPath(), srcSnapshot.getVolume().getPath(), snapshotUuid, secondaryStorageUrl,
-                                prevSnapshotUuid, prevBackupUuid, hostService.getWorkerName(context, cmd, 1));
+                                prevSnapshotUuid, prevBackupUuid, hostService.getWorkerName(context, cmd, 1), nfsVersion);
                 snapshotBackupUuid = backupResult.first();
 
                 success = (snapshotBackupUuid != null);
@@ -1186,7 +1190,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
 
                     // Get snapshot physical size
                     long physicalSize = 0l;
-                    String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl, null);
+                    String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl, nfsVersion);
                     String snapshotDir =  destSnapshot.getPath() + "/" + snapshotBackupUuid;
                     File[] files = new File(secondaryMountPoint + "/" + snapshotDir).listFiles();
                     if(files != null) {
@@ -2144,7 +2148,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
     }
 
     private Long restoreVolumeFromSecStorage(VmwareHypervisorHost hyperHost, DatastoreMO primaryDsMo, String newVolumeName, String secStorageUrl, String secStorageDir,
-            String backupName, long wait) throws Exception {
+            String backupName, long wait, String nfsVersion) throws Exception {
 
         String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, null);
         String srcOVAFileName = null;
@@ -2248,7 +2252,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
                 backedUpSnapshotUuid = backedUpSnapshotUuid.replace(".ovf", "");
             }
             DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
-            restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secondaryStorageUrl, backupPath, backedUpSnapshotUuid, (long)cmd.getWait() * 1000);
+            restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secondaryStorageUrl, backupPath, backedUpSnapshotUuid, (long)cmd.getWait() * 1000, ImageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
 
             VolumeObjectTO newVol = new VolumeObjectTO();
             newVol.setPath(newVolumeName);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java
index 5beab05..77a71f5 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java
@@ -21,7 +21,6 @@ package com.cloud.storage.resource;
 import java.io.File;
 
 import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.storage.command.CopyCmdAnswer;
 import org.apache.cloudstack.storage.command.CopyCommand;
 import org.apache.cloudstack.storage.command.DeleteCommand;
@@ -38,6 +37,7 @@ import com.cloud.agent.api.to.S3TO;
 import com.cloud.agent.api.to.SwiftTO;
 import com.cloud.hypervisor.vmware.manager.VmwareStorageManager;
 import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.ImageStoreDetailsUtil;
 
 public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemCommandHandlerBase {
     private static final Logger s_logger = Logger.getLogger(VmwareStorageSubsystemCommandHandler.class);
@@ -78,11 +78,12 @@ public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemComman
             }
         }
 
+        String nfsVersion = ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid());
         if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole() == DataStoreRole.Image) {
             //need to take extra processing for vmware, such as packing to ova, before sending to S3
             if (srcData.getObjectType() == DataObjectType.VOLUME) {
                 NfsTO cacheStore = (NfsTO)srcDataStore;
-                String parentPath = storageResource.getRootDir(cacheStore.getUrl(), null);
+                String parentPath = storageResource.getRootDir(cacheStore.getUrl(), nfsVersion);
                 VolumeObjectTO vol = (VolumeObjectTO)srcData;
                 String path = vol.getPath();
                 int index = path.lastIndexOf(File.separator);
@@ -95,7 +96,7 @@ public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemComman
             } else if (srcData.getObjectType() == DataObjectType.SNAPSHOT) {
                 // pack ova first
                 // sync snapshot from NFS cache to S3 in NFS migration to S3 case
-                String parentPath = storageResource.getRootDir(srcDataStore.getUrl(), null);
+                String parentPath = storageResource.getRootDir(srcDataStore.getUrl(), nfsVersion);
                 SnapshotObjectTO snap = (SnapshotObjectTO)srcData;
                 String path = snap.getPath();
                 int index = path.lastIndexOf(File.separator);
@@ -138,7 +139,7 @@ public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemComman
                     return answer;
                 }
                 NfsTO cacheStore = (NfsTO)cmd.getCacheTO().getDataStore();
-                String parentPath = storageResource.getRootDir(cacheStore.getUrl(), null);
+                String parentPath = storageResource.getRootDir(cacheStore.getUrl(), nfsVersion);
                 SnapshotObjectTO newSnapshot = (SnapshotObjectTO)answer.getNewData();
                 String path = newSnapshot.getPath();
                 int index = path.lastIndexOf(File.separator);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/server/src/com/cloud/server/StatsCollector.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/StatsCollector.java b/server/src/com/cloud/server/StatsCollector.java
index c66ada8..cb73ecb 100644
--- a/server/src/com/cloud/server/StatsCollector.java
+++ b/server/src/com/cloud/server/StatsCollector.java
@@ -36,7 +36,6 @@ import javax.inject.Inject;
 import org.apache.cloudstack.utils.usage.UsageUtils;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
@@ -91,6 +90,7 @@ import com.cloud.resource.ResourceManager;
 import com.cloud.resource.ResourceState;
 import com.cloud.service.ServiceOfferingVO;
 import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.storage.ImageStoreDetailsUtil;
 import com.cloud.storage.StorageManager;
 import com.cloud.storage.StorageStats;
 import com.cloud.storage.VolumeStats;
@@ -718,7 +718,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
                         continue;
                     }
 
-                    GetStorageStatsCommand command = new GetStorageStatsCommand(store.getTO(), getNfsVersion(store.getId()));
+                    GetStorageStatsCommand command = new GetStorageStatsCommand(store.getTO(), ImageStoreDetailsUtil.getNfsVersion(store.getId()));
                     EndPoint ssAhost = _epSelector.select(store);
                     if (ssAhost == null) {
                         s_logger.debug("There is no secondary storage VM for secondary storage host " + store.getName());
@@ -766,16 +766,6 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
             }
         }
 
-        private String getNfsVersion(long storeId) {
-            String nfsVersion = null;
-            if (_imageStoreDetailsDao.getDetails(storeId) != null){
-                Map<String, String> storeDetails = _imageStoreDetailsDao.getDetails(storeId);
-                if (storeDetails != null && storeDetails.containsKey("nfs.version")){
-                    nfsVersion = storeDetails.get("nfs.version");
-                }
-            }
-            return nfsVersion;
-        }
     }
 
     class AutoScaleMonitor extends ManagedContextRunnable {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/server/src/com/cloud/storage/ImageStoreDetailsUtil.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/ImageStoreDetailsUtil.java b/server/src/com/cloud/storage/ImageStoreDetailsUtil.java
new file mode 100755
index 0000000..48b33fa
--- /dev/null
+++ b/server/src/com/cloud/storage/ImageStoreDetailsUtil.java
@@ -0,0 +1,59 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.storage;
+
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
+
+public class ImageStoreDetailsUtil {
+
+    @Inject
+    private static ImageStoreDao imageStoreDao;
+    @Inject
+    private static ImageStoreDetailsDao imageStoreDetailsDao;
+
+    /**
+     * Obtain NFS protocol version (if provided) for a store id.<br/>
+     * It can be set by adding an entry in {@code image_store_details} table, providing {@code name=nfs.version} and {@code value=X} (e.g. 3)
+     * @param storeId image store id
+     * @return {@code null} if {@code nfs.version} is not found for storeId <br/>
+     * {@code X} if {@code nfs.version} is found found for storeId
+     */
+    public static String getNfsVersion(long storeId) {
+        String nfsVersion = null;
+        if (imageStoreDetailsDao.getDetails(storeId) != null){
+            Map<String, String> storeDetails = imageStoreDetailsDao.getDetails(storeId);
+            if (storeDetails != null && storeDetails.containsKey("nfs.version")){
+                nfsVersion = storeDetails.get("nfs.version");
+            }
+        }
+        return nfsVersion;
+    }
+
+    public static String getNfsVersionByUuid(String storeUuid){
+        ImageStoreVO imageStore = imageStoreDao.findByUuid(storeUuid);
+        if (imageStore != null){
+            return getNfsVersion(imageStore.getId());
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
index 1ae5d5b..a51b8d5 100644
--- a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
+++ b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
@@ -39,7 +39,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
-import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
@@ -102,6 +101,7 @@ import com.cloud.resource.ServerResource;
 import com.cloud.resource.UnableDeleteHostException;
 import com.cloud.service.ServiceOfferingVO;
 import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.storage.ImageStoreDetailsUtil;
 import com.cloud.storage.Storage;
 import com.cloud.storage.UploadVO;
 import com.cloud.storage.VMTemplateVO;
@@ -237,8 +237,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
     @Inject
     ImageStoreDao _imageStoreDao;
     @Inject
-    ImageStoreDetailsDao _imageStoreDetailsDao;
-    @Inject
     TemplateDataStoreDao _tmplStoreDao;
     @Inject
     VolumeDataStoreDao _volumeStoreDao;
@@ -313,7 +311,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
                     setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs);
                 }
 
-                setupCmd.setNfsVersion(getNfsVersion(ssStore.getId()));
+                setupCmd.setNfsVersion(ImageStoreDetailsUtil.getNfsVersion(ssStore.getId()));
 
                 //template/volume file upload key
                 String postUploadKey = _configDao.getValue(Config.SSVMPSK.key());
@@ -363,17 +361,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
         return true;
     }
 
-    private String getNfsVersion(long storeId) {
-        String nfsVersion = null;
-        if (_imageStoreDetailsDao.getDetails(storeId) != null){
-            Map<String, String> storeDetails = _imageStoreDetailsDao.getDetails(storeId);
-            if (storeDetails != null && storeDetails.containsKey("nfs.version")){
-                nfsVersion = storeDetails.get("nfs.version");
-            }
-        }
-        return nfsVersion;
-    }
-
     @Override
     public boolean generateVMSetupCommand(Long ssAHostId) {
         HostVO ssAHost = _hostDao.findById(ssAHostId);
@@ -1446,4 +1433,5 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
     public void setSecondaryStorageVmAllocators(List<SecondaryStorageVmAllocator> ssVmAllocators) {
         _ssVmAllocators = ssVmAllocators;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index b71c96f..3b32961 100644
--- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -53,6 +53,7 @@ import com.cloud.storage.template.TemplateConstants;
 import com.cloud.utils.EncryptionUtil;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
+
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelInitializer;
@@ -66,6 +67,7 @@ import io.netty.handler.codec.http.HttpRequestDecoder;
 import io.netty.handler.codec.http.HttpResponseEncoder;
 import io.netty.handler.logging.LogLevel;
 import io.netty.handler.logging.LoggingHandler;
+
 import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand;
 import org.apache.cloudstack.storage.template.UploadEntity;
 import org.apache.cloudstack.utils.imagestore.ImageStoreUtil;
@@ -144,6 +146,7 @@ import com.cloud.host.Host.Type;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.resource.ServerResourceBase;
 import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.ImageStoreDetailsUtil;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.StorageLayer;
 import com.cloud.storage.VMTemplateStorageResourceAssoc;
@@ -165,6 +168,7 @@ import com.cloud.utils.net.NetUtils;
 import com.cloud.utils.script.OutputInterpreter;
 import com.cloud.utils.script.Script;
 import com.cloud.vm.SecondaryStorageVm;
+
 import org.joda.time.DateTime;
 import org.joda.time.format.ISODateTimeFormat;
 
@@ -364,7 +368,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         final String storagePath = destImageStore.getUrl();
         final String destPath = destData.getPath();
         try {
-            String downloadPath = determineStorageTemplatePath(storagePath, destPath);
+            String downloadPath = determineStorageTemplatePath(storagePath, destPath, ImageStoreDetailsUtil.getNfsVersionByUuid(destImageStore.getUuid()));
             final File downloadDirectory = _storage.getFile(downloadPath);
 
             if (downloadDirectory.exists()) {
@@ -391,7 +395,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
 
         try {
 
-            String downloadPath = determineStorageTemplatePath(storagePath, destPath);
+            String downloadPath = determineStorageTemplatePath(storagePath, destPath, ImageStoreDetailsUtil.getNfsVersionByUuid(destImageStore.getUuid()));
             final File downloadDirectory = _storage.getFile(downloadPath);
 
             if (downloadDirectory.exists()) {
@@ -424,7 +428,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
 
     protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData,
             NfsTO destDataStore) {
-        String srcMountPoint = getRootDir(srcDataStore.getUrl(), null);
+        String srcMountPoint = getRootDir(srcDataStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
         String snapshotPath = srcData.getPath();
         int index = snapshotPath.lastIndexOf("/");
         String snapshotName = snapshotPath.substring(index + 1);
@@ -434,7 +438,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         snapshotPath = snapshotPath.substring(0, index);
 
         snapshotPath = srcMountPoint + File.separator + snapshotPath;
-        String destMountPoint = getRootDir(destDataStore.getUrl(), null);
+        String destMountPoint = getRootDir(destDataStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(destDataStore.getUuid()));
         String destPath = destMountPoint + File.separator + destData.getPath();
 
         String errMsg = null;
@@ -492,8 +496,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         if (srcData.getHypervisorType() == HypervisorType.XenServer) {
             return copySnapshotToTemplateFromNfsToNfsXenserver(cmd, srcData, srcDataStore, destData, destDataStore);
         } else if (srcData.getHypervisorType() == HypervisorType.KVM) {
-            File srcFile = getFile(srcData.getPath(), srcDataStore.getUrl());
-            File destFile = getFile(destData.getPath(), destDataStore.getUrl());
+            File srcFile = getFile(srcData.getPath(), srcDataStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
+            File destFile = getFile(destData.getPath(), destDataStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(destDataStore.getUuid()));
 
             VolumeObjectTO volumeObjectTO = srcData.getVolume();
             ImageFormat srcFormat = null;
@@ -577,8 +581,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         return new CopyCmdAnswer("");
     }
 
-    protected File getFile(String path, String nfsPath) {
-        String filePath = getRootDir(nfsPath, null) + File.separator + path;
+    protected File getFile(String path, String nfsPath, String nfsVersion) {
+        String filePath = getRootDir(nfsPath, nfsVersion) + File.separator + path;
         File f = new File(filePath);
         if (!f.exists()) {
             _storage.mkdirs(filePath);
@@ -610,7 +614,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
                 }
                 s_logger.debug("starting copy template to swift");
                 DataTO newTemplate = answer.getNewData();
-                File templateFile = getFile(newTemplate.getPath(), ((NfsTO)srcDataStore).getUrl());
+                File templateFile = getFile(newTemplate.getPath(), ((NfsTO)srcDataStore).getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
                 SwiftTO swift = (SwiftTO)destDataStore;
                 String containterName = SwiftUtil.getContainerName(destData.getObjectType().toString(), destData.getId());
                 String swiftPath = SwiftUtil.putObject(swift, templateFile, containterName, templateFile.getName());
@@ -717,8 +721,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         return Long.parseLong(StringUtils.substringAfterLast(StringUtils.substringBeforeLast(key, S3Utils.SEPARATOR), S3Utils.SEPARATOR));
     }
 
-    private String determineStorageTemplatePath(final String storagePath, String dataPath) {
-        return join(asList(getRootDir(storagePath, null), dataPath), File.separator);
+    private String determineStorageTemplatePath(final String storagePath, String dataPath, String nfsVersion) {
+        return join(asList(getRootDir(storagePath, nfsVersion), dataPath), File.separator);
     }
 
     protected File downloadFromUrlToNfs(String url, NfsTO nfs, String path, String name) {
@@ -732,7 +736,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
                 throw new CloudRuntimeException("Failed to get url: " + url);
             }
 
-            String nfsMountPath = getRootDir(nfs.getUrl(), null);
+            String nfsMountPath = getRootDir(nfs.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(nfs.getUuid()));
 
             String filePath = nfsMountPath + File.separator + path;
             File directory = new File(filePath);
@@ -897,7 +901,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         final S3TO s3 = (S3TO)destDataStore;
 
         try {
-            final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath());
+            final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath(), ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid()));
 
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath + " to upload to S3.");
@@ -1110,7 +1114,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         if (dstore instanceof NfsTO) {
             NfsTO nfs = (NfsTO)dstore;
             String relativeSnapshotPath = cmd.getDirectory();
-            String parent = getRootDir(nfs.getUrl(), null);
+            String parent = getRootDir(nfs.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
 
             if (relativeSnapshotPath.startsWith(File.separator)) {
                 relativeSnapshotPath = relativeSnapshotPath.substring(1);
@@ -1188,7 +1192,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
             return new Answer(cmd, false, "can't handle non nfs data store");
         }
         NfsTO nfsStore = (NfsTO)store;
-        String parent = getRootDir(nfsStore.getUrl(), null);
+        String parent = getRootDir(nfsStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(store.getUuid()));
 
         if (relativeTemplatePath.startsWith(File.separator)) {
             relativeTemplatePath = relativeTemplatePath.substring(1);
@@ -1409,7 +1413,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         DataStoreTO dstore = obj.getDataStore();
         if (dstore instanceof NfsTO) {
             NfsTO nfs = (NfsTO)dstore;
-            String parent = getRootDir(nfs.getUrl(), null);
+            String parent = getRootDir(nfs.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
             if (!parent.endsWith(File.separator)) {
                 parent += File.separator;
             }
@@ -1602,7 +1606,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         }
         DataStoreTO store = cmd.getDataStore();
         if (store instanceof NfsTO) {
-            String root = getRootDir(cmd.getSecUrl(), null);
+            String root = getRootDir(cmd.getSecUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(store.getUuid()));
             Map<Long, TemplateProp> templateInfos = _dlMgr.gatherVolumeInfo(root);
             return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
         } else if (store instanceof S3TO) {
@@ -1771,7 +1775,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         if (dstore instanceof NfsTO) {
             NfsTO nfs = (NfsTO)dstore;
             String relativeTemplatePath = obj.getPath();
-            String parent = getRootDir(nfs.getUrl(), null);
+            String parent = getRootDir(nfs.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
 
             if (relativeTemplatePath.startsWith(File.separator)) {
                 relativeTemplatePath = relativeTemplatePath.substring(1);
@@ -1875,7 +1879,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
         if (dstore instanceof NfsTO) {
             NfsTO nfs = (NfsTO)dstore;
             String relativeVolumePath = obj.getPath();
-            String parent = getRootDir(nfs.getUrl(), null);
+            String parent = getRootDir(nfs.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid()));
 
             if (relativeVolumePath.startsWith(File.separator)) {
                 relativeVolumePath = relativeVolumePath.substring(1);
@@ -2672,7 +2676,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
                 //relative path with out ssvm mount info.
                 uploadEntity.setTemplatePath(absolutePath);
                 String dataStoreUrl = cmd.getDataTo();
-                String installPathPrefix = this.getRootDir(dataStoreUrl, null) + File.separator + absolutePath;
+                String installPathPrefix = this.getRootDir(dataStoreUrl, cmd.getNfsVersion()) + File.separator + absolutePath;
                 uploadEntity.setInstallPathPrefix(installPathPrefix);
                 uploadEntity.setHvm(cmd.getRequiresHvm());
                 uploadEntity.setChksum(cmd.getChecksum());
@@ -2694,7 +2698,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
     }
 
     private synchronized void checkSecondaryStorageResourceLimit(TemplateOrVolumePostUploadCommand cmd, int contentLengthInGB) {
-        String rootDir = this.getRootDir(cmd.getDataTo(), null) + File.separator;
+        String rootDir = this.getRootDir(cmd.getDataTo(), cmd.getNfsVersion()) + File.separator;
         long accountId = cmd.getAccountId();
 
         long accountTemplateDirSize = 0;
@@ -2741,7 +2745,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
 
     private boolean isOneTimePostUrlUsed(TemplateOrVolumePostUploadCommand cmd) {
         String uuid = cmd.getEntityUUID();
-        String uploadPath = this.getRootDir(cmd.getDataTo(), null) + File.separator + cmd.getAbsolutePath();
+        String uploadPath = this.getRootDir(cmd.getDataTo(), cmd.getNfsVersion()) + File.separator + cmd.getAbsolutePath();
         return uploadEntityStateMap.containsKey(uuid) || new File(uploadPath).exists();
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/76dc2705/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
index 7829bf6..dec6005 100644
--- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
@@ -53,6 +53,7 @@ import com.cloud.agent.api.to.DataStoreTO;
 import com.cloud.agent.api.to.NfsTO;
 import com.cloud.agent.api.to.S3TO;
 import com.cloud.exception.InternalErrorException;
+import com.cloud.storage.ImageStoreDetailsUtil;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.StorageLayer;
 import com.cloud.storage.VMTemplateHostVO;
@@ -708,7 +709,7 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
         String installPathPrefix = cmd.getInstallPath();
         // for NFS, we need to get mounted path
         if (dstore instanceof NfsTO) {
-            installPathPrefix = resource.getRootDir(((NfsTO)dstore).getUrl(), null) + File.separator + installPathPrefix;
+            installPathPrefix = resource.getRootDir(((NfsTO)dstore).getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(dstore.getUuid())) + File.separator + installPathPrefix;
         }
         String user = null;
         String password = null;


Mime
View raw message