Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > ebe084c140192657f9094e135a84202c > files > 126

libvirt-0.8.2-29.el5.src.rpm

From 7e66b71eff23e0d2470eca1854d49273350894c4 Mon Sep 17 00:00:00 2001
Message-Id: <7e66b71eff23e0d2470eca1854d49273350894c4.1284409900.git.jdenemar@redhat.com>
From: Chris Wright <chrisw@redhat.com>
Date: Mon, 26 Jul 2010 18:34:24 +0200
Subject: [PATCH] qemudDomainAttachHostPciDevice refactor to use new helpers

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=630620

- src/qemu/qemu_driver.c: Eliminate code duplication by using the new
  helpers qemuPrepareHostdevPCIDevices and qemuDomainReAttachHostdevDevices.
  This reduces the number of open coded calls to pciResetDevice.
(cherry picked from commit 042b208370e70615a6b5e4046384dab3b9e50d53)
---
 src/qemu/qemu_driver.c |   37 +++----------------------------------
 1 files changed, 3 insertions(+), 34 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 859f2af..97ca6c1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7802,7 +7802,6 @@ static int qemudDomainAttachHostPciDevice(struct qemud_driver *driver,
                                           unsigned long long qemuCmdFlags)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    pciDevice *pci;
     int ret;
     char *devstr = NULL;
     int configfd = -1;
@@ -7813,25 +7812,8 @@ static int qemudDomainAttachHostPciDevice(struct qemud_driver *driver,
         return -1;
     }
 
-    pci = pciGetDevice(hostdev->source.subsys.u.pci.domain,
-                       hostdev->source.subsys.u.pci.bus,
-                       hostdev->source.subsys.u.pci.slot,
-                       hostdev->source.subsys.u.pci.function);
-    if (!pci)
-        return -1;
-
-    if (!pciDeviceIsAssignable(pci, !driver->relaxedACS) ||
-        (hostdev->managed && pciDettachDevice(pci, driver->activePciHostdevs) < 0) ||
-        pciResetDevice(pci, driver->activePciHostdevs) < 0) {
-        pciFreeDevice(pci);
-        return -1;
-    }
-
-    if (pciDeviceListAdd(driver->activePciHostdevs, pci) < 0) {
-        pciFreeDevice(pci);
-        return -1;
-    }
-    pci = NULL; /* activePciHostdevs owns the 'pci' reference now */
+    if (qemuPrepareHostdevPCIDevices(driver, &hostdev, 1))
+    return -1;
 
     if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
         if (qemuAssignDeviceHostdevAlias(vm->def, hostdev, -1) < 0)
@@ -7899,20 +7881,7 @@ error:
         qemuDomainPCIAddressReleaseAddr(priv->pciaddrs, &hostdev->info) < 0)
         VIR_WARN0("Unable to release PCI address on host device");
 
-    pci = pciGetDevice(hostdev->source.subsys.u.pci.domain,
-                       hostdev->source.subsys.u.pci.bus,
-                       hostdev->source.subsys.u.pci.slot,
-                       hostdev->source.subsys.u.pci.function);
-
-    pciDeviceListDel(driver->activePciHostdevs, pci);
-
-    if (pciResetDevice(pci, driver->activePciHostdevs) < 0)
-        VIR_WARN0("Unable to reset PCI device after assign failure");
-    else if (hostdev->managed &&
-             pciReAttachDevice(pci, driver->activePciHostdevs) < 0)
-        VIR_WARN0("Unable to re-attach PCI device after assign failure");
-    pciFreeDevice(pci);
-
+    qemuDomainReAttachHostdevDevices(driver, &hostdev, 1);
 
     VIR_FREE(devstr);
     VIR_FREE(configfd_name);
-- 
1.7.2.2