[libvirt] [PATCH 07/34] Convert monitor over to use virDomainDeviceAddress

Daniel P. Berrange berrange at redhat.com
Fri Jan 8 17:23:03 UTC 2010


Convert the QEMU monitor APIs over to use virDomainDeviceAddress
structs for passing addresses in/out, instead of individual bits.
This makes the number of parameters smaller & easier to deal with.
No functional change

* 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       |   35 +++++++++---------------
 src/qemu/qemu_monitor.c      |   60 ++++++++++++------------------------------
 src/qemu/qemu_monitor.h      |   21 +++-----------
 src/qemu/qemu_monitor_json.c |   55 +++++++++++++++++---------------------
 src/qemu/qemu_monitor_json.h |   22 +++------------
 src/qemu/qemu_monitor_text.c |   56 ++++++++++++++-------------------------
 src/qemu/qemu_monitor_text.h |   22 +++------------
 7 files changed, 90 insertions(+), 181 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3588531..8c2e6d6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5080,6 +5080,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)) {
@@ -5098,13 +5099,12 @@ static int qemudDomainAttachPciDiskDevice(virConnectPtr conn,
     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);
     }
 
@@ -5161,6 +5161,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",
@@ -5229,13 +5230,12 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
 
     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;
@@ -5287,6 +5287,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);
@@ -5314,17 +5315,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->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;
 
@@ -5563,9 +5560,7 @@ static int qemudDomainDetachPciDiskDevice(virConnectPtr conn,
 
     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;
     }
@@ -5635,9 +5630,7 @@ qemudDomainDetachNetDevice(virConnectPtr conn,
 
     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;
     }
@@ -5724,9 +5717,7 @@ static int qemudDomainDetachHostPciDevice(virConnectPtr conn,
 
     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;
     }
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 750e3e6..caf2d35 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1117,33 +1117,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 +1136,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 db00b26..e0a0552 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -222,13 +222,8 @@ 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);
 
 /* XXX disk driver type eg,  qcow/etc.
  * XXX cache mode
@@ -236,23 +231,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 b96f4ac..e0a3225 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1206,9 +1206,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 +1217,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, "%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;
     }
@@ -1279,7 +1278,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 +1290,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 +1319,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 +1330,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 +1340,7 @@ int qemuMonitorJSONAddPCINetwork(qemuMonitorPtr mon,
                                                      NULL);
     virJSONValuePtr reply = NULL;
 
-    *guestDomain = *guestBus = *guestSlot = 0;
+    memset(guestAddr, 0, sizeof(*guestAddr));
 
     if (!cmd)
         return -1;
@@ -1355,7 +1351,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 +1361,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..74d88b2 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -112,32 +112,20 @@ int qemuMonitorJSONAddUSBDeviceMatch(qemuMonitorPtr mon,
 
 
 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 5b9ced2..7c8b0a2 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -1281,9 +1281,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;
 
@@ -1300,7 +1298,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;
         }
@@ -1318,7 +1316,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;
     }
@@ -1335,7 +1333,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;
     }
@@ -1345,23 +1343,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;
     }
@@ -1378,10 +1371,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;
@@ -1399,9 +1389,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;
@@ -1427,8 +1416,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);
@@ -1453,9 +1441,7 @@ cleanup:
 
 int qemuMonitorTextAddPCINetwork(qemuMonitorPtr mon,
                                  const char *nicstr,
-                                 unsigned *guestDomain,
-                                 unsigned *guestBus,
-                                 unsigned *guestSlot)
+                                 virDomainDevicePCIAddress *guestAddr)
 {
     char *cmd;
     char *reply = NULL;
@@ -1472,8 +1458,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;
@@ -1489,9 +1474,7 @@ cleanup:
 
 
 int qemuMonitorTextRemovePCIDevice(qemuMonitorPtr mon,
-                                   unsigned guestDomain,
-                                   unsigned guestBus,
-                                   unsigned guestSlot)
+                                   virDomainDevicePCIAddress *guestAddr)
 {
     char *cmd = NULL;
     char *reply = NULL;
@@ -1500,13 +1483,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;
         }
@@ -1534,7 +1518,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 5897a03..f1f2f77 100644
--- a/src/qemu/qemu_monitor_text.h
+++ b/src/qemu/qemu_monitor_text.h
@@ -116,32 +116,20 @@ int qemuMonitorTextAddUSBDeviceMatch(qemuMonitorPtr mon,
 
 
 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




More information about the libvir-list mailing list