mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
Store USB port path as an array of integers
In preparation to tracking which USB addresses are occupied. Introduce two helper functions for printing the port path as a string and appending it to a virBuffer.
This commit is contained in:
parent
4f90364318
commit
f820d5bf6f
@ -84,7 +84,7 @@ typedef struct _virDomainDeviceCcidAddress {
|
|||||||
|
|
||||||
typedef struct _virDomainDeviceUSBAddress {
|
typedef struct _virDomainDeviceUSBAddress {
|
||||||
unsigned int bus;
|
unsigned int bus;
|
||||||
char *port;
|
unsigned int port[VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH];
|
||||||
} virDomainDeviceUSBAddress, *virDomainDeviceUSBAddressPtr;
|
} virDomainDeviceUSBAddress, *virDomainDeviceUSBAddressPtr;
|
||||||
|
|
||||||
typedef struct _virDomainDeviceSpaprVioAddress {
|
typedef struct _virDomainDeviceSpaprVioAddress {
|
||||||
|
@ -1251,3 +1251,36 @@ virDomainVirtioSerialAddrRelease(virDomainVirtioSerialAddrSetPtr addrs,
|
|||||||
VIR_FREE(str);
|
VIR_FREE(str);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
virDomainUSBAddressPortIsValid(unsigned int *port)
|
||||||
|
{
|
||||||
|
return port[0] != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
virDomainUSBAddressPortFormatBuf(virBufferPtr buf,
|
||||||
|
unsigned int *port)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH; i++) {
|
||||||
|
if (port[i] == 0)
|
||||||
|
break;
|
||||||
|
virBufferAsprintf(buf, "%u.", port[i]);
|
||||||
|
}
|
||||||
|
virBufferTrim(buf, ".", -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *
|
||||||
|
virDomainUSBAddressPortFormat(unsigned int *port)
|
||||||
|
{
|
||||||
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
virDomainUSBAddressPortFormatBuf(&buf, port);
|
||||||
|
if (virBufferCheckError(&buf) < 0)
|
||||||
|
return NULL;
|
||||||
|
return virBufferContentAndReset(&buf);
|
||||||
|
}
|
||||||
|
@ -237,4 +237,16 @@ virDomainVirtioSerialAddrRelease(virDomainVirtioSerialAddrSetPtr addrs,
|
|||||||
virDomainDeviceInfoPtr info)
|
virDomainDeviceInfoPtr info)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||||
|
|
||||||
|
bool
|
||||||
|
virDomainUSBAddressPortIsValid(unsigned int *port)
|
||||||
|
ATTRIBUTE_NONNULL(1);
|
||||||
|
|
||||||
|
void
|
||||||
|
virDomainUSBAddressPortFormatBuf(virBufferPtr buf,
|
||||||
|
unsigned int *port)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||||
|
char *
|
||||||
|
virDomainUSBAddressPortFormat(unsigned int *port)
|
||||||
|
ATTRIBUTE_NONNULL(1);
|
||||||
|
|
||||||
#endif /* __DOMAIN_ADDR_H__ */
|
#endif /* __DOMAIN_ADDR_H__ */
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "virerror.h"
|
#include "virerror.h"
|
||||||
#include "datatypes.h"
|
#include "datatypes.h"
|
||||||
|
#include "domain_addr.h"
|
||||||
#include "domain_conf.h"
|
#include "domain_conf.h"
|
||||||
#include "snapshot_conf.h"
|
#include "snapshot_conf.h"
|
||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
@ -3325,8 +3326,6 @@ virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
|
|||||||
void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info)
|
void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info)
|
||||||
{
|
{
|
||||||
VIR_FREE(info->alias);
|
VIR_FREE(info->alias);
|
||||||
if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB)
|
|
||||||
VIR_FREE(info->addr.usb.port);
|
|
||||||
memset(&info->addr, 0, sizeof(info->addr));
|
memset(&info->addr, 0, sizeof(info->addr));
|
||||||
info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE;
|
info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE;
|
||||||
VIR_FREE(info->romfile);
|
VIR_FREE(info->romfile);
|
||||||
@ -4840,7 +4839,11 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
|
|||||||
|
|
||||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
|
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
|
||||||
virBufferAsprintf(buf, " bus='%d'", info->addr.usb.bus);
|
virBufferAsprintf(buf, " bus='%d'", info->addr.usb.bus);
|
||||||
virBufferEscapeString(buf, " port='%s'", info->addr.usb.port);
|
if (virDomainUSBAddressPortIsValid(info->addr.usb.port)) {
|
||||||
|
virBufferAddLit(buf, " port='");
|
||||||
|
virDomainUSBAddressPortFormatBuf(buf, info->addr.usb.port);
|
||||||
|
virBufferAddLit(buf, "'");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
|
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
|
||||||
@ -5072,14 +5075,14 @@ virDomainDeviceCcidAddressParseXML(xmlNodePtr node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virDomainDeviceUSBAddressParsePort(char *port)
|
virDomainDeviceUSBAddressParsePort(virDomainDeviceUSBAddressPtr addr,
|
||||||
|
char *port)
|
||||||
{
|
{
|
||||||
unsigned int p;
|
|
||||||
char *tmp = port;
|
char *tmp = port;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH; i++) {
|
for (i = 0; i < VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH; i++) {
|
||||||
if (virStrToLong_uip(tmp, &tmp, 10, &p) < 0)
|
if (virStrToLong_uip(tmp, &tmp, 10, &addr->port[i]) < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (*tmp == '\0')
|
if (*tmp == '\0')
|
||||||
@ -5106,12 +5109,9 @@ virDomainDeviceUSBAddressParseXML(xmlNodePtr node,
|
|||||||
port = virXMLPropString(node, "port");
|
port = virXMLPropString(node, "port");
|
||||||
bus = virXMLPropString(node, "bus");
|
bus = virXMLPropString(node, "bus");
|
||||||
|
|
||||||
if (port && virDomainDeviceUSBAddressParsePort(port) < 0)
|
if (port && virDomainDeviceUSBAddressParsePort(addr, port) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
addr->port = port;
|
|
||||||
port = NULL;
|
|
||||||
|
|
||||||
if (bus &&
|
if (bus &&
|
||||||
virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) {
|
virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
@ -107,6 +107,9 @@ virDomainPCIAddressSetGrow;
|
|||||||
virDomainPCIAddressSlotInUse;
|
virDomainPCIAddressSlotInUse;
|
||||||
virDomainPCIAddressValidate;
|
virDomainPCIAddressValidate;
|
||||||
virDomainPCIControllerModelToConnectType;
|
virDomainPCIControllerModelToConnectType;
|
||||||
|
virDomainUSBAddressPortFormat;
|
||||||
|
virDomainUSBAddressPortFormatBuf;
|
||||||
|
virDomainUSBAddressPortIsValid;
|
||||||
virDomainVirtioSerialAddrAssign;
|
virDomainVirtioSerialAddrAssign;
|
||||||
virDomainVirtioSerialAddrAutoAssign;
|
virDomainVirtioSerialAddrAutoAssign;
|
||||||
virDomainVirtioSerialAddrIsComplete;
|
virDomainVirtioSerialAddrIsComplete;
|
||||||
|
@ -376,7 +376,10 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
|
|||||||
info->addr.usb.bus)))
|
info->addr.usb.bus)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
virBufferAsprintf(buf, ",bus=%s.0", contAlias);
|
virBufferAsprintf(buf, ",bus=%s.0", contAlias);
|
||||||
virBufferEscapeString(buf, ",port=%s", info->addr.usb.port);
|
if (virDomainUSBAddressPortIsValid(info->addr.usb.port)) {
|
||||||
|
virBufferAddLit(buf, ",port=");
|
||||||
|
virDomainUSBAddressPortFormatBuf(buf, info->addr.usb.port);
|
||||||
|
}
|
||||||
} else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO) {
|
} else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO) {
|
||||||
if (info->addr.spaprvio.has_reg)
|
if (info->addr.spaprvio.has_reg)
|
||||||
virBufferAsprintf(buf, ",reg=0x%llx", info->addr.spaprvio.reg);
|
virBufferAsprintf(buf, ",reg=0x%llx", info->addr.spaprvio.reg);
|
||||||
|
Loading…
Reference in New Issue
Block a user