Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ public class CopyToSecondaryStorageCommand extends StorageSubSystemCommand {
private String secondaryStorageUrl;
private String systemVmIp;
private String fileName;
private String nfsVersion;

public CopyToSecondaryStorageCommand(String secondaryStorageUrl, String systemVmIp, String fileName) {
public CopyToSecondaryStorageCommand(String secondaryStorageUrl, String systemVmIp, String fileName, String nfsVersion) {
this.secondaryStorageUrl = secondaryStorageUrl;
this.systemVmIp = systemVmIp;
this.fileName = fileName;
this.nfsVersion = nfsVersion;
}

public String getSecondaryStorageUrl() {
Expand All @@ -41,6 +43,10 @@ public String getFileName() {
return fileName;
}

public String getNfsVersion() {
return nfsVersion;
}

@Override
public boolean executeInSequence() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,15 @@
*/
package org.apache.cloudstack.storage.image;

import java.util.Map;

import javax.inject.Inject;

import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;

import com.cloud.capacity.CapacityManager;

public abstract class NfsImageStoreDriverImpl extends BaseImageStoreDriverImpl {

@Inject
ImageStoreDetailsDao _imageStoreDetailsDao;

/**
* Retrieve NFS version to be used for imgStoreId store, if provided in image_store_details table
* @param imgStoreId store id
* @return "secstorage.nfs.version" associated value for imgStoreId in image_store_details table if exists, null if not
* Retrieve the NFS version to be used for the imgStoreId store
*/
protected String getNfsVersion(long imgStoreId){
Map<String, String> imgStoreDetails = _imageStoreDetailsDao.getDetails(imgStoreId);
String nfsVersionKey = CapacityManager.ImageStoreNFSVersion.key();
if (imgStoreDetails != null && imgStoreDetails.containsKey(nfsVersionKey)){
Comment thread
sureshanaparti marked this conversation as resolved.
return imgStoreDetails.get(nfsVersionKey);
}
return null;
protected String getNfsVersion(long imgStoreId) {
return CapacityManager.ImageStoreNFSVersion.valueIn(imgStoreId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,8 @@ public VBD createPatchVbd(final Connection conn, final String vmName, final VM v
return cdromVBD;
}

protected boolean createSecondaryStorageFolder(final Connection conn, final String remoteMountPath, final String newFolder) {
final String result = callHostPlugin(conn, "vmopsSnapshot", "create_secondary_storage_folder", "remoteMountPath", remoteMountPath, "newFolder", newFolder);
protected boolean createSecondaryStorageFolder(final Connection conn, final String remoteMountPath, final String newFolder, final String nfsVersion) {
final String result = callHostPlugin(conn, "vmopsSnapshot", "create_secondary_storage_folder", "remoteMountPath", remoteMountPath, "newFolder", newFolder, "nfsVersion", nfsVersion);
return result != null;
}

Expand Down Expand Up @@ -1482,8 +1482,8 @@ public VM createWorkingVM(final Connection conn, final String vmName, final Stri
return vm;
}

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

Expand Down Expand Up @@ -4102,7 +4102,7 @@ protected void plugDom0Vif(final Connection conn, final VIF dom0Vif) throws XmlR
}

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

if (templateDescription == null) {
templateDescription = "";
Expand All @@ -4113,7 +4113,7 @@ protected boolean postCreatePrivateTemplate(final Connection conn, final String
}

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

boolean success = false;
if (result != null && !result.isEmpty()) {
Expand Down Expand Up @@ -5661,6 +5661,7 @@ public Answer copyDiagnosticsFileToSecondaryStorage(Connection conn, CopyToSecon
String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
String vmIP = cmd.getSystemVmIp();
String diagnosticsZipFile = cmd.getFileName();
String nfsVersion = cmd.getNfsVersion();

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

private String mountNfs(Connection conn, String remoteDir, String localDir) {
private String mountNfs(Connection conn, String remoteDir, String localDir, String nfsVersion) {
if (localDir == null) {
localDir = BASE_MOUNT_POINT_ON_REMOTE + UUID.nameUUIDFromBytes(remoteDir.getBytes());
}
return callHostPlugin(conn, "cloud-plugin-storage", "mountNfsSecondaryStorage", "localDir", localDir, "remoteDir", remoteDir);
return callHostPlugin(conn, "cloud-plugin-storage", "mountNfsSecondaryStorage", "localDir", localDir, "remoteDir", remoteDir, "nfsVersion", nfsVersion);
}

// Unmount secondary storage from host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,9 @@ public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
try {
final NfsTO nfsStore = (NfsTO) destStore;
final URI uri = new URI(nfsStore.getUrl());
final String nfsVersion = nfsStore.getNfsVersion();
// Create the volume folder
if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath())) {
if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath(), nfsVersion)) {
throw new InternalErrorException("Failed to create the volume folder.");
}

Expand Down Expand Up @@ -1179,6 +1180,7 @@ public Answer backupSnapshot(final CopyCommand cmd) {
secondaryStorageUrl = cacheStore.getUrl();
destPath = destData.getPath();
}
String nfsVersion = cacheStore.getNfsVersion();

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

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

final String secondaryStoragePoolURL = destStore.getUrl();
final String volumeUUID = volume.getPath();
Expand All @@ -1364,7 +1367,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) {
final URI uri = new URI(secondaryStoragePoolURL);
secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
installPath = template.getPath();
if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath)) {
if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath, nfsVersion)) {
details = " Filed to create folder " + installPath + " in secondary storage";
s_logger.warn(details);
return new CopyCmdAnswer(details);
Expand All @@ -1391,7 +1394,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) {
final String templatePath = secondaryStorageMountPath + "/" + installPath;
result =
hypervisorResource.postCreatePrivateTemplate(conn, templatePath, tmpltFilename, tmpltUUID, userSpecifiedName, null, physicalSize, virtualSize,
template.getId());
template.getId(), nfsVersion);
if (!result) {
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI);
}
Expand All @@ -1411,7 +1414,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) {
hypervisorResource.removeSR(conn, tmpltSR);
}
if (secondaryStorageMountPath != null) {
hypervisorResource.deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath);
hypervisorResource.deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath, nfsVersion);
}
details = "Creating template from volume " + volumeUUID + " failed due to " + e.toString();
s_logger.error(details, e);
Expand Down Expand Up @@ -1465,7 +1468,8 @@ public Answer createTemplateFromSnapshot(final CopyCommand cmd) {

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

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

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

result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, userSpecifiedTemplateName, null,
physicalSize, virtualSize, templateObjTO.getId());
physicalSize, virtualSize, templateObjTO.getId(), destNfsVersion);

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