Skip to content

Commit 3e92a63

Browse files
authored
[XenServer/XCP-ng] Pass the image store NFS version on storage commands (apache#5886)
* Add NFS version to mount command * Remove extra line * Extend NFS version to mount secondary storage * Unused import * Refactor NFS version to be granular * Make use of the ConfigKey on the NFS version setting value
1 parent 1fc7d70 commit 3e92a63

8 files changed

Lines changed: 79 additions & 64 deletions

File tree

core/src/main/java/org/apache/cloudstack/diagnostics/CopyToSecondaryStorageCommand.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ public class CopyToSecondaryStorageCommand extends StorageSubSystemCommand {
2222
private String secondaryStorageUrl;
2323
private String systemVmIp;
2424
private String fileName;
25+
private String nfsVersion;
2526

26-
public CopyToSecondaryStorageCommand(String secondaryStorageUrl, String systemVmIp, String fileName) {
27+
public CopyToSecondaryStorageCommand(String secondaryStorageUrl, String systemVmIp, String fileName, String nfsVersion) {
2728
this.secondaryStorageUrl = secondaryStorageUrl;
2829
this.systemVmIp = systemVmIp;
2930
this.fileName = fileName;
31+
this.nfsVersion = nfsVersion;
3032
}
3133

3234
public String getSecondaryStorageUrl() {
@@ -41,6 +43,10 @@ public String getFileName() {
4143
return fileName;
4244
}
4345

46+
public String getNfsVersion() {
47+
return nfsVersion;
48+
}
49+
4450
@Override
4551
public boolean executeInSequence() {
4652
return false;

engine/storage/src/main/java/org/apache/cloudstack/storage/image/NfsImageStoreDriverImpl.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,15 @@
1818
*/
1919
package org.apache.cloudstack.storage.image;
2020

21-
import java.util.Map;
22-
23-
import javax.inject.Inject;
24-
25-
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
26-
2721
import com.cloud.capacity.CapacityManager;
2822

2923
public abstract class NfsImageStoreDriverImpl extends BaseImageStoreDriverImpl {
3024

31-
@Inject
32-
ImageStoreDetailsDao _imageStoreDetailsDao;
33-
3425
/**
35-
* Retrieve NFS version to be used for imgStoreId store, if provided in image_store_details table
36-
* @param imgStoreId store id
37-
* @return "secstorage.nfs.version" associated value for imgStoreId in image_store_details table if exists, null if not
26+
* Retrieve the NFS version to be used for the imgStoreId store
3827
*/
39-
protected String getNfsVersion(long imgStoreId){
40-
Map<String, String> imgStoreDetails = _imageStoreDetailsDao.getDetails(imgStoreId);
41-
String nfsVersionKey = CapacityManager.ImageStoreNFSVersion.key();
42-
if (imgStoreDetails != null && imgStoreDetails.containsKey(nfsVersionKey)){
43-
return imgStoreDetails.get(nfsVersionKey);
44-
}
45-
return null;
28+
protected String getNfsVersion(long imgStoreId) {
29+
return CapacityManager.ImageStoreNFSVersion.valueIn(imgStoreId);
4630
}
4731

4832
}

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,8 @@ public VBD createPatchVbd(final Connection conn, final String vmName, final VM v
11101110
return cdromVBD;
11111111
}
11121112

1113-
protected boolean createSecondaryStorageFolder(final Connection conn, final String remoteMountPath, final String newFolder) {
1114-
final String result = callHostPlugin(conn, "vmopsSnapshot", "create_secondary_storage_folder", "remoteMountPath", remoteMountPath, "newFolder", newFolder);
1113+
protected boolean createSecondaryStorageFolder(final Connection conn, final String remoteMountPath, final String newFolder, final String nfsVersion) {
1114+
final String result = callHostPlugin(conn, "vmopsSnapshot", "create_secondary_storage_folder", "remoteMountPath", remoteMountPath, "newFolder", newFolder, "nfsVersion", nfsVersion);
11151115
return result != null;
11161116
}
11171117

@@ -1482,8 +1482,8 @@ public VM createWorkingVM(final Connection conn, final String vmName, final Stri
14821482
return vm;
14831483
}
14841484

1485-
protected boolean deleteSecondaryStorageFolder(final Connection conn, final String remoteMountPath, final String folder) {
1486-
final String details = callHostPlugin(conn, "vmopsSnapshot", "delete_secondary_storage_folder", "remoteMountPath", remoteMountPath, "folder", folder);
1485+
protected boolean deleteSecondaryStorageFolder(final Connection conn, final String remoteMountPath, final String folder, final String nfsVersion) {
1486+
final String details = callHostPlugin(conn, "vmopsSnapshot", "delete_secondary_storage_folder", "remoteMountPath", remoteMountPath, "folder", folder, "nfsVersion", nfsVersion);
14871487
return details != null && details.equals("1");
14881488
}
14891489

@@ -4102,7 +4102,7 @@ protected void plugDom0Vif(final Connection conn, final VIF dom0Vif) throws XmlR
41024102
}
41034103

41044104
protected boolean postCreatePrivateTemplate(final Connection conn, final String templatePath, final String tmpltFilename, final String templateName, String templateDescription, String checksum,
4105-
final long size, final long virtualSize, final long templateId) {
4105+
final long size, final long virtualSize, final long templateId, final String nfsVersion) {
41064106

41074107
if (templateDescription == null) {
41084108
templateDescription = "";
@@ -4113,7 +4113,7 @@ protected boolean postCreatePrivateTemplate(final Connection conn, final String
41134113
}
41144114

41154115
final String result = callHostPlugin(conn, "vmopsSnapshot", "post_create_private_template", "templatePath", templatePath, "templateFilename", tmpltFilename, "templateName", templateName,
4116-
"templateDescription", templateDescription, "checksum", checksum, "size", String.valueOf(size), "virtualSize", String.valueOf(virtualSize), "templateId", String.valueOf(templateId));
4116+
"templateDescription", templateDescription, "checksum", checksum, "size", String.valueOf(size), "virtualSize", String.valueOf(virtualSize), "templateId", String.valueOf(templateId), "nfsVersion", nfsVersion);
41174117

41184118
boolean success = false;
41194119
if (result != null && !result.isEmpty()) {
@@ -5661,6 +5661,7 @@ public Answer copyDiagnosticsFileToSecondaryStorage(Connection conn, CopyToSecon
56615661
String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
56625662
String vmIP = cmd.getSystemVmIp();
56635663
String diagnosticsZipFile = cmd.getFileName();
5664+
String nfsVersion = cmd.getNfsVersion();
56645665

56655666
String localDir = null;
56665667
boolean success;
@@ -5671,7 +5672,7 @@ public Answer copyDiagnosticsFileToSecondaryStorage(Connection conn, CopyToSecon
56715672
URI uri = new URI(secondaryStorageUrl);
56725673
secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
56735674
localDir = BASE_MOUNT_POINT_ON_REMOTE + UUID.nameUUIDFromBytes(secondaryStorageMountPath.getBytes());
5674-
String mountPoint = mountNfs(conn, secondaryStorageMountPath, localDir);
5675+
String mountPoint = mountNfs(conn, secondaryStorageMountPath, localDir, nfsVersion);
56755676
if (org.apache.commons.lang.StringUtils.isBlank(mountPoint)) {
56765677
return new CopyToSecondaryStorageAnswer(cmd, false, "Could not mount secondary storage " + secondaryStorageMountPath + " on host " + localDir);
56775678
}
@@ -5698,11 +5699,11 @@ public Answer copyDiagnosticsFileToSecondaryStorage(Connection conn, CopyToSecon
56985699
}
56995700
}
57005701

5701-
private String mountNfs(Connection conn, String remoteDir, String localDir) {
5702+
private String mountNfs(Connection conn, String remoteDir, String localDir, String nfsVersion) {
57025703
if (localDir == null) {
57035704
localDir = BASE_MOUNT_POINT_ON_REMOTE + UUID.nameUUIDFromBytes(remoteDir.getBytes());
57045705
}
5705-
return callHostPlugin(conn, "cloud-plugin-storage", "mountNfsSecondaryStorage", "localDir", localDir, "remoteDir", remoteDir);
5706+
return callHostPlugin(conn, "cloud-plugin-storage", "mountNfsSecondaryStorage", "localDir", localDir, "remoteDir", remoteDir, "nfsVersion", nfsVersion);
57065707
}
57075708

57085709
// Unmount secondary storage from host

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,9 @@ public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
916916
try {
917917
final NfsTO nfsStore = (NfsTO) destStore;
918918
final URI uri = new URI(nfsStore.getUrl());
919+
final String nfsVersion = nfsStore.getNfsVersion();
919920
// Create the volume folder
920-
if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath())) {
921+
if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath(), nfsVersion)) {
921922
throw new InternalErrorException("Failed to create the volume folder.");
922923
}
923924

@@ -1179,6 +1180,7 @@ public Answer backupSnapshot(final CopyCommand cmd) {
11791180
secondaryStorageUrl = cacheStore.getUrl();
11801181
destPath = destData.getPath();
11811182
}
1183+
String nfsVersion = cacheStore.getNfsVersion();
11821184

11831185
final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) srcData;
11841186
final SnapshotObjectTO snapshotOnImage = (SnapshotObjectTO) destData;
@@ -1235,7 +1237,7 @@ public Answer backupSnapshot(final CopyCommand cmd) {
12351237
if (fullbackup) {
12361238
// the first snapshot is always a full snapshot
12371239

1238-
if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, folder)) {
1240+
if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, folder, nfsVersion)) {
12391241
details = " Filed to create folder " + folder + " in secondary storage";
12401242
s_logger.warn(details);
12411243
return new CopyCmdAnswer(details);
@@ -1349,6 +1351,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) {
13491351
final TemplateObjectTO template = (TemplateObjectTO) cmd.getDestTO();
13501352
final NfsTO destStore = (NfsTO) cmd.getDestTO().getDataStore();
13511353
final int wait = cmd.getWait();
1354+
final String nfsVersion = destStore.getNfsVersion();
13521355

13531356
final String secondaryStoragePoolURL = destStore.getUrl();
13541357
final String volumeUUID = volume.getPath();
@@ -1364,7 +1367,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) {
13641367
final URI uri = new URI(secondaryStoragePoolURL);
13651368
secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
13661369
installPath = template.getPath();
1367-
if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath)) {
1370+
if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath, nfsVersion)) {
13681371
details = " Filed to create folder " + installPath + " in secondary storage";
13691372
s_logger.warn(details);
13701373
return new CopyCmdAnswer(details);
@@ -1391,7 +1394,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) {
13911394
final String templatePath = secondaryStorageMountPath + "/" + installPath;
13921395
result =
13931396
hypervisorResource.postCreatePrivateTemplate(conn, templatePath, tmpltFilename, tmpltUUID, userSpecifiedName, null, physicalSize, virtualSize,
1394-
template.getId());
1397+
template.getId(), nfsVersion);
13951398
if (!result) {
13961399
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI);
13971400
}
@@ -1411,7 +1414,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) {
14111414
hypervisorResource.removeSR(conn, tmpltSR);
14121415
}
14131416
if (secondaryStorageMountPath != null) {
1414-
hypervisorResource.deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath);
1417+
hypervisorResource.deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath, nfsVersion);
14151418
}
14161419
details = "Creating template from volume " + volumeUUID + " failed due to " + e.toString();
14171420
s_logger.error(details, e);
@@ -1465,7 +1468,8 @@ public Answer createTemplateFromSnapshot(final CopyCommand cmd) {
14651468

14661469
final String destNfsPath = destUri.getHost() + ":" + destUri.getPath();
14671470

1468-
if (!hypervisorResource.createSecondaryStorageFolder(conn, destNfsPath, destDir)) {
1471+
String destNfsVersion = destStore.getNfsVersion();
1472+
if (!hypervisorResource.createSecondaryStorageFolder(conn, destNfsPath, destDir, destNfsVersion)) {
14691473
final String details = " Failed to create folder " + destDir + " in secondary storage";
14701474

14711475
s_logger.warn(details);
@@ -1500,7 +1504,7 @@ public Answer createTemplateFromSnapshot(final CopyCommand cmd) {
15001504
templatePath = templatePath.replaceAll("//", "/");
15011505

15021506
result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, userSpecifiedTemplateName, null,
1503-
physicalSize, virtualSize, templateObjTO.getId());
1507+
physicalSize, virtualSize, templateObjTO.getId(), destNfsVersion);
15041508

15051509
if (!result) {
15061510
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + templateUri);

0 commit comments

Comments
 (0)