|
|
6ae9ed |
From 2debcb6bcdca2837ff5b44480d9f6addeaba76bc Mon Sep 17 00:00:00 2001
|
|
|
6ae9ed |
Message-Id: <2debcb6bcdca2837ff5b44480d9f6addeaba76bc@dist-git>
|
|
|
6ae9ed |
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
|
|
|
6ae9ed |
Date: Thu, 21 Jul 2016 15:57:49 +0200
|
|
|
6ae9ed |
Subject: [PATCH] Store USB port path as an array of integers
|
|
|
6ae9ed |
MIME-Version: 1.0
|
|
|
6ae9ed |
Content-Type: text/plain; charset=UTF-8
|
|
|
6ae9ed |
Content-Transfer-Encoding: 8bit
|
|
|
6ae9ed |
|
|
|
6ae9ed |
In preparation to tracking which USB addresses are occupied.
|
|
|
6ae9ed |
Introduce two helper functions for printing the port path
|
|
|
6ae9ed |
as a string and appending it to a virBuffer.
|
|
|
6ae9ed |
|
|
|
6ae9ed |
(cherry picked from commit f820d5bf6fafa2932ee6b21c34fee4c464500ef3)
|
|
|
6ae9ed |
Signed-off-by: Ján Tomko <jtomko@redhat.com>
|
|
|
6ae9ed |
|
|
|
6ae9ed |
https://bugzilla.redhat.com/show_bug.cgi?id=1215968
|
|
|
6ae9ed |
---
|
|
|
6ae9ed |
src/conf/device_conf.h | 2 +-
|
|
|
6ae9ed |
src/conf/domain_addr.c | 33 +++++++++++++++++++++++++++++++++
|
|
|
6ae9ed |
src/conf/domain_addr.h | 12 ++++++++++++
|
|
|
6ae9ed |
src/conf/domain_conf.c | 20 ++++++++++----------
|
|
|
6ae9ed |
src/libvirt_private.syms | 3 +++
|
|
|
6ae9ed |
src/qemu/qemu_command.c | 5 ++++-
|
|
|
6ae9ed |
6 files changed, 63 insertions(+), 12 deletions(-)
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
|
|
|
6ae9ed |
index 9b79160..8443de6 100644
|
|
|
6ae9ed |
--- a/src/conf/device_conf.h
|
|
|
6ae9ed |
+++ b/src/conf/device_conf.h
|
|
|
6ae9ed |
@@ -84,7 +84,7 @@ typedef struct _virDomainDeviceCcidAddress {
|
|
|
6ae9ed |
|
|
|
6ae9ed |
typedef struct _virDomainDeviceUSBAddress {
|
|
|
6ae9ed |
unsigned int bus;
|
|
|
6ae9ed |
- char *port;
|
|
|
6ae9ed |
+ unsigned int port[VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH];
|
|
|
6ae9ed |
} virDomainDeviceUSBAddress, *virDomainDeviceUSBAddressPtr;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
typedef struct _virDomainDeviceSpaprVioAddress {
|
|
|
6ae9ed |
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
|
|
|
6ae9ed |
index 794270d..741d045 100644
|
|
|
6ae9ed |
--- a/src/conf/domain_addr.c
|
|
|
6ae9ed |
+++ b/src/conf/domain_addr.c
|
|
|
6ae9ed |
@@ -1251,3 +1251,36 @@ virDomainVirtioSerialAddrRelease(virDomainVirtioSerialAddrSetPtr addrs,
|
|
|
6ae9ed |
VIR_FREE(str);
|
|
|
6ae9ed |
return ret;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+bool
|
|
|
6ae9ed |
+virDomainUSBAddressPortIsValid(unsigned int *port)
|
|
|
6ae9ed |
+{
|
|
|
6ae9ed |
+ return port[0] != 0;
|
|
|
6ae9ed |
+}
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+void
|
|
|
6ae9ed |
+virDomainUSBAddressPortFormatBuf(virBufferPtr buf,
|
|
|
6ae9ed |
+ unsigned int *port)
|
|
|
6ae9ed |
+{
|
|
|
6ae9ed |
+ size_t i;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ for (i = 0; i < VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH; i++) {
|
|
|
6ae9ed |
+ if (port[i] == 0)
|
|
|
6ae9ed |
+ break;
|
|
|
6ae9ed |
+ virBufferAsprintf(buf, "%u.", port[i]);
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+ virBufferTrim(buf, ".", -1);
|
|
|
6ae9ed |
+}
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+char *
|
|
|
6ae9ed |
+virDomainUSBAddressPortFormat(unsigned int *port)
|
|
|
6ae9ed |
+{
|
|
|
6ae9ed |
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
6ae9ed |
+ virDomainUSBAddressPortFormatBuf(&buf, port);
|
|
|
6ae9ed |
+ if (virBufferCheckError(&buf) < 0)
|
|
|
6ae9ed |
+ return NULL;
|
|
|
6ae9ed |
+ return virBufferContentAndReset(&buf;;
|
|
|
6ae9ed |
+}
|
|
|
6ae9ed |
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
|
|
|
6ae9ed |
index f3eda89..cfc74d5 100644
|
|
|
6ae9ed |
--- a/src/conf/domain_addr.h
|
|
|
6ae9ed |
+++ b/src/conf/domain_addr.h
|
|
|
6ae9ed |
@@ -237,4 +237,16 @@ virDomainVirtioSerialAddrRelease(virDomainVirtioSerialAddrSetPtr addrs,
|
|
|
6ae9ed |
virDomainDeviceInfoPtr info)
|
|
|
6ae9ed |
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
6ae9ed |
|
|
|
6ae9ed |
+bool
|
|
|
6ae9ed |
+virDomainUSBAddressPortIsValid(unsigned int *port)
|
|
|
6ae9ed |
+ ATTRIBUTE_NONNULL(1);
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+void
|
|
|
6ae9ed |
+virDomainUSBAddressPortFormatBuf(virBufferPtr buf,
|
|
|
6ae9ed |
+ unsigned int *port)
|
|
|
6ae9ed |
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
6ae9ed |
+char *
|
|
|
6ae9ed |
+virDomainUSBAddressPortFormat(unsigned int *port)
|
|
|
6ae9ed |
+ ATTRIBUTE_NONNULL(1);
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
#endif /* __DOMAIN_ADDR_H__ */
|
|
|
6ae9ed |
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
|
|
|
6ae9ed |
index 0bd8a30..bc01633 100644
|
|
|
6ae9ed |
--- a/src/conf/domain_conf.c
|
|
|
6ae9ed |
+++ b/src/conf/domain_conf.c
|
|
|
6ae9ed |
@@ -32,6 +32,7 @@
|
|
|
6ae9ed |
#include "internal.h"
|
|
|
6ae9ed |
#include "virerror.h"
|
|
|
6ae9ed |
#include "datatypes.h"
|
|
|
6ae9ed |
+#include "domain_addr.h"
|
|
|
6ae9ed |
#include "domain_conf.h"
|
|
|
6ae9ed |
#include "snapshot_conf.h"
|
|
|
6ae9ed |
#include "viralloc.h"
|
|
|
6ae9ed |
@@ -3313,8 +3314,6 @@ virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
|
|
|
6ae9ed |
void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info)
|
|
|
6ae9ed |
{
|
|
|
6ae9ed |
VIR_FREE(info->alias);
|
|
|
6ae9ed |
- if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB)
|
|
|
6ae9ed |
- VIR_FREE(info->addr.usb.port);
|
|
|
6ae9ed |
memset(&info->addr, 0, sizeof(info->addr));
|
|
|
6ae9ed |
info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE;
|
|
|
6ae9ed |
VIR_FREE(info->romfile);
|
|
|
6ae9ed |
@@ -4860,7 +4859,11 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
|
|
|
6ae9ed |
|
|
|
6ae9ed |
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
|
|
|
6ae9ed |
virBufferAsprintf(buf, " bus='%d'", info->addr.usb.bus);
|
|
|
6ae9ed |
- virBufferEscapeString(buf, " port='%s'", info->addr.usb.port);
|
|
|
6ae9ed |
+ if (virDomainUSBAddressPortIsValid(info->addr.usb.port)) {
|
|
|
6ae9ed |
+ virBufferAddLit(buf, " port='");
|
|
|
6ae9ed |
+ virDomainUSBAddressPortFormatBuf(buf, info->addr.usb.port);
|
|
|
6ae9ed |
+ virBufferAddLit(buf, "'");
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
break;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
|
|
|
6ae9ed |
@@ -5092,14 +5095,14 @@ virDomainDeviceCcidAddressParseXML(xmlNodePtr node,
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
static int
|
|
|
6ae9ed |
-virDomainDeviceUSBAddressParsePort(char *port)
|
|
|
6ae9ed |
+virDomainDeviceUSBAddressParsePort(virDomainDeviceUSBAddressPtr addr,
|
|
|
6ae9ed |
+ char *port)
|
|
|
6ae9ed |
{
|
|
|
6ae9ed |
- unsigned int p;
|
|
|
6ae9ed |
char *tmp = port;
|
|
|
6ae9ed |
size_t i;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
for (i = 0; i < VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH; i++) {
|
|
|
6ae9ed |
- if (virStrToLong_uip(tmp, &tmp, 10, &p) < 0)
|
|
|
6ae9ed |
+ if (virStrToLong_uip(tmp, &tmp, 10, &addr->port[i]) < 0)
|
|
|
6ae9ed |
break;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
if (*tmp == '\0')
|
|
|
6ae9ed |
@@ -5126,12 +5129,9 @@ virDomainDeviceUSBAddressParseXML(xmlNodePtr node,
|
|
|
6ae9ed |
port = virXMLPropString(node, "port");
|
|
|
6ae9ed |
bus = virXMLPropString(node, "bus");
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- if (port && virDomainDeviceUSBAddressParsePort(port) < 0)
|
|
|
6ae9ed |
+ if (port && virDomainDeviceUSBAddressParsePort(addr, port) < 0)
|
|
|
6ae9ed |
goto cleanup;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- addr->port = port;
|
|
|
6ae9ed |
- port = NULL;
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
if (bus &&
|
|
|
6ae9ed |
virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) {
|
|
|
6ae9ed |
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
6ae9ed |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
6ae9ed |
index de620a8..44b78e0 100644
|
|
|
6ae9ed |
--- a/src/libvirt_private.syms
|
|
|
6ae9ed |
+++ b/src/libvirt_private.syms
|
|
|
6ae9ed |
@@ -107,6 +107,9 @@ virDomainPCIAddressSetGrow;
|
|
|
6ae9ed |
virDomainPCIAddressSlotInUse;
|
|
|
6ae9ed |
virDomainPCIAddressValidate;
|
|
|
6ae9ed |
virDomainPCIControllerModelToConnectType;
|
|
|
6ae9ed |
+virDomainUSBAddressPortFormat;
|
|
|
6ae9ed |
+virDomainUSBAddressPortFormatBuf;
|
|
|
6ae9ed |
+virDomainUSBAddressPortIsValid;
|
|
|
6ae9ed |
virDomainVirtioSerialAddrAssign;
|
|
|
6ae9ed |
virDomainVirtioSerialAddrAutoAssign;
|
|
|
6ae9ed |
virDomainVirtioSerialAddrIsComplete;
|
|
|
6ae9ed |
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
|
|
|
6ae9ed |
index af6146f..300c01c 100644
|
|
|
6ae9ed |
--- a/src/qemu/qemu_command.c
|
|
|
6ae9ed |
+++ b/src/qemu/qemu_command.c
|
|
|
6ae9ed |
@@ -376,7 +376,10 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
|
|
|
6ae9ed |
info->addr.usb.bus)))
|
|
|
6ae9ed |
goto cleanup;
|
|
|
6ae9ed |
virBufferAsprintf(buf, ",bus=%s.0", contAlias);
|
|
|
6ae9ed |
- virBufferEscapeString(buf, ",port=%s", info->addr.usb.port);
|
|
|
6ae9ed |
+ if (virDomainUSBAddressPortIsValid(info->addr.usb.port)) {
|
|
|
6ae9ed |
+ virBufferAddLit(buf, ",port=");
|
|
|
6ae9ed |
+ virDomainUSBAddressPortFormatBuf(buf, info->addr.usb.port);
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
} else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO) {
|
|
|
6ae9ed |
if (info->addr.spaprvio.has_reg)
|
|
|
6ae9ed |
virBufferAsprintf(buf, ",reg=0x%llx", info->addr.spaprvio.reg);
|
|
|
6ae9ed |
--
|
|
|
6ae9ed |
2.9.2
|
|
|
6ae9ed |
|