Skip to content

Create volume on a specified storage pool#12966

Open
abh1sar wants to merge 1 commit intoapache:4.22from
shapeblue:create-vol-on-stroage
Open

Create volume on a specified storage pool#12966
abh1sar wants to merge 1 commit intoapache:4.22from
shapeblue:create-vol-on-stroage

Conversation

@abh1sar
Copy link
Copy Markdown
Contributor

@abh1sar abh1sar commented Apr 6, 2026

Description

This PR adds support for creating volume on the specified storage pool in the Ready state.
This can be done without attaching the volume to any instance. This can be helpful with vmware2kvm scenarios.

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

Screenshots (if appropriate):

How Has This Been Tested?

Created volume using the storageid parameter on an NFS storage pool.
Verified that volume was in Ready state with a qcow2 file created with the specified virtual size.

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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2026

Codecov Report

❌ Patch coverage is 12.50000% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.00%. Comparing base (59b6c32) to head (30ee7e2).
⚠️ Report is 3 commits behind head on 4.22.

Files with missing lines Patch % Lines
...n/java/com/cloud/storage/VolumeApiServiceImpl.java 18.18% 9 Missing ⚠️
...stack/api/command/user/volume/CreateVolumeCmd.java 0.00% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #12966      +/-   ##
============================================
+ Coverage     17.60%   18.00%   +0.39%     
- Complexity    15676    16463     +787     
============================================
  Files          5918     5977      +59     
  Lines        531667   537742    +6075     
  Branches      65001    66028    +1027     
============================================
+ Hits          93617    96834    +3217     
- Misses       427491   429990    +2499     
- Partials      10559    10918     +359     
Flag Coverage Δ
uitests 3.52% <ø> (-0.18%) ⬇️
unittests 19.17% <12.50%> (+0.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@sureshanaparti sureshanaparti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@abh1sar abh1sar changed the base branch from main to 4.22 April 6, 2026 12:56
@abh1sar
Copy link
Copy Markdown
Contributor Author

abh1sar commented Apr 7, 2026

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17378

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances CloudStack’s createVolume API to support creating a data volume directly on a specified primary storage pool (so it can reach Ready state without attaching to a VM), aimed at workflows like vmware2kvm migrations.

Changes:

  • Adds a new storageid parameter to createVolume.
  • Implements a new code path in VolumeApiServiceImpl.createVolume to create the volume on the requested primary storage pool via volService.createVolumeAsync.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java Adds a storageid branch that triggers backend volume creation on a specified primary store.
api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java Introduces the storageid API parameter and a getter intended to enforce snapshot/storage mutual exclusivity.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1046 to +1054
private VolumeVO allocateVolumeOnStorage(Long volumeId, Long storageId) throws ExecutionException, InterruptedException {
DataStore destStore = dataStoreMgr.getDataStore(storageId, DataStoreRole.Primary);
VolumeInfo destVolume = volFactory.getVolume(volumeId, destStore);
AsyncCallFuture<VolumeApiResult> createVolumeFuture = volService.createVolumeAsync(destVolume, destStore);
VolumeApiResult createVolumeResult = createVolumeFuture.get();
if (createVolumeResult.isFailed()) {
throw new CloudRuntimeException("Creation of a dest volume failed: " + createVolumeResult.getResult());
}
return _volsDao.findById(destVolume.getId());
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allocateVolumeOnStorage() doesn’t validate that the provided storageId resolves to an existing/accessible primary storage pool (dataStoreMgr.getDataStore may return null) and doesn’t check pool conditions (e.g., in-maintenance/disabled, zone mismatch with the volume, storage access groups). As-is, this can lead to NPEs and also allows callers to force volume creation on arbitrary pools bypassing the normal allocation/compatibility checks.

Consider resolving StoragePoolVO/PrimaryDataStore first, rejecting null / in-maintenance, validating the pool is in the expected state (Ready/Up) and in the same zone as the volume, and running the same compatibility checks used elsewhere (e.g., storageMgr.checkIfReadyVolumeFitsInStoragePoolWithStorageAccessGroups and doesStoragePoolSupportDiskOffering / capacity checks) before calling volService.createVolumeAsync.

Copilot uses AI. Check for mistakes.
Comment on lines +1046 to +1050
private VolumeVO allocateVolumeOnStorage(Long volumeId, Long storageId) throws ExecutionException, InterruptedException {
DataStore destStore = dataStoreMgr.getDataStore(storageId, DataStoreRole.Primary);
VolumeInfo destVolume = volFactory.getVolume(volumeId, destStore);
AsyncCallFuture<VolumeApiResult> createVolumeFuture = volService.createVolumeAsync(destVolume, destStore);
VolumeApiResult createVolumeResult = createVolumeFuture.get();
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allocateVolumeOnStorage() is a bit misleadingly named: it actually triggers backend creation (createVolumeAsync) and blocks waiting for completion. Renaming it to reflect the side-effect (e.g., createVolumeOnStoragePool) would make the control flow in createVolume() clearer and reduce confusion with allocVolume(), which only persists DB state.

Copilot uses AI. Check for mistakes.
Comment on lines +163 to +168
public Long getStorageId() {
if (snapshotId != null && storageId != null) {
throw new IllegalArgumentException("StorageId parameter cannot be specified with the SnapshotId parameter.");
}
return storageId;
}
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mutual-exclusion check for snapshotId vs storageId is currently ineffective: when snapshotId is provided, createVolume() never calls getStorageId(), so a request with both parameters will silently ignore storageid and proceed down the snapshot path.

To ensure the API contract is enforced, validate this combination in a code path that always runs (e.g., in CreateVolumeCmd.create()/execute() or in VolumeApiServiceImpl.allocVolume/createVolume before branching) and throw an InvalidParameterValueException/ServerApiException rather than letting the conflict slip through.

Copilot uses AI. Check for mistakes.
@Parameter(name = ApiConstants.STORAGE_ID,
type = CommandType.UUID,
entityType = StoragePoolResponse.class,
description = "Storage pool ID to create the volume in. Exclusive with SnapshotId parameter.")
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

storageid is a user-exposed parameter here, but there’s no indication it’s restricted (no authorized=Admin) and the backend path in VolumeApiServiceImpl doesn’t enforce pool-level access/compatibility checks. If this is intended primarily for admin/migration workflows, consider restricting the parameter to admins (as done in other user commands that expose storage pool IDs) or ensure the service layer performs full access checks before acting on the provided pool ID.

Suggested change
description = "Storage pool ID to create the volume in. Exclusive with SnapshotId parameter.")
description = "Storage pool ID to create the volume in. Exclusive with SnapshotId parameter.",
authorized = {RoleType.Admin})

Copilot uses AI. Check for mistakes.
Comment on lines +1088 to +1089
} else if (cmd.getStorageId() != null) {
volume = allocateVolumeOnStorage(cmd.getEntityId(), cmd.getStorageId());
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New storageid-driven creation path in createVolume()/allocateVolumeOnStorage isn’t covered by existing unit tests (there are tests for VolumeApiServiceImpl in server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java, but none exercise this new branch). Adding a unit test that verifies pool validation + volService.createVolumeAsync invocation and failure handling would help prevent regressions.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants