Skip to content
Draft
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 @@ -80,6 +80,7 @@
import org.apache.cloudstack.storage.service.UnifiedSANStrategy;
import org.apache.cloudstack.storage.service.model.AccessGroup;
import org.apache.cloudstack.storage.service.model.CloudStackVolume;
import org.apache.cloudstack.storage.service.model.NfsProtocolSpec;
import org.apache.cloudstack.storage.service.model.ProtocolType;
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
import org.apache.cloudstack.storage.utils.OntapStorageUtils;
Expand Down Expand Up @@ -277,7 +278,7 @@ private CreateCmdResult recordCreatedVolume(StoragePoolVO storagePool, VolumeInf
logger.info("createAsync: Created LUN [{}] for volume [{}]. LUN mapping will occur during grantAccess() to per-host igroup.",
lunName, volumeVO.getId());
createCmdResult = new CreateCmdResult(lunName, new Answer(null, true, null));
} else if (ProtocolType.NFS3.name().equalsIgnoreCase(details.get(OntapStorageConstants.PROTOCOL))) {
}else if (NfsProtocolSpec.isNfs(details.get(OntapStorageConstants.PROTOCOL))) {
createCmdResult = new CreateCmdResult(volInfo.getUuid(), new Answer(null, true, null));
logger.info("createAsync: Managed NFS volume [{}] with path [{}] associated with pool {}",
volumeVO.getId(), volInfo.getUuid(), storagePool.getId());
Expand Down Expand Up @@ -1077,7 +1078,7 @@ private CopyCommandResult copySnapshotToTemporaryVolume(DataObject srcData, Volu
logger.info("copySnapshotToTemporaryVolume: Cloning CS snapshot [{}] into temporary volume [{}] on pool [{}] for template creation",
srcData.getId(), volInfo.getId(), storagePool.getId());
CloudStackVolume cloned = cloneCloudStackVolumeFromSnapshot(storagePool, volInfo, details, srcData.getId(), false);
if (ProtocolType.NFS3.name().equalsIgnoreCase(details.get(OntapStorageConstants.PROTOCOL))) {
if (NfsProtocolSpec.isNfs(details.get(OntapStorageConstants.PROTOCOL))) {
volumeVO.setPath(volInfo.getUuid());
}
recordCreatedVolume(storagePool, volInfo, volumeVO, details, cloned);
Expand Down Expand Up @@ -1279,8 +1280,8 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore
if (ProtocolType.ISCSI.name().equalsIgnoreCase(details.get(OntapStorageConstants.PROTOCOL))) {
// Only retrieve LUN name for iSCSI volumes
grantAccessIscsi(host, volumeVO, details, svmName, storagePool);
} else if (ProtocolType.NFS3.name().equalsIgnoreCase(details.get(OntapStorageConstants.PROTOCOL))) {
// For NFS, no access grant needed - file is accessible via mount
} else if (NfsProtocolSpec.isNfs(details.get(OntapStorageConstants.PROTOCOL))) {
// For NFS (v3 or v4.1), no access grant needed - file is accessible via mount
logger.debug("grantAccess: NFS volume [{}], no igroup mapping required", volumeVO.getUuid());
return true;
}
Expand Down Expand Up @@ -1948,8 +1949,8 @@ public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCm
* @return The ONTAP path (file path for NFS, LUN name for iSCSI)
*/
private String resolveVolumePathOnOntap(VolumeVO volumeVO, String protocol, Map<String, String> poolDetails) {
if (ProtocolType.NFS3.name().equalsIgnoreCase(protocol)) {
// For NFS, use the volume's file path
if (NfsProtocolSpec.isNfs(protocol)) {
// For NFS (v3 or v4.1), use the volume's file path
return volumeVO.getPath();
} else if (ProtocolType.ISCSI.name().equalsIgnoreCase(protocol)) {
// For iSCSI, retrieve the LUN name from volume details
Expand Down Expand Up @@ -2134,6 +2135,7 @@ private CloudStackVolume createDeleteCloudStackVolumeRequest(StoragePool storage
ProtocolType protocolType = ProtocolType.valueOf(protocol);
switch (protocolType) {
case NFS3:
case NFS4_1:
cloudStackVolumeDeleteRequest = new CloudStackVolume();
cloudStackVolumeDeleteRequest.setDatastoreId(String.valueOf(storagePool.getId()));
cloudStackVolumeDeleteRequest.setVolumeInfo(volumeInfo);
Expand Down Expand Up @@ -2182,6 +2184,7 @@ private CloudStackVolume resizeCloudStackVolumeRequest(Map<String, String> detai
ProtocolType protocolType = ProtocolType.valueOf(protocol);
switch (protocolType) {
case NFS3:
case NFS4_1:
FileInfo fileInfo = new FileInfo();
fileInfo.setQosPolicy(qosPolicyReference);
resizeRequest.setFile(fileInfo);
Expand Down Expand Up @@ -2219,6 +2222,7 @@ private CloudStackVolume createCloudStackVolumeRequestByProtocol(StoragePoolVO s
ProtocolType protocolType = ProtocolType.valueOf(protocol);
switch (protocolType) {
case NFS3:
case NFS4_1:
CloudStackVolume nfsRequest = new CloudStackVolume();
nfsRequest.setDatastoreId(String.valueOf(storagePool.getId()));
nfsRequest.setFlexVolumeUuid(details.get(OntapStorageConstants.VOLUME_UUID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.cloudstack.storage.feign.model.ExportPolicy;
import org.apache.cloudstack.storage.feign.model.FileCloneRequest;
import org.apache.cloudstack.storage.feign.model.FileInfo;
import org.apache.cloudstack.storage.feign.model.NfsService;
import org.apache.cloudstack.storage.feign.model.response.JobResponse;
import org.apache.cloudstack.storage.feign.model.response.OntapResponse;
import feign.Headers;
Expand Down Expand Up @@ -94,4 +95,12 @@ void deleteExportPolicyById(@Param("authHeader") String authHeader,
OntapResponse<ExportPolicy> updateExportPolicy(@Param("authHeader") String authHeader,
@Param("id") String id,
ExportPolicy request);

// NFS Service Operations — v4.x enablement / ID mapping config lives here,
// NOT on /api/svm/svms (which only exposes nfs.enabled).
@RequestLine("GET /api/protocols/nfs/services/{svmUuid}")
@Headers({"Authorization: {authHeader}"})
NfsService getNfsService(@Param("authHeader") String authHeader,
@Param("svmUuid") String svmUuid,
@QueryMap Map<String, Object> queryMap);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* 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 org.apache.cloudstack.storage.feign.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Represents ONTAP REST {@code /api/protocols/nfs/services/{svm.uuid}}: the per-SVM
* NFS service document. Carries v4.x enablement and ID-mapping configuration that
* is NOT addressable on the {@code /api/svm/svms} endpoint.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class NfsService {

@JsonProperty("enabled")
private Boolean enabled;

@JsonProperty("protocol")
private Protocol protocol;

public Boolean getEnabled() {
return Boolean.TRUE.equals(enabled);
}

public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}

public Protocol getProtocol() {
return protocol;
}

public void setProtocol(Protocol protocol) {
this.protocol = protocol;
}

public boolean isV41Enabled() {
return protocol != null && Boolean.TRUE.equals(protocol.v41Enabled);
}

public boolean isV4NumericIds() {
return protocol != null && Boolean.TRUE.equals(protocol.v4NumericIds);
}

public String getV4IdDomain() {
return protocol != null ? protocol.v4IdDomain : null;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Protocol {

@JsonProperty("v3_enabled")
private Boolean v3Enabled;

@JsonProperty("v40_enabled")
private Boolean v40Enabled;

@JsonProperty("v41_enabled")
private Boolean v41Enabled;

@JsonProperty("v41_pnfs_enabled")
private Boolean v41PnfsEnabled;

@JsonProperty("v4_id_domain")
private String v4IdDomain;

@JsonProperty("v4_numeric_ids")
private Boolean v4NumericIds;

public Boolean getV3Enabled() { return v3Enabled; }
public void setV3Enabled(Boolean v3Enabled) { this.v3Enabled = v3Enabled; }

public Boolean getV40Enabled() { return v40Enabled; }
public void setV40Enabled(Boolean v40Enabled) { this.v40Enabled = v40Enabled; }

public Boolean getV41Enabled() { return v41Enabled; }
public void setV41Enabled(Boolean v41Enabled) { this.v41Enabled = v41Enabled; }

public Boolean getV41PnfsEnabled() { return v41PnfsEnabled; }
public void setV41PnfsEnabled(Boolean v41PnfsEnabled) { this.v41PnfsEnabled = v41PnfsEnabled; }

public String getV4IdDomain() { return v4IdDomain; }
public void setV4IdDomain(String v4IdDomain) { this.v4IdDomain = v4IdDomain; }

public Boolean getV4NumericIds() { return v4NumericIds; }
public void setV4NumericIds(Boolean v4NumericIds) { this.v4NumericIds = v4NumericIds; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.cloudstack.storage.provider.StorageProviderFactory;
import org.apache.cloudstack.storage.service.StorageStrategy;
import org.apache.cloudstack.storage.service.model.AccessGroup;
import org.apache.cloudstack.storage.service.model.NfsProtocolSpec;
import org.apache.cloudstack.storage.service.model.ProtocolType;
import org.apache.cloudstack.storage.utils.OntapStorageConstants;
import org.apache.cloudstack.storage.utils.OntapStorageUtils;
Expand Down Expand Up @@ -191,13 +192,16 @@ public DataStore initialize(Map<String, Object> dsInfos) {
int port;
switch (protocol) {
case NFS3:
case NFS4_1: {
NfsProtocolSpec spec = NfsProtocolSpec.forProtocol(protocol);
parameters.setType(Storage.StoragePoolType.NetworkFilesystem);
path = OntapStorageConstants.SLASH + storagePoolName;
port = OntapStorageConstants.NFS3_PORT;
// Force NFSv3 for ONTAP managed storage to avoid NFSv4 ID mapping issues
details.put(ApiConstants.NFS_MOUNT_OPTIONS, OntapStorageConstants.NFS3_MOUNT_OPTIONS_VER_3);
logger.info("Setting NFS path for storage pool: " + path + ", port: " + port + " with mount option: vers=3");
port = OntapStorageConstants.NFS_PORT;
details.put(ApiConstants.NFS_MOUNT_OPTIONS, spec.mountOptions());
logger.info("Setting NFS path for storage pool: " + path + ", port: " + port
+ " with mount option: " + spec.mountOptions());
break;
}
case ISCSI:
parameters.setType(Storage.StoragePoolType.OntapiSCSI);
path = storageStrategy.getStoragePath();
Expand Down Expand Up @@ -431,6 +435,7 @@ private boolean validateProtocolSupportAndFetchHostsIdentifier(List<HostVO> host
}
break;
case NFS3:
case NFS4_1:
String ip = "";
for (HostVO host : hosts) {
if (host != null) {
Expand All @@ -453,13 +458,14 @@ private boolean validateProtocolSupportAndFetchHostsIdentifier(List<HostVO> host
}

/**
* Creates an NFS export policy (access group) on the ONTAP storage if the protocol is NFS3
* and there are eligible hosts. Skipped for iSCSI (igroups are created per-host in grantAccess).
* Creates an NFS export policy (access group) on the ONTAP storage for any NFS pool
* (NFSv3 or NFSv4.1) when there are eligible hosts. Skipped for iSCSI (igroups are
* created per-host in grantAccess).
*/
private void createNfsAccessGroupIfNeeded(Map<String, String> details, List<String> hostsIdentifier,
List<HostVO> hostsToConnect, Scope scope,
StoragePoolVO storagePool, StorageStrategy strategy) {
if (!ProtocolType.NFS3.name().equalsIgnoreCase(details.get(OntapStorageConstants.PROTOCOL))) {
if (!NfsProtocolSpec.isNfs(details.get(OntapStorageConstants.PROTOCOL))) {
return;
}
if (hostsIdentifier.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.service.StorageStrategy;
import org.apache.cloudstack.storage.service.model.AccessGroup;
import org.apache.cloudstack.storage.service.model.ProtocolType;
import org.apache.cloudstack.storage.service.model.NfsProtocolSpec;
import org.apache.cloudstack.storage.utils.OntapStorageConstants;
import org.apache.cloudstack.storage.utils.OntapStorageUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -101,7 +101,7 @@ public boolean hostConnect(long hostId, long poolId) {
return false;
}

// Update NFS export policy for this connected host when the pool protocol is NFS3.
// Update NFS export policy for this connected host when the pool protocol is NFS (v3 or v4.1).
updateNfsExportPolicyForConnectedHostIfNeeded(poolId, hostId, host, detailsMap);

// Create the ModifyStoragePoolCommand to send to the agent
Expand Down Expand Up @@ -173,11 +173,11 @@ public boolean hostConnect(long hostId, long poolId) {
}

private void updateNfsExportPolicyForConnectedHostIfNeeded(long poolId, long hostId, Host host, Map<String, String> detailsMap) {
if (!ProtocolType.NFS3.name().equalsIgnoreCase(detailsMap.get(OntapStorageConstants.PROTOCOL))) {
if (!NfsProtocolSpec.isNfs(detailsMap.get(OntapStorageConstants.PROTOCOL))) {
return;
}

if (!isNfs3EnabledOnHost(host)) {
if (!isNfsEnabledOnHost(host)) {
throw new CloudRuntimeException("NFS protocol is not enabled on host with id: " + hostId);
}

Expand All @@ -190,14 +190,19 @@ private void updateNfsExportPolicyForConnectedHostIfNeeded(long poolId, long hos
logger.info("hostConnect: updateNfsExportPolicyForConnectedHostIfNeeded: Updated NFS export policy rules for host {} on storage pool {}", host.getName(), poolId);
}

private boolean isNfs3EnabledOnHost(Host host) {
/**
* The eligibility check is identical for NFSv3 and NFSv4.1 — presence of a storage or
* private IP the SVM export rule can match on. Kernel version negotiation happens
* at mount time on the KVM host.
*/
private boolean isNfsEnabledOnHost(Host host) {
if (host == null) {
return false;
}

String storageIp = host.getStorageIpAddress() != null ? host.getStorageIpAddress().trim() : "";
if (storageIp.isEmpty() && StringUtils.isBlank(host.getPrivateIpAddress())) {
logger.warn("isNfs3EnabledOnHost: Host {} is not eligible for NFS3 protocol: both storage IP and private IP are empty",
logger.warn("isNfsEnabledOnHost: Host {} is not eligible for NFS: both storage IP and private IP are empty",
host.getId());
return false;
}
Expand Down Expand Up @@ -252,13 +257,13 @@ private void removeHostFromOntapPoolIfNeeded(StoragePoolVO pool, Host host) {
return;
}

// Skip non-NFS3 pools; Currently, for iSCSI type, iGroup rules are being handled as part of revokeAccess in OntapPrimaryDataStoreDriver, so no need to handle here.
if (!ProtocolType.NFS3.name().equalsIgnoreCase(detailsMap.get(OntapStorageConstants.PROTOCOL))) {
// Skip non-NFS pools; for iSCSI, iGroup rules are handled in revokeAccess inside the driver.
if (!NfsProtocolSpec.isNfs(detailsMap.get(OntapStorageConstants.PROTOCOL))) {
return;
}

logger.info("hostAboutToBeRemoved: removeHostFromOntapPoolIfNeeded: Removing export policy rule for host {} from storage pool {}", host.getName(), pool.getName());
if (!isNfs3EnabledOnHost(host)) {
if (!isNfsEnabledOnHost(host)) {
logger.warn("hostAboutToBeRemoved: removeHostFromOntapPoolIfNeeded: Skipping NFS export policy removal for host {} on pool {} as host is not NFS-enabled",
host.getId(), pool.getId());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static StorageStrategy getStrategy(OntapStorage ontapStorage) {
protocol);
switch (protocol) {
case NFS3:
case NFS4_1:
UnifiedNASStrategy unifiedNASStrategy = new UnifiedNASStrategy(ontapStorage);
ComponentContext.inject(unifiedNASStrategy);
return unifiedNASStrategy;
Expand Down
Loading