Skip to content

PowerFlex: support creating a volume from a volume snapshot - #14842

Open
DRDAVIDBANNER wants to merge 3 commits into
apache:mainfrom
DRDAVIDBANNER:powerflex-create-volume-from-snapshot
Open

DRDAVIDBANNER wants to merge 3 commits into
apache:mainfrom
DRDAVIDBANNER:powerflex-create-volume-from-snapshot

Conversation

@DRDAVIDBANNER

@DRDAVIDBANNER DRDAVIDBANNER commented Nov 24, 2026 •

Copy link
Copy Markdown

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). It blocks creating a new
volume from an existing volume snapshot (for example, to recover files, or for backup tools that clone a volume from a
snapshot to read it). Reverting a volume to a snapshot already works and is unchanged.

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:

  • with the API check removed, createVolume "succeeds" and returns an empty volume (reproduced, see testing);
  • deployVirtualMachine with snapshotid, which does not go through that API check, has the same problem today: the
    new Instance gets an empty ROOT volume.

Changes

Driver (ScaleIOPrimaryDataStoreDriver), so that the volume is filled:

  1. createVolume honours cloneOfSnapshot. Before anything is created on PowerFlex, it checks:

    • that the snapshot is on primary storage on the same pool;
    • that the snapshot's volume record exists, and neither it nor the new volume is encrypted (passphrase or KMS key).
  2. After creating the new PowerFlex volume it copies the snapshot into it through a KVM host:

    • Host: candidates are a host the pool is attached to, then the eligible KVM hosts for the pool (storage access
      groups, enabled clusters not excluded from storage operations, the pool's cluster for cluster-scoped pools). Up to
      three are tried, until one has a usable SDC. With on-demand SDC connection a host's attachment to the pool is
      removed when nothing is mapped to its SDC, so the copy can't rely on it.
    • Copy: the snapshot volume and the new volume are mapped to the host's SDC, and a CopyCommand runs the agent's
      existing PowerFlex primary-to-primary copy (copyVolumeFromPrimaryToPrimary, qemu-img convert). The source is
      always sent as RAW: a PowerFlex snapshot is a raw block device, whatever format the volume record says.
    • Unmap: the new volume is unmapped, and the snapshot only if this copy mapped it (it may be mapped for another
      operation). The unmap is best effort, as in revokeAccess. If the copy mapped nothing, the host's SDC is released
      when nothing else is mapped to it, as revokeAccess does.
  3. Lock: copies from the same snapshot on the same host are serialized with a GlobalLock, taken before the SDC is
    prepared. One such copy therefore can't unmap the snapshot, or release the SDC, while another one is preparing or
    reading it.

    • If another host can be tried, a copy waits at most 60 s for the lock, then moves to the next host.
    • Other operations on the host's SDC (an Instance stop, a template from a snapshot) are not serialized with it, as
      for grantAccess/revokeAccess today. If they overlap, either side can fail, cleanly.
    • Copies from one snapshot are therefore largely sequential (deploying many Instances from one snapshot); copies
      from different snapshots on the same host are not serialized with each other.
  4. Failure: if the copy fails (no host or SDC, a mapping failure, an agent error, or no answer), the new PowerFlex
    volume is removed, its identifiers are cleared from the volume row, and the operation fails with the cause (the
    createVolume job, or the deployVirtualMachine call).

    • The pool's used bytes are released only if the removal succeeds; otherwise a warning and a storage alert name the
      PowerFlex volume to remove by hand.
    • Deleting the snapshot is refused ("in use") while a volume is being created from it (the existing snapshot volume
      detail, not the new lock).
    • deleteAsync treats a volume with no PowerFlex volume as nothing to delete. Without that, deleting the failed
      volume row with the deleteVolume API failed ("Volume id cannot be null"), as seen in testing.
    • If the copy fails on a host before any data is copied (for example a mapping), the next candidate host is
      tried; after the copy has started it is not retried.
  5. 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.

Server and orchestration, so that it is allowed:

  1. VolumeApiServiceImpl: the PowerFlex refusal is removed. For a snapshot on a PowerFlex pool, two requests are now
    refused synchronously, after the access check (SnapshotHelper#validateVolumeFromSnapshotOnStorageCreatingVolumes):

    • a volume in another zone (it must be on the snapshot's pool);
    • an encrypted disk offering or a KMS key (the copy cannot produce an encrypted volume).

    UserVmManagerImpl (deployVirtualMachine with snapshotid) makes the same checks before the Instance is
    allocated, with the root disk offering and rootdiskkmskeyid. Both paths also refuse a snapshot of an encrypted
    volume up front.

    As before this PR, deployVirtualMachine with snapshotid creates the ROOT volume during the synchronous part of
    the API call. On PowerFlex that now includes the data copy, so a large snapshot can take minutes; API clients
    should allow for it.

  2. VolumeOrchestrator.createVolumeFromSnapshot: a volume from a PowerFlex snapshot is allocated on the snapshot's
    pool only (avoidPoolsOtherThanRequiredForSnapshot, which avoids the zone's other pools). Without this, the allocator
    could pick another pool with matching tags (another PowerFlex pool, or a non-managed pool), and the job would fail
    late.

  3. 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), and 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.
    • The decision now lives in prepareSnapshotForVolumeCreation, and is unchanged for other storage.
  4. The orchestration changes are limited to PowerFlex (SnapshotHelper#isSnapshotOnStorageCreatingVolumesFromIt,
    #getStoragePoolIdRequiredToCreateVolumeFromSnapshot, #validateVolumeFromSnapshotOnStorageCreatingVolumes). Not every
    driver that advertises CAN_CREATE_VOLUME_FROM_SNAPSHOT fills a volume created with cloneOfSnapshot, so other
    storage types are unchanged. A driver capability could replace the pool-type list later.

  5. Marvin:

    • test_snapshots.py no longer expects the refusal on PowerFlex;
    • new test_scaleio_volumes.py::test_13_create_volume_from_snapshot_keeps_the_data writes data, takes a snapshot,
      overwrites the data, creates a volume from the snapshot and compares checksums in the Instance. It needs SSH to the
      Instance (the suite's prerequisites say so) and skips without it;
    • new test_14_deploy_vm_from_root_volume_snapshot deploys an Instance from a ROOT volume snapshot.

    I have not run the Marvin tests: there was no PowerFlex Marvin environment, see testing.

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)
  • 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
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Unit tests (all pass):

  • ScaleIOPrimaryDataStoreDriverVolumeFromSnapshotTest (new, 40 tests) covers:
    • the cloneOfSnapshot lookup, and the up-front refusals (snapshot not on primary, on another pool, an encrypted
      new or source volume by passphrase or KMS key, a missing source volume record), before any PowerFlex call;
    • the copy: map snapshot, map volume, CopyCommand with a RAW source and the managed-volume TOs, unmap, all under
      the per-snapshot, per-host lock; an existing snapshot mapping is left in place;
    • failures: agent error, no answer, an exception, a mapping failure, no SDC, no host, a lock timeout. Each removes
      the new volume and releases an idle SDC; a removal failure keeps the used bytes and raises an alert;
    • host selection: the attached host first, eligible KVM hosts of the zone or the pool's cluster, at most three, and
      the next host only when the copy has not started;
    • deleteAsync of a volume without a PowerFlex volume, and createVolume with and without the detail.
  • New tests in SnapshotHelperTest (pool-type checks, required pool, up-front validation), VolumeOrchestratorTest
    (pool pinning, staging skipped for PowerFlex only) and VolumeApiServiceImplTest/UserVmManagerImplTest (the
    validation is called on both paths).
  • Totals: the scaleio plugin (68), VolumeApiServiceImplTest (168), UserVmManagerImplTest (278),
    VolumeOrchestratorTest (53) and SnapshotHelperTest (35).

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). The management server ran 4.22.1.1 with this PR's changes backported (the
KMS checks left out, as 4.22 has no KMS); the agent was unchanged. Each check wrote a known pattern to a volume of a
running Instance, took a volume snapshot, then overwrote the volume.

Before this PR:

Build Request Result
4.22.1.1 as released createVolume(snapshotid) refused synchronously ("not supported for PowerFlex volume snapshots")
4.22.1.1 as released deployVirtualMachine(snapshotid) of a ROOT snapshot Instance created with an empty ROOT volume
API check removed only createVolume(snapshotid) job "succeeds", but the new volume is all zeros
API check + driver, no staging change, snapshot.backup.to.secondary=false createVolume(snapshotid) job fails: "Could not find snapshot [..] in Image storage" (error 530)

With this PR, every group was run with snapshot.backup.to.secondary true and false:

Group Checks true false
volume from snapshot Ready, on the PowerFlex pool, own VTree, not a snapshot, unmapped after the copy, byte-identical to the snapshot over the full 8 GiB, holds the snapshot-time data in the Instance, writes don't touch the source 14/14 14/14
backup-tool flow createVolume with only name, zoneid and snapshotid; attach, read, detach (unmapped), delete (removed from PowerFlex); snapshot kept 8/8 8/8
copy failure new volume exported read-only, so qemu-img convert fails: the job fails with the agent's error, no orphan PowerFlex volume, snapshot unmapped, record not Ready and expungeable, source intact, retry succeeds 12/12 12/12
concurrent two createVolume from one snapshot at once (serialized by the lock): both succeed, both hold the snapshot data, the snapshot is unmapped after both 9/9 9/9
no Instance on the pool nothing mapped to any SDC beforehand: two volumes from a snapshot, both with the snapshot data 9/9 9/9
pool pinning an NFS pool with the same tag: four volumes from the snapshot all land on the snapshot's pool 9/9 9/9
deploy from ROOT snapshot deployVirtualMachine(snapshotid, startvm=false): the new ROOT equals the snapshot before the first boot, and the Instance starts 4/4 4/4

In total, 65/65 checks passed with each setting, in one run on the final code. Two timing defects of the simulator's SDC
stand-in turned up while testing (NBD device reuse, and an unmap that stopped the export before the host had
released the device) and made back-to-back copies fail. Both were fixed in the simulator before that run.

End to end with an external backup tool. It backs up through the CloudStack API, with snapshot.backup.to.secondary=false, an Instance whose ROOT and DATA volumes are both on the PowerFlex pool, and an ext4 file system with known files on the DATA volume. Two backups were taken, with files changed in between. For each volume, CloudStack ran:
createSnapshot, createVolume(snapshotid) (the copy in this PR), attach to the tool's appliance Instance, detach, deleteVolume, deleteSnapshot.

  • All async jobs succeeded.
  • Files restored from each backup matched the files at that point by sha256.
  • After each backup no clone volume, snapshot or PowerFlex volume was left behind.

I have not run the Marvin tests: there was no PowerFlex Marvin environment.

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 source volume, a snapshot on another pool, or a volume in another zone: refused before
    any change on PowerFlex (synchronously in the API for createVolume and deployVirtualMachine).
  • Two volumes from one snapshot at the same time: serialized per snapshot and host; both get the data, and the
    snapshot is unmapped afterwards.
  • No Instance on the pool, so no SDC is connected beforehand: the host's SDC is prepared for the copy and released
    after it.
  • Another pool with the same storage tag: never chosen for a volume from a PowerFlex snapshot.
  • 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

DRDAVIDBANNER and others added 2 commits November 24, 2026 14:51
Creating a volume from a snapshot of a volume on a PowerFlex/ScaleIO pool
was refused by the API ("Create volume from snapshot is not supported for
PowerFlex volume snapshots"). The refusal guarded a real gap: the driver
advertises CAN_CREATE_VOLUME_FROM_SNAPSHOT, so StorageSystemDataMotionStrategy
creates the new volume with the "cloneOfSnapshot" volume detail and, on KVM,
expects the driver to fill it; the PowerFlex driver ignored the detail and
created an empty volume.

ScaleIOPrimaryDataStoreDriver.createVolume now honours "cloneOfSnapshot":
after creating the new PowerFlex volume it maps the snapshot and the new
volume to the SDC of a KVM host and copies the data with a CopyCommand
(the agent's existing PowerFlex primary-to-primary copy). The new volume is
independent of the source volume's VTree (its own lifecycle, migrations and
VTree snapshot limit). Both are unmapped afterwards; if the copy fails, the
new PowerFlex volume is removed and the job fails with the cause. Creating
an encrypted volume from a snapshot, or onto a different pool than the
snapshot's, is refused with a clear error.

The API check is removed, and the Marvin smoke test no longer expects it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With snapshot.backup.to.secondary=false, VolumeOrchestrator.createVolumeFromSnapshot
tries to back up a KVM snapshot that is kept only on primary storage to
secondary storage first. For a PowerFlex snapshot that backup is a no-op
(StorageSystemSnapshotStrategy keeps it on primary), so the lookup of the
secondary copy then fails ("Could not find snapshot [..] in Image storage")
and the job fails with error 530.

The PowerFlex driver creates the volume from its snapshot on the pool itself,
so for snapshots on a PowerFlex pool the orchestrator now skips the staging
and uses the snapshot on primary storage, as it already does when
snapshot.backup.to.secondary=true. Other storage types are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Before creating anything on PowerFlex, check that the snapshot is on the
  same pool and that neither the new volume nor the snapshot's volume is
  encrypted; refuse the same up front in createVolume and in
  deployVirtualMachine with a snapshot (other zone, encryption), after the
  access check.
- Send the snapshot to the agent as RAW: a PowerFlex snapshot is a raw block
  device, whatever format the volume record says.
- Copy host: a host the pool is attached to, then eligible KVM hosts (storage
  access groups, enabled clusters not excluded from storage operations, the
  pool's cluster for cluster-scoped pools); up to three are tried. With
  on-demand SDC connection the pool attachment is removed when nothing is
  mapped, so the copy must not depend on it.
- Serialize copies from the same snapshot on the same host with a GlobalLock
  taken before the SDC is prepared; unmap the snapshot only if this copy
  mapped it; release an SDC a copy prepared but did not use.
- On failure, remove the new PowerFlex volume, clear its identifiers, release
  its used bytes only if the removal succeeded, else raise a storage alert;
  deleteAsync treats a volume without a PowerFlex volume as nothing to delete.
- Allocate a volume from a PowerFlex snapshot on the snapshot's pool only.
- Move the snapshot staging decision of createVolumeFromSnapshot into
  prepareSnapshotForVolumeCreation (unchanged for other storage).
- Tests: driver, SnapshotHelper, VolumeOrchestrator unit tests; Marvin
  test_13 (data check of a volume from a snapshot) and test_14 (deploy an
  Instance from a ROOT volume snapshot).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DRDAVIDBANNER
DRDAVIDBANNER marked this pull request as ready for review November 24, 2026 20:57

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant