Skip to content

Commit c5d5428

Browse files
CSTACKEX-18_2: incorporating the review comments.
1 parent d2b6a27 commit c5d5428

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public long getUsedIops(StoragePool storagePool) {
532532

533533
@Override
534534
public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback) {
535-
s_logger.error("temp takeSnapshot : entered with snapshot id: " + snapshot.getId() + " and name: " + snapshot.getName());
535+
s_logger.info("takeSnapshot : entered with snapshot id: " + snapshot.getId() + " and name: " + snapshot.getName());
536536
CreateCmdResult result;
537537

538538
try {
@@ -553,19 +553,25 @@ public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCm
553553
Map<String, String> poolDetails = storagePoolDetailsDao.listDetailsKeyPairs(volumeVO.getPoolId());
554554
StorageStrategy storageStrategy = Utility.getStrategyByStoragePoolDetails(poolDetails);
555555

556-
Map<String, String> cloudStackVolumeRequestMap = new HashMap<>();
557-
cloudStackVolumeRequestMap.put(Constants.VOLUME_UUID, poolDetails.get(Constants.VOLUME_UUID));
558-
cloudStackVolumeRequestMap.put(Constants.FILE_PATH, volumeVO.getPath());
559-
CloudStackVolume cloudStackVolume = storageStrategy.getCloudStackVolume(cloudStackVolumeRequestMap);
560-
if (cloudStackVolume == null || cloudStackVolume.getFile() == null) {
561-
throw new CloudRuntimeException("takeSnapshot: Failed to get source file to take snapshot");
562-
}
563-
long capacityBytes = storagePool.getCapacityBytes();
564-
s_logger.error("temp takeSnapshot : entered after getting cloudstack volume with file path: " + cloudStackVolume.getFile().getPath() + " and size: " + cloudStackVolume.getFile().getSize());
556+
CloudStackVolume cloudStackVolume = null;
565557
long usedBytes = getUsedBytes(storagePool);
566-
long fileSize = cloudStackVolume.getFile().getSize();
558+
long capacityBytes = storagePool.getCapacityBytes();
567559

568-
usedBytes += fileSize;
560+
// Only proceed for NFS3 protocol
561+
if (ProtocolType.NFS3.name().equalsIgnoreCase(poolDetails.get(Constants.PROTOCOL))) {
562+
Map<String, String> cloudStackVolumeRequestMap = new HashMap<>();
563+
cloudStackVolumeRequestMap.put(Constants.VOLUME_UUID, poolDetails.get(Constants.VOLUME_UUID));
564+
cloudStackVolumeRequestMap.put(Constants.FILE_PATH, volumeVO.getPath());
565+
cloudStackVolume = storageStrategy.getCloudStackVolume(cloudStackVolumeRequestMap);
566+
if (cloudStackVolume == null || cloudStackVolume.getFile() == null) {
567+
throw new CloudRuntimeException("takeSnapshot: Failed to get source file to take snapshot");
568+
}
569+
s_logger.info("takeSnapshot : entered after getting cloudstack volume with file path: " + cloudStackVolume.getFile().getPath() + " and size: " + cloudStackVolume.getFile().getSize());
570+
long fileSize = cloudStackVolume.getFile().getSize();
571+
usedBytes += fileSize;
572+
}
573+
574+
569575

570576
if (usedBytes > capacityBytes) {
571577
throw new CloudRuntimeException("Insufficient space remains in this primary storage to take a snapshot");
@@ -575,16 +581,16 @@ public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCm
575581

576582
SnapshotObjectTO snapshotObjectTo = (SnapshotObjectTO)snapshot.getTO();
577583

578-
String fileSnapshotName = volumeInfo.getName() + "-" + snapshot.getUuid();
584+
String snapshotName = volumeInfo.getName() + "-" + snapshot.getUuid();
579585

580586
int maxSnapshotNameLength = 64;
581-
int trimRequired = fileSnapshotName.length() - maxSnapshotNameLength;
587+
int trimRequired = snapshotName.length() - maxSnapshotNameLength;
582588

583589
if (trimRequired > 0) {
584-
fileSnapshotName = StringUtils.left(volumeInfo.getName(), (volumeInfo.getName().length() - trimRequired)) + "-" + snapshot.getUuid();
590+
snapshotName = StringUtils.left(volumeInfo.getName(), (volumeInfo.getName().length() - trimRequired)) + "-" + snapshot.getUuid();
585591
}
586592

587-
CloudStackVolume snapCloudStackVolumeRequest = snapshotCloudStackVolumeRequestByProtocol(poolDetails, volumeVO.getPath(), fileSnapshotName);
593+
CloudStackVolume snapCloudStackVolumeRequest = snapshotCloudStackVolumeRequestByProtocol(poolDetails, volumeVO.getPath(), snapshotName);
588594
CloudStackVolume cloneCloudStackVolume = storageStrategy.snapshotCloudStackVolume(snapCloudStackVolumeRequest);
589595

590596
updateSnapshotDetails(snapshot.getId(), volumeInfo.getId(), poolDetails.get(Constants.VOLUME_UUID), cloneCloudStackVolume.getFile().getPath(), volumeVO.getPoolId(), fileSize);

0 commit comments

Comments
 (0)