提交 dc67d00c 编写于 作者: J Ján Tomko

Recreate the USB address cache at reconnect

When starting a new domain, we allocate the USB addresses and keep
an address cache in the domain object's private data.

However this data is lost on libvirtd restart.

Also generate the address cache if all the addresses have been
specified, so that devices hotplugged after libvirtd restart
also get theirs assigned.

https://bugzilla.redhat.com/show_bug.cgi?id=1387666
上级 244ebb8f
......@@ -1830,6 +1830,18 @@ virDomainUSBAddressAssign(virDomainUSBAddressSetPtr addrs,
}
int
virDomainUSBAddressPresent(virDomainDeviceInfoPtr info,
void *data ATTRIBUTE_UNUSED)
{
if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB &&
virDomainUSBAddressPortIsValid(info->addr.usb.port))
return 0;
return -1;
}
int
virDomainUSBAddressReserve(virDomainDeviceInfoPtr info,
void *data)
......
......@@ -300,6 +300,10 @@ size_t
virDomainUSBAddressCountAllPorts(virDomainDefPtr def);
void virDomainUSBAddressSetFree(virDomainUSBAddressSetPtr addrs);
int
virDomainUSBAddressPresent(virDomainDeviceInfoPtr info,
void *data)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int
virDomainUSBAddressReserve(virDomainDeviceInfoPtr info,
void *data)
......
......@@ -116,6 +116,7 @@ virDomainUSBAddressEnsure;
virDomainUSBAddressPortFormat;
virDomainUSBAddressPortFormatBuf;
virDomainUSBAddressPortIsValid;
virDomainUSBAddressPresent;
virDomainUSBAddressRelease;
virDomainUSBAddressReserve;
virDomainUSBAddressSetAddControllers;
......
......@@ -1750,12 +1750,24 @@ qemuDomainUSBAddressAddHubs(virDomainDefPtr def)
static int
qemuDomainAssignUSBAddresses(virDomainDefPtr def,
virDomainObjPtr obj)
virDomainObjPtr obj,
bool newDomain)
{
int ret = -1;
virDomainUSBAddressSetPtr addrs = NULL;
qemuDomainObjPrivatePtr priv = NULL;
if (!newDomain) {
/* only create the address cache for:
* new domains
* domains that already have all the addresses specified
* otherwise libvirt's attempt to recreate the USB topology via
* QEMU command line might fail */
if (virDomainUSBDeviceDefForeach(def, virDomainUSBAddressPresent, NULL,
false) < 0)
return 0;
}
if (!(addrs = virDomainUSBAddressSetCreate()))
goto cleanup;
......@@ -1812,7 +1824,7 @@ qemuDomainAssignAddresses(virDomainDefPtr def,
if (qemuDomainAssignPCIAddresses(def, qemuCaps, obj) < 0)
return -1;
if (newDomain && qemuDomainAssignUSBAddresses(def, obj) < 0)
if (qemuDomainAssignUSBAddresses(def, obj, newDomain) < 0)
return -1;
return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册