CreateSharedFileSystem NPE ("template is null") when zone has mixed hypervisor types
已经有一个关联 PR 被合并了。
- #13830 来自 @Dogface2k —— 已合并
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- java
调研方向
首先查看已合并的 pull request #13830,然后检查 plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycle.java 中的 deploySharedFSVM。使用混合的 hypervisor 类型重现 createSharedFileSystem,并验证缺少模板不再导致 NPE,且可以选择有效的 system VM 模板。
由索引模型根据 Issue 内容生成。
描述
Bug: CreateSharedFileSystem throws NPE ("template is null") when a zone has more than one hypervisor type
Component: plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycle.java
Affected versions: 4.22.1.0 (confirmed present on main as of 2026-08-06 — same code, unrelated to the two unrelated API-signature diffs between main and 4.22.1.0 in this file)
Summary
createSharedFileSystem fails immediately with:
java.lang.NullPointerException: Cannot invoke "com.cloud.storage.VMTemplateVO.getId()" because "template" is null
on any zone that has more than one hypervisor type, where at least one of those hypervisor types has no system VM template available (e.g. an External/MaaS cluster alongside a KVM cluster in the same zone).
Root cause
In deploySharedFSVM():
List<Hypervisor.HypervisorType> hypervisors = resourceMgr.getSupportedHypervisorTypes(zoneId, false, null);
if (hypervisors.size() > 0) {
Collections.shuffle(hypervisors);
} ...
for (final Iterator<Hypervisor.HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
final Hypervisor.HypervisorType hypervisor = iter.next();
VMTemplateVO template = templateDao.findSystemVMReadyTemplate(zoneId, hypervisor, preferredArchitecture);
if (template == null && !iter.hasNext()) {
throw new CloudRuntimeException(...);
}
LaunchPermissionVO existingPermission = launchPermissionDao.findByTemplateAndAccount(template.getId(), owner.getId());
...
The hypervisor list is shuffled, and the null-check only throws when the current hypervisor is the last one in the iteration (!iter.hasNext()). If template is null for a hypervisor that is not last in the (randomized) order — e.g. External, which has no CloudStack system VM template by design — the code falls through to template.getId() on the same iteration instead of continue-ing to the next hypervisor. This crashes before ever reaching a hypervisor (e.g. KVM) that does have a valid, Ready system VM template.
Because the list is shuffled, this is intermittent: the call succeeds whenever the working hypervisor happens to be drawn first, and fails whenever a hypervisor with no system VM template is drawn first with more entries still pending.
Reproduction
- Zone with two clusters of different hypervisor types, one of which has no system VM template registered (e.g.
KVM+External/MaaS). - Call
createSharedFileSystemrepeatedly. - Observe intermittent NPE vs. success depending on shuffle order, even though the working hypervisor's system VM template is verified
Active/Ready/ fully downloaded in the DB (vm_template,template_zone_ref,template_store_ref).
Impact
Any deployment mixing hypervisor types within one zone (common with hybrid KVM + MaaS/External or KVM + VMware setups) can hit this nondeterministically for every Shared FileSystem creation attempt, with no workaround short of isolating hypervisor types into separate zones.
- 主要语言
- Java
- 星标
- 3.1k
- 派生
- 1.4k
- 平均合并
- 7 天 5 小时
- 30 天内合并 PR
- 28
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/cloudstack 的其他 Issue
-
bug
难度 1/5 1 小时以内 新手友好度 90/100
apache/cloudstack#14222 ·
-
bug component:kubernetes
难度 1/5 1 小时以内 新手友好度 88/100
apache/cloudstack#14180 ·
-
bug component:projects component:UI
难度 1/5 1 小时以内 新手友好度 88/100
apache/cloudstack#14070 · 5 条评论 ·
-
component:backup
难度 2/5 1-3 小时 新手友好度 76/100
apache/cloudstack#14013 ·
-
KVM agent fails to connect to Ceph RBD storage pool after upgrading Ceph client to Tentacle 20.2.4 未关闭bug component:ceph
难度 2/5 1-3 小时 新手友好度 78/100
apache/cloudstack#13989 · 3 条评论 ·
查看 apache/cloudstack 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
-
1.0.0-alpha2 Type/Improvement
难度 2/5 1-3 小时 新手友好度 68/100
wso2/dpdp-accelerator#272 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
infinispan/infinispan#18150 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
puj-course/FIS_2630_1204_G1#294 ·
-
area/frontend
难度 2/5 1-3 小时 新手友好度 65/100