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 @@ -27,16 +27,23 @@

protected Map<String, Long> mapVolumeToSnapshotSize;
private String nvramSnapshotPath;
private String memorySnapshotPath;

Check warning on line 30 in core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotAnswer.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make this private field "final", it is never reassigned.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaItl1vSh2r7PbCfI5XD&open=AaItl1vSh2r7PbCfI5XD&pullRequest=14926

public CreateDiskOnlyVmSnapshotAnswer(Command command, boolean success, String details, Map<String, Long> mapVolumeToSnapshotSize) {
this(command, success, details, mapVolumeToSnapshotSize, null);
}

public CreateDiskOnlyVmSnapshotAnswer(Command command, boolean success, String details, Map<String, Long> mapVolumeToSnapshotSize,
String nvramSnapshotPath) {
this(command, success, details, mapVolumeToSnapshotSize, nvramSnapshotPath, null);
}

public CreateDiskOnlyVmSnapshotAnswer(Command command, boolean success, String details, Map<String, Long> mapVolumeToSnapshotSize,
String nvramSnapshotPath, String memorySnapshotPath) {
super(command, success, details);
this.mapVolumeToSnapshotSize = mapVolumeToSnapshotSize;
this.nvramSnapshotPath = nvramSnapshotPath;
this.memorySnapshotPath = memorySnapshotPath;
}

public Map<String, Long> getMapVolumeToSnapshotSize() {
Expand All @@ -46,4 +53,8 @@
public String getNvramSnapshotPath() {
return nvramSnapshotPath;
}

public String getMemorySnapshotPath() {
return memorySnapshotPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
protected VirtualMachine.State vmState;
private final String vmUuid;
private final boolean uefiEnabled;
private final boolean snapshotMemory;

List<Pair<VolumeObjectTO, String>> volumeTosAndNewPaths;

Expand All @@ -42,12 +43,18 @@

public CreateDiskOnlyVmSnapshotCommand(String vmName, String vmUuid, VMSnapshotTO snapshot, List<Pair<VolumeObjectTO, String>> volumeTosAndNewPaths, String guestOSType,
VirtualMachine.State vmState, boolean uefiEnabled) {
this(vmName, vmUuid, snapshot, volumeTosAndNewPaths, guestOSType, vmState, uefiEnabled, false);
}

public CreateDiskOnlyVmSnapshotCommand(String vmName, String vmUuid, VMSnapshotTO snapshot, List<Pair<VolumeObjectTO, String>> volumeTosAndNewPaths, String guestOSType,

Check warning on line 49 in core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotCommand.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Constructor has 8 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaItl1vLh2r7PbCfI5XC&open=AaItl1vLh2r7PbCfI5XC&pullRequest=14926
VirtualMachine.State vmState, boolean uefiEnabled, boolean snapshotMemory) {
super(vmName, snapshot, volumeTosAndNewPaths == null ? null : volumeTosAndNewPaths.stream()
.map(Pair::first).collect(Collectors.toList()), guestOSType);
this.vmUuid = vmUuid;
this.vmState = vmState;
this.volumeTosAndNewPaths = volumeTosAndNewPaths;
this.uefiEnabled = uefiEnabled;
this.snapshotMemory = snapshotMemory;
}

public VirtualMachine.State getVmState() {
Expand All @@ -65,4 +72,8 @@
public boolean isUefiEnabled() {
return uefiEnabled;
}

public boolean isSnapshotMemory() {
return snapshotMemory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class DeleteDiskOnlyVmSnapshotCommand extends Command {
private final List<DataTO> snapshots;
private final String nvramSnapshotPath;
private final PrimaryDataStoreTO primaryDataStore;
private final String memorySnapshotPath;

public DeleteDiskOnlyVmSnapshotCommand(List<DataTO> snapshots) {
this(snapshots, null);
Expand All @@ -39,9 +40,14 @@ public DeleteDiskOnlyVmSnapshotCommand(List<DataTO> snapshots, String nvramSnaps
}

public DeleteDiskOnlyVmSnapshotCommand(List<DataTO> snapshots, String nvramSnapshotPath, PrimaryDataStoreTO primaryDataStore) {
this(snapshots, nvramSnapshotPath, primaryDataStore, null);
}

public DeleteDiskOnlyVmSnapshotCommand(List<DataTO> snapshots, String nvramSnapshotPath, PrimaryDataStoreTO primaryDataStore, String memorySnapshotPath) {
this.snapshots = snapshots;
this.nvramSnapshotPath = nvramSnapshotPath;
this.primaryDataStore = primaryDataStore;
this.memorySnapshotPath = memorySnapshotPath;
}

public List<DataTO> getSnapshots() {
Expand All @@ -52,6 +58,10 @@ public String getNvramSnapshotPath() {
return nvramSnapshotPath;
}

public String getMemorySnapshotPath() {
return memorySnapshotPath;
}

public PrimaryDataStoreTO getPrimaryDataStore() {
return primaryDataStore;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,25 @@ public class RevertDiskOnlyVmSnapshotCommand extends Command {
private final String vmUuid;
private final boolean uefiEnabled;
private final String nvramSnapshotPath;
private final String memorySnapshotPath;

public RevertDiskOnlyVmSnapshotCommand(List<SnapshotObjectTO> snapshotObjectTos, String vmName) {
this(snapshotObjectTos, vmName, null, false, null);
}

public RevertDiskOnlyVmSnapshotCommand(List<SnapshotObjectTO> snapshotObjectTos, String vmName, String vmUuid, boolean uefiEnabled, String nvramSnapshotPath) {
this(snapshotObjectTos, vmName, vmUuid, uefiEnabled, nvramSnapshotPath, null);
}

public RevertDiskOnlyVmSnapshotCommand(List<SnapshotObjectTO> snapshotObjectTos, String vmName, String vmUuid, boolean uefiEnabled, String nvramSnapshotPath,
String memorySnapshotPath) {
super();
this.snapshotObjectTos = snapshotObjectTos;
this.vmName = vmName;
this.vmUuid = vmUuid;
this.uefiEnabled = uefiEnabled;
this.nvramSnapshotPath = nvramSnapshotPath;
this.memorySnapshotPath = memorySnapshotPath;
}

public List<SnapshotObjectTO> getSnapshotObjectTos() {
Expand All @@ -64,6 +71,10 @@ public String getNvramSnapshotPath() {
return nvramSnapshotPath;
}

public String getMemorySnapshotPath() {
return memorySnapshotPath;
}

@Override
public boolean executeInSequence() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@

public interface VMSnapshotManager extends VMSnapshotService, Manager {

static final ConfigKey<Integer> VMSnapshotExpireInterval = new ConfigKey<Integer>("Advanced", Integer.class, "vmsnapshot.expire.interval", "-1",

Check failure on line 31 in engine/components-api/src/main/java/com/cloud/vm/snapshot/VMSnapshotManager.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "Advanced" 3 times.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaItl1u3h2r7PbCfI5XB&open=AaItl1u3h2r7PbCfI5XB&pullRequest=14926
"VM Snapshot expire interval in hours", true, ConfigKey.Scope.Account);

ConfigKey<Integer> VMSnapshotMax = new ConfigKey<Integer>("Advanced", Integer.class, "vmsnapshot.max", "10", "Maximum VM snapshots for a single VM", true, ConfigKey.Scope.Account);

ConfigKey<Boolean> VMSnapshotClvmNgMemoryEnabled = new ConfigKey<Boolean>("Advanced", Boolean.class, "kvm.clvmng.vmsnapshot.memory.enabled", "false",
"EXPERIMENTAL: allow Instance snapshots with memory for running KVM Instances whose volumes are all on CLVM_NG storage. Each such snapshot reserves an extra LV the size "
+ "of the Instance memory, and writing it is slow on busy shared storage. All KVM hosts of the zone must run an agent that supports it.", true, ConfigKey.Scope.Zone);

/**
* Delete all VM snapshots belonging to one VM
* @param id, VM id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public StrategyPriority canHandle(VMSnapshot vmSnapshot) {
UserVmVO vm = userVmDao.findById(vmSnapshot.getVmId());
String cantHandleLog = String.format("Default VM snapshot cannot handle VM snapshot for [%s]", vm);

if (isRunningVMVolumeOnCLVMStorage(vm, cantHandleLog)) {
if (isRunningVMVolumeOnCLVMStorage(vm, cantHandleLog) || hasVolumeOnClvmNgStorage(vm, cantHandleLog)) {
return StrategyPriority.CANT_HANDLE;
}

Expand Down Expand Up @@ -501,6 +501,18 @@ public boolean deleteVMSnapshotFromDB(VMSnapshot vmSnapshot, boolean unmanage) {
return vmSnapshotDao.remove(vmSnapshot.getId());
}

/** Internal snapshots grow the qcow2 file, which cannot happen on a fixed size CLVM_NG LV; those VMs are handled by the KVM file based strategy. */
protected boolean hasVolumeOnClvmNgStorage(UserVmVO vm, String cantHandleLog) {
for (VolumeVO volume : volumeDao.findByInstance(vm.getId())) {
StoragePool pool = primaryDataStoreDao.findById(volume.getPoolId());
if (pool != null && pool.getPoolType() == Storage.StoragePoolType.CLVM_NG) {
logger.debug("{} - the VM has a volume on CLVM_NG storage (pool: {}), which only supports external VM snapshots.", cantHandleLog, pool.getName());
return true;
}
}
return false;
}

protected boolean isRunningVMVolumeOnCLVMStorage(UserVmVO vm, String cantHandleLog) {
Long vmId = vm.getId();
if (State.Running.equals(vm.getState())) {
Expand All @@ -522,7 +534,7 @@ public StrategyPriority canHandle(Long vmId, Long rootPoolId, boolean snapshotMe
UserVmVO vm = userVmDao.findById(vmId);
String cantHandleLog = String.format("Default VM snapshot cannot handle VM snapshot for [%s]", vm);

if (isRunningVMVolumeOnCLVMStorage(vm, cantHandleLog)) {
if (isRunningVMVolumeOnCLVMStorage(vm, cantHandleLog) || hasVolumeOnClvmNgStorage(vm, cantHandleLog)) {
return StrategyPriority.CANT_HANDLE;
}

Expand Down
Loading
Loading