Skip to content

Linstor: fix create volume from snapshot on primary storage#13043

Open
Kukunin wants to merge 1 commit intoapache:mainfrom
Kukunin:linstor-snapshot-to-volume
Open

Linstor: fix create volume from snapshot on primary storage#13043
Kukunin wants to merge 1 commit intoapache:mainfrom
Kukunin:linstor-snapshot-to-volume

Conversation

@Kukunin
Copy link
Copy Markdown

@Kukunin Kukunin commented Apr 18, 2026

Context

I run a private cloud using 4.22 CloudStack, with Linstor primary storage, Kubernetes, CloudStack CSI driver with additional registry.k8s.io/sig-storage/csi-snapshotter:v8.2.1 sidecar and snapshot-controller.

I wanted to duplicate PVC from kubectl, by creating a snapshot and restoring another PVC from the snapshot. The main problem is that the snapshot wanted to be copied to SecondaryStorage, which is not what I wanted. Secondary storage is slow and outside of the network, so transferring 1TB volume is long and silly. I got a chain of errors, identified those, and prepared a patch that solved my issues. I built and pushed only cloud-plugin-storage-volume-linstor-4.22.0.0.jar to my servers, and after restarting both management / agent services, the PVC copy via snapshots worked fine. Also I modified the following cloudstack settings:

Setting Value Was Purpose
kvm.snapshot.enabled true false Allow snapshots on running KVM VMs
snapshot.backup.to.secondary false true Skip secondary storage backup for snapshots
lin.backup.snapshots false false Linstor-specific: keep snapshots on primary storage only

Description

When creating a volume from a snapshot on Linstor primary storage (with lin.backup.snapshots=false), the operation fails with:

Only the following image types are currently supported: VHD, OVA, QCOW2, RAW (for PowerFlex and FiberChannel)

Root cause: The Linstor driver does not handle SNAPSHOT → VOLUME in its canCopy()/copyAsync() methods. This causes DataMotionServiceImpl to fall through to StorageSystemDataMotionStrategy (selected because Linstor advertises STORAGE_SYSTEM_SNAPSHOT=true). That strategy's verifyFormatWithPoolType() rejects RAW format for Linstor pools, since RAW is only allowed for PowerFlex and FiberChannel.

Additionally, VolumeOrchestrator.createVolumeFromSnapshot() attempts to back up the snapshot to secondary storage when the storage plugin does not advertise CAN_CREATE_TEMPLATE_FROM_SNAPSHOT. This backup fails because the snapshot only exists on Linstor primary storage.

Fix:

  • Add CAN_CREATE_TEMPLATE_FROM_SNAPSHOT capability so the orchestrator skips the backup-to-secondary path
  • Add canCopySnapshotToVolumeCond() to match SNAPSHOT → VOLUME when both are on the same Linstor primary store
  • Wire it into canCopy() to intercept at DataMotionServiceImpl before strategy selection, bypassing StorageSystemDataMotionStrategy entirely
  • Implement copySnapshotToVolume() which delegates to the existing createResourceFromSnapshot() for native Linstor snapshot restore

This follows the same pattern used by the StorPool plugin, which handles SNAPSHOT → VOLUME directly in its driver rather than going through StorageSystemDataMotionStrategy.

Fixes: #11451

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

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

Unit tests: 5 new tests added to LinstorPrimaryDataStoreDriverImplTest:

  • testGetCapabilitiesIncludesCreateTemplateFromSnapshot — verifies the capability is advertised
  • testCanCopySnapshotToVolumeOnSamePrimary — verifies canCopy() returns true for SNAPSHOT → VOLUME on same Linstor primary
  • testCanCopySnapshotToVolumeRejectsNonLinstor — verifies canCopy() returns false for non-Linstor storage
  • testCanCopySnapshotToVolumeRejectsCrossPrimary — verifies canCopy() returns false across different primary stores
  • testCanCopySnapshotToVolumeRejectsImageDest — verifies canCopy() returns false when destination is Image store

Integration test: Tested on CloudStack 4.22 with Linstor LVM_THIN storage (DRBD-replicated across 3 nodes), creating a volume from a 1TB CNPG Postgres database snapshot via createVolume API:

  • Volume creates successfully with state=Ready and correct UUID path
  • Volume deletes cleanly (both CloudStack DB and Linstor resource)
  • Linstor resource is properly created via native snapshot restore (resourceSnapshotRestore API)

How did you try to break this feature and the system with this change?

  • Verified that the existing canCopy() paths (SNAPSHOT→SNAPSHOT to Image, TEMPLATE→TEMPLATE, VOLUME→VOLUME/TEMPLATE) are not affected by the new condition being checked first
  • Verified cross-primary-store and non-Linstor scenarios are rejected
  • Verified volume path is stored as UUID (not device path) to ensure delete operations work correctly
  • The change is confined to the Linstor plugin — no modifications to shared CloudStack code

When creating a volume from a snapshot on Linstor primary storage
(with lin.backup.snapshots=false), the operation fails with:
"Only the following image types are currently supported: VHD, OVA,
QCOW2, RAW (for PowerFlex and FiberChannel)"

Root cause: the Linstor driver does not handle SNAPSHOT -> VOLUME in
its canCopy()/copyAsync() methods. This causes DataMotionServiceImpl
to fall through to StorageSystemDataMotionStrategy (selected because
Linstor advertises STORAGE_SYSTEM_SNAPSHOT=true). That strategy's
verifyFormatWithPoolType() rejects RAW format for Linstor pools,
since RAW is only allowed for PowerFlex and FiberChannel.

Additionally, VolumeOrchestrator.createVolumeFromSnapshot() attempts
to back up the snapshot to secondary storage when the storage plugin
does not advertise CAN_CREATE_TEMPLATE_FROM_SNAPSHOT. This backup
fails because the snapshot only exists on Linstor primary storage.

Fix:
- Add CAN_CREATE_TEMPLATE_FROM_SNAPSHOT capability so the
  orchestrator skips the backup-to-secondary path
- Add canCopySnapshotToVolumeCond() to match SNAPSHOT -> VOLUME
  when both are on the same Linstor primary store
- Wire it into canCopy() to intercept at DataMotionServiceImpl
  before strategy selection, bypassing StorageSystemDataMotionStrategy
- Implement copySnapshotToVolume() which delegates to the existing
  createResourceFromSnapshot() for native Linstor snapshot restore

This follows the same pattern used by the StorPool plugin, which
handles SNAPSHOT -> VOLUME directly in its driver rather than going
through StorageSystemDataMotionStrategy.

Tested on CloudStack 4.22 with Linstor LVM_THIN storage, creating
a volume from a 1TB CNPG Postgres database snapshot. Volume creates
successfully with correct path and deletes cleanly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Kukunin Kukunin requested a review from rp- as a code owner April 18, 2026 01:55
@boring-cyborg
Copy link
Copy Markdown

boring-cyborg bot commented Apr 18, 2026

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

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.

LINSTOR create template from snapshot not working

1 participant