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 @@ -2695,8 +2695,19 @@ public Answer createVolumeFromSnapshot(final CopyCommand cmd) {

final String snapshotFullPath = snapshot.getPath();
final int index = snapshotFullPath.lastIndexOf("/");
final String snapshotPath = snapshotFullPath.substring(0, index);
final String snapshotName = snapshotFullPath.substring(index + 1);
final String snapshotPath;
final String snapshotName;
if (index >= 0) {
snapshotPath = snapshotFullPath.substring(0, index);
snapshotName = snapshotFullPath.substring(index + 1);
} else {
if (pool.getPoolType() == StoragePoolType.SharedMountPoint) {
snapshotPath = pool.getPath();
snapshotName = snapshotFullPath;
} else {
throw new CloudRuntimeException("Invalid snapshot path format: " + snapshotFullPath);
}
}
KVMPhysicalDisk disk = null;
if (imageStore instanceof NfsTO) {
disk = createVolumeFromSnapshotOnNFS(cmd, pool, imageStore, volume, snapshotPath, snapshotName);
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10698,7 +10698,7 @@ public Optional<UserVm> cloneVirtualMachine(CloneVMCmd cmd) throws ResourceAlloc
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create vm snapshot: " + e.getMessage(), e);
}

List<VMSnapshotDetailsVO> listSnapshots = vmSnapshotDetailsDao.findDetails(vmSnapshot.getId(), "kvmStorageSnapshot");
List<VMSnapshotDetailsVO> listSnapshots = vmSnapshotDetailsDao.findDetails(vmSnapshot.getId(), "kvmFileBasedStorageSnapshot");

Integer countOfCloneVM = cmd.getCount();
for (int cnt = 1; cnt <= countOfCloneVM; cnt++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import com.cloud.storage.VolumeApiService;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.StoragePoolTagsDao;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.GuestOSHypervisorDao;
import com.cloud.storage.dao.SnapshotDao;
Expand Down Expand Up @@ -250,6 +251,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
@Inject
private DiskOfferingDao diskOfferingDao;
@Inject
private StoragePoolTagsDao storagePoolTagsDao;
@Inject
private ResourceManager resourceManager;
@Inject
private ResourceLimitService resourceLimitService;
Expand Down Expand Up @@ -2201,16 +2204,43 @@ private List<StoragePoolVO> findInstanceConversionDestinationStoragePoolsInClust
Cluster destinationCluster, ServiceOfferingVO serviceOffering,
Map<String, Long> dataDiskOfferingMap,
DataStoreTO temporaryConvertLocation, boolean forceConvertToPool) {
List<StoragePoolVO> poolsList;
List<StoragePoolVO> poolsList = new ArrayList<>();
if (!forceConvertToPool) {
Set<StoragePoolVO> pools = new HashSet<>(primaryDataStoreDao.findClusterWideStoragePoolsByHypervisorAndPoolType(destinationCluster.getId(), Hypervisor.HypervisorType.KVM, Storage.StoragePoolType.NetworkFilesystem));
pools.addAll(primaryDataStoreDao.findZoneWideStoragePoolsByHypervisorAndPoolType(destinationCluster.getDataCenterId(), Hypervisor.HypervisorType.KVM, Storage.StoragePoolType.NetworkFilesystem));
if (pools.isEmpty()) {
String msg = String.format("Cannot find suitable storage pools in the cluster %s for the conversion", destinationCluster.getName());
logger.error(msg);
throw new CloudRuntimeException(msg);
// Try to find pools based on disk offering tags
Set<Long> candidatePoolIds = new HashSet<>();
if (serviceOffering.getDiskOfferingId() != null) {
DiskOfferingVO diskOffering = diskOfferingDao.findById(serviceOffering.getDiskOfferingId());
if (diskOffering != null && StringUtils.isNotBlank(diskOffering.getTags())) {
String tag = diskOffering.getTags();
List<Long> ids = storagePoolTagsDao.listPoolIdsByTag(tag);
if (ids != null) {
candidatePoolIds.addAll(ids);
}
}
}

if (!candidatePoolIds.isEmpty()) {
for (Long poolid : candidatePoolIds) {
StoragePoolVO pool = primaryDataStoreDao.findById(poolid);
if (pool == null) {
continue;
}
poolsList.add(pool);
}
}
logger.info("find poolsList : " + poolsList);

// Fallback to previous behavior if no tagged pools found
if (poolsList.isEmpty()) {
Set<StoragePoolVO> pools = new HashSet<>(primaryDataStoreDao.listPoolsByCluster(destinationCluster.getId()));
pools.addAll(primaryDataStoreDao.findZoneWideStoragePoolsByHypervisor(destinationCluster.getDataCenterId(), Hypervisor.HypervisorType.KVM));
if (pools.isEmpty()) {
String msg = String.format("Cannot find suitable storage pools in the cluster %s for the conversion", destinationCluster.getName());
logger.error(msg);
throw new CloudRuntimeException(msg);
}
poolsList.addAll(pools);
}
poolsList = new ArrayList<>(pools);
} else {
DataStore dataStore = dataStoreManager.getDataStore(temporaryConvertLocation.getUuid(), temporaryConvertLocation.getRole());
poolsList = Collections.singletonList(primaryDataStoreDao.findById(dataStore.getId()));
Expand Down
Loading