| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
updateVmSharesIfNeeded assumed <shares> is always present, but CpuTuneDef omits it when the calculated shares is 0. Add the element (and <cputune> if needed) when the destination requires shares, and leave the XML alone when it does not.
| Back | FazBrowse Home | New Git URL |
Description
CpuTuneDef.toString() omits <shares> when the calculated shares is 0 (e.g. a 100 MHz offering with a high cluster CPU overcommit ratio), so the running domain XML can have no <shares> element. During live migration, if the shares computed on the source differ from newVmCpuShares returned by the destination (cgroup v1 to v2, or a lowered overcommit ratio), updateVmSharesIfNeeded called getTextContent() on a null node and the migration failed with a NullPointerException before libvirt was called.
When <shares> is missing, the method now creates it (and <cputune> if absent) with the value required by the destination. If the destination does not need shares (newVmCpuShares <= 0) the XML is left unchanged. Behaviour when <shares> exists is unchanged.
Fixes: #14652
Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
How Has This Been Tested?
Added three unit tests to LibvirtMigrateCommandWrapperTest (no <shares> in an existing <cputune>, no <cputune> at all, and no new shares needed). They fail with the NPE without the fix.
mvn -pl plugins/hypervisors/kvm test -Dtest=LibvirtMigrateCommandWrapperTest: 40 tests, 0 failures (checkstyle passes). That run was on main; this branch is the same commit cherry-picked onto 4.20 (using the local getXml(document) helper, since 4.20 has no LibvirtXMLParser), and I did not re-run the build on 4.20 locally. Not tested on real cgroup v1 -> v2 hosts.
How did you try to break this feature and the system with this change?
Existing cases (<shares> present, shares equal on both hosts) are covered by the existing tests and still pass. I did not change how shares are calculated at VM start.