Skip to content

Commit fc7c2e0

Browse files
authored
Merge pull request #129 from NetApp/bugfix/CSTACKEX-348
CSTACKEX-348 Fix NFS volume from snapshot source path
2 parents 0458ffb + b387f0f commit fc7c2e0

7 files changed

Lines changed: 23 additions & 49 deletions

File tree

‎plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
204204
* - DATA or ROOT snapshot → new attachable data volume (ROOT is never bootable
205205
* via this path; bootable recovery is createTemplate(snapshotid) → deploy).
206206
* - Backend: iSCSI → POST /api/storage/luns (clone.source in .snapshot/);
207-
* NFS → POST /api/storage/file/clone with snapshot.name.
207+
* NFS → POST /api/storage/file/clone with source_path
208+
* ./.snapshot/<snapshot-name>/<source-file>.
208209
* - IOPS: the new volume's min/max (snapshot values, or the root offering when one
209210
* is supplied). Applied here; the temporary template clone does not get a policy.
210211
*
@@ -517,7 +518,8 @@ private Long getSnapshotIdForCloning(long volumeId) {
517518
* {@code createTemplate(snapshotid)} then deploy.</li>
518519
* <li><b>iSCSI</b> — {@code POST /api/storage/luns} with
519520
* {@code clone.source.name=/vol/&lt;fv&gt;/.snapshot/&lt;snap&gt;/&lt;lun&gt;}</li>
520-
* <li><b>NFS3</b> — {@code POST /api/storage/file/clone} with {@code snapshot.name}</li>
521+
* <li><b>NFS3</b> — {@code POST /api/storage/file/clone} with
522+
* {@code source_path=./.snapshot/&lt;snapshot-name&gt;/&lt;source-file&gt;}</li>
521523
* <li><b>Not this path</b> — in-place revert ({@code revertSnapshot}); VM/instance snapshots;
522524
* secondary-storage archive restore.</li>
523525
* </ul>
@@ -2390,14 +2392,17 @@ private CloudStackVolume createCloneFileFromSnapshotRequest(StoragePoolVO storag
23902392
String flexVolName = details.get(OntapStorageConstants.VOLUME_NAME);
23912393

23922394
FileInfo file = new FileInfo();
2393-
file.setPath(OntapStorageUtils.toFlexVolRelativePath(sourceVolumePath, flexVolName));
2395+
// FlexVol-relative source path, for example "<source-file-uuid>".
2396+
String relativeSourcePath = OntapStorageUtils.toFlexVolRelativePath(sourceVolumePath, flexVolName);
2397+
// Path assigned to file.setPath(), for example "./.snapshot/<snapshot-name>/<source-file-uuid>".
2398+
file.setPath(OntapStorageConstants.DOT + OntapStorageConstants.SNAPSHOT_PATH_SEGMENT + snapshotName
2399+
+ OntapStorageConstants.SLASH + relativeSourcePath);
23942400

23952401
CloudStackVolume request = new CloudStackVolume();
23962402
request.setDatastoreId(String.valueOf(storagePool.getId()));
23972403
request.setVolumeInfo(volumeInfo);
23982404
request.setFile(file);
23992405
request.setDestinationPath(OntapStorageUtils.toFlexVolRelativePath(volumeInfo.getUuid(), flexVolName));
2400-
request.setSnapshotName(snapshotName);
24012406
return request;
24022407
}
24032408

‎plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/model/FileCloneRequest.java‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ public FileCloneRequest(String flexVolUuid, String flexVolName, String sourcePat
6464
this.destinationPath = destinationPath;
6565
}
6666

67-
public FileCloneRequest(String flexVolUuid, String flexVolName, String sourcePath, String destinationPath,
68-
String snapshotName) {
69-
this(flexVolUuid, flexVolName, sourcePath, destinationPath);
70-
if (snapshotName != null && !snapshotName.isEmpty()) {
71-
this.snapshot = new SnapshotRef(snapshotName);
72-
}
73-
}
74-
7567
public VolumeRef getVolume() {
7668
return volume;
7769
}
@@ -177,7 +169,6 @@ public void setName(String name) {
177169
public String toString() {
178170
return "FileCloneRequest{volume=" + (volume != null ? volume.getUuid() : null)
179171
+ ", sourcePath=" + sourcePath
180-
+ ", destinationPath=" + destinationPath
181-
+ ", snapshot=" + (snapshot != null ? snapshot.getName() : null) + "}";
172+
+ ", destinationPath=" + destinationPath + "}";
182173
}
183174
}

‎plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/StorageStrategy.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,9 @@ abstract public CloudStackVolume createTemplateCache(StoragePoolVO storagePool,
934934
* <ul>
935935
* <li><b>SAN</b> — {@code lun.clone.source.name} set to
936936
* {@code /vol/&lt;fv&gt;/.snapshot/&lt;snap&gt;/&lt;lun&gt;}</li>
937-
* <li><b>NAS</b> — {@link CloudStackVolume#getSnapshotName()} set; it is sent as
938-
* {@code snapshot.name} on {@code POST /api/storage/file/clone}</li>
937+
* <li><b>NAS</b> — {@code file.path} set to
938+
* {@code ./.snapshot/&lt;snapshot-name&gt;/&lt;source-file&gt;} and sent as
939+
* {@code source_path} on {@code POST /api/storage/file/clone}</li>
939940
* </ul>
940941
*
941942
* @param cloudstackVolume describes the clone to create; the source is carried in the

‎plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ public void deleteCloudStackVolume(CloudStackVolume cloudstackVolume) {
181181
* Clones a file inside the FlexVolume using ONTAP's file clone API.
182182
*
183183
* <p>The source is taken from {@code file.path} and the destination from
184-
* {@code destinationPath}, both relative to the root of the FlexVolume backing the pool.
185-
* When {@code snapshotName} is set, the source is read from that FlexVolume snapshot.</p>
184+
* {@code destinationPath}, both relative to the root of the FlexVolume backing the pool.</p>
186185
*/
187186
@Override
188187
public CloudStackVolume cloneCloudStackVolume(CloudStackVolume cloudstackVolume) {
@@ -203,12 +202,11 @@ public CloudStackVolume cloneCloudStackVolume(CloudStackVolume cloudstackVolume)
203202
}
204203
String sourcePath = cloudstackVolume.getFile().getPath();
205204
String destinationPath = cloudstackVolume.getDestinationPath();
206-
String snapshotName = cloudstackVolume.getSnapshotName();
207205

208-
logger.info("cloneCloudStackVolume: Cloning file [{}] to [{}] in FlexVol [{}] from snapshot [{}]",
209-
sourcePath, destinationPath, flexVolName, snapshotName);
206+
logger.info("cloneCloudStackVolume: Cloning file [{}] to [{}] in FlexVol [{}]",
207+
sourcePath, destinationPath, flexVolName);
210208
try {
211-
FileCloneRequest request = new FileCloneRequest(flexVolUuid, flexVolName, sourcePath, destinationPath, snapshotName);
209+
FileCloneRequest request = new FileCloneRequest(flexVolUuid, flexVolName, sourcePath, destinationPath);
212210
JobResponse jobResponse = nasFeignClient.cloneFile(getAuthHeader(), request);
213211
pollJobIfPresent(jobResponse, "clone file [" + sourcePath + "] to [" + destinationPath + "]");
214212

@@ -221,7 +219,6 @@ public CloudStackVolume cloneCloudStackVolume(CloudStackVolume cloudstackVolume)
221219
clonedCloudStackVolume.setFile(clonedFile);
222220
clonedCloudStackVolume.setDatastoreId(cloudstackVolume.getDatastoreId());
223221
clonedCloudStackVolume.setVolumeInfo(cloudstackVolume.getVolumeInfo());
224-
clonedCloudStackVolume.setSnapshotName(snapshotName);
225222
return clonedCloudStackVolume;
226223
} catch (FeignException e) {
227224
logger.error("FeignException occurred while cloning file [{}], Status: {}, Exception: {}",

‎plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/model/CloudStackVolume.java‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ public class CloudStackVolume {
5151
*/
5252
private String destinationPath;
5353

54-
/**
55-
* ONTAP FlexVolume snapshot name when cloning a new file/LUN from a snapshot
56-
* (create-volume-from-snapshot). Null for live clones (e.g. template cache).
57-
*/
58-
private String snapshotName;
59-
6054
private DataObject volumeInfo; // This is needed as we need DataObject to be passed to agent to create volume
6155

6256
public FileInfo getFile() {
@@ -107,12 +101,4 @@ public void setDestinationPath(String destinationPath) {
107101
this.destinationPath = destinationPath;
108102
}
109103

110-
public String getSnapshotName() {
111-
return snapshotName;
112-
}
113-
114-
public void setSnapshotName(String snapshotName) {
115-
this.snapshotName = snapshotName;
116-
}
117-
118104
}

‎plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,9 +1236,8 @@ void testCreateAsync_VolumeClonedFromSnapshot_NfsSuccess() {
12361236
ArgumentCaptor<CloudStackVolume> requestCaptor = ArgumentCaptor.forClass(CloudStackVolume.class);
12371237
verify(nasStrategy).cloneCloudStackVolume(requestCaptor.capture());
12381238
CloudStackVolume request = requestCaptor.getValue();
1239-
assertEquals("source-file-uuid", request.getFile().getPath());
1239+
assertEquals("./.snapshot/snap_cs200/source-file-uuid", request.getFile().getPath());
12401240
assertEquals("new-volume-uuid", request.getDestinationPath());
1241-
assertEquals("snap_cs200", request.getSnapshotName());
12421241
assertEquals("1", request.getDatastoreId());
12431242
verify(nasStrategy, never()).createCloudStackVolume(any());
12441243
}
@@ -3461,9 +3460,9 @@ void testCopyAsync_NfsTemporarySnapshotCopy_SetsFilePath() {
34613460

34623461
ArgumentCaptor<CloudStackVolume> requestCaptor = ArgumentCaptor.forClass(CloudStackVolume.class);
34633462
verify(nasStrategy).cloneCloudStackVolume(requestCaptor.capture());
3464-
assertEquals("source-file-uuid", requestCaptor.getValue().getFile().getPath());
3463+
assertEquals("./.snapshot/snap_cs200/source-file-uuid",
3464+
requestCaptor.getValue().getFile().getPath());
34653465
assertEquals("tmp-volume-uuid", requestCaptor.getValue().getDestinationPath());
3466-
assertEquals("snap_cs200", requestCaptor.getValue().getSnapshotName());
34673466

34683467
assertEquals("tmp-volume-uuid", dbVolume.getPath());
34693468
assertEquals(Storage.ImageFormat.QCOW2, dbVolume.getFormat());

‎plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/UnifiedNASStrategyTest.java‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,11 +1176,10 @@ public void testCloneCloudStackVolume_Success() {
11761176
assertEquals("volume-uuid", captor.getValue().getDestinationPath());
11771177
assertEquals("flexvol1", captor.getValue().getVolume().getName());
11781178
assertEquals("flexvol-uuid-1", captor.getValue().getVolume().getUuid());
1179-
assertNull(captor.getValue().getSnapshot());
11801179
}
11811180

11821181
@Test
1183-
public void testCloneCloudStackVolume_SnapshotSource_SendsSnapshotName() {
1182+
public void testCloneCloudStackVolume_SnapshotSource_UsesSnapshotSourcePath() {
11841183
VolumeObject volumeObject = mock(VolumeObject.class);
11851184
VolumeVO volumeVO = mock(VolumeVO.class);
11861185
when(volumeObject.getId()).thenReturn(100L);
@@ -1193,26 +1192,22 @@ public void testCloneCloudStackVolume_SnapshotSource_SendsSnapshotName() {
11931192
when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(details);
11941193

11951194
FileInfo source = new FileInfo();
1196-
source.setPath("source-file-uuid");
1195+
source.setPath("./.snapshot/snap_cs200/source-file-uuid");
11971196
CloudStackVolume request = new CloudStackVolume();
11981197
request.setDatastoreId("1");
11991198
request.setVolumeInfo(volumeObject);
12001199
request.setFile(source);
12011200
request.setDestinationPath("new-volume-uuid");
1202-
request.setSnapshotName("snap_cs200");
12031201

12041202
when(nasFeignClient.cloneFile(anyString(), any(FileCloneRequest.class))).thenReturn(new JobResponse());
12051203

12061204
CloudStackVolume result = strategy.cloneCloudStackVolume(request);
12071205

12081206
assertEquals("new-volume-uuid", result.getFile().getPath());
1209-
assertEquals("snap_cs200", result.getSnapshotName());
12101207
ArgumentCaptor<FileCloneRequest> captor = ArgumentCaptor.forClass(FileCloneRequest.class);
12111208
verify(nasFeignClient).cloneFile(anyString(), captor.capture());
1212-
assertEquals("source-file-uuid", captor.getValue().getSourcePath());
1209+
assertEquals("./.snapshot/snap_cs200/source-file-uuid", captor.getValue().getSourcePath());
12131210
assertEquals("new-volume-uuid", captor.getValue().getDestinationPath());
1214-
assertNotNull(captor.getValue().getSnapshot());
1215-
assertEquals("snap_cs200", captor.getValue().getSnapshot().getName());
12161211
}
12171212

12181213
@Test

0 commit comments

Comments
 (0)