Skip to content

vpc: let users set the public interface rate of a VPC, applied live - #21

Open
calvix wants to merge 6 commits into
integration/all-fixes-4.23.0.0from
feature/vpc-network-rate-4.23
Open

calvix wants to merge 6 commits into
integration/all-fixes-4.23.0.0from
feature/vpc-network-rate-4.23

Conversation

@calvix

@calvix calvix commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Adds a networkrate parameter (Mbps) to createVPC and updateVPC and returns it in the VPC response. The rate is stored as the VPC detail networkrate and is used for the public NICs of the VPC's routers ahead of the network offering's rate; 0 is unlimited, like an offering rate of 0, and a root admin can set -1 to return the VPC to its offering's rate. A new system setting vpc.max.network.rate, set per account, caps what a non-root caller may set: the default 0 means they cannot set a rate, and a value must be between 1 and the cap. Every caller is limited to 16777215 Mbps, the most every hypervisor can turn into kilobytes per second.

updateVPC applies a new rate to running KVM routers live, after the rest of the update is saved: UpdateVmNicCommand carries an optional rate, and the KVM wrapper reads the running NIC's XML, sets the new <bandwidth> and writes it back with updateDeviceFlags(LIVE). Routers it cannot reach, or that are starting or migrating, are named in an error while the update stays saved; repeating it with the same rate retries them, and they get it at their next start anyway. libvirt refuses the live update when anything else in the NIC differs from the running device, which exposed two existing agent bugs on that path, both fixed here: the domain XML parser dropped the NIC's <rom bar='off'/>, and LibvirtVMDef only learned the libvirt and QEMU versions when a VM was defined, so after an agent restart the rebuilt XML lacked <bandwidth> and driver options; the agent now reads the versions at configure time. The live update is limited to NICs of the bridge VIF driver, as the parsed NIC lacks what other drivers add, such as an Open vSwitch port. Unit tests cover validation, storage, the applied rate, the error path and the KVM side.

A VPC has no rate of its own: the public NICs of its virtual routers take
the rate of the first guest network offering found on the router (in no
particular order), and changing it means changing network offerings and
rebuilding the routers.

createVPC and updateVPC get a networkrate parameter (Mbps, 0 = unlimited),
stored as a VPC detail. getNetworkRate() uses it for the public NICs of
the VPC's routers ahead of the network offering rule. updateVPC applies a
changed rate to the running KVM routers at once: UpdateVmNicCommand gets an
optional rate, and the KVM agent updates the live interface's bandwidth.
Stopped routers, and routers on other hypervisors, take it at their next
start.

Root admins can set any rate. Other callers can set 1 up to the new
account-scoped setting vpc.max.network.rate; with its default of 0 they
cannot set a rate at all, so nothing changes for existing clouds.

The domain XML parser now also reads a NIC's link state, so a rate update
does not bring a NIC that was set down back up.
UpdateVmNicCommand rebuilds the interface XML from the parsed domain and
hands it to updateDeviceFlags(). The parser ignored <rom bar='off'/>,
which virtual router NICs always have, so the rebuilt XML asked libvirt to
turn the ROM BAR back on, and libvirt refused: "Operation not supported:
cannot modify network device rom bar setting". The parser now keeps it.
A failed live apply leaves the new rate stored. Skipping an unchanged rate
meant a retry never reached the routers, so a repeated updateVPC now
applies it again.
@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

LibvirtVMDef writes version-dependent device XML (NIC bandwidth, packed
virtqueues, ...) from static versions that were only set when a VM was
defined. After an agent restart, and before the first VM start on the host,
they were 0, so XML built in that window silently lost those parts: a
plugged NIC came up without its rate limit or packed virtqueues, and a live
NIC update (UpdateVmNicCommand) failed because libvirt refuses to change the
driver options or the bandwidth it no longer saw. The versions are now
handed to LibvirtVMDef when the agent reads them at configure time.
- The rate is applied to the routers after the VPC is updated and restarted,
  and a router it could not be applied to no longer fails the update half
  way: the update is saved, and the error names the routers, which get the
  rate at their next start or when the update is repeated. Routers that are
  starting or migrating are reported too, as they can keep their old rate.
- The routers get the rate the public NIC actually has, from the network
  model, so a VPC networkrate of 0 is unlimited there as on every other NIC
  (-1), which XenServer needs.
- A root admin can set networkrate=-1 to return a VPC to the rate of its
  network offering.
- networkrate is at most 16777215 Mbps, the highest every hypervisor can turn
  into kilobytes per second without overflowing.
- vpc.max.network.rate is a system setting, which a domain admin cannot raise
  for an account of the domain.
- A networkrate-only update no longer calls the Netris provider's VPC update.
The live update writes the NIC back as the domain XML parser read it, which
keeps only what the bridge VIF driver writes. Other drivers add more, like an
Open vSwitch port and its VLAN tag, which the update would drop or libvirt
would refuse to change. Such NICs get the new rate at the VM's next start.

getInterface() also skips NICs the parser gives no MAC address, like direct
and vhost-user ones, instead of failing on them.
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