DRDAVIDBANNER opened a new pull request, #14842:
URL: https://github.com/apache/cloudstack/pull/14842

   ### Description
   
   Creating a volume from a snapshot of a volume on a PowerFlex/ScaleIO pool is 
refused today:
   `createVolume` with `snapshotid` fails with "Create volume from snapshot is 
not supported for PowerFlex volume
   snapshots". The check has been in `VolumeApiServiceImpl` since the plugin 
was added (#4304). PowerFlex users hit it
   for every restore-from-snapshot and for backup tools that clone a volume 
from a snapshot to read it.
   
   This PR makes it work and keeps the new volume independent of the source 
volume.
   
   **Why the API check existed, and why removing it is not enough.** The 
PowerFlex driver advertises
   `CAN_CREATE_VOLUME_FROM_SNAPSHOT` and `STORAGE_SYSTEM_SNAPSHOT`, so a 
snapshot → volume copy goes to
   
`StorageSystemDataMotionStrategy.handleCreateManagedVolumeFromManagedSnapshot`. 
That method creates the volume with
   the volume detail `cloneOfSnapshot=<snapshot id>` and, on KVM, copies 
nothing: it expects the driver to fill the
   volume (SolidFire, Datera and Linstor do this in their `createVolume`). The 
PowerFlex driver ignored the detail, so
   with the API check removed the operation "succeeds" and returns an **empty** 
volume. This was reproduced (see testing).
   
   **Changes**
   
   1. `ScaleIOPrimaryDataStoreDriver.createVolume` honours `cloneOfSnapshot`. 
After creating the new PowerFlex volume
      it:
      - picks a KVM host for the pool and prepares its SDC;
      - maps the snapshot volume and the new volume to that SDC;
      - sends a `CopyCommand` (snapshot → new volume, both managed volumes), so 
the agent's existing PowerFlex
        primary-to-primary copy (`copyVolumeFromPrimaryToPrimary`, `qemu-img 
convert`) copies the data;
      - unmaps both.
   
      If anything fails, the new PowerFlex volume is removed and the job fails 
with the cause.
   2. Why a copy and not a PowerFlex snapshot of the snapshot: a PowerFlex 
snapshot belongs to the volume tree (VTree) of
      its source volume, and so would a snapshot of it. Such a volume would 
share the source's VTree, which brings two
      problems:
      - it uses up the VTree's snapshot slots (127);
      - it moves with the source on `migrateVTree` and vice versa, so 
`migrateVolume` of one silently moves the other.
   
      A copy gives an ordinary, independent volume. A PowerFlex-native "fast 
clone" could be an opt-in follow-up.
   3. `VolumeApiServiceImpl`: the PowerFlex refusal is removed.
   4. `VolumeOrchestrator.createVolumeFromSnapshot` / `SnapshotHelper`: with 
`snapshot.backup.to.secondary=false`, the
      orchestrator first tries to stage a KVM snapshot that is only on primary 
storage onto secondary storage. For a
      PowerFlex snapshot that backup is a no-op 
(`StorageSystemSnapshotStrategy` keeps it on primary). The lookup of the
      secondary copy then failed ("Could not find snapshot [..] in Image 
storage", error 530). For snapshots on a
      PowerFlex pool the staging is now skipped, which is the same path as with 
`snapshot.backup.to.secondary=true`.
      Other storage types are unchanged: `isStorageSupportSnapshotToVolume` is 
limited to PowerFlex because not every
      driver that advertises `CAN_CREATE_VOLUME_FROM_SNAPSHOT` fills a volume 
created with `cloneOfSnapshot`.
   5. Refused with a clear error instead: an encrypted new volume (the copy 
would overwrite the LUKS header), and a new
      volume on a different pool than the snapshot's (already refused by 
`StorageSystemDataMotionStrategy`).
   6. Marvin `test_snapshots.py` no longer expects the refusal on PowerFlex.
   
   No agent changes: the management server reuses an existing agent copy path. 
Mixed versions are fine, and it works
   with 4.22 agents unchanged.
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [x] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   - [ ] Build/CI
   - [ ] Test (unit or integration test code)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [x] Major
   - [ ] Minor
   - [ ] Trivial
   
   ### Screenshots (if appropriate):
   
   ### How Has This Been Tested?
   
   Unit tests:
   - `ScaleIOPrimaryDataStoreDriverVolumeFromSnapshotTest` (new, 13 tests) 
covers:
     - detail lookup;
     - copy order (map snapshot, map volume, `CopyCommand`, unmap both);
     - the TOs sent to the agent;
     - removal of the new volume on copy failure, map failure, no SDC, and no 
host;
     - refusal for a snapshot on another pool, a snapshot not on primary, and 
encryption (before any PowerFlex call);
     - `createVolume` with and without the detail.
   - `SnapshotHelperTest`: 5 new tests for `isStorageSupportSnapshotToVolume` 
(PowerFlex primary, secondary role, every
     other pool type, missing capability, null).
   - All tests pass: the scaleio plugin (41), `VolumeApiServiceImplTest` (168), 
`SnapshotHelperTest` (25) and
     `VolumeOrchestratorTest` (47).
   
   Lab testing. No PowerFlex hardware was available, so the management server 
and KVM agent talked to a PowerFlex
   gateway REST simulator:
   - The simulator implements the gateway calls `ScaleIOGatewayClientImpl` 
makes: login/token, systems, pools,
     volumes, `snapshotVolumes`, SDC mapping, stats and 
`overwriteVolumeContent`.
   - It is backed by real LVM thin volumes and thin snapshots, exported over 
NBD to the KVM host.
   - An SDC stand-in on the host provides `drv_cfg` and `scini` and the 
`/dev/disk/by-id/emc-vol-<system>-<volume>`
     devices, so the KVM agent ran unmodified.
   - The real `ScaleIOGatewayClientImpl` passed 34 API checks against the 
simulator.
   - MDM, SDS, QoS enforcement and VTree migration are not simulated.
   
   The setup was CloudStack 4.22.1.1: management server and KVM agent on Ubuntu 
24.04, an Advanced zone, and the pool
   added as PowerFlex (zone-wide, tagged). Each check wrote a known 64 MiB 
pattern to a data volume of a running
   Instance, took a volume snapshot, then overwrote the volume:
   
   | Build | `snapshot.backup.to.secondary` | Result |
   |---|---|---|
   | 4.22.1.1 as released | true | `createVolume(snapshotid)` refused 
synchronously ("not supported for PowerFlex volume snapshots") |
   | API check removed only | true | job "succeeds", but the new volume is 
**all zeros** (the snapshot data is not there) |
   | first change only (API check + driver), without the staging change | false 
| job fails: "Could not find snapshot [..] in Image storage" (error 530) |
   | this PR | true | PASS (33/33 checks: the list below, the backup-tool flow 
and the copy-failure path) |
   | this PR | false | PASS (33/33, same checks) |
   
   The "this PR" rows checked, each time:
   - the new volume is Ready and on the PowerFlex pool;
   - it is an independent volume with its own VTree, not a snapshot;
   - the snapshot and the new volume are unmapped after the copy;
   - the backend devices of the snapshot and the new volume are byte-identical 
over the full 8 GiB;
   - attached to the Instance, the new volume holds the snapshot-time data and 
not the later data;
   - writing to it leaves the source untouched.
   
   Also tested:
   - **The flow a backup tool uses**: `createVolume` with only name, zoneid and 
snapshotid (no offering or size), then
     attach, read, detach and delete. The new volume is unmapped on detach and 
removed from PowerFlex on delete, and the
     snapshot is kept.
   - **Copy failure**: the simulator exported the new volume read-only, so 
`qemu-img convert` on the agent failed.
     - The job fails, and the driver logs the agent's error.
     - The new PowerFlex volume is removed, so no orphan is left on the pool.
     - The snapshot is unmapped, the CloudStack volume record goes to Destroy, 
and the source is intact.
     - Retrying with the same snapshot succeeds.
   
   #### How did you try to break this feature and the system with this change?
   
   - The copy fails on the agent, or there is no host or SDC, or a mapping 
fails: the new PowerFlex volume is removed and
     both are unmapped (`finally`). The job fails with the reason, and the 
volume record ends in Destroy.
   - An encrypted new volume, or a snapshot on another pool: refused before any 
change on PowerFlex.
   - `snapshot.backup.to.secondary` true and false: both work; the staging 
change is limited to PowerFlex.
   
   Not covered (possible follow-ups):
   - Creating a template from a PowerFlex snapshot with 
`snapshot.backup.to.secondary=false` goes through the same
     staging in `TemplateManagerImpl` and probably fails in the same way. It is 
unchanged here and was not tested.
   - An opt-in PowerFlex-native clone (snapshot of the snapshot), for 
short-lived clones where copy time matters.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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