1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

hyperv: XML parsing of Ethernet adapters

Co-authored-by: Sri Ramanujam <sramanujam@datto.com>
Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Matt Coleman 2021-02-01 19:48:39 -05:00 committed by Michal Privoznik
parent 26e94bcd94
commit 67e2786a0e
5 changed files with 260 additions and 0 deletions

View File

@ -1379,6 +1379,105 @@ hypervDomainDefParseSerial(virDomainDefPtr def, Msvm_ResourceAllocationSettingDa
} }
static int
hypervDomainDefParseEthernetAdapter(virDomainDefPtr def,
Msvm_EthernetPortAllocationSettingData *net,
hypervPrivate *priv)
{
g_autoptr(virDomainNetDef) ndef = g_new0(virDomainNetDef, 1);
g_autoptr(Msvm_SyntheticEthernetPortSettingData) sepsd = NULL;
g_autoptr(Msvm_VirtualEthernetSwitch) vSwitch = NULL;
char **switchConnection = NULL;
g_autofree char *switchConnectionEscaped = NULL;
char *sepsdPATH = NULL;
g_autofree char *sepsdEscaped = NULL;
g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
VIR_DEBUG("Parsing ethernet adapter '%s'", net->data->InstanceID);
ndef->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
/*
* If there's no switch port connection or the EnabledState is disabled,
* then the adapter isn't hooked up to anything and we don't have to
* do anything more.
*/
switchConnection = net->data->HostResource.data;
if (net->data->HostResource.count < 1 || !*switchConnection ||
net->data->EnabledState == MSVM_ETHERNETPORTALLOCATIONSETTINGDATA_ENABLEDSTATE_DISABLED) {
VIR_DEBUG("Adapter not connected to switch");
return 0;
}
/*
* Now we retrieve the associated Msvm_SyntheticEthernetPortSettingData and
* Msvm_VirtualEthernetSwitch objects and use them to build the XML definition.
*/
/* begin by getting the Msvm_SyntheticEthernetPortSettingData object */
sepsdPATH = net->data->Parent;
sepsdEscaped = virStringReplace(sepsdPATH, "\\", "\\\\");
virBufferAsprintf(&query,
MSVM_SYNTHETICETHERNETPORTSETTINGDATA_WQL_SELECT "WHERE __PATH = '%s'",
sepsdEscaped);
if (hypervGetWmiClass(Msvm_SyntheticEthernetPortSettingData, &sepsd) < 0)
return -1;
if (!sepsd) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not retrieve NIC settings"));
return -1;
}
/* set mac address */
if (virMacAddrParseHex(sepsd->data->Address, &ndef->mac) < 0)
return -1;
/* now we get the Msvm_VirtualEthernetSwitch */
virBufferFreeAndReset(&query);
switchConnectionEscaped = virStringReplace(*switchConnection, "\\", "\\\\");
virBufferAsprintf(&query,
MSVM_VIRTUALETHERNETSWITCH_WQL_SELECT "WHERE __PATH = '%s'",
switchConnectionEscaped);
if (hypervGetWmiClass(Msvm_VirtualEthernetSwitch, &vSwitch) < 0)
return -1;
if (!vSwitch) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not retrieve virtual switch"));
return -1;
}
/* get bridge name */
ndef->data.bridge.brname = g_strdup(vSwitch->data->Name);
if (VIR_APPEND_ELEMENT(def->nets, def->nnets, ndef) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not append definition to domain"));
return -1;
}
return 0;
}
static int
hypervDomainDefParseEthernet(virDomainPtr domain,
virDomainDefPtr def,
Msvm_EthernetPortAllocationSettingData *nets)
{
Msvm_EthernetPortAllocationSettingData *entry = nets;
hypervPrivate *priv = domain->conn->privateData;
while (entry) {
if (hypervDomainDefParseEthernetAdapter(def, entry, priv) < 0)
return -1;
entry = entry->next;
}
return 0;
}
/* /*
* Driver functions * Driver functions
*/ */
@ -2240,6 +2339,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
g_autoptr(Msvm_StorageAllocationSettingData) sasd = NULL; g_autoptr(Msvm_StorageAllocationSettingData) sasd = NULL;
g_autoptr(Msvm_SerialPortSettingData) spsd = NULL; g_autoptr(Msvm_SerialPortSettingData) spsd = NULL;
Msvm_ResourceAllocationSettingData *serialDevices = NULL; Msvm_ResourceAllocationSettingData *serialDevices = NULL;
g_autoptr(Msvm_EthernetPortAllocationSettingData) nets = NULL;
virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL); virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL);
@ -2281,6 +2381,10 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
if (hypervGetSerialPortSD(priv, virtualSystemSettingData->data->InstanceID, &spsd) < 0) if (hypervGetSerialPortSD(priv, virtualSystemSettingData->data->InstanceID, &spsd) < 0)
return NULL; return NULL;
if (hypervGetEthernetPortAllocationSD(priv,
virtualSystemSettingData->data->InstanceID, &nets) < 0)
return NULL;
/* Fill struct */ /* Fill struct */
def->virtType = VIR_DOMAIN_VIRT_HYPERV; def->virtType = VIR_DOMAIN_VIRT_HYPERV;
@ -2342,6 +2446,10 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
def->controllers = g_new0(virDomainControllerDefPtr, 5); def->controllers = g_new0(virDomainControllerDefPtr, 5);
def->ncontrollers = 0; def->ncontrollers = 0;
/* 8 synthetic + 4 legacy NICs */
def->nets = g_new0(virDomainNetDefPtr, 12);
def->nnets = 0;
if (hypervDomainDefParseStorage(priv, def, rasd, sasd) < 0) if (hypervDomainDefParseStorage(priv, def, rasd, sasd) < 0)
return NULL; return NULL;
@ -2353,6 +2461,9 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
if (hypervDomainDefParseSerial(def, serialDevices) < 0) if (hypervDomainDefParseSerial(def, serialDevices) < 0)
return NULL; return NULL;
if (hypervDomainDefParseEthernet(domain, def, nets) < 0)
return NULL;
/* XXX xmlopts must be non-NULL */ /* XXX xmlopts must be non-NULL */
return virDomainDefFormat(def, NULL, virDomainDefFormatConvertXMLFlags(flags)); return virDomainDefFormat(def, NULL, virDomainDefFormatConvertXMLFlags(flags));
} }

View File

@ -1498,6 +1498,26 @@ hypervGetSerialPortSD(hypervPrivate *priv,
} }
int
hypervGetSyntheticEthernetPortSD(hypervPrivate *priv,
const char *id,
Msvm_SyntheticEthernetPortSettingData **data)
{
hypervGetSettingData(Msvm_SyntheticEthernetPortSettingData, id, data);
return 0;
}
int
hypervGetEthernetPortAllocationSD(hypervPrivate *priv,
const char *id,
Msvm_EthernetPortAllocationSettingData **data)
{
hypervGetSettingData(Msvm_EthernetPortAllocationSettingData, id, data);
return 0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Msvm_VirtualSystemManagementService * Msvm_VirtualSystemManagementService
*/ */

View File

@ -258,6 +258,14 @@ int hypervGetSerialPortSD(hypervPrivate *priv,
const char *id, const char *id,
Msvm_SerialPortSettingData **data); Msvm_SerialPortSettingData **data);
int hypervGetSyntheticEthernetPortSD(hypervPrivate *priv,
const char *id,
Msvm_SyntheticEthernetPortSettingData **data);
int hypervGetEthernetPortAllocationSD(hypervPrivate *priv,
const char *id,
Msvm_EthernetPortAllocationSettingData **data);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Msvm_VirtualSystemManagementService * Msvm_VirtualSystemManagementService
*/ */

View File

@ -119,6 +119,18 @@ enum _Msvm_ResourceAllocationSettingData_ResourceType {
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Msvm_EthernetPortAllocationSettingData
*/
/* https://docs.microsoft.com/en-us/windows/win32/hyperv_v2/msvm-ethernetportallocationsettingdata#enabled */
enum _Msvm_EthernetPortAllocationSettingData_EnabledState {
MSVM_ETHERNETPORTALLOCATIONSETTINGDATA_ENABLEDSTATE_ENABLED = 2,
MSVM_ETHERNETPORTALLOCATIONSETTINGDATA_ENABLEDSTATE_DISABLED = 3,
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* WMI * WMI
*/ */

View File

@ -827,3 +827,112 @@ class Msvm_StorageAllocationSettingData
string IOPSAllocationUnits string IOPSAllocationUnits
boolean PersistentReservationsSupported boolean PersistentReservationsSupported
end end
class Msvm_SyntheticEthernetPortSettingData
string InstanceID
string Caption
string Description
string ElementName
uint16 ResourceType
string OtherResourceType
string ResourceSubType
string PoolID
uint16 ConsumerVisibility
string HostResource[]
string AllocationUnits
uint64 VirtualQuantity
uint64 Reservation
uint64 Limit
uint32 Weight
boolean AutomaticAllocation
boolean AutomaticDeallocation
string Parent
string Connection[]
string Address
uint16 MappingBehavior
string AddressOnParent
string VirtualQuantityUnits
uint16 DesiredVLANEndpointMode
string OtherEndpointMode
string VirtualSystemIdentifiers[]
# DeviceNamingEnabled and AllowPacketDirect are not present in Windows Server 2012R2.
# They were added in Windows 10 and Windows Server 2016.
# They have been omitted to retain compatibility with Windows Server 2012R2.
# boolean DeviceNamingEnabled
# boolean AllowPacketDirect
boolean StaticMacAddress
boolean ClusterMonitored
end
class Msvm_EthernetPortAllocationSettingData
string InstanceID
string Caption
string Description
string ElementName
uint16 ResourceType
string OtherResourceType
string ResourceSubType
string PoolID
uint16 ConsumerVisibility
string HostResource[]
string AllocationUnits
uint64 VirtualQuantity
uint64 Reservation
uint64 Limit
uint32 Weight
boolean AutomaticAllocation
boolean AutomaticDeallocation
string Parent
string Connection[]
string Address
uint16 MappingBehavior
string AddressOnParent
string VirtualQuantityUnits
uint16 DesiredVLANEndpointMode
string OtherEndpointMode
uint16 EnabledState
string RequiredFeatures[]
string RequiredFeatureHints[]
string TestReplicaPoolID
string TestReplicaSwitchName
end
class Msvm_VirtualEthernetSwitch
string InstanceID
string Caption
string Description
string ElementName
datetime InstallDate
uint16 OperationalStatus[]
string StatusDescriptions[]
string Status
uint16 HealthState
uint16 CommunicationStatus
uint16 DetailedStatus
uint16 OperatingStatus
uint16 PrimaryStatus
uint16 EnabledState
string OtherEnabledState
uint16 RequestedState
uint16 EnabledDefault
datetime TimeOfLastStateChange
uint16 AvailableRequestedStates[]
uint16 TransitioningToState
string CreationClassName
string Name
string PrimaryOwnerName
string PrimaryOwnerContact
string Roles[]
string NameFormat
string OtherIdentifyingInfo[]
string IdentifyingDescriptions[]
uint16 Dedicated[]
string OtherDedicatedDescriptions[]
uint16 ResetCapability
uint16 PowerManagementCapabilities[]
uint32 MaxVMQOffloads
uint32 MaxIOVOffloads
end