Skip to content

<fix>[kvm]: user vm mount model#3599

Open
MatheMatrix wants to merge 1 commit intofeature-5.5.12-dgpufrom
sync/zhong.xian/feat/ZSTAC-83157@@2
Open

<fix>[kvm]: user vm mount model#3599
MatheMatrix wants to merge 1 commit intofeature-5.5.12-dgpufrom
sync/zhong.xian/feat/ZSTAC-83157@@2

Conversation

@MatheMatrix
Copy link
Owner

DBImpact

Resolves: ZSTAC-83157

Change-Id: I746679736f7a7176646e646d797969766f697a76

sync from gitlab !9459

@coderabbitai
Copy link

coderabbitai bot commented Mar 26, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: a692432a-f80a-4ba6-85fa-7d9c4cfe3b3a

📥 Commits

Reviewing files that changed from the base of the PR and between 8f3da0f and 40df30e.

⛔ Files ignored due to path filters (10)
  • conf/i18n/globalErrorCodeMapping/global-error-zh_CN.json is excluded by !**/*.json
  • sdk/src/main/java/SourceClassMap.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/MountModelToVmInstanceAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/MountModelToVmInstanceResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/QueryVmModelMountAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/QueryVmModelMountResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UnmountModelFromVmInstanceAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UnmountModelFromVmInstanceResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/VmModelMountInventory.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/VmModelMountStatus.java is excluded by !sdk/**
📒 Files selected for processing (4)
  • conf/db/upgrade/V5.5.12__schema.sql
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMConstant.java
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
  • utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
✅ Files skipped from review due to trivial changes (1)
  • conf/db/upgrade/V5.5.12__schema.sql
🚧 Files skipped from review as they are similar to previous changes (2)
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMConstant.java
  • utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

Walkthrough

新增 VM 模型挂载持久化表、KVM 路由常量、测试库 API 封装方法及 12 个错误码常量,涉及数据库模式、KVM 常量、测试库与错误码声明的基础设施改动(均为新增内容,无现有逻辑删除)。

Changes

Cohort / File(s) Summary
数据库模式
conf/db/upgrade/V5.5.12__schema.sql
新增表 zstack.VmModelMountVO,字段包含 uuid(主键)、vmInstanceUuidmodelUuidmodelNamemountPathsourcePathstatushostUuidaccountUuid、审计时间;增加唯一约束 uk_vm_mountpath (vmInstanceUuid, mountPath(255))vmInstanceUuidmodelUuid 分别为 VmInstanceEO(uuid)ModelVO(uuid) 的外键,均 ON DELETE CASCADE
KVM 常量
plugin/kvm/src/main/java/org/zstack/kvm/KVMConstant.java
新增三个公开常量路径:KVM_VIRTIOFS_ATTACH_PATH = "/virtiofs/attach"KVM_VIRTIOFS_DETACH_PATH = "/virtiofs/detach"KVM_MODEL_CENTER_MOUNT_PATH = "/modelcenter/mount"
测试库(ApiHelper)
testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
新增三方法:mountModelToVmInstancequeryVmModelMountunmountModelFromVmInstance;每方法构建对应 SDK Action、设置 sessionId、通过闭包填充请求并执行;支持可选的 API 路径追踪(apipath 系统属性)并返回调用结果;queryVmModelMount 在调用前将 conditions 元素转换为字符串。
错误码常量
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
新增 12 个错误码常量:ORG_ZSTACK_AI_10138ORG_ZSTACK_AI_10149,用于模型挂载相关错误标识。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

庆祝诗

🐰 我在代码丛中跳跃忙,
新表新径悄然长,
测试轻敲开门窗,
错误码排队响,
模型挂载乐融融!


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Title check ❌ Error PR title uses <fix> prefix but changes introduce new feature (VM model mount functionality), should be <feature> per reviewer comment N1. Change PR title from <fix>[kvm]: user vm mount model to <feature>[kvm]: user vm mount model to accurately reflect that this is a new feature, not a fix.
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 (1 passed)
Check name Status Explanation
Description check ✅ Passed PR description mentions DBImpact, JIRA ticket ZSTAC-83157, and references the upstream GitLab MR, which relate to the changeset of adding VM model mount functionality.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/zhong.xian/feat/ZSTAC-83157@@2

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.41.1)
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java (2)

5189-5214: 建议为新增 DTO 字段补充 @GrayVersion,让灰度升级行为更可控。

当前新增命令/响应字段未标注版本信息。建议按本文件既有模式补齐,避免升级窗口期出现字段下发不一致。

♻️ 参考改法(示例)
 public static class KvmAttachVirtiofsCmd extends AgentCommand {
+    `@GrayVersion`(value = "5.5.12")
     public String vmInstanceUuid;
+    `@GrayVersion`(value = "5.5.12")
     public String tag;
+    `@GrayVersion`(value = "5.5.12")
     public String sourcePath;
+    `@GrayVersion`(value = "5.5.12")
     public String mountPath;
 }

As per coding guidelines “向后兼容原则:之前的代码产生的行为不要直接去改动…应当做好兼容/开关控制”。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java` around lines
5189 - 5214, Add `@GrayVersion` annotations to the newly introduced DTOs/fields so
gray/rolling upgrades remain controlled; specifically annotate the classes
and/or their fields in KvmAttachVirtiofsCmd (vmInstanceUuid, tag, sourcePath,
mountPath), KvmAttachVirtiofsRsp, KvmDetachVirtiofsCmd (vmInstanceUuid, tag),
KvmDetachVirtiofsRsp, MountModelCenterCmd (modelCenterUuid, zdfsUrl) and
MountModelCenterRsp (mountPoint) following the existing `@GrayVersion` placement
pattern used elsewhere in this file (match annotation placement and version
values consistent with neighboring DTOs) to preserve backward compatibility
during rollout.

5189-5210: 建议对新增命令参数做 trim 归一化,避免因空白字符导致挂载参数失配。

这些字段来自上游消息输入,当前直接暴露为 public 且无归一化处理,容易把复制粘贴带来的空格/换行带入 uuid/url/path/tag

♻️ 参考改法(示例)
 public static class MountModelCenterCmd extends AgentCommand {
-    public String modelCenterUuid;
-    public String zdfsUrl;
+    private String modelCenterUuid;
+    private String zdfsUrl;
+
+    public String getModelCenterUuid() {
+        return modelCenterUuid;
+    }
+
+    public void setModelCenterUuid(String modelCenterUuid) {
+        this.modelCenterUuid = modelCenterUuid == null ? null : modelCenterUuid.trim();
+    }
+
+    public String getZdfsUrl() {
+        return zdfsUrl;
+    }
+
+    public void setZdfsUrl(String zdfsUrl) {
+        this.zdfsUrl = zdfsUrl == null ? null : zdfsUrl.trim();
+    }
 }

As per coding guidelines “注意检查来自 Message 的参数是否做过 trim,用户可能在浏览器上复制粘贴的数据带有空格、换行符等”。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java` around lines
5189 - 5210, The new AgentCommand classes expose raw public string fields that
may contain leading/trailing whitespace from upstream messages; update
KvmAttachVirtiofsCmd (vmInstanceUuid, tag, sourcePath, mountPath),
KvmDetachVirtiofsCmd (vmInstanceUuid, tag) and MountModelCenterCmd
(modelCenterUuid, zdfsUrl) to normalize inputs by trimming whitespace: make the
string fields private and add setters that call .trim() (or add a
normalize/validate() method that trims all fields and is invoked after
deserialization) so all UUID/URL/path/tag values are canonicalized before use.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java`:
- Around line 5189-5214: Add `@GrayVersion` annotations to the newly introduced
DTOs/fields so gray/rolling upgrades remain controlled; specifically annotate
the classes and/or their fields in KvmAttachVirtiofsCmd (vmInstanceUuid, tag,
sourcePath, mountPath), KvmAttachVirtiofsRsp, KvmDetachVirtiofsCmd
(vmInstanceUuid, tag), KvmDetachVirtiofsRsp, MountModelCenterCmd
(modelCenterUuid, zdfsUrl) and MountModelCenterRsp (mountPoint) following the
existing `@GrayVersion` placement pattern used elsewhere in this file (match
annotation placement and version values consistent with neighboring DTOs) to
preserve backward compatibility during rollout.
- Around line 5189-5210: The new AgentCommand classes expose raw public string
fields that may contain leading/trailing whitespace from upstream messages;
update KvmAttachVirtiofsCmd (vmInstanceUuid, tag, sourcePath, mountPath),
KvmDetachVirtiofsCmd (vmInstanceUuid, tag) and MountModelCenterCmd
(modelCenterUuid, zdfsUrl) to normalize inputs by trimming whitespace: make the
string fields private and add setters that call .trim() (or add a
normalize/validate() method that trims all fields and is invoked after
deserialization) so all UUID/URL/path/tag values are canonicalized before use.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 1df8207b-0207-42b1-9154-53fa2280c06f

📥 Commits

Reviewing files that changed from the base of the PR and between f07267a and bf9f93e.

⛔ Files ignored due to path filters (10)
  • conf/i18n/globalErrorCodeMapping/global-error-zh_CN.json is excluded by !**/*.json
  • sdk/src/main/java/SourceClassMap.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/MountModelToVmInstanceAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/MountModelToVmInstanceResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/QueryVmModelMountAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/QueryVmModelMountResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UnmountModelFromVmInstanceAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UnmountModelFromVmInstanceResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/VmModelMountInventory.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/VmModelMountStatus.java is excluded by !sdk/**
📒 Files selected for processing (5)
  • conf/db/upgrade/V5.5.12__schema.sql
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMConstant.java
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
  • utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

@ZStack-Robot
Copy link
Collaborator

Comment from ye.zou:

Code Review: ZSTAC-83157 — 用户VM挂载模型 (zstack 部分)

Verdict: 🚫 BLOCK — 完整 review 见 premium !13327 评论,此处列本 MR 相关问题。

本 MR 问题

N1. MR title 写 <fix>[kvm],这是新功能不是 bug fix,应该 <feature>[kvm]

M1. KVM 命令命名冗余前缀

public static class KvmAttachVirtiofsCmd extends AgentCommand { ... }
public static class KvmDetachVirtiofsCmd extends AgentCommand { ... }

KVMAgentCommands 内部类不需要 Kvm 前缀,同文件其他命令都没有(StartVmCmd, StopVmCmd, AttachDataVolumeCmd)。改成 AttachVirtiofsCmd / DetachVirtiofsCmd

其余部分没问题

  • DB schema VmModelMountVO 表结构合理,唯一约束 uk_vm_mountpath 正确
  • error code 分配 10138-10149 连续无冲突
  • SDK 生成文件无需手动审

完整 review 含 4 Critical + 5 Major 见 premium !13327
Review by @ye.zou

@zstack-robot-2
Copy link
Collaborator

Comment from ye.zou:

补充 Review:命名规范

M2. MountModelCenterCmd.zdfsUrl 绑死 ZDFS 实现 — 必须改

public static class MountModelCenterCmd extends AgentCommand {
    public String modelCenterUuid;
    public String zdfsUrl;     // ← 绑死 ZDFS
}

Agent 协议是跨版本契约,字段改名要做兼容处理,代价随版本递增。第一版就该取对:zdfsUrlstorageUrlmetaUrl

"ZDFS" 是当前实现选择(ZStack 封装的 JuiceFS),不是能力描述。如果明天换 CephFS/NFS,这个字段名就是负债。

详见 premium !13327 补充 review。


补充 Review by @ye.zou

@ZStack-Robot
Copy link
Collaborator

Comment from zhong.xian:

已修改

@zstack-robot-1
Copy link
Collaborator

Comment from zhong.xian:

已经修改

@MatheMatrix MatheMatrix force-pushed the sync/zhong.xian/feat/ZSTAC-83157@@2 branch 3 times, most recently from a6eae48 to 8f3da0f Compare March 27, 2026 08:04
Add virtiofs-based model mounting capability for user VMs:
- Add VmModelMountVO database table and schema with hostUuid tracking
- Add AttachVirtiofsCmd/DetachVirtiofsCmd for KVM agent
- Add MountModelCenterCmd with storageUrl field
- Add SDK actions for mount/unmount/query operations
- Add error codes 10138-10149

Resolves: ZSTAC-83157
Change-Id: I746679736f7a7176646e646d797969766f697a76
@MatheMatrix MatheMatrix force-pushed the sync/zhong.xian/feat/ZSTAC-83157@@2 branch from 8f3da0f to 40df30e Compare March 27, 2026 08:32
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.

4 participants