Convert the QEMU monitor APIs over to use virDomainDeviceAddress structs for passing addresses in/out, instead of individual bits * src/qemu/qemu_driver.c, src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h, src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Change monitor hotplug APIs to take an explicit address ptr for all host/guest addresses --- src/qemu/qemu_driver.c | 38 ++++++++-------------- src/qemu/qemu_monitor.c | 69 +++++++++++++----------------------------- src/qemu/qemu_monitor.h | 24 ++++----------- src/qemu/qemu_monitor_json.c | 60 ++++++++++++++++-------------------- src/qemu/qemu_monitor_json.h | 25 ++++----------- src/qemu/qemu_monitor_text.c | 61 +++++++++++++----------------------- src/qemu/qemu_monitor_text.h | 25 ++++----------- 7 files changed, 102 insertions(+), 200 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 85cbaf7..321cd4e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4930,6 +4930,7 @@ static int qemudDomainAttachPciDiskDevice(virConnectPtr conn, 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)) { @@ -4948,13 +4949,12 @@ static int qemudDomainAttachPciDiskDevice(virConnectPtr conn, ret = qemuMonitorAddPCIDisk(priv->mon, dev->data.disk->src, type, - &dev->data.disk->addr.data.pci.domain, - &dev->data.disk->addr.data.pci.bus, - &dev->data.disk->addr.data.pci.slot); + &guestAddr); qemuDomainObjExitMonitorWithDriver(driver, vm); if (ret == 0) { dev->data.disk->addr.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; + memcpy(&dev->data.disk->addr.data.pci, &guestAddr, sizeof(guestAddr)); virDomainDiskInsertPreAlloced(vm->def, dev->data.disk); } @@ -5011,6 +5011,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn, 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", @@ -5079,13 +5080,12 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn, qemuDomainObjEnterMonitorWithDriver(driver, vm); if (qemuMonitorAddPCINetwork(priv->mon, nicstr, - &net->addr.data.pci.domain, - &net->addr.data.pci.bus, - &net->addr.data.pci.slot) < 0) { + &guestAddr) < 0) { qemuDomainObjExitMonitorWithDriver(driver, vm); goto try_remove; } net->addr.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; + memcpy(&net->addr.data.pci, &guestAddr, sizeof(guestAddr)); qemuDomainObjExitMonitorWithDriver(driver, vm); ret = 0; @@ -5137,6 +5137,7 @@ static int qemudDomainAttachHostPciDevice(virConnectPtr conn, 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); @@ -5164,17 +5165,13 @@ static int qemudDomainAttachHostPciDevice(virConnectPtr 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->addr.data.pci.domain, - &hostdev->addr.data.pci.bus, - &hostdev->addr.data.pci.slot); + &hostdev->source.subsys.u.pci, + &guestAddr); qemuDomainObjExitMonitorWithDriver(driver, vm); if (ret < 0) goto error; hostdev->addr.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; + memcpy(&hostdev->addr.data.pci, &guestAddr, sizeof(guestAddr)); vm->def->hostdevs[vm->def->nhostdevs++] = hostdev; @@ -5206,8 +5203,7 @@ static int qemudDomainAttachHostUsbDevice(virConnectPtr conn, dev->data.hostdev->source.subsys.u.usb.product); } else { ret = qemuMonitorAddUSBDeviceExact(priv->mon, - dev->data.hostdev->source.subsys.u.usb.addr.bus, - dev->data.hostdev->source.subsys.u.usb.addr.dev); + &dev->data.hostdev->source.subsys.u.usb.addr); } qemuDomainObjExitMonitorWithDriver(driver, vm); @@ -5413,9 +5409,7 @@ static int qemudDomainDetachPciDiskDevice(virConnectPtr conn, qemuDomainObjEnterMonitorWithDriver(driver, vm); if (qemuMonitorRemovePCIDevice(priv->mon, - detach->addr.data.pci.domain, - detach->addr.data.pci.bus, - detach->addr.data.pci.slot) < 0) { + &detach->addr.data.pci) < 0) { qemuDomainObjExitMonitor(vm); goto cleanup; } @@ -5485,9 +5479,7 @@ qemudDomainDetachNetDevice(virConnectPtr conn, qemuDomainObjEnterMonitorWithDriver(driver, vm); if (qemuMonitorRemovePCIDevice(priv->mon, - detach->addr.data.pci.domain, - detach->addr.data.pci.bus, - detach->addr.data.pci.slot) < 0) { + &detach->addr.data.pci) < 0) { qemuDomainObjExitMonitorWithDriver(driver, vm); goto cleanup; } @@ -5574,9 +5566,7 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn, qemuDomainObjEnterMonitorWithDriver(driver, vm); if (qemuMonitorRemovePCIDevice(priv->mon, - detach->addr.data.pci.domain, - detach->addr.data.pci.bus, - detach->addr.data.pci.slot) < 0) { + &detach->addr.data.pci) < 0) { qemuDomainObjExitMonitorWithDriver(driver, vm); return -1; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 103cf28..ded1622 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1087,16 +1087,15 @@ int qemuMonitorAddUSBDisk(qemuMonitorPtr mon, int qemuMonitorAddUSBDeviceExact(qemuMonitorPtr mon, - int bus, - int dev) + virDomainDeviceUSBAddress *hostAddr) { int ret; - DEBUG("mon=%p, fd=%d bus=%d dev=%d", mon, mon->fd, bus, dev); + DEBUG("mon=%p, fd=%d bus=%d dev=%d", mon, mon->fd, hostAddr->bus, hostAddr->dev); if (mon->json) - ret = qemuMonitorJSONAddUSBDeviceExact(mon, bus, dev); + ret = qemuMonitorJSONAddUSBDeviceExact(mon, hostAddr); else - ret = qemuMonitorTextAddUSBDeviceExact(mon, bus, dev); + ret = qemuMonitorTextAddUSBDeviceExact(mon, hostAddr); return ret; } @@ -1117,33 +1116,18 @@ int qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon, 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; } @@ -1151,58 +1135,47 @@ int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon, 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; } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 8b1e3a3..46f412e 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -213,21 +213,15 @@ int qemuMonitorAddUSBDisk(qemuMonitorPtr mon, const char *path); int qemuMonitorAddUSBDeviceExact(qemuMonitorPtr mon, - int bus, - int dev); + virDomainDeviceUSBAddress *hostAddr); int qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon, int vendor, int product); 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 @@ -235,23 +229,17 @@ int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon, 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, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 03562e8..48eca13 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1166,13 +1166,12 @@ int qemuMonitorJSONAddUSBDisk(qemuMonitorPtr mon, int qemuMonitorJSONAddUSBDeviceExact(qemuMonitorPtr mon, - int bus, - int dev) + virDomainDeviceUSBAddress *hostAddr) { int ret; char *addr; - if (virAsprintf(&addr, "host:%.3d.%.3d", bus, dev) < 0) { + if (virAsprintf(&addr, "host:%.3d.%.3d", hostAddr->bus, hostAddr->dev) < 0) { virReportOOMError(NULL); return -1; } @@ -1206,9 +1205,7 @@ int qemuMonitorJSONAddUSBDeviceMatch(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; @@ -1219,47 +1216,48 @@ qemuMonitorJSONGetGuestAddress(virJSONValuePtr reply, return -1; } - if (virJSONValueObjectGetNumberUint(addr, "domain", guestDomain) < 0) { + if (virJSONValueObjectGetNumberUint(addr, "domain", &guestAddr->domain) < 0) { qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("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, _("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, _("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; } @@ -1279,7 +1277,7 @@ int qemuMonitorJSONAddPCIHostDevice(qemuMonitorPtr mon, ret = qemuMonitorJSONCheckError(cmd, reply); if (ret == 0 && - qemuMonitorJSONGetGuestAddress(reply, guestDomain, guestBus, guestSlot) < 0) + qemuMonitorJSONGetGuestAddress(reply, guestAddr) < 0) ret = -1; virJSONValueFree(cmd); @@ -1291,15 +1289,14 @@ int qemuMonitorJSONAddPCIHostDevice(qemuMonitorPtr mon, 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); @@ -1321,7 +1318,7 @@ int qemuMonitorJSONAddPCIDisk(qemuMonitorPtr mon, ret = qemuMonitorJSONCheckError(cmd, reply); if (ret == 0 && - qemuMonitorJSONGetGuestAddress(reply, guestDomain, guestBus, guestSlot) < 0) + qemuMonitorJSONGetGuestAddress(reply, guestAddr) < 0) ret = -1; virJSONValueFree(cmd); @@ -1332,9 +1329,7 @@ int qemuMonitorJSONAddPCIDisk(qemuMonitorPtr mon, int qemuMonitorJSONAddPCINetwork(qemuMonitorPtr mon, const char *nicstr, - unsigned *guestDomain, - unsigned *guestBus, - unsigned *guestSlot) + virDomainDevicePCIAddress *guestAddr) { int ret; virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("pci_add", @@ -1344,7 +1339,7 @@ int qemuMonitorJSONAddPCINetwork(qemuMonitorPtr mon, NULL); virJSONValuePtr reply = NULL; - *guestDomain = *guestBus = *guestSlot = 0; + memset(guestAddr, 0, sizeof(*guestAddr)); if (!cmd) return -1; @@ -1355,7 +1350,7 @@ int qemuMonitorJSONAddPCINetwork(qemuMonitorPtr mon, ret = qemuMonitorJSONCheckError(cmd, reply); if (ret == 0 && - qemuMonitorJSONGetGuestAddress(reply, guestDomain, guestBus, guestSlot) < 0) + qemuMonitorJSONGetGuestAddress(reply, guestAddr) < 0) ret = -1; virJSONValueFree(cmd); @@ -1365,17 +1360,16 @@ int qemuMonitorJSONAddPCINetwork(qemuMonitorPtr mon, 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; } diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 62a88c0..9df96f5 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -104,40 +104,27 @@ int qemuMonitorJSONAddUSBDisk(qemuMonitorPtr mon, const char *path); int qemuMonitorJSONAddUSBDeviceExact(qemuMonitorPtr mon, - int bus, - int dev); + virDomainDeviceUSBAddress *hostAddr); int qemuMonitorJSONAddUSBDeviceMatch(qemuMonitorPtr mon, int vendor, int product); 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, diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 72cb2bb..27c213d 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -1159,13 +1159,12 @@ cleanup: int qemuMonitorTextAddUSBDeviceExact(qemuMonitorPtr mon, - int bus, - int dev) + virDomainDeviceUSBAddress *hostAddr) { int ret; char *addr; - if (virAsprintf(&addr, "host:%.3d.%.3d", bus, dev) < 0) { + if (virAsprintf(&addr, "host:%.3d.%.3d", hostAddr->bus, hostAddr->dev) < 0) { virReportOOMError(NULL); return -1; } @@ -1198,9 +1197,7 @@ int qemuMonitorTextAddUSBDeviceMatch(qemuMonitorPtr mon, static int qemuMonitorTextParsePciAddReply(qemuMonitorPtr mon ATTRIBUTE_UNUSED, const char *reply, - unsigned *domain, - unsigned *bus, - unsigned *slot) + virDomainDevicePCIAddress *addr) { char *s, *e; @@ -1217,7 +1214,7 @@ qemuMonitorTextParsePciAddReply(qemuMonitorPtr mon ATTRIBUTE_UNUSED, 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; } @@ -1235,7 +1232,7 @@ qemuMonitorTextParsePciAddReply(qemuMonitorPtr mon ATTRIBUTE_UNUSED, } 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; } @@ -1252,7 +1249,7 @@ qemuMonitorTextParsePciAddReply(qemuMonitorPtr mon ATTRIBUTE_UNUSED, } 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; } @@ -1262,23 +1259,18 @@ qemuMonitorTextParsePciAddReply(qemuMonitorPtr mon ATTRIBUTE_UNUSED, 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; } @@ -1295,10 +1287,7 @@ int qemuMonitorTextAddPCIHostDevice(qemuMonitorPtr mon, 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; @@ -1316,9 +1305,8 @@ 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; @@ -1344,8 +1332,7 @@ try_command: 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); @@ -1370,9 +1357,7 @@ cleanup: int qemuMonitorTextAddPCINetwork(qemuMonitorPtr mon, const char *nicstr, - unsigned *guestDomain, - unsigned *guestBus, - unsigned *guestSlot) + virDomainDevicePCIAddress *guestAddr) { char *cmd; char *reply = NULL; @@ -1389,8 +1374,7 @@ int qemuMonitorTextAddPCINetwork(qemuMonitorPtr mon, 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; @@ -1406,9 +1390,7 @@ cleanup: int qemuMonitorTextRemovePCIDevice(qemuMonitorPtr mon, - unsigned guestDomain, - unsigned guestBus, - unsigned guestSlot) + virDomainDevicePCIAddress *guestAddr) { char *cmd = NULL; char *reply = NULL; @@ -1417,13 +1399,14 @@ int qemuMonitorTextRemovePCIDevice(qemuMonitorPtr mon, 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; } @@ -1451,7 +1434,7 @@ try_command: 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; } diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h index bc52ad2..f304795 100644 --- a/src/qemu/qemu_monitor_text.h +++ b/src/qemu/qemu_monitor_text.h @@ -104,40 +104,27 @@ int qemuMonitorTextAddUSBDisk(qemuMonitorPtr mon, const char *path); int qemuMonitorTextAddUSBDeviceExact(qemuMonitorPtr mon, - int bus, - int dev); + virDomainDeviceUSBAddress *hostAddr); int qemuMonitorTextAddUSBDeviceMatch(qemuMonitorPtr mon, int vendor, int product); 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, -- 1.6.5.2 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list