int i, ret;
const char* type = virDomainDiskBusTypeToString(dev->data.disk->bus);
qemuDomainObjPrivatePtr priv = vm->privateData;
+ virDomainDevicePCIAddress guestAddr;
for (i = 0 ; i < vm->def->ndisks ; i++) {
if (STREQ(vm->def->disks[i]->dst, dev->data.disk->dst)) {
ret = qemuMonitorAddPCIDisk(priv->mon,
dev->data.disk->src,
type,
- &dev->data.disk->info.addr.pci.domain,
- &dev->data.disk->info.addr.pci.bus,
- &dev->data.disk->info.addr.pci.slot);
+ &guestAddr);
qemuDomainObjExitMonitorWithDriver(driver, vm);
if (ret == 0) {
dev->data.disk->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+ memcpy(&dev->data.disk->info.addr.pci, &guestAddr, sizeof(guestAddr));
virDomainDiskInsertPreAlloced(vm->def, dev->data.disk);
}
char *nicstr = NULL;
char *netstr = NULL;
int ret = -1;
+ virDomainDevicePCIAddress guestAddr;
if (!(qemuCmdFlags & QEMUD_CMD_FLAG_HOST_NET_ADD)) {
qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT, "%s",
qemuDomainObjEnterMonitorWithDriver(driver, vm);
if (qemuMonitorAddPCINetwork(priv->mon, nicstr,
- &net->info.addr.pci.domain,
- &net->info.addr.pci.bus,
- &net->info.addr.pci.slot) < 0) {
+ &guestAddr) < 0) {
qemuDomainObjExitMonitorWithDriver(driver, vm);
goto try_remove;
}
net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+ memcpy(&net->info.addr.pci, &guestAddr, sizeof(guestAddr));
qemuDomainObjExitMonitorWithDriver(driver, vm);
ret = 0;
virDomainHostdevDefPtr hostdev = dev->data.hostdev;
pciDevice *pci;
int ret;
+ virDomainDevicePCIAddress guestAddr;
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) {
virReportOOMError(conn);
qemuDomainObjEnterMonitorWithDriver(driver, vm);
ret = qemuMonitorAddPCIHostDevice(priv->mon,
- hostdev->source.subsys.u.pci.domain,
- hostdev->source.subsys.u.pci.bus,
- hostdev->source.subsys.u.pci.slot,
- hostdev->source.subsys.u.pci.function,
- &hostdev->info.addr.pci.domain,
- &hostdev->info.addr.pci.bus,
- &hostdev->info.addr.pci.slot);
+ &hostdev->source.subsys.u.pci,
+ &guestAddr);
qemuDomainObjExitMonitorWithDriver(driver, vm);
if (ret < 0)
goto error;
hostdev->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+ memcpy(&hostdev->info.addr.pci, &guestAddr, sizeof(guestAddr));
vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
qemuDomainObjEnterMonitorWithDriver(driver, vm);
if (qemuMonitorRemovePCIDevice(priv->mon,
- detach->info.addr.pci.domain,
- detach->info.addr.pci.bus,
- detach->info.addr.pci.slot) < 0) {
+ &detach->info.addr.pci) < 0) {
qemuDomainObjExitMonitor(vm);
goto cleanup;
}
qemuDomainObjEnterMonitorWithDriver(driver, vm);
if (qemuMonitorRemovePCIDevice(priv->mon,
- detach->info.addr.pci.domain,
- detach->info.addr.pci.bus,
- detach->info.addr.pci.slot) < 0) {
+ &detach->info.addr.pci) < 0) {
qemuDomainObjExitMonitorWithDriver(driver, vm);
goto cleanup;
}
qemuDomainObjEnterMonitorWithDriver(driver, vm);
if (qemuMonitorRemovePCIDevice(priv->mon,
- detach->info.addr.pci.domain,
- detach->info.addr.pci.bus,
- detach->info.addr.pci.slot) < 0) {
+ &detach->info.addr.pci) < 0) {
qemuDomainObjExitMonitorWithDriver(driver, vm);
return -1;
}
int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon,
- unsigned hostDomain,
- unsigned hostBus,
- unsigned hostSlot,
- unsigned hostFunction,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot)
+ virDomainDevicePCIAddress *hostAddr,
+ virDomainDevicePCIAddress *guestAddr)
{
int ret;
DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d function=%d",
mon, mon->fd,
- hostDomain, hostBus, hostSlot, hostFunction);
+ hostAddr->domain, hostAddr->bus, hostAddr->slot, hostAddr->function);
if (mon->json)
- ret = qemuMonitorJSONAddPCIHostDevice(mon, hostDomain,
- hostBus, hostSlot,
- hostFunction,
- guestDomain,
- guestBus,
- guestSlot);
+ ret = qemuMonitorJSONAddPCIHostDevice(mon, hostAddr, guestAddr);
else
- ret = qemuMonitorTextAddPCIHostDevice(mon, hostDomain,
- hostBus, hostSlot,
- hostFunction,
- guestDomain,
- guestBus,
- guestSlot);
+ ret = qemuMonitorTextAddPCIHostDevice(mon, hostAddr, guestAddr);
return ret;
}
int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
const char *path,
const char *bus,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot)
+ virDomainDevicePCIAddress *guestAddr)
{
int ret;
DEBUG("mon=%p, fd=%d path=%s bus=%s",
mon, mon->fd, path, bus);
if (mon->json)
- ret = qemuMonitorJSONAddPCIDisk(mon, path, bus,
- guestDomain, guestBus, guestSlot);
+ ret = qemuMonitorJSONAddPCIDisk(mon, path, bus, guestAddr);
else
- ret = qemuMonitorTextAddPCIDisk(mon, path, bus,
- guestDomain, guestBus, guestSlot);
+ ret = qemuMonitorTextAddPCIDisk(mon, path, bus, guestAddr);
return ret;
}
int qemuMonitorAddPCINetwork(qemuMonitorPtr mon,
const char *nicstr,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot)
+ virDomainDevicePCIAddress *guestAddr)
{
int ret;
DEBUG("mon=%p, fd=%d nicstr=%s", mon, mon->fd, nicstr);
if (mon->json)
- ret = qemuMonitorJSONAddPCINetwork(mon, nicstr, guestDomain,
- guestBus, guestSlot);
+ ret = qemuMonitorJSONAddPCINetwork(mon, nicstr, guestAddr);
else
- ret = qemuMonitorTextAddPCINetwork(mon, nicstr, guestDomain,
- guestBus, guestSlot);
+ ret = qemuMonitorTextAddPCINetwork(mon, nicstr, guestAddr);
return ret;
}
int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
- unsigned guestDomain,
- unsigned guestBus,
- unsigned guestSlot)
+ virDomainDevicePCIAddress *guestAddr)
{
int ret;
- DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d",
- mon, mon->fd, guestDomain, guestBus, guestSlot);
+ DEBUG("mon=%p, fd=%d domain=%d bus=%d slot=%d function=%d",
+ mon, mon->fd, guestAddr->domain, guestAddr->bus,
+ guestAddr->slot, guestAddr->function);
if (mon->json)
- ret = qemuMonitorJSONRemovePCIDevice(mon, guestDomain,
- guestBus, guestSlot);
+ ret = qemuMonitorJSONRemovePCIDevice(mon, guestAddr);
else
- ret = qemuMonitorTextRemovePCIDevice(mon, guestDomain,
- guestBus, guestSlot);
+ ret = qemuMonitorTextRemovePCIDevice(mon, guestAddr);
return ret;
}
int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon,
- unsigned hostDomain,
- unsigned hostBus,
- unsigned hostSlot,
- unsigned hostFunction,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot);
+ virDomainDevicePCIAddress *hostAddr,
+ virDomainDevicePCIAddress *guestAddr);
/* XXX disk driver type eg, qcow/etc.
* XXX cache mode
int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
const char *path,
const char *bus,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot);
+ virDomainDevicePCIAddress *guestAddr);
/* XXX do we really want to hardcode 'nicstr' as the
* sendable item here
*/
int qemuMonitorAddPCINetwork(qemuMonitorPtr mon,
const char *nicstr,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot);
+ virDomainDevicePCIAddress *guestAddr);
int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
- unsigned guestDomain,
- unsigned guestBus,
- unsigned guestSlot);
+ virDomainDevicePCIAddress *guestAddr);
int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
/* XXX qemu also returns a 'function' number now */
static int
qemuMonitorJSONGetGuestAddress(virJSONValuePtr reply,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot)
+ virDomainDevicePCIAddress *guestAddr)
{
virJSONValuePtr addr;
return -1;
}
- if (virJSONValueObjectGetNumberUint(addr, "domain", guestDomain) < 0) {
+ if (virJSONValueObjectGetNumberUint(addr, "domain", &guestAddr->domain) < 0) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
_("pci_add reply was missing device domain number"));
return -1;
}
- if (virJSONValueObjectGetNumberUint(addr, "bus", guestBus) < 0) {
+ if (virJSONValueObjectGetNumberUint(addr, "bus", &guestAddr->bus) < 0) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
_("pci_add reply was missing device bus number"));
return -1;
}
- if (virJSONValueObjectGetNumberUint(addr, "slot", guestSlot) < 0) {
+ if (virJSONValueObjectGetNumberUint(addr, "slot", &guestAddr->slot) < 0) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
_("pci_add reply was missing device slot number"));
return -1;
}
+ if (virJSONValueObjectGetNumberUint(addr, "function", &guestAddr->function) < 0) {
+ qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("pci_add reply was missing device function number"));
+ return -1;
+ }
+
return 0;
}
int qemuMonitorJSONAddPCIHostDevice(qemuMonitorPtr mon,
- unsigned hostDomain ATTRIBUTE_UNUSED,
- unsigned hostBus,
- unsigned hostSlot,
- unsigned hostFunction,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot)
+ virDomainDevicePCIAddress *hostAddr,
+ virDomainDevicePCIAddress *guestAddr)
{
int ret;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
char *dev;
- *guestDomain = *guestBus = *guestSlot = 0;
+ memset(guestAddr, 0, sizeof(*guestAddr));
/* XXX hostDomain */
if (virAsprintf(&dev, "host=%.2x:%.2x.%.1x",
- hostBus, hostSlot, hostFunction) < 0) {
+ hostAddr->bus, hostAddr->slot, hostAddr->function) < 0) {
virReportOOMError(NULL);
return -1;
}
ret = qemuMonitorJSONCheckError(cmd, reply);
if (ret == 0 &&
- qemuMonitorJSONGetGuestAddress(reply, guestDomain, guestBus, guestSlot) < 0)
+ qemuMonitorJSONGetGuestAddress(reply, guestAddr) < 0)
ret = -1;
virJSONValueFree(cmd);
int qemuMonitorJSONAddPCIDisk(qemuMonitorPtr mon,
const char *path,
const char *bus,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot) {
+ virDomainDevicePCIAddress *guestAddr)
+{
int ret;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
char *dev;
- *guestDomain = *guestBus = *guestSlot = 0;
+ memset(guestAddr, 0, sizeof(*guestAddr));
if (virAsprintf(&dev, "file=%s,if=%s", path, bus) < 0) {
virReportOOMError(NULL);
ret = qemuMonitorJSONCheckError(cmd, reply);
if (ret == 0 &&
- qemuMonitorJSONGetGuestAddress(reply, guestDomain, guestBus, guestSlot) < 0)
+ qemuMonitorJSONGetGuestAddress(reply, guestAddr) < 0)
ret = -1;
virJSONValueFree(cmd);
int qemuMonitorJSONAddPCINetwork(qemuMonitorPtr mon,
const char *nicstr,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot)
+ virDomainDevicePCIAddress *guestAddr)
{
int ret;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("pci_add",
NULL);
virJSONValuePtr reply = NULL;
- *guestDomain = *guestBus = *guestSlot = 0;
+ memset(guestAddr, 0, sizeof(*guestAddr));
if (!cmd)
return -1;
ret = qemuMonitorJSONCheckError(cmd, reply);
if (ret == 0 &&
- qemuMonitorJSONGetGuestAddress(reply, guestDomain, guestBus, guestSlot) < 0)
+ qemuMonitorJSONGetGuestAddress(reply, guestAddr) < 0)
ret = -1;
virJSONValueFree(cmd);
int qemuMonitorJSONRemovePCIDevice(qemuMonitorPtr mon,
- unsigned guestDomain,
- unsigned guestBus,
- unsigned guestSlot)
+ virDomainDevicePCIAddress *guestAddr)
{
int ret;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
char *addr;
+ /* XXX what about function ? */
if (virAsprintf(&addr, "%.4x:%.2x:%.2x",
- guestDomain, guestBus, guestSlot) < 0) {
+ guestAddr->domain, guestAddr->bus, guestAddr->slot) < 0) {
virReportOOMError(NULL);
return -1;
}
int qemuMonitorJSONAddPCIHostDevice(qemuMonitorPtr mon,
- unsigned hostDomain,
- unsigned hostBus,
- unsigned hostSlot,
- unsigned hostFunction,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot);
+ virDomainDevicePCIAddress *hostAddr,
+ virDomainDevicePCIAddress *guestAddr);
int qemuMonitorJSONAddPCIDisk(qemuMonitorPtr mon,
const char *path,
const char *bus,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot);
+ virDomainDevicePCIAddress *guestAddr);
int qemuMonitorJSONAddPCINetwork(qemuMonitorPtr mon,
const char *nicstr,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot);
+ virDomainDevicePCIAddress *guestAddr);
int qemuMonitorJSONRemovePCIDevice(qemuMonitorPtr mon,
- unsigned guestDomain,
- unsigned guestBus,
- unsigned guestSlot);
-
+ virDomainDevicePCIAddress *guestAddr);
int qemuMonitorJSONSendFileHandle(qemuMonitorPtr mon,
const char *fdname,
static int
qemuMonitorTextParsePciAddReply(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
const char *reply,
- unsigned *domain,
- unsigned *bus,
- unsigned *slot)
+ virDomainDevicePCIAddress *addr)
{
char *s, *e;
if (STRPREFIX(s, "domain ")) {
s += strlen("domain ");
- if (virStrToLong_ui(s, &e, 10, domain) == -1) {
+ if (virStrToLong_ui(s, &e, 10, &addr->domain) == -1) {
VIR_WARN(_("Unable to parse domain number '%s'\n"), s);
return -1;
}
}
s += strlen("bus ");
- if (virStrToLong_ui(s, &e, 10, bus) == -1) {
+ if (virStrToLong_ui(s, &e, 10, &addr->bus) == -1) {
VIR_WARN(_("Unable to parse bus number '%s'\n"), s);
return -1;
}
}
s += strlen("slot ");
- if (virStrToLong_ui(s, &e, 10, slot) == -1) {
+ if (virStrToLong_ui(s, &e, 10, &addr->slot) == -1) {
VIR_WARN(_("Unable to parse slot number '%s'\n"), s);
return -1;
}
int qemuMonitorTextAddPCIHostDevice(qemuMonitorPtr mon,
- unsigned hostDomain ATTRIBUTE_UNUSED,
- unsigned hostBus,
- unsigned hostSlot,
- unsigned hostFunction,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot)
+ virDomainDevicePCIAddress *hostAddr,
+ virDomainDevicePCIAddress *guestAddr)
{
char *cmd;
char *reply = NULL;
int ret = -1;
- *guestDomain = *guestBus = *guestSlot = 0;
+ memset(guestAddr, 0, sizeof(*guestAddr));
- /* XXX hostDomain */
+ /* XXX hostAddr->domain */
if (virAsprintf(&cmd, "pci_add pci_addr=auto host host=%.2x:%.2x.%.1x",
- hostBus, hostSlot, hostFunction) < 0) {
+ hostAddr->bus, hostAddr->slot, hostAddr->function) < 0) {
virReportOOMError(NULL);
goto cleanup;
}
goto cleanup;
}
- if (qemuMonitorTextParsePciAddReply(mon, reply,
- guestDomain,
- guestBus,
- guestSlot) < 0) {
+ if (qemuMonitorTextParsePciAddReply(mon, reply, guestAddr) < 0) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
_("parsing pci_add reply failed: %s"), reply);
goto cleanup;
int qemuMonitorTextAddPCIDisk(qemuMonitorPtr mon,
const char *path,
const char *bus,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot) {
+ virDomainDevicePCIAddress *guestAddr)
+{
char *cmd = NULL;
char *reply = NULL;
char *safe_path = NULL;
goto cleanup;
}
- if (qemuMonitorTextParsePciAddReply(mon, reply,
- guestDomain, guestBus, guestSlot) < 0) {
+ if (qemuMonitorTextParsePciAddReply(mon, reply, guestAddr) < 0) {
if (!tryOldSyntax && strstr(reply, "invalid char in expression")) {
VIR_FREE(reply);
VIR_FREE(cmd);
int qemuMonitorTextAddPCINetwork(qemuMonitorPtr mon,
const char *nicstr,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot)
+ virDomainDevicePCIAddress *guestAddr)
{
char *cmd;
char *reply = NULL;
goto cleanup;
}
- if (qemuMonitorTextParsePciAddReply(mon, reply,
- guestDomain, guestBus, guestSlot) < 0) {
+ if (qemuMonitorTextParsePciAddReply(mon, reply, guestAddr) < 0) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
_("parsing pci_add reply failed: %s"), reply);
goto cleanup;
int qemuMonitorTextRemovePCIDevice(qemuMonitorPtr mon,
- unsigned guestDomain,
- unsigned guestBus,
- unsigned guestSlot)
+ virDomainDevicePCIAddress *guestAddr)
{
char *cmd = NULL;
char *reply = NULL;
try_command:
if (tryOldSyntax) {
- if (virAsprintf(&cmd, "pci_del 0 %.2x", guestSlot) < 0) {
+ if (virAsprintf(&cmd, "pci_del 0 %.2x", guestAddr->slot) < 0) {
virReportOOMError(NULL);
goto cleanup;
}
} else {
+ /* XXX function ? */
if (virAsprintf(&cmd, "pci_del pci_addr=%.4x:%.2x:%.2x",
- guestDomain, guestBus, guestSlot) < 0) {
+ guestAddr->domain, guestAddr->bus, guestAddr->slot) < 0) {
virReportOOMError(NULL);
goto cleanup;
}
strstr(reply, "Invalid pci address")) {
qemudReportError (NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
_("failed to detach PCI device, invalid address %.4x:%.2x:%.2x: %s"),
- guestDomain, guestBus, guestSlot, reply);
+ guestAddr->domain, guestAddr->bus, guestAddr->slot, reply);
goto cleanup;
}
int qemuMonitorTextAddPCIHostDevice(qemuMonitorPtr mon,
- unsigned hostDomain,
- unsigned hostBus,
- unsigned hostSlot,
- unsigned hostFunction,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot);
+ virDomainDevicePCIAddress *hostAddr,
+ virDomainDevicePCIAddress *guestAddr);
int qemuMonitorTextAddPCIDisk(qemuMonitorPtr mon,
const char *path,
const char *bus,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot);
+ virDomainDevicePCIAddress *guestAddr);
int qemuMonitorTextAddPCINetwork(qemuMonitorPtr mon,
const char *nicstr,
- unsigned *guestDomain,
- unsigned *guestBus,
- unsigned *guestSlot);
+ virDomainDevicePCIAddress *guestAddr);
int qemuMonitorTextRemovePCIDevice(qemuMonitorPtr mon,
- unsigned guestDomain,
- unsigned guestBus,
- unsigned guestSlot);
-
+ virDomainDevicePCIAddress *guestAddr);
int qemuMonitorTextSendFileHandle(qemuMonitorPtr mon,
const char *fdname,