From: Matt Coleman Date: Tue, 2 Feb 2021 00:48:36 +0000 (-0500) Subject: hyperv: XML parsing of serial ports X-Git-Tag: v7.1.0-rc1~375 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3550d11a79781e9b3fde6ae8fab591d562509ec0;p=thirdparty%2Flibvirt.git hyperv: XML parsing of serial ports Co-authored-by: Sri Ramanujam Signed-off-by: Matt Coleman Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index bdc084790a..9a603dc621 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1253,6 +1253,52 @@ hypervDomainDefParseStorage(hypervPrivate *priv, } +static int +hypervDomainDefParseSerial(virDomainDefPtr def, Msvm_ResourceAllocationSettingData *rasd) +{ + for (; rasd; rasd = rasd->next) { + int port_num = 0; + char **conn = NULL; + const char *srcPath = NULL; + virDomainChrDefPtr serial = NULL; + + if (rasd->data->ResourceType != MSVM_RASD_RESOURCETYPE_SERIAL_PORT) + continue; + + /* get port number */ + port_num = rasd->data->ElementName[4] - '0'; + if (port_num < 1) { + continue; + } + + serial = virDomainChrDefNew(NULL); + + serial->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; + serial->source->type = VIR_DOMAIN_CHR_TYPE_PIPE; + serial->target.port = port_num; + + /* set up source */ + if (rasd->data->Connection.count < 1) { + srcPath = "-1"; + } else { + conn = rasd->data->Connection.data; + if (!*conn) + srcPath = "-1"; + else + srcPath = *conn; + } + + serial->source->data.file.path = g_strdup(srcPath); + + if (VIR_APPEND_ELEMENT(def->serials, def->nserials, serial) < 0) { + virDomainChrDefFree(serial); + return -1; + } + } + + return 0; +} + /* * Driver functions @@ -2113,6 +2159,8 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) g_autoptr(Msvm_MemorySettingData) memorySettingData = NULL; g_autoptr(Msvm_ResourceAllocationSettingData) rasd = NULL; g_autoptr(Msvm_StorageAllocationSettingData) sasd = NULL; + g_autoptr(Msvm_SerialPortSettingData) spsd = NULL; + Msvm_ResourceAllocationSettingData *serialDevices = NULL; virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL); @@ -2151,6 +2199,9 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) return NULL; } + if (hypervGetSerialPortSD(priv, virtualSystemSettingData->data->InstanceID, &spsd) < 0) + return NULL; + /* Fill struct */ def->virtType = VIR_DOMAIN_VIRT_HYPERV; @@ -2215,6 +2266,14 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) if (hypervDomainDefParseStorage(priv, def, rasd, sasd) < 0) return NULL; + if (g_str_has_prefix(priv->version, "6.")) + serialDevices = rasd; + else + serialDevices = (Msvm_ResourceAllocationSettingData *)spsd; + + if (hypervDomainDefParseSerial(def, serialDevices) < 0) + return NULL; + /* XXX xmlopts must be non-NULL */ return virDomainDefFormat(def, NULL, virDomainDefFormatConvertXMLFlags(flags)); } diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index a28bb0e815..f5f0797605 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -1488,6 +1488,16 @@ hypervGetStorageAllocationSD(hypervPrivate *priv, } +int +hypervGetSerialPortSD(hypervPrivate *priv, + const char *id, + Msvm_SerialPortSettingData **data) +{ + hypervGetSettingData(Msvm_SerialPortSettingData, id, data); + return 0; +} + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Msvm_VirtualSystemManagementService */ diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index f09948895e..2b0d0e4a3f 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -254,6 +254,10 @@ int hypervGetStorageAllocationSD(hypervPrivate *priv, const char *id, Msvm_StorageAllocationSettingData **data); +int hypervGetSerialPortSD(hypervPrivate *priv, + const char *id, + Msvm_SerialPortSettingData **data); + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Msvm_VirtualSystemManagementService */ diff --git a/src/hyperv/hyperv_wmi_classes.h b/src/hyperv/hyperv_wmi_classes.h index 2c03ca3745..2f813bedb3 100644 --- a/src/hyperv/hyperv_wmi_classes.h +++ b/src/hyperv/hyperv_wmi_classes.h @@ -113,6 +113,7 @@ enum _Msvm_ResourceAllocationSettingData_ResourceType { MSVM_RASD_RESOURCETYPE_DVD_DRIVE = 16, MSVM_RASD_RESOURCETYPE_DISK_DRIVE = 17, MSVM_RASD_RESOURCETYPE_STORAGE_EXTENT = 19, + MSVM_RASD_RESOURCETYPE_SERIAL_PORT = 21, MSVM_RASD_RESOURCETYPE_LOGICAL_DISK = 31, }; diff --git a/src/hyperv/hyperv_wmi_generator.input b/src/hyperv/hyperv_wmi_generator.input index e1b4fd3f9f..765ffba169 100644 --- a/src/hyperv/hyperv_wmi_generator.input +++ b/src/hyperv/hyperv_wmi_generator.input @@ -629,6 +629,11 @@ class Msvm_ResourceAllocationSettingData end +class Msvm_SerialPortSettingData : Msvm_ResourceAllocationSettingData + boolean DebuggerMode +end + + class Msvm_Keyboard string InstanceID string Caption