Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions api/src/main/java/com/cloud/host/Host.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ public static String[] toStrings(Host.Type... types) {
String HOST_QEMU_RBD_SUPPORT = "host.qemu.rbd.support";
String HOST_SSH_PORT = "host.ssh.port";
String HOST_CDROM_MAX_COUNT = "host.cdrom.max.count";
String HOST_VLAN_FILTERING_ENABLED = "vlan.filtering.enabled";
// Prefix for a per-Guest-physical-network host_details key: the full key is this plus "." plus the
// physical network id, e.g. "vlan.filtering.enabled.205". A host's guest bridges are independent of
// each other, so this is never stored as a single value for the whole host.
String HOST_VLAN_FILTERING_ENABLED_PREFIX = "vlan.filtering.enabled.";
String HOST_VLAN_TRUNK_XML_SUPPORTED = "vlan.trunk.xml.supported";
String HOST_GUEST_BRIDGE_STP_ENABLED = "guest.bridge.stp.enabled";
// Prefix for a per-Guest-physical-network host_details key: the full key is this plus "." plus the
// physical network id, e.g. "guest.bridge.stp.enabled.205". STP is a property of one bridge, not the
// whole host, so this is never stored as a single value for the whole host.
String HOST_GUEST_BRIDGE_STP_ENABLED_PREFIX = "guest.bridge.stp.enabled.";
String GUEST_OS_CATEGORY_ID = "guest.os.category.id";
String GUEST_OS_RULE = "guest.os.rule";
String HOST_CPU_MAX_SPEED_MHZ = "host.cpu.max.speed.mhz";
Expand Down
10 changes: 6 additions & 4 deletions api/src/main/java/com/cloud/server/ManagementService.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,13 @@ public interface ManagementService {
String getMultiNetworkNicUnsuitableReason(VirtualMachine vm, Host host);

/**
* If host's guest bridge has STP enabled, returns a human-readable caution about the forward-delay outage
* every new port on it incurs (migration, nic plug, vm start); null otherwise. Applies to every VM, not
* just ones with a multi-VLAN trunk NIC - unlike getMultiNetworkNicUnsuitableReason, never excludes the host.
* Returns a human-readable migration caution for this VM on this host, checked per nic against its own
* network's physical network: either that the nic's bridge has STP enabled (forward-delay outage on migrate,
* nic plug, vm start), or that the VM has a multi-VLAN trunk NIC but this host's libvirt version doesn't
* support native VLAN trunk XML (VLAN membership is applied manually after migration instead). Null if
* neither applies. Unlike getMultiNetworkNicUnsuitableReason, never excludes the host.
*/
String getGuestBridgeStpMigrationCaution(Host host);
String getGuestBridgeStpMigrationCaution(VirtualMachine vm, Host host);

/**
* Apply affinity group constraints and other exclusion rules for VM migration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ public class ApiConstants {
public static final String IMAGE_PATH = "imagepath";
public static final String INSTANCE_CONVERSION_SUPPORTED = "instanceconversionsupported";
public static final String VLAN_FILTERING_ENABLED = "vlanfilteringenabled";
public static final String VLAN_FILTERING_ENABLED_BY_PHYSICAL_NETWORK = "vlanfilteringenabledbyphysicalnetwork";
public static final String VLAN_TRUNK_XML_SUPPORTED = "vlantrunkxmlsupported";
public static final String INTERNAL_DNS1 = "internaldns1";
public static final String INTERNAL_DNS2 = "internaldns2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public void execute() {
if (!suitableForMigration && vm != null) {
hostResponse.setUnsuitableReason(_mgr.getMultiNetworkNicUnsuitableReason(vm, host));
}
hostResponse.setMigrationCaution(_mgr.getGuestBridgeStpMigrationCaution(host));
if (vm != null) {
hostResponse.setMigrationCaution(_mgr.getGuestBridgeStpMigrationCaution(vm, host));
}

hostResponse.setObjectName("host");
hostResponses.add(hostResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,15 @@ public class HostResponse extends BaseResponseWithAnnotations {
private Boolean instanceConversionSupported;

@SerializedName(ApiConstants.VLAN_FILTERING_ENABLED)
@Param(description = "true if vlan_filtering is enabled on this host's guest bridge, so it can accept multi-VLAN trunk nics", since = "24.0.0")
@Param(description = "true only if vlan_filtering is enabled on every one of this host's Guest physical networks; "
+ "see vlanfilteringenabledbyphysicalnetwork for the state of each one", since = "24.0.0")
private Boolean vlanFilteringEnabled;

@SerializedName(ApiConstants.VLAN_FILTERING_ENABLED_BY_PHYSICAL_NETWORK)
@Param(description = "whether vlan_filtering is enabled on this host's guest bridge for each Guest physical network, "
+ "keyed by physical network id - a host can have it enabled on one physical network and not another", since = "24.0.0")
private Map<String, Boolean> vlanFilteringEnabledByPhysicalNetwork;

@SerializedName(ApiConstants.VLAN_TRUNK_XML_SUPPORTED)
@Param(description = "true if this host's libvirt version supports trunk vlan tap membership natively", since = "24.0.0")
private Boolean vlanTrunkXmlSupported;
Expand Down Expand Up @@ -916,6 +922,10 @@ public void setVlanFilteringEnabled(Boolean vlanFilteringEnabled) {
this.vlanFilteringEnabled = vlanFilteringEnabled;
}

public void setVlanFilteringEnabledByPhysicalNetwork(Map<String, Boolean> vlanFilteringEnabledByPhysicalNetwork) {
this.vlanFilteringEnabledByPhysicalNetwork = vlanFilteringEnabledByPhysicalNetwork;
}

public void setVlanTrunkXmlSupported(Boolean vlanTrunkXmlSupported) {
this.vlanTrunkXmlSupported = vlanTrunkXmlSupported;
}
Expand Down Expand Up @@ -1020,6 +1030,10 @@ public Boolean getVlanFilteringEnabled() {
return vlanFilteringEnabled;
}

public Map<String, Boolean> getVlanFilteringEnabledByPhysicalNetwork() {
return vlanFilteringEnabledByPhysicalNetwork;
}

public Boolean getVlanTrunkXmlSupported() {
return vlanTrunkXmlSupported;
}
Expand Down
26 changes: 26 additions & 0 deletions core/src/main/java/com/cloud/agent/api/CheckNetworkAnswer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@

package com.cloud.agent.api;

import java.util.Map;

public class CheckNetworkAnswer extends Answer {
// indicate if agent reconnect is needed after setupNetworkNames command
private boolean _reconnect;

// Each Guest physical network's own guest bridge may or may not have vlan_filtering enabled,
// independent of any other physical network on this host, so this is reported per physical
// network rather than once for the whole host.
private Map<Long, Boolean> vlanFilteringEnabledByPhysicalNetwork;

// Same per-physical-network reasoning as above: STP is a property of one bridge, not the whole host.
private Map<Long, Boolean> stpEnabledByPhysicalNetwork;

public CheckNetworkAnswer() {
}

Expand All @@ -39,4 +49,20 @@ public boolean needReconnect() {
return _reconnect;
}

public Map<Long, Boolean> getVlanFilteringEnabledByPhysicalNetwork() {
return vlanFilteringEnabledByPhysicalNetwork;
}

public void setVlanFilteringEnabledByPhysicalNetwork(Map<Long, Boolean> vlanFilteringEnabledByPhysicalNetwork) {
this.vlanFilteringEnabledByPhysicalNetwork = vlanFilteringEnabledByPhysicalNetwork;
}

public Map<Long, Boolean> getStpEnabledByPhysicalNetwork() {
return stpEnabledByPhysicalNetwork;
}

public void setStpEnabledByPhysicalNetwork(Map<Long, Boolean> stpEnabledByPhysicalNetwork) {
this.stpEnabledByPhysicalNetwork = stpEnabledByPhysicalNetwork;
}

}
13 changes: 8 additions & 5 deletions core/src/main/java/com/cloud/agent/api/MigrateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ public class MigrateCommand extends Command {
Map<String, Boolean> vlanToPersistenceMap = new HashMap<>();

// null means unknown capability, not false
private Boolean destVlanFilteringEnabled;
private Boolean destVlanTrunkXmlSupported;
private Map<String, String> nicBridgeMapping = new HashMap<>();
// whether vlan_filtering is enabled on the destination bridge resolved for each nic MAC - read live
// off the destination host's own bridge (PrepareForMigrationAnswer), not a single cached host-wide
// flag, since a host can have vlan_filtering enabled on one Guest physical network's bridge and not another
private Map<String, Boolean> nicVlanFilteringMapping = new HashMap<>();

public Map<String, DpdkTO> getDpdkInterfaceMapping() {
return dpdkInterfaceMapping;
Expand Down Expand Up @@ -164,12 +167,12 @@ public void setClvmCrossPoolMigration(boolean clvmCrossPoolMigration) {
this.clvmCrossPoolMigration = clvmCrossPoolMigration;
}

public Boolean getDestVlanFilteringEnabled() {
return destVlanFilteringEnabled;
public Map<String, Boolean> getNicVlanFilteringMapping() {
return nicVlanFilteringMapping;
}

public void setDestVlanFilteringEnabled(Boolean destVlanFilteringEnabled) {
this.destVlanFilteringEnabled = destVlanFilteringEnabled;
public void setNicVlanFilteringMapping(Map<String, Boolean> nicVlanFilteringMapping) {
this.nicVlanFilteringMapping = nicVlanFilteringMapping;
}

public Boolean getDestVlanTrunkXmlSupported() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class PrepareForMigrationAnswer extends Answer {
// destination bridge name per nic MAC, computed by the destination's own local capability
private Map<String, String> nicBridgeMapping = new HashMap<>();

// whether vlan_filtering is enabled on the destination bridge resolved for each nic MAC above -
// read live off the destination host's own bridge, not a single cached host-wide flag, since a
// host can have vlan_filtering enabled on one Guest physical network's bridge and not another
private Map<String, Boolean> nicVlanFilteringMapping = new HashMap<>();

protected PrepareForMigrationAnswer() {
}

Expand Down Expand Up @@ -71,4 +76,12 @@ public Map<String, String> getNicBridgeMapping() {
public void setNicBridgeMapping(Map<String, String> nicBridgeMapping) {
this.nicBridgeMapping = nicBridgeMapping;
}

public Map<String, Boolean> getNicVlanFilteringMapping() {
return nicVlanFilteringMapping;
}

public void setNicVlanFilteringMapping(Map<String, Boolean> nicVlanFilteringMapping) {
this.nicVlanFilteringMapping = nicVlanFilteringMapping;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.net.URI;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
Expand Down Expand Up @@ -58,43 +57,50 @@ public static void populateVlanTrunkMigrationDetails(MigrateCommand migrateComma
migrateCommand.setNicBridgeMapping(nicBridgeMapping);
}

DetailVO destVlanFilteringDetail = hostDetailsDao.findDetail(destHostId, Host.HOST_VLAN_FILTERING_ENABLED);
migrateCommand.setDestVlanFilteringEnabled(destVlanFilteringDetail == null ? null : Boolean.parseBoolean(destVlanFilteringDetail.getValue()));
// per-nic, read live off the destination host's own resolved bridge during PrepareForMigration -
// not a single host-wide flag, since a host can have vlan_filtering enabled on one Guest physical
// network's bridge and not another
Map<String, Boolean> nicVlanFilteringMapping = prepareForMigrationAnswer.getNicVlanFilteringMapping();
if (MapUtils.isNotEmpty(nicVlanFilteringMapping)) {
migrateCommand.setNicVlanFilteringMapping(nicVlanFilteringMapping);
}

DetailVO destVlanTrunkXmlDetail = hostDetailsDao.findDetail(destHostId, Host.HOST_VLAN_TRUNK_XML_SUPPORTED);
migrateCommand.setDestVlanTrunkXmlSupported(destVlanTrunkXmlDetail == null ? null : Boolean.parseBoolean(destVlanTrunkXmlDetail.getValue()));
}

public static boolean vmNeedsPostMigrationVlanTrunkMembership(long vmId, long dstHostId, NicDao nicDao, HostDetailsDao hostDetailsDao) {
public static boolean vmNeedsPostMigrationVlanTrunkMembership(long vmId, long dstHostId, NicDao nicDao, NetworkDao networkDao, HostDetailsDao hostDetailsDao) {
DetailVO trunkXmlDetail = hostDetailsDao.findDetail(dstHostId, Host.HOST_VLAN_TRUNK_XML_SUPPORTED);
if (trunkXmlDetail != null && Boolean.parseBoolean(trunkXmlDetail.getValue())) {
return false;
}
DetailVO vlanFilteringDetail = hostDetailsDao.findDetail(dstHostId, Host.HOST_VLAN_FILTERING_ENABLED);
boolean destVlanFilteringEnabled = vlanFilteringDetail != null && Boolean.parseBoolean(vlanFilteringDetail.getValue());
return nicDao.listByVmId(vmId).stream().anyMatch(nic -> nicNeedsManualVlanMembership(nic, destVlanFilteringEnabled));
return nicDao.listByVmId(vmId).stream().anyMatch(nic -> nicNeedsManualVlanMembership(nic, dstHostId, networkDao, hostDetailsDao));
}

// A multi-VLAN trunk nic needs a VLAN-filtering host; a Guest VLAN 1 nic needs a legacy host, as the shared bridge's PVID is VLAN 1. Null when the host fits.
// A multi-VLAN trunk nic needs a VLAN-filtering host (on its own physical network's bridge); a Guest VLAN 1
// nic needs a legacy (non-filtering) host on ITS physical network, as the shared bridge's PVID is VLAN 1.
// Each nic is checked against its own network's physical network, not one flag for the whole host. Null when the host fits.
public static String getVlanFilteringUnsuitableReason(long vmId, long hostId, NicDao nicDao, NetworkDao networkDao, HostDetailsDao hostDetailsDao) {
List<NicVO> nics = nicDao.listByVmId(vmId);
boolean hasTrunkNic = hasTrunkNic(nics);
boolean hasNativeVlanNic = hasNativeVlanGuestNic(nics, networkDao);
if (!hasTrunkNic && !hasNativeVlanNic) {
return null;
}
boolean vlanFilteringEnabled = isVlanFilteringEnabled(hostId, hostDetailsDao);
if (hasTrunkNic && !vlanFilteringEnabled) {
return "Instance has a multi-VLAN trunk NIC, but this host does not have VLAN filtering enabled";
}
if (hasNativeVlanNic && vlanFilteringEnabled) {
return NATIVE_VLAN_ON_FILTERING_HOST_REASON;
for (NicVO nic : nicDao.listByVmId(vmId)) {
Long physicalNetworkId = resolvePhysicalNetworkId(nic, networkDao);
if (physicalNetworkId == null) {
continue;
}
boolean vlanFilteringEnabled = isVlanFilteringEnabled(hostId, physicalNetworkId, hostDetailsDao);
if (nic.getMultiNetwork() && !vlanFilteringEnabled) {
return "Instance has a multi-VLAN trunk NIC, but this host's bridge for that NIC's physical network does not have VLAN filtering enabled";
}
if (isNativeVlanGuestNic(nic, networkDao) && vlanFilteringEnabled) {
return NATIVE_VLAN_ON_FILTERING_HOST_REASON;
}
}
return null;
}

// For a network about to be plugged into a running Instance on this host.
public static String getNativeVlanUnsuitableReason(Network network, long hostId, HostDetailsDao hostDetailsDao) {
return isNativeVlanGuestNetwork(network) && isVlanFilteringEnabled(hostId, hostDetailsDao) ? NATIVE_VLAN_ON_FILTERING_HOST_REASON : null;
return isNativeVlanGuestNetwork(network) && network.getPhysicalNetworkId() != null
&& isVlanFilteringEnabled(hostId, network.getPhysicalNetworkId(), hostDetailsDao) ? NATIVE_VLAN_ON_FILTERING_HOST_REASON : null;
}

public static boolean hasTrunkNic(Collection<NicVO> nics) {
Expand All @@ -110,11 +116,16 @@ public static boolean isNativeVlanGuestNetwork(Network network) {
return network.getTrafficType() == Networks.TrafficType.Guest && isNativeVlan(network.getBroadcastUri());
}

private static boolean isVlanFilteringEnabled(long hostId, HostDetailsDao hostDetailsDao) {
DetailVO vlanFilteringDetail = hostDetailsDao.findDetail(hostId, Host.HOST_VLAN_FILTERING_ENABLED);
private static boolean isVlanFilteringEnabled(long hostId, long physicalNetworkId, HostDetailsDao hostDetailsDao) {
DetailVO vlanFilteringDetail = hostDetailsDao.findDetail(hostId, Host.HOST_VLAN_FILTERING_ENABLED_PREFIX + physicalNetworkId);
return vlanFilteringDetail != null && Boolean.parseBoolean(vlanFilteringDetail.getValue());
}

private static Long resolvePhysicalNetworkId(NicVO nic, NetworkDao networkDao) {
NetworkVO network = networkDao.findById(nic.getNetworkId());
return network == null ? null : network.getPhysicalNetworkId();
}

// a stopped Instance's nics carry no broadcast URI (released on stop), so fall back to the network's
private static boolean isNativeVlanGuestNic(NicVO nic, NetworkDao networkDao) {
if (nic.getMultiNetwork()) {
Expand All @@ -136,14 +147,20 @@ private static boolean isNativeVlan(URI broadcastUri) {
&& "1".equals(Networks.BroadcastDomainType.getValue(broadcastUri));
}

public static boolean nicNeedsManualVlanMembership(NicVO nic, boolean vlanFilteringEnabled) {
return nic.getBroadcastUri() != null && Networks.BroadcastDomainType.getSchemeValue(nic.getBroadcastUri()) == Networks.BroadcastDomainType.Vlan
&& (nic.getMultiNetwork() || vlanFilteringEnabled);
public static boolean nicNeedsManualVlanMembership(NicVO nic, long hostId, NetworkDao networkDao, HostDetailsDao hostDetailsDao) {
if (nic.getBroadcastUri() == null || Networks.BroadcastDomainType.getSchemeValue(nic.getBroadcastUri()) != Networks.BroadcastDomainType.Vlan) {
return false;
}
if (nic.getMultiNetwork()) {
return true;
}
Long physicalNetworkId = resolvePhysicalNetworkId(nic, networkDao);
return physicalNetworkId != null && isVlanFilteringEnabled(hostId, physicalNetworkId, hostDetailsDao);
}

public static void sendPostMigrationVlanTrunkMembershipIfNeeded(VirtualMachineTO vmTO, long dstHostId,
NicDao nicDao, HostDetailsDao hostDetailsDao, CommandSender commandSender, Logger logger) {
if (!vmNeedsPostMigrationVlanTrunkMembership(vmTO.getId(), dstHostId, nicDao, hostDetailsDao)) {
NicDao nicDao, NetworkDao networkDao, HostDetailsDao hostDetailsDao, CommandSender commandSender, Logger logger) {
if (!vmNeedsPostMigrationVlanTrunkMembership(vmTO.getId(), dstHostId, nicDao, networkDao, hostDetailsDao)) {
return;
}
final String warningMsg = "Post-migration VLAN trunk membership tasks did not complete for VM [{}] "
Expand Down
Loading
Loading