Skip to content

Commit 009af96

Browse files
nvazquezabhinandanprateek
authored andcommitted
CLOUDSTACK-9252: Support configurable nfs version
1 parent 206df75 commit 009af96

File tree

17 files changed

+144
-73
lines changed

17 files changed

+144
-73
lines changed

plugins/hypervisors/simulator/src/com/cloud/resource/AgentStorageResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
109109
}
110110

111111
@Override
112-
public String getRootDir(String url) {
112+
public String getRootDir(String url, String nfsVersion) {
113113
// TODO Auto-generated method stub
114114
return null;
115115
}

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public interface VmwareManager {
3636

3737
String getSystemVMDefaultNicAdapterType();
3838

39-
void prepareSecondaryStorageStore(String strStorageUrl);
39+
void prepareSecondaryStorageStore(String strStorageUrl, Long storeId);
4040

4141
void setupResourceStartupParams(Map<String, Object> params);
4242

@@ -48,7 +48,7 @@ public interface VmwareManager {
4848

4949
String getManagementPortGroupName();
5050

51-
String getSecondaryStorageStoreUrl(long dcId);
51+
Pair<String, Long> getSecondaryStorageStoreUrlAndId(long dcId);
5252

5353
File getSystemVMKeyFile();
5454

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
4747
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
4848
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
49+
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
4950
import org.apache.cloudstack.utils.identity.ManagementServerNode;
5051

5152
import com.cloud.agent.AgentManager;
@@ -167,6 +168,8 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
167168
private ManagementServerHostPeerDao _mshostPeerDao;
168169
@Inject
169170
private ClusterManager _clusterMgr;
171+
@Inject
172+
private ImageStoreDetailsDao _imageDetailsStoreDao;
170173

171174
private String _mountParent;
172175
private StorageLayer _storage;
@@ -439,12 +442,14 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
439442
}
440443

441444
@Override
442-
public String getSecondaryStorageStoreUrl(long dcId) {
445+
public Pair<String, Long> getSecondaryStorageStoreUrlAndId(long dcId) {
443446

444447
String secUrl = null;
448+
Long secId = null;
445449
DataStore secStore = _dataStoreMgr.getImageStore(dcId);
446450
if (secStore != null) {
447451
secUrl = secStore.getUri();
452+
secId = secStore.getId();
448453
}
449454

450455
if (secUrl == null) {
@@ -453,12 +458,13 @@ public String getSecondaryStorageStoreUrl(long dcId) {
453458
DataStore cacheStore = _dataStoreMgr.getImageCacheStore(dcId);
454459
if (cacheStore != null) {
455460
secUrl = cacheStore.getUri();
461+
secId = cacheStore.getId();
456462
} else {
457463
s_logger.warn("No staging storage is found when non-NFS secondary storage is used");
458464
}
459465
}
460466

461-
return secUrl;
467+
return new Pair<String, Long>(secUrl, secId);
462468
}
463469

464470
@Override
@@ -546,8 +552,17 @@ public boolean needRecycle(String workerTag) {
546552
}
547553

548554
@Override
549-
public void prepareSecondaryStorageStore(String storageUrl) {
550-
String mountPoint = getMountPoint(storageUrl);
555+
public void prepareSecondaryStorageStore(String storageUrl, Long storeId) {
556+
String nfsVersion = null;
557+
if (storeId != null){
558+
Map<String, String> details = _imageDetailsStoreDao.getDetails(storeId);
559+
for (String detailKey : details.keySet()) {
560+
if (detailKey.equals("nfs.version")){
561+
nfsVersion = details.get(detailKey);
562+
}
563+
}
564+
}
565+
String mountPoint = getMountPoint(storageUrl, nfsVersion);
551566

552567
GlobalLock lock = GlobalLock.getInternLock("prepare.systemvm");
553568
try {
@@ -655,7 +670,7 @@ public void run() {
655670
}
656671

657672
@Override
658-
public String getMountPoint(String storageUrl) {
673+
public String getMountPoint(String storageUrl, String nfsVersion) {
659674
String mountPoint = null;
660675
synchronized (_storageMounts) {
661676
mountPoint = _storageMounts.get(storageUrl);
@@ -670,7 +685,8 @@ public String getMountPoint(String storageUrl) {
670685
s_logger.error("Invalid storage URL format ", e);
671686
throw new CloudRuntimeException("Unable to create mount point due to invalid storage URL format " + storageUrl);
672687
}
673-
mountPoint = mount(uri.getHost() + ":" + uri.getPath(), _mountParent);
688+
689+
mountPoint = mount(uri.getHost() + ":" + uri.getPath(), _mountParent, nfsVersion);
674690
if (mountPoint == null) {
675691
s_logger.error("Unable to create mount point for " + storageUrl);
676692
return "/mnt/sec"; // throw new CloudRuntimeException("Unable to create mount point for " + storageUrl);
@@ -745,7 +761,7 @@ private void shutdownCleanup() {
745761
}
746762
}
747763

748-
protected String mount(String path, String parent) {
764+
protected String mount(String path, String parent, String nfsVersion) {
749765
String mountPoint = setupMountPoint(parent);
750766
if (mountPoint == null) {
751767
s_logger.warn("Unable to create a mount point");
@@ -756,6 +772,9 @@ protected String mount(String path, String parent) {
756772
String result = null;
757773
Script command = new Script(true, "mount", _timeout, s_logger);
758774
command.add("-t", "nfs");
775+
if (nfsVersion != null){
776+
command.add("-o", "vers=" + nfsVersion);
777+
}
759778
// command.add("-o", "soft,timeo=133,retrans=2147483647,tcp,acdirmax=0,acdirmin=0");
760779
if ("Mac OS X".equalsIgnoreCase(System.getProperty("os.name"))) {
761780
command.add("-o", "resvport");
@@ -1234,4 +1253,5 @@ public boolean hasNexusVSM(Long clusterId) {
12341253
return true;
12351254
}
12361255
}
1256+
12371257
}

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public String createOvaForTemplate(TemplateObjectTO template) {
156156
String secStorageUrl = nfsStore.getUrl();
157157
assert (secStorageUrl != null);
158158
String installPath = template.getPath();
159-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
159+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
160160
String installFullPath = secondaryMountPoint + "/" + installPath;
161161
try {
162162
if (installFullPath.endsWith(".ova")) {
@@ -194,7 +194,7 @@ public String createOvaForVolume(VolumeObjectTO volume) {
194194
String installPath = volume.getPath();
195195
int index = installPath.lastIndexOf(File.separator);
196196
String volumeUuid = installPath.substring(index + 1);
197-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
197+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
198198
//The real volume path
199199
String volumePath = installPath + File.separator + volumeUuid + ".ova";
200200
String installFullPath = secondaryMountPoint + "/" + installPath;
@@ -547,7 +547,7 @@ private void copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost,
547547
s_logger.info("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " +
548548
templatePathAtSecondaryStorage + ", templateName: " + templateName);
549549

550-
String secondaryMountPoint = _mountService.getMountPoint(secondaryStorageUrl);
550+
String secondaryMountPoint = _mountService.getMountPoint(secondaryStorageUrl, null);
551551
s_logger.info("Secondary storage mount point: " + secondaryMountPoint);
552552

553553
String srcOVAFileName = secondaryMountPoint + "/" + templatePathAtSecondaryStorage + templateName + "." + ImageFormat.OVA.getFileExtension();
@@ -600,7 +600,7 @@ private void copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost,
600600
private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vmMo, long accountId, long templateId, String templateUniqueName, String secStorageUrl,
601601
String volumePath, String workerVmName) throws Exception {
602602

603-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
603+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
604604
String installPath = getTemplateRelativeDirInSecStorage(accountId, templateId);
605605
String installFullPath = secondaryMountPoint + "/" + installPath;
606606
synchronized (installPath.intern()) {
@@ -665,7 +665,7 @@ private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vm
665665
private Ternary<String, Long, Long> createTemplateFromSnapshot(long accountId, long templateId, String templateUniqueName, String secStorageUrl, long volumeId,
666666
String backedUpSnapshotUuid) throws Exception {
667667

668-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
668+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
669669
String installPath = getTemplateRelativeDirInSecStorage(accountId, templateId);
670670
String installFullPath = secondaryMountPoint + "/" + installPath;
671671
String installFullOVAName = installFullPath + "/" + templateUniqueName + ".ova"; //Note: volss for tmpl
@@ -856,7 +856,7 @@ private String createVolumeFromSnapshot(VmwareHypervisorHost hyperHost, Datastor
856856
private void restoreVolumeFromSecStorage(VmwareHypervisorHost hyperHost, DatastoreMO primaryDsMo, String newVolumeName, String secStorageUrl, String secStorageDir,
857857
String backupName) throws Exception {
858858

859-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
859+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
860860
String srcOVAFileName = secondaryMountPoint + "/" + secStorageDir + "/" + backupName + "." + ImageFormat.OVA.getFileExtension();
861861
String snapshotDir = "";
862862
if (backupName.contains("/")) {
@@ -924,7 +924,7 @@ private String backupSnapshotToSecondaryStorage(VirtualMachineMO vmMo, long acco
924924
private void exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volumePath, String secStorageUrl, String secStorageDir, String exportName,
925925
String workerVmName) throws Exception {
926926

927-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
927+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
928928
String exportPath = secondaryMountPoint + "/" + secStorageDir + "/" + exportName;
929929

930930
synchronized (exportPath.intern()) {
@@ -1446,7 +1446,7 @@ public RevertToVMSnapshotAnswer execute(VmwareHostService hostService, RevertToV
14461446
}
14471447

14481448
private String deleteVolumeDirOnSecondaryStorage(long volumeId, String secStorageUrl) throws Exception {
1449-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl);
1449+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, null);
14501450
String volumeMountRoot = secondaryMountPoint + "/" + getVolumeRelativeDirInSecStroage(volumeId);
14511451

14521452
return deleteDir(volumeMountRoot);

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageMount.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
package com.cloud.hypervisor.vmware.manager;
1818

1919
public interface VmwareStorageMount {
20-
String getMountPoint(String storageUrl);
20+
String getMountPoint(String storageUrl, String nfsVersion);
2121
}

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,12 +1637,14 @@ protected StartAnswer execute(StartCommand cmd) {
16371637
// prepare systemvm patch ISO
16381638
if (vmSpec.getType() != VirtualMachine.Type.User) {
16391639
// attach ISO (for patching of system VM)
1640-
String secStoreUrl = mgr.getSecondaryStorageStoreUrl(Long.parseLong(_dcId));
1640+
Pair<String, Long> secStoreUrlAndId = mgr.getSecondaryStorageStoreUrlAndId(Long.parseLong(_dcId));
1641+
String secStoreUrl = secStoreUrlAndId.first();
1642+
Long secStoreId = secStoreUrlAndId.second();
16411643
if (secStoreUrl == null) {
16421644
String msg = "secondary storage for dc " + _dcId + " is not ready yet?";
16431645
throw new Exception(msg);
16441646
}
1645-
mgr.prepareSecondaryStorageStore(secStoreUrl);
1647+
mgr.prepareSecondaryStorageStore(secStoreUrl, secStoreId);
16461648

16471649
ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnHost(secStoreUrl);
16481650
if (morSecDs == null) {
@@ -3210,12 +3212,14 @@ protected Answer execute(PrepareForMigrationCommand cmd) {
32103212
prepareNetworkFromNicInfo(new HostMO(getServiceContext(), _morHyperHost), nic, false, cmd.getVirtualMachine().getType());
32113213
}
32123214

3213-
String secStoreUrl = mgr.getSecondaryStorageStoreUrl(Long.parseLong(_dcId));
3215+
Pair<String, Long> secStoreUrlAndId = mgr.getSecondaryStorageStoreUrlAndId(Long.parseLong(_dcId));
3216+
String secStoreUrl = secStoreUrlAndId.first();
3217+
Long secStoreId = secStoreUrlAndId.second();
32143218
if (secStoreUrl == null) {
32153219
String msg = "secondary storage for dc " + _dcId + " is not ready yet?";
32163220
throw new Exception(msg);
32173221
}
3218-
mgr.prepareSecondaryStorageStore(secStoreUrl);
3222+
mgr.prepareSecondaryStorageStore(secStoreUrl, secStoreId);
32193223

32203224
ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnHost(secStoreUrl);
32213225
if (morSecDs == null) {
@@ -3426,12 +3430,14 @@ protected Answer execute(MigrateWithStorageCommand cmd) {
34263430
}
34273431

34283432
// Ensure secondary storage mounted on target host
3429-
String secStoreUrl = mgr.getSecondaryStorageStoreUrl(Long.parseLong(_dcId));
3433+
Pair<String, Long> secStoreUrlAndId = mgr.getSecondaryStorageStoreUrlAndId(Long.parseLong(_dcId));
3434+
String secStoreUrl = secStoreUrlAndId.first();
3435+
Long secStoreId = secStoreUrlAndId.second();
34303436
if (secStoreUrl == null) {
34313437
String msg = "secondary storage for dc " + _dcId + " is not ready yet?";
34323438
throw new Exception(msg);
34333439
}
3434-
mgr.prepareSecondaryStorageStore(secStoreUrl);
3440+
mgr.prepareSecondaryStorageStore(secStoreUrl, secStoreId);
34353441
ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnSpecificHost(secStoreUrl, tgtHyperHost);
34363442
if (morSecDs == null) {
34373443
String msg = "Failed to prepare secondary storage on host, secondary store url: " + secStoreUrl;

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public String getWorkerName(VmwareContext context, Command cmd, int workerSequen
304304
}
305305

306306
@Override
307-
public String getMountPoint(String storageUrl) {
308-
return _resource.getRootDir(storageUrl);
307+
public String getMountPoint(String storageUrl, String nfsVersion) {
308+
return _resource.getRootDir(storageUrl, nfsVersion);
309309
}
310310
}

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private VirtualMachineMO copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost
160160
s_logger.info("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " +
161161
templatePathAtSecondaryStorage + ", templateName: " + templateName);
162162

163-
String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl);
163+
String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl, null);
164164
s_logger.info("Secondary storage mount point: " + secondaryMountPoint);
165165

166166
String srcOVAFileName =
@@ -539,7 +539,7 @@ private Pair<String, String> copyVolumeFromSecStorage(VmwareHypervisorHost hyper
539539
}
540540

541541
private String deleteVolumeDirOnSecondaryStorage(String volumeDir, String secStorageUrl) throws Exception {
542-
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl);
542+
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, null);
543543
String volumeMountRoot = secondaryMountPoint + File.separator + volumeDir;
544544

545545
return deleteDir(volumeMountRoot);
@@ -722,7 +722,7 @@ private void postCreatePrivateTemplate(String installFullPath, long templateId,
722722
private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vmMo, String installPath, long templateId, String templateUniqueName,
723723
String secStorageUrl, String volumePath, String workerVmName) throws Exception {
724724

725-
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl);
725+
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, null);
726726
String installFullPath = secondaryMountPoint + "/" + installPath;
727727
synchronized (installPath.intern()) {
728728
Script command = new Script(false, "mkdir", _timeout, s_logger);
@@ -899,7 +899,7 @@ private Ternary<String, Long, Long> createTemplateFromSnapshot(String installPat
899899
snapshotFolder = StringUtils.join(tokens, File.separator, 0, tokens.length - 1);
900900
}
901901

902-
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl);
902+
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, null);
903903
String installFullPath = secondaryMountPoint + "/" + installPath;
904904
String installFullOVAName = installFullPath + "/" + templateUniqueName + ".ova"; //Note: volss for tmpl
905905
String snapshotRoot = secondaryMountPoint + "/" + snapshotFolder;
@@ -1054,7 +1054,7 @@ public Answer createTemplateFromSnapshot(CopyCommand cmd) {
10541054
private Pair<String, String[]> exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volumePath, String secStorageUrl, String secStorageDir,
10551055
String exportName, String workerVmName) throws Exception {
10561056

1057-
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl);
1057+
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, null);
10581058
String exportPath = secondaryMountPoint + "/" + secStorageDir + "/" + exportName;
10591059

10601060
synchronized (exportPath.intern()) {
@@ -1186,7 +1186,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
11861186

11871187
// Get snapshot physical size
11881188
long physicalSize = 0l;
1189-
String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl);
1189+
String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl, null);
11901190
String snapshotDir = destSnapshot.getPath() + "/" + snapshotBackupUuid;
11911191
File[] files = new File(secondaryMountPoint + "/" + snapshotDir).listFiles();
11921192
if(files != null) {
@@ -2146,7 +2146,7 @@ private List<String> getManagedIqnsFromVirtualDisks(List<VirtualDisk> virtualDis
21462146
private Long restoreVolumeFromSecStorage(VmwareHypervisorHost hyperHost, DatastoreMO primaryDsMo, String newVolumeName, String secStorageUrl, String secStorageDir,
21472147
String backupName, long wait) throws Exception {
21482148

2149-
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl);
2149+
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, null);
21502150
String srcOVAFileName = null;
21512151
String srcOVFFileName = null;
21522152

0 commit comments

Comments
 (0)