Skip to content

KVM: fix NPE on live migration when the domain XML has no CPU shares - #14685

Open
HawkForge wants to merge 1 commit into
apache:4.20from
HawkForge:fix/kvm-migrate-shares-npe-4.20
Open

HawkForge wants to merge 1 commit into
apache:4.20from
HawkForge:fix/kvm-migrate-shares-npe-4.20

Conversation

@HawkForge

Copy link
Copy Markdown

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

  • 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

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

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.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant