Skip to content

<feature>[storage]: switch volume encryption conversion to new install path#4530

Open
ZStack-Robot wants to merge 1 commit into
dev/encrypted-volume-snapshot-conversion-rollback@@3from
sync/zstackio/dev/encrypted-volume-snapshot-new-install-path@@3
Open

<feature>[storage]: switch volume encryption conversion to new install path#4530
ZStack-Robot wants to merge 1 commit into
dev/encrypted-volume-snapshot-conversion-rollback@@3from
sync/zstackio/dev/encrypted-volume-snapshot-new-install-path@@3

Conversation

@ZStack-Robot

Copy link
Copy Markdown
Collaborator

Summary

Switch volume/snapshot encryption conversion to generate a new installPath on top of the rollback refactor branch. Source bits stay untouched before DB commit; rollback only cleans the new target path.

Changes

  • Generate unique target installPath for each volume/snapshot conversion.
  • Remove pre-conversion source-to-trash rename from the conversion command model.
  • Update volume/snapshot/ref installPath in one DB commit and record old source paths in Trash after commit.
  • Keep the existing RBD snapshot restriction from the rollback branch.

Testing

  • cbok zsv groovy_test --refresh-worktree --test-class org.zstack.test.integration.crypto.volume.EncryptVolumeConversionCase --test-mode case --run-id encrypted-volume-snapshot-conversion-rollback (Tests run: 1, Failures: 0, Errors: 0, Skipped: 0)

sync from gitlab !10492

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dcd13595-2947-4e75-9c05-e1280307f76e

📥 Commits

Reviewing files that changed from the base of the PR and between 9b021ab and 5130ac3.

⛔ Files ignored due to path filters (1)
  • conf/springConfigXml/VolumeManager.xml is excluded by !**/*.xml
📒 Files selected for processing (34)
  • compute/src/main/java/org/zstack/compute/vm/VmInstantiateOtherDiskFlow.java
  • header/src/main/java/org/zstack/header/storage/addon/primary/CreateVolumeSpec.java
  • header/src/main/java/org/zstack/header/storage/addon/primary/PrimaryStorageControllerSvc.java
  • header/src/main/java/org/zstack/header/storage/addon/primary/ZbsVolumeEncryptionBackend.java
  • header/src/main/java/org/zstack/header/storage/addon/primary/ZbsVolumeEncryptionExtensionPoint.java
  • header/src/main/java/org/zstack/header/storage/primary/ConvertVolumeEncryptionOnPrimaryStorageMsg.java
  • header/src/main/java/org/zstack/header/storage/primary/EncryptVolumeBitsOnPrimaryStorageMsg.java
  • header/src/main/java/org/zstack/header/storage/primary/EncryptVolumeBitsOnPrimaryStorageReply.java
  • plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java
  • plugin/expon/src/main/java/org/zstack/expon/ExponStorageController.java
  • plugin/zbs/src/main/java/org/zstack/storage/zbs/ZbsStorageController.java
  • plugin/zbs/src/main/java/org/zstack/storage/zbs/ZbsVolumeEncryptionBackendImpl.java
  • storage/src/main/java/org/zstack/storage/addon/primary/ExternalPrimaryStorage.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsEncryptedEmptyVolumeCreator.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsEncryptedSnapshotVolumeCopier.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsEncryptedVolumeCloner.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsEncryptedVolumeResizer.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsVolumeEncryptInPlaceHandler.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsVolumeEncryptionCleanup.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsVolumeEncryptionCommands.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsVolumeEncryptionConstants.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsVolumeEncryptionExtension.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsVolumeEncryptionKvmCaller.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsVolumeEncryptionMaterial.java
  • storage/src/main/java/org/zstack/storage/encrypt/ZbsVolumeEncryptionMaterialFactory.java
  • storage/src/main/java/org/zstack/storage/volume/VolumeBase.java
  • storage/src/main/java/org/zstack/storage/volume/VolumeInPlaceEncryptor.java
  • storage/src/main/java/org/zstack/storage/volume/VolumeManagerImpl.java
  • test/src/test/groovy/org/zstack/storage/volume/VolumeManagerImplHostSelectionTest.groovy
  • test/src/test/groovy/org/zstack/test/integration/storage/primary/addon/zbs/ZbsVolumeEncryptionCase.groovy
  • test/src/test/groovy/org/zstack/test/unittest/storage/encrypt/VolumeEncryptedInitialExtensionTest.groovy
  • testlib/src/main/java/org/zstack/testlib/CephPrimaryStorageSpec.groovy
  • testlib/src/main/java/org/zstack/testlib/LocalStorageSpec.groovy
  • testlib/src/main/java/org/zstack/testlib/NfsPrimaryStorageSpec.groovy

Walkthrough

Changes

卷加密转换流程

Layer / File(s) Summary
转换路径与上下文准备
header/src/main/java/org/zstack/header/storage/primary/ConvertVolumeEncryptionOnPrimaryStorageMsg.java, storage/src/main/java/org/zstack/storage/volume/VolumeBase.java
转换项移除源Trash安装路径;转换目标路径改用目标加密状态和转换UUID生成,并调整旧libvirt secret及主机标签清理。
Ceph转换与大小同步
plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java
转换前检查目标路径,随后发送KVM转换命令;成功响应优先使用actualSize,缺失时同步目标卷大小,并移除旧替换命令及路径。
转换模拟同步
testlib/src/main/java/org/zstack/testlib/CephPrimaryStorageSpec.groovy
移除LUKS_REPLACE_VOLUME_PATH对应的测试模拟逻辑。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant VolumeBase
  participant CephPrimaryStorageBase
  participant KVMHost
  participant TargetVolume
  VolumeBase->>CephPrimaryStorageBase: 提交加密转换项
  CephPrimaryStorageBase->>KVMHost: 检查目标路径
  CephPrimaryStorageBase->>KVMHost: 执行LUKS转换
  KVMHost-->>CephPrimaryStorageBase: 返回actualSize或空结果
  CephPrimaryStorageBase->>TargetVolume: 空结果时同步实际大小
  CephPrimaryStorageBase-->>VolumeBase: 返回转换结果
Loading

Poem

小兔挥爪改路径,
Trash 不再藏秘密。
KVM 转换亮晶晶,
大小同步落成形。
Ceph 回声传得远,
新流程蹦过田。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了本 PR 的核心变更:为卷加密转换切换到新的 installPath。
Description check ✅ Passed 描述与代码变更一致,概述了新的目标路径生成、去除 source-to-trash 以及提交后更新路径。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/zstackio/dev/encrypted-volume-snapshot-new-install-path@@3

Comment @coderabbitai help to get the list of available commands.

@MatheMatrix MatheMatrix force-pushed the sync/zstackio/dev/encrypted-volume-snapshot-new-install-path@@3 branch 4 times, most recently from 3a1ea10 to 9b021ab Compare July 10, 2026 08:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
storage/src/main/java/org/zstack/storage/volume/VolumeBase.java (1)

3636-3660: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

布尔参数在调用点含义不明确,建议改进。

makeConvertedResourceFileName(resourceUuid, targetEncrypted, conversionUuid, qcow2File)qcow2File(以及 makeConvertedVolumeInstallPath/makeConvertedSnapshotInstallPathtargetEncrypted)在调用点以裸 true/false 传入,可读性较差,例如 makeConvertedResourceFileName(resourceUuid, targetEncrypted, conversionUuid, false)。可考虑拆分为语义化方法(如 makeConvertedQcow2FileName/makeConvertedRawFileName)或使用枚举表达文件类型。

As per path instructions: 避免使用布尔型参数造成含义不明确,建议拆分为不同函数或使用枚举表达操作类型。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@storage/src/main/java/org/zstack/storage/volume/VolumeBase.java` around lines
3636 - 3660, 重构 makeConvertedResourceFileName 及其调用点,避免通过裸布尔值表示文件类型;拆分为语义明确的
makeConvertedQcow2FileName 和 makeConvertedRawFileName,或使用枚举表达类型,并更新
makeConvertedVolumeInstallPath、makeConvertedSnapshotInstallPath 中的所有调用。

Source: Path instructions

plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java (1)

3620-3641: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

建议将 DEK 封装移到目标存在性检查通过之后。

当前 materializeAndSealVolumeDekForHost(...)(Line 3620)在 CheckIsBitsExistingCmd 检查之前执行;若目标路径已存在(Line 3628 直接返回错误),则已在宿主上封装/暂存的 DEK 未被使用,属于无谓开销,并可能在宿主上残留 secret 材料。建议把 kcmd.encryptedDek = ... 移入存在性检查成功且 !isExisting() 的分支(即 convertVolumeEncryptionOnKvmHost 调用前)再计算。

请确认 materializeAndSealVolumeDekForHost 是否在宿主侧产生需要清理的 secret 副作用,以评估影响范围。

♻️ 建议的调整
         KVMHostLuksConvertCmd kcmd = new KVMHostLuksConvertCmd();
         kcmd.psUuid = self.getUuid();
         kcmd.installPath = item.getSourceInstallPath();
         kcmd.targetInstallPath = item.getTargetInstallPath();
         kcmd.targetEncrypted = msg.isTargetEncrypted();
         kcmd.virtualSize = msg.getVolume().getSize();
-        kcmd.encryptedDek = volumeEncryptedSecretHelper.materializeAndSealVolumeDekForHost(hostUuid, msg.getVolume().getUuid());

         CheckIsBitsExistingCmd checkTargetCmd = new CheckIsBitsExistingCmd();
         checkTargetCmd.setInstallPath(item.getTargetInstallPath());
         httpCall(CHECK_BITS_PATH, checkTargetCmd, CheckIsBitsExistingRsp.class,
                 new ReturnValueCompletion<CheckIsBitsExistingRsp>(msg) {
                     `@Override`
                     public void success(CheckIsBitsExistingRsp returnValue) {
                         if (returnValue.isExisting()) {
                             reply.setError(operr("RBD LUKS conversion target already exists: %s", item.getTargetInstallPath()));
                             bus.reply(msg, reply);
                             return;
                         }
+                        kcmd.encryptedDek = volumeEncryptedSecretHelper.materializeAndSealVolumeDekForHost(hostUuid, msg.getVolume().getUuid());
                         convertVolumeEncryptionOnKvmHost(msg, reply, kcmd, hostUuid);
                     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java`
around lines 3620 - 3641, 将 materializeAndSealVolumeDekForHost 的调用从
CheckIsBitsExistingCmd 检查之前移入 success 方法中确认 !returnValue.isExisting() 的分支,并在调用
convertVolumeEncryptionOnKvmHost 前为 kcmd.encryptedDek 赋值;保持目标已存在或检查失败时不生成
DEK,同时确认该方法产生的宿主侧 secret 副作用及清理行为。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java`:
- Around line 3620-3641: 将 materializeAndSealVolumeDekForHost 的调用从
CheckIsBitsExistingCmd 检查之前移入 success 方法中确认 !returnValue.isExisting() 的分支,并在调用
convertVolumeEncryptionOnKvmHost 前为 kcmd.encryptedDek 赋值;保持目标已存在或检查失败时不生成
DEK,同时确认该方法产生的宿主侧 secret 副作用及清理行为。

In `@storage/src/main/java/org/zstack/storage/volume/VolumeBase.java`:
- Around line 3636-3660: 重构 makeConvertedResourceFileName
及其调用点,避免通过裸布尔值表示文件类型;拆分为语义明确的 makeConvertedQcow2FileName 和
makeConvertedRawFileName,或使用枚举表达类型,并更新
makeConvertedVolumeInstallPath、makeConvertedSnapshotInstallPath 中的所有调用。

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b6531ed8-e10b-481f-b03e-6eb5a83dca86

📥 Commits

Reviewing files that changed from the base of the PR and between 763f2db and 9b021ab.

📒 Files selected for processing (4)
  • header/src/main/java/org/zstack/header/storage/primary/ConvertVolumeEncryptionOnPrimaryStorageMsg.java
  • plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java
  • storage/src/main/java/org/zstack/storage/volume/VolumeBase.java
  • testlib/src/main/java/org/zstack/testlib/CephPrimaryStorageSpec.groovy
💤 Files with no reviewable changes (2)
  • header/src/main/java/org/zstack/header/storage/primary/ConvertVolumeEncryptionOnPrimaryStorageMsg.java
  • testlib/src/main/java/org/zstack/testlib/CephPrimaryStorageSpec.groovy

@MatheMatrix MatheMatrix force-pushed the sync/zstackio/dev/encrypted-volume-snapshot-new-install-path@@3 branch 8 times, most recently from 23608ea to 21355ca Compare July 11, 2026 05:12
Resolves: ZSV-12469

Change-Id: I65c44aa24161e828aab27463512ff5046c402789
@MatheMatrix MatheMatrix force-pushed the dev/encrypted-volume-snapshot-conversion-rollback@@3 branch from 763f2db to ab4f2b5 Compare July 11, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant