slavkap commented on code in PR #14788:
URL: https://github.com/apache/cloudstack/pull/14788#discussion_r4666330677


##########
plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolVMSnapshotStrategy.java:
##########
@@ -185,16 +186,36 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) {
 
     @Override
     public StrategyPriority canHandle(VMSnapshot vmSnapshot) {
+        if (VMSnapshot.State.Allocated.equals(vmSnapshot.getState()) && 
VMSnapshot.Type.DiskAndMemory.equals(vmSnapshot.getType())) {
+            return StrategyPriority.CANT_HANDLE;
+        }
         return areAllVolumesOnStorPool(vmSnapshot.getVmId());
     }
 
     public StrategyPriority canHandle(Long vmId, Long rootPoolId, boolean 
snapshotMemory) {
         if (snapshotMemory) {
+            if (isAnyVolumeOnStorPool(vmId)) {

Review Comment:
   Thanks for the review. The order of the strategies doesn't matter here. 
`StorageStrategyFactoryImpl.bestMatch()` doesn't stop at the first strategy 
that accepts. It calls `canHandle()` on every registered strategy and keeps the 
one with the highest priority:
   
   ```
   for (T strategy : collection) {
       StrategyPriority priority = canHandle.canHandle(strategy);
       if (priority.ordinal() > highestPriority.ordinal()) { ... }
   }
   ```
   
   So `StorPoolVMSnapshotStrategy.canHandle(vmId, rootPoolId, true)` is always 
called during `allocVMSnapshot`, wherever it is in the list, and the exception 
always reaches the user before anything is persisted.
   
   No other strategy can legitimately take a memory snapshot of a VM with 
StorPool volumes either:
   - `StorageVMSnapshotStrategy`, `ScaleIOVMSnapshotStrategy`, 
`KvmFileBasedStorageVmSnapshotStrategy` and `LinstorVMSnapshotStrategy` all 
return `CANT_HANDLE` when `snapshotMemory` is true.
   - `DefaultVMSnapshotStrategy` is the only one that accepts, and only because 
StorPool volumes are recorded as QCOW2 in the DB. That is exactly the case this 
check prevents: the disks are raw block devices, and the snapshot ends up taken 
by the StorPool strategy as a disk-only group snapshot saved as `DiskAndMemory`.
   
   As for doing it earlier: `allocVMSnapshot` is the first point where the 
strategy is selected, and this runs as part of that selection, before the VM 
snapshot record is created. Moving it into `VMSnapshotManagerImpl` would mean 
adding StorPool-specific checks to the core manager, which the strategy 
abstraction is meant to avoid.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to