Copilot commented on code in PR #14803:
URL: https://github.com/apache/cloudstack/pull/14803#discussion_r4672991290
##########
server/src/main/java/com/cloud/network/NetworkServiceImpl.java:
##########
@@ -1283,6 +1283,26 @@ private void publishAssociationUsageEvent(VirtualMachine
vm, NicVO nic, NetworkV
VirtualMachine.class.getName(), vm.getUuid(), nic.getId(),
network, 0L, vm.isDisplay());
}
+ // The association is already committed and billed by now, so an
unreachable router must not fail the call;
+ // the entry is re-synced on the Instance's next start
(UserVmManagerImpl.finalizeStart).
+ private void pushDhcpEntryForAssociationBestEffort(VirtualMachine vm,
NicVO nic, NetworkVO network) {
+ try {
+ pushDhcpEntryForAssociation(vm, nic, network);
+ } catch (ResourceUnavailableException e) {
Review Comment:
If sending a DHCP update to one running router throws, this outer catch ends
the shared router loop, so later reachable routers never receive the
association update. The same issue affects removal at lines 1299–1300, leaving
stale reservations after disassociation succeeds and releases the address.
Catch failures per router, continue syncing the remaining routers, and report
any failures after the loop.
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java:
##########
@@ -695,6 +703,71 @@ protected String replaceDpdkInterfaces(String xmlDesc,
Map<String, DpdkTO> dpdkP
return LibvirtXMLParser.getXml(doc);
}
+ // Trunk nics always need it; ordinary nics only when the zone opted in to
the shared VLAN-aware bridge
+ // A VLAN nic cut off by a failed post-migration is link-down in the
source XML, which migration carries to the destination. Where the
+ // destination applies no VLAN membership by hand (libvirt does it from
the XML, or it has dedicated per-VLAN bridges) nothing would ever bring
+ // the link back, so an enabled nic arrives up. Where the post-migration
command will run it must stay down until that has applied the VLANs,
+ // so the nic is not exposed on VLAN 1 meanwhile. Other nics are left as
they are.
+ protected String restoreCutOffNicLinks(String xmlDesc, MigrateCommand
command, String vmName)
+ throws ParserConfigurationException, IOException, SAXException,
TransformerException {
+ NicTO[] nics = command.getVirtualMachine().getNics();
+ if (!destinationAppliesNoManualVlanMembership(command) ||
!LINK_DOWN_ELEMENT.matcher(xmlDesc).find() || nics == null
+ || Arrays.stream(nics).noneMatch(this::isEnabledVlanNic)) {
+ return xmlDesc;
+ }
+ Document doc =
ParserUtils.getSaferDocumentBuilderFactory().newDocumentBuilder().parse(IOUtils.toInputStream(xmlDesc));
+ boolean restored = false;
+ NodeList interfaces = doc.getElementsByTagName("interface");
+ for (int i = 0; i < interfaces.getLength(); i++) {
+ Element interfaceElement = (Element) interfaces.item(i);
+ String mac = findInterfaceMacAddress(interfaceElement);
+ NicTO nic = mac == null ? null : findNicByMac(nics, mac);
+ if (nic != null && isEnabledVlanNic(nic) &&
setLinkUp(interfaceElement)) {
+ logger.info("The link of nic {} of VM {} is down on the
source; it is set up in the destination definition because the nic is enabled",
mac, vmName);
+ restored = true;
+ }
+ }
+ return restored ? LibvirtXMLParser.getXml(doc) : xmlDesc;
+ }
+
+ private void
warnAboutNicsOnVlanAwareBridgeDespiteOptOut(List<InterfaceDef> liveInterfaces,
MigrateCommand command,
+ LibvirtComputingResource libvirtComputingResource, String vmName) {
+ NicTO[] nics = command.getVirtualMachine().getNics();
+ if (nics == null) {
+ return;
+ }
+ for (InterfaceDef liveInterface : liveInterfaces) {
+ NicTO nic = liveInterface.getMacAddress() == null ? null :
findNicByMac(nics, liveInterface.getMacAddress());
+ if (nic != null) {
+
libvirtComputingResource.warnIfNicOnVlanAwareBridgeDespiteOptOut(liveInterface,
nic, vmName);
+ }
+ }
+ }
+
+ private boolean destinationAppliesNoManualVlanMembership(MigrateCommand
command) {
+ return Boolean.TRUE.equals(command.getDestVlanTrunkXmlSupported()) ||
Boolean.FALSE.equals(command.getDestVlanFilteringEnabled());
+ }
+
+ private boolean isEnabledVlanNic(NicTO nic) {
+ return nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan &&
nic.isEnabled();
+ }
+
+ private boolean setLinkUp(Element interfaceElement) {
+ NodeList links = interfaceElement.getElementsByTagName("link");
+ for (int i = 0; i < links.getLength(); i++) {
+ Element link = (Element) links.item(i);
+ if ("down".equals(link.getAttribute("state"))) {
+ link.setAttribute("state", "up");
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean needsVlanRewrite(NicTO nic, boolean
sourceVlanFilteringEnabled, boolean destVlanFilteringEnabled) {
+ return nic.isTrunkVlan() || (nic.isSharedVlanBridgeEnabled() &&
(sourceVlanFilteringEnabled || destVlanFilteringEnabled));
Review Comment:
With the zone enabled, a NIC can use filtering `cloudbr1` while the
host-wide flag reflects non-filtering `cloudbr2`. On pre-11 libvirt, migration
between such hosts skips VLAN rewriting and post-migration membership, leaving
ordinary VLAN NICs on VLAN 1; line 748 can also restore a cut-off link too
early. Propagate per-NIC requirements through migration, link restoration, and
`VlanTrunkMigrationHelper`, or reject mixed-filtering configurations.
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java:
##########
@@ -695,6 +703,71 @@ protected String replaceDpdkInterfaces(String xmlDesc,
Map<String, DpdkTO> dpdkP
return LibvirtXMLParser.getXml(doc);
}
+ // Trunk nics always need it; ordinary nics only when the zone opted in to
the shared VLAN-aware bridge
+ // A VLAN nic cut off by a failed post-migration is link-down in the
source XML, which migration carries to the destination. Where the
+ // destination applies no VLAN membership by hand (libvirt does it from
the XML, or it has dedicated per-VLAN bridges) nothing would ever bring
+ // the link back, so an enabled nic arrives up. Where the post-migration
command will run it must stay down until that has applied the VLANs,
+ // so the nic is not exposed on VLAN 1 meanwhile. Other nics are left as
they are.
+ protected String restoreCutOffNicLinks(String xmlDesc, MigrateCommand
command, String vmName)
+ throws ParserConfigurationException, IOException, SAXException,
TransformerException {
+ NicTO[] nics = command.getVirtualMachine().getNics();
+ if (!destinationAppliesNoManualVlanMembership(command) ||
!LINK_DOWN_ELEMENT.matcher(xmlDesc).find() || nics == null
+ || Arrays.stream(nics).noneMatch(this::isEnabledVlanNic)) {
Review Comment:
The new migration XML link-restoration path is not covered by
`LibvirtMigrateCommandWrapperTest`; the added post-migration tests do not
exercise it, and destinations with native VLAN XML support skip that
post-migration command. Please test that an enabled VLAN NIC's down link is
restored for XML-capable/dedicated-bridge destinations, remains down for
manual-membership destinations, and disabled or non-VLAN NICs remain untouched.
Cover both single- and double-quoted input XML as handled by the new prefilter.
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java:
##########
@@ -100,6 +105,10 @@ public Answer execute(final PlugNicCommand command, final
LibvirtComputingResour
throw new InternalErrorException("Failed to locate live
tap for trunk nic " + nic.getMac() + ": " + e.getMessage());
}
}
+ if (linkDownUntilVlansApplied) {
+ interfaceDef.setLinkStateUp(nic.isEnabled());
+ vm.updateDeviceFlags(interfaceDef.toString(),
Domain.DeviceModifyFlags.LIVE);
Review Comment:
The new hot-plug link-state sequence has no regression coverage:
LibvirtPlugNicCommandWrapperTest currently tests only PCI-slot helpers. Please
add execute() tests that verify attachment occurs link-down, VLAN membership is
applied before the link is restored, membership failure never raises the link,
and an administratively disabled NIC remains down. These assertions are
important because changing the call order reintroduces the VLAN-1 exposure this
fix is intended to prevent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]