mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
conf: make hostdev info a separate object
In order to allow for a virDomainHostdevDef that uses the virDomainDeviceInfo of a "higher level" device (such as a virDomainNetDef), this patch changes the virDomainDeviceInfo in the HostdevDef into a virDomainDeviceInfoPtr. Rather than adding checks all over the code to check for a null info, we just guarantee that it is always valid. The new function virDomainHostdevDefAlloc() allocates a virDomainDeviceInfo and plugs it in, and virDomainHostdevDefFree() makes sure it is freed. There were 4 places allocating virDomainHostdevDefs, all of them parsers of one sort or another, and those have all had their VIR_ALLOC(hostdev) changed to virDomainHostdevDefAlloc(). Other than that, and the new functions, all the rest of the changes are just mechanical removals of "&" or changing "." to "->".
This commit is contained in:
parent
2f925c650c
commit
29293930a9
@ -786,6 +786,15 @@ bool virDomainObjTaint(virDomainObjPtr obj,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
virDomainDeviceInfoFree(virDomainDeviceInfoPtr info)
|
||||||
|
{
|
||||||
|
if (info) {
|
||||||
|
virDomainDeviceInfoClear(info);
|
||||||
|
VIR_FREE(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virDomainGraphicsAuthDefClear(virDomainGraphicsAuthDefPtr def)
|
virDomainGraphicsAuthDefClear(virDomainGraphicsAuthDefPtr def)
|
||||||
@ -1294,12 +1303,42 @@ void virDomainVideoDefFree(virDomainVideoDefPtr def)
|
|||||||
VIR_FREE(def);
|
VIR_FREE(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virDomainHostdevDefPtr virDomainHostdevDefAlloc(void)
|
||||||
|
{
|
||||||
|
virDomainHostdevDefPtr def = NULL;
|
||||||
|
|
||||||
|
if (VIR_ALLOC(def) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (VIR_ALLOC(def->info) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
VIR_FREE(def);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
|
||||||
|
{
|
||||||
|
if (!def)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Free all resources in the hostdevdef. Currently the only
|
||||||
|
* such resource is the virDomainDeviceInfo.
|
||||||
|
*/
|
||||||
|
|
||||||
|
virDomainDeviceInfoFree(def->info);
|
||||||
|
}
|
||||||
|
|
||||||
void virDomainHostdevDefFree(virDomainHostdevDefPtr def)
|
void virDomainHostdevDefFree(virDomainHostdevDefPtr def)
|
||||||
{
|
{
|
||||||
if (!def)
|
if (!def)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virDomainDeviceInfoClear(&def->info);
|
/* free all subordinate objects */
|
||||||
|
virDomainHostdevDefClear(def);
|
||||||
|
|
||||||
VIR_FREE(def);
|
VIR_FREE(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1877,7 +1916,7 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def,
|
|||||||
device.type = VIR_DOMAIN_DEVICE_HOSTDEV;
|
device.type = VIR_DOMAIN_DEVICE_HOSTDEV;
|
||||||
for (i = 0; i < def->nhostdevs ; i++) {
|
for (i = 0; i < def->nhostdevs ; i++) {
|
||||||
device.data.hostdev = def->hostdevs[i];
|
device.data.hostdev = def->hostdevs[i];
|
||||||
if (cb(def, &device, &def->hostdevs[i]->info, opaque) < 0)
|
if (cb(def, &device, def->hostdevs[i]->info, opaque) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
device.type = VIR_DOMAIN_DEVICE_VIDEO;
|
device.type = VIR_DOMAIN_DEVICE_VIDEO;
|
||||||
@ -2743,14 +2782,14 @@ virDomainHostdevSubsysPciDefParseXML(const xmlNodePtr node,
|
|||||||
char *devaddr = virXMLPropString(cur, "devaddr");
|
char *devaddr = virXMLPropString(cur, "devaddr");
|
||||||
if (devaddr &&
|
if (devaddr &&
|
||||||
virDomainParseLegacyDeviceAddress(devaddr,
|
virDomainParseLegacyDeviceAddress(devaddr,
|
||||||
&def->info.addr.pci) < 0) {
|
&def->info->addr.pci) < 0) {
|
||||||
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
|
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unable to parse devaddr parameter '%s'"),
|
_("Unable to parse devaddr parameter '%s'"),
|
||||||
devaddr);
|
devaddr);
|
||||||
VIR_FREE(devaddr);
|
VIR_FREE(devaddr);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
def->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
|
def->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
|
||||||
} else if ((flags & VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES) &&
|
} else if ((flags & VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES) &&
|
||||||
xmlStrEqual(cur->name, BAD_CAST "origstates")) {
|
xmlStrEqual(cur->name, BAD_CAST "origstates")) {
|
||||||
virDomainHostdevOrigStatesPtr states = &def->origstates;
|
virDomainHostdevOrigStatesPtr states = &def->origstates;
|
||||||
@ -6379,10 +6418,8 @@ virDomainHostdevDefParseXML(const xmlNodePtr node,
|
|||||||
virDomainHostdevDefPtr def;
|
virDomainHostdevDefPtr def;
|
||||||
char *mode, *type = NULL, *managed = NULL;
|
char *mode, *type = NULL, *managed = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0) {
|
if (!(def = virDomainHostdevDefAlloc()))
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
mode = virXMLPropString(node, "mode");
|
mode = virXMLPropString(node, "mode");
|
||||||
if (mode) {
|
if (mode) {
|
||||||
@ -6445,8 +6482,8 @@ virDomainHostdevDefParseXML(const xmlNodePtr node,
|
|||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
|
if (def->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
|
||||||
if (virDomainDeviceInfoParseXML(node, bootMap, &def->info,
|
if (virDomainDeviceInfoParseXML(node, bootMap, def->info,
|
||||||
flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT
|
flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT
|
||||||
| VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0)
|
| VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -6455,8 +6492,8 @@ virDomainHostdevDefParseXML(const xmlNodePtr node,
|
|||||||
if (def->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
|
if (def->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
|
||||||
switch (def->source.subsys.type) {
|
switch (def->source.subsys.type) {
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
|
||||||
if (def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
|
if (def->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
|
||||||
def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
|
def->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
|
||||||
virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("PCI host devices must use 'pci' address type"));
|
_("PCI host devices must use 'pci' address type"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -9015,7 +9052,7 @@ static bool virDomainHostdevDefCheckABIStability(virDomainHostdevDefPtr src,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info))
|
if (!virDomainDeviceInfoCheckABIStability(src->info, dst->info))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
identical = true;
|
identical = true;
|
||||||
@ -11551,7 +11588,7 @@ virDomainHostdevDefFormat(virBufferPtr buf,
|
|||||||
|
|
||||||
virBufferAddLit(buf, " </source>\n");
|
virBufferAddLit(buf, " </source>\n");
|
||||||
|
|
||||||
if (virDomainDeviceInfoFormat(buf, &def->info,
|
if (virDomainDeviceInfoFormat(buf, def->info,
|
||||||
flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT
|
flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT
|
||||||
| VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0)
|
| VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -380,7 +380,7 @@ struct _virDomainHostdevDef {
|
|||||||
} caps;
|
} caps;
|
||||||
} source;
|
} source;
|
||||||
virDomainHostdevOrigStates origstates;
|
virDomainHostdevOrigStates origstates;
|
||||||
virDomainDeviceInfo info; /* Guest address */
|
virDomainDeviceInfoPtr info; /* Guest address */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Two types of disk backends */
|
/* Two types of disk backends */
|
||||||
@ -1773,6 +1773,8 @@ void virDomainSoundDefFree(virDomainSoundDefPtr def);
|
|||||||
void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def);
|
void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def);
|
||||||
void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def);
|
void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def);
|
||||||
void virDomainVideoDefFree(virDomainVideoDefPtr def);
|
void virDomainVideoDefFree(virDomainVideoDefPtr def);
|
||||||
|
virDomainHostdevDefPtr virDomainHostdevDefAlloc(void);
|
||||||
|
void virDomainHostdevDefClear(virDomainHostdevDefPtr def);
|
||||||
void virDomainHostdevDefFree(virDomainHostdevDefPtr def);
|
void virDomainHostdevDefFree(virDomainHostdevDefPtr def);
|
||||||
void virDomainHubDefFree(virDomainHubDefPtr def);
|
void virDomainHubDefFree(virDomainHubDefPtr def);
|
||||||
void virDomainRedirdevDefFree(virDomainRedirdevDefPtr def);
|
void virDomainRedirdevDefFree(virDomainRedirdevDefPtr def);
|
||||||
|
@ -351,6 +351,8 @@ virDomainGraphicsSpiceZlibCompressionTypeFromString;
|
|||||||
virDomainGraphicsSpiceZlibCompressionTypeToString;
|
virDomainGraphicsSpiceZlibCompressionTypeToString;
|
||||||
virDomainGraphicsTypeFromString;
|
virDomainGraphicsTypeFromString;
|
||||||
virDomainGraphicsTypeToString;
|
virDomainGraphicsTypeToString;
|
||||||
|
virDomainHostdevDefAlloc;
|
||||||
|
virDomainHostdevDefClear;
|
||||||
virDomainHostdevDefFree;
|
virDomainHostdevDefFree;
|
||||||
virDomainHostdevModeTypeToString;
|
virDomainHostdevModeTypeToString;
|
||||||
virDomainHostdevSubsysTypeToString;
|
virDomainHostdevSubsysTypeToString;
|
||||||
|
@ -568,7 +568,7 @@ qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev
|
|||||||
idx = 0;
|
idx = 0;
|
||||||
for (i = 0 ; i < def->nhostdevs ; i++) {
|
for (i = 0 ; i < def->nhostdevs ; i++) {
|
||||||
int thisidx;
|
int thisidx;
|
||||||
if ((thisidx = qemuDomainDeviceAliasIndex(&def->hostdevs[i]->info, "hostdev")) < 0) {
|
if ((thisidx = qemuDomainDeviceAliasIndex(def->hostdevs[i]->info, "hostdev")) < 0) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Unable to determine device index for hostdev device"));
|
_("Unable to determine device index for hostdev device"));
|
||||||
return -1;
|
return -1;
|
||||||
@ -578,7 +578,7 @@ qemuAssignDeviceHostdevAlias(virDomainDefPtr def, virDomainHostdevDefPtr hostdev
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virAsprintf(&hostdev->info.alias, "hostdev%d", idx) < 0) {
|
if (virAsprintf(&hostdev->info->alias, "hostdev%d", idx) < 0) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1419,13 +1419,13 @@ qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs)
|
|||||||
|
|
||||||
/* Host PCI devices */
|
/* Host PCI devices */
|
||||||
for (i = 0; i < def->nhostdevs ; i++) {
|
for (i = 0; i < def->nhostdevs ; i++) {
|
||||||
if (def->hostdevs[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
|
if (def->hostdevs[i]->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
|
||||||
continue;
|
continue;
|
||||||
if (def->hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
|
if (def->hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
|
||||||
def->hostdevs[i]->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
|
def->hostdevs[i]->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (qemuDomainPCIAddressSetNextAddr(addrs, &def->hostdevs[i]->info) < 0)
|
if (qemuDomainPCIAddressSetNextAddr(addrs, def->hostdevs[i]->info) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2977,14 +2977,14 @@ qemuBuildPCIHostdevDevStr(virDomainHostdevDefPtr dev, const char *configfd,
|
|||||||
dev->source.subsys.u.pci.bus,
|
dev->source.subsys.u.pci.bus,
|
||||||
dev->source.subsys.u.pci.slot,
|
dev->source.subsys.u.pci.slot,
|
||||||
dev->source.subsys.u.pci.function);
|
dev->source.subsys.u.pci.function);
|
||||||
virBufferAsprintf(&buf, ",id=%s", dev->info.alias);
|
virBufferAsprintf(&buf, ",id=%s", dev->info->alias);
|
||||||
if (configfd && *configfd)
|
if (configfd && *configfd)
|
||||||
virBufferAsprintf(&buf, ",configfd=%s", configfd);
|
virBufferAsprintf(&buf, ",configfd=%s", configfd);
|
||||||
if (dev->info.bootIndex)
|
if (dev->info->bootIndex)
|
||||||
virBufferAsprintf(&buf, ",bootindex=%d", dev->info.bootIndex);
|
virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex);
|
||||||
if (qemuBuildDeviceAddressStr(&buf, &dev->info, qemuCaps) < 0)
|
if (qemuBuildDeviceAddressStr(&buf, dev->info, qemuCaps) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (qemuBuildRomStr(&buf, &dev->info, qemuCaps) < 0)
|
if (qemuBuildRomStr(&buf, dev->info, qemuCaps) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virBufferError(&buf)) {
|
if (virBufferError(&buf)) {
|
||||||
@ -3070,9 +3070,9 @@ qemuBuildUSBHostdevDevStr(virDomainHostdevDefPtr dev,
|
|||||||
virBufferAsprintf(&buf, "usb-host,hostbus=%d,hostaddr=%d,id=%s",
|
virBufferAsprintf(&buf, "usb-host,hostbus=%d,hostaddr=%d,id=%s",
|
||||||
dev->source.subsys.u.usb.bus,
|
dev->source.subsys.u.usb.bus,
|
||||||
dev->source.subsys.u.usb.device,
|
dev->source.subsys.u.usb.device,
|
||||||
dev->info.alias);
|
dev->info->alias);
|
||||||
|
|
||||||
if (qemuBuildDeviceAddressStr(&buf, &dev->info, qemuCaps) < 0)
|
if (qemuBuildDeviceAddressStr(&buf, dev->info, qemuCaps) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virBufferError(&buf)) {
|
if (virBufferError(&buf)) {
|
||||||
@ -5702,7 +5702,7 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
virDomainHostdevDefPtr hostdev = def->hostdevs[i];
|
virDomainHostdevDefPtr hostdev = def->hostdevs[i];
|
||||||
char *devstr;
|
char *devstr;
|
||||||
|
|
||||||
if (hostdev->info.bootIndex) {
|
if (hostdev->info->bootIndex) {
|
||||||
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
|
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
|
||||||
hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
|
hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
|
||||||
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
@ -6654,43 +6654,37 @@ cleanup:
|
|||||||
static virDomainHostdevDefPtr
|
static virDomainHostdevDefPtr
|
||||||
qemuParseCommandLinePCI(const char *val)
|
qemuParseCommandLinePCI(const char *val)
|
||||||
{
|
{
|
||||||
virDomainHostdevDefPtr def = NULL;
|
|
||||||
int bus = 0, slot = 0, func = 0;
|
int bus = 0, slot = 0, func = 0;
|
||||||
const char *start;
|
const char *start;
|
||||||
char *end;
|
char *end;
|
||||||
|
virDomainHostdevDefPtr def = virDomainHostdevDefAlloc();
|
||||||
|
|
||||||
|
if (!def)
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (!STRPREFIX(val, "host=")) {
|
if (!STRPREFIX(val, "host=")) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unknown PCI device syntax '%s'"), val);
|
_("unknown PCI device syntax '%s'"), val);
|
||||||
VIR_FREE(def);
|
goto error;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start = val + strlen("host=");
|
start = val + strlen("host=");
|
||||||
if (virStrToLong_i(start, &end, 16, &bus) < 0 || *end != ':') {
|
if (virStrToLong_i(start, &end, 16, &bus) < 0 || *end != ':') {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract PCI device bus '%s'"), val);
|
_("cannot extract PCI device bus '%s'"), val);
|
||||||
VIR_FREE(def);
|
goto error;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
if (virStrToLong_i(start, &end, 16, &slot) < 0 || *end != '.') {
|
if (virStrToLong_i(start, &end, 16, &slot) < 0 || *end != '.') {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract PCI device slot '%s'"), val);
|
_("cannot extract PCI device slot '%s'"), val);
|
||||||
VIR_FREE(def);
|
goto error;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
if (virStrToLong_i(start, NULL, 16, &func) < 0) {
|
if (virStrToLong_i(start, NULL, 16, &func) < 0) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract PCI device function '%s'"), val);
|
_("cannot extract PCI device function '%s'"), val);
|
||||||
VIR_FREE(def);
|
goto error;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0) {
|
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
|
def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
|
||||||
@ -6699,9 +6693,11 @@ qemuParseCommandLinePCI(const char *val)
|
|||||||
def->source.subsys.u.pci.bus = bus;
|
def->source.subsys.u.pci.bus = bus;
|
||||||
def->source.subsys.u.pci.slot = slot;
|
def->source.subsys.u.pci.slot = slot;
|
||||||
def->source.subsys.u.pci.function = func;
|
def->source.subsys.u.pci.function = func;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return def;
|
return def;
|
||||||
|
|
||||||
|
error:
|
||||||
|
virDomainHostdevDefFree(def);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -6711,16 +6707,18 @@ cleanup:
|
|||||||
static virDomainHostdevDefPtr
|
static virDomainHostdevDefPtr
|
||||||
qemuParseCommandLineUSB(const char *val)
|
qemuParseCommandLineUSB(const char *val)
|
||||||
{
|
{
|
||||||
virDomainHostdevDefPtr def = NULL;
|
virDomainHostdevDefPtr def = virDomainHostdevDefAlloc();
|
||||||
int first = 0, second = 0;
|
int first = 0, second = 0;
|
||||||
const char *start;
|
const char *start;
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
|
if (!def)
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (!STRPREFIX(val, "host:")) {
|
if (!STRPREFIX(val, "host:")) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unknown USB device syntax '%s'"), val);
|
_("unknown USB device syntax '%s'"), val);
|
||||||
VIR_FREE(def);
|
goto error;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start = val + strlen("host:");
|
start = val + strlen("host:");
|
||||||
@ -6728,37 +6726,28 @@ qemuParseCommandLineUSB(const char *val)
|
|||||||
if (virStrToLong_i(start, &end, 16, &first) < 0 || *end != ':') {
|
if (virStrToLong_i(start, &end, 16, &first) < 0 || *end != ':') {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract USB device vendor '%s'"), val);
|
_("cannot extract USB device vendor '%s'"), val);
|
||||||
VIR_FREE(def);
|
goto error;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
if (virStrToLong_i(start, NULL, 16, &second) < 0) {
|
if (virStrToLong_i(start, NULL, 16, &second) < 0) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract USB device product '%s'"), val);
|
_("cannot extract USB device product '%s'"), val);
|
||||||
VIR_FREE(def);
|
goto error;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (virStrToLong_i(start, &end, 10, &first) < 0 || *end != '.') {
|
if (virStrToLong_i(start, &end, 10, &first) < 0 || *end != '.') {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract USB device bus '%s'"), val);
|
_("cannot extract USB device bus '%s'"), val);
|
||||||
VIR_FREE(def);
|
goto error;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
if (virStrToLong_i(start, NULL, 10, &second) < 0) {
|
if (virStrToLong_i(start, NULL, 10, &second) < 0) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot extract USB device address '%s'"), val);
|
_("cannot extract USB device address '%s'"), val);
|
||||||
VIR_FREE(def);
|
goto error;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0) {
|
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
|
def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
|
||||||
def->managed = 0;
|
def->managed = 0;
|
||||||
def->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB;
|
def->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB;
|
||||||
@ -6769,9 +6758,11 @@ qemuParseCommandLineUSB(const char *val)
|
|||||||
def->source.subsys.u.usb.vendor = first;
|
def->source.subsys.u.usb.vendor = first;
|
||||||
def->source.subsys.u.usb.product = second;
|
def->source.subsys.u.usb.product = second;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return def;
|
return def;
|
||||||
|
|
||||||
|
error:
|
||||||
|
virDomainHostdevDefFree(def);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -918,14 +918,14 @@ int qemuDomainAttachHostPciDevice(struct qemud_driver *driver,
|
|||||||
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
|
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
|
||||||
if (qemuAssignDeviceHostdevAlias(vm->def, hostdev, -1) < 0)
|
if (qemuAssignDeviceHostdevAlias(vm->def, hostdev, -1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (qemuDomainPCIAddressEnsureAddr(priv->pciaddrs, &hostdev->info) < 0)
|
if (qemuDomainPCIAddressEnsureAddr(priv->pciaddrs, hostdev->info) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
releaseaddr = true;
|
releaseaddr = true;
|
||||||
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_PCI_CONFIGFD)) {
|
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_PCI_CONFIGFD)) {
|
||||||
configfd = qemuOpenPCIConfig(hostdev);
|
configfd = qemuOpenPCIConfig(hostdev);
|
||||||
if (configfd >= 0) {
|
if (configfd >= 0) {
|
||||||
if (virAsprintf(&configfd_name, "fd-%s",
|
if (virAsprintf(&configfd_name, "fd-%s",
|
||||||
hostdev->info.alias) < 0) {
|
hostdev->info->alias) < 0) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -947,7 +947,7 @@ int qemuDomainAttachHostPciDevice(struct qemud_driver *driver,
|
|||||||
configfd, configfd_name);
|
configfd, configfd_name);
|
||||||
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
||||||
} else {
|
} else {
|
||||||
virDomainDevicePCIAddress guestAddr = hostdev->info.addr.pci;
|
virDomainDevicePCIAddress guestAddr = hostdev->info->addr.pci;
|
||||||
|
|
||||||
qemuDomainObjEnterMonitorWithDriver(driver, vm);
|
qemuDomainObjEnterMonitorWithDriver(driver, vm);
|
||||||
ret = qemuMonitorAddPCIHostDevice(priv->mon,
|
ret = qemuMonitorAddPCIHostDevice(priv->mon,
|
||||||
@ -955,8 +955,8 @@ int qemuDomainAttachHostPciDevice(struct qemud_driver *driver,
|
|||||||
&guestAddr);
|
&guestAddr);
|
||||||
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
||||||
|
|
||||||
hostdev->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
|
hostdev->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
|
||||||
memcpy(&hostdev->info.addr.pci, &guestAddr, sizeof(guestAddr));
|
memcpy(&hostdev->info->addr.pci, &guestAddr, sizeof(guestAddr));
|
||||||
}
|
}
|
||||||
virDomainAuditHostdev(vm, hostdev, "attach", ret == 0);
|
virDomainAuditHostdev(vm, hostdev, "attach", ret == 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -972,10 +972,10 @@ int qemuDomainAttachHostPciDevice(struct qemud_driver *driver,
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) &&
|
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) &&
|
||||||
(hostdev->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) &&
|
(hostdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) &&
|
||||||
releaseaddr &&
|
releaseaddr &&
|
||||||
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
|
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
|
||||||
hostdev->info.addr.pci.slot) < 0)
|
hostdev->info->addr.pci.slot) < 0)
|
||||||
VIR_WARN("Unable to release PCI address on host device");
|
VIR_WARN("Unable to release PCI address on host device");
|
||||||
|
|
||||||
qemuDomainReAttachHostdevDevices(driver, vm->def->name, &hostdev, 1);
|
qemuDomainReAttachHostdevDevices(driver, vm->def->name, &hostdev, 1);
|
||||||
@ -2018,14 +2018,14 @@ qemuDomainDetachHostPciDevice(struct qemud_driver *driver,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) {
|
if (qemuIsMultiFunctionDevice(vm->def, detach->info)) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("cannot hot unplug multifunction PCI device: %s"),
|
_("cannot hot unplug multifunction PCI device: %s"),
|
||||||
dev->data.disk->dst);
|
dev->data.disk->dst);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virDomainDeviceAddressIsValid(&detach->info,
|
if (!virDomainDeviceAddressIsValid(detach->info,
|
||||||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)) {
|
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
"%s", _("device cannot be detached without a PCI address"));
|
"%s", _("device cannot be detached without a PCI address"));
|
||||||
@ -2034,9 +2034,9 @@ qemuDomainDetachHostPciDevice(struct qemud_driver *driver,
|
|||||||
|
|
||||||
qemuDomainObjEnterMonitorWithDriver(driver, vm);
|
qemuDomainObjEnterMonitorWithDriver(driver, vm);
|
||||||
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
|
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
|
||||||
ret = qemuMonitorDelDevice(priv->mon, detach->info.alias);
|
ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
|
||||||
} else {
|
} else {
|
||||||
ret = qemuMonitorRemovePCIDevice(priv->mon, &detach->info.addr.pci);
|
ret = qemuMonitorRemovePCIDevice(priv->mon, &detach->info->addr.pci);
|
||||||
}
|
}
|
||||||
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
||||||
virDomainAuditHostdev(vm, detach, "detach", ret == 0);
|
virDomainAuditHostdev(vm, detach, "detach", ret == 0);
|
||||||
@ -2062,7 +2062,7 @@ qemuDomainDetachHostPciDevice(struct qemud_driver *driver,
|
|||||||
|
|
||||||
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) &&
|
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) &&
|
||||||
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
|
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
|
||||||
detach->info.addr.pci.slot) < 0)
|
detach->info->addr.pci.slot) < 0)
|
||||||
VIR_WARN("Unable to release PCI address on host device");
|
VIR_WARN("Unable to release PCI address on host device");
|
||||||
|
|
||||||
if (vm->def->nhostdevs > 1) {
|
if (vm->def->nhostdevs > 1) {
|
||||||
@ -2131,7 +2131,7 @@ qemuDomainDetachHostUsbDevice(struct qemud_driver *driver,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!detach->info.alias) {
|
if (!detach->info->alias) {
|
||||||
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
"%s", _("device cannot be detached without a device alias"));
|
"%s", _("device cannot be detached without a device alias"));
|
||||||
return -1;
|
return -1;
|
||||||
@ -2144,7 +2144,7 @@ qemuDomainDetachHostUsbDevice(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
qemuDomainObjEnterMonitorWithDriver(driver, vm);
|
qemuDomainObjEnterMonitorWithDriver(driver, vm);
|
||||||
ret = qemuMonitorDelDevice(priv->mon, detach->info.alias);
|
ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
|
||||||
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
||||||
virDomainAuditHostdev(vm, detach, "detach", ret == 0);
|
virDomainAuditHostdev(vm, detach, "detach", ret == 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@ -1076,8 +1076,8 @@ xenParseSxprPCI(virDomainDefPtr def,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(dev) < 0)
|
if (!(dev = virDomainHostdevDefAlloc()))
|
||||||
goto no_memory;
|
goto error;
|
||||||
|
|
||||||
dev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
|
dev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
|
||||||
dev->managed = 0;
|
dev->managed = 0;
|
||||||
@ -1088,6 +1088,7 @@ xenParseSxprPCI(virDomainDefPtr def,
|
|||||||
dev->source.subsys.u.pci.function = funcID;
|
dev->source.subsys.u.pci.function = funcID;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) {
|
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) {
|
||||||
|
virDomainHostdevDefFree(dev);
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -815,8 +815,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
|
|||||||
if (virStrToLong_i(func, NULL, 16, &funcID) < 0)
|
if (virStrToLong_i(func, NULL, 16, &funcID) < 0)
|
||||||
goto skippci;
|
goto skippci;
|
||||||
|
|
||||||
if (VIR_ALLOC(hostdev) < 0)
|
if (!(hostdev = virDomainHostdevDefAlloc()))
|
||||||
goto no_memory;
|
goto cleanup;
|
||||||
|
|
||||||
hostdev->managed = 0;
|
hostdev->managed = 0;
|
||||||
hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
|
hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
|
||||||
@ -825,8 +825,10 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
|
|||||||
hostdev->source.subsys.u.pci.slot = slotID;
|
hostdev->source.subsys.u.pci.slot = slotID;
|
||||||
hostdev->source.subsys.u.pci.function = funcID;
|
hostdev->source.subsys.u.pci.function = funcID;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0)
|
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) {
|
||||||
|
virDomainHostdevDefFree(hostdev);
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
}
|
||||||
def->hostdevs[def->nhostdevs++] = hostdev;
|
def->hostdevs[def->nhostdevs++] = hostdev;
|
||||||
hostdev = NULL;
|
hostdev = NULL;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user