38f2fd
From 27dbf10245342d3547a969b9b69e95fee96932e0 Mon Sep 17 00:00:00 2001
38f2fd
Message-Id: <27dbf10245342d3547a969b9b69e95fee96932e0@dist-git>
38f2fd
From: Andrea Bolognani <abologna@redhat.com>
38f2fd
Date: Fri, 20 Nov 2015 13:29:13 +0100
38f2fd
Subject: [PATCH] qemu: Use qemuDomainRequiresMlock() when attaching PCI
38f2fd
 hostdev
38f2fd
38f2fd
The function is used everywhere else to check whether the locked
38f2fd
memory limit should be set / updated, and it should be used here
38f2fd
as well.
38f2fd
38f2fd
Moreover, qemuDomainGetMlockLimitBytes() expects the hostdev to
38f2fd
have already been added to the domain definition, but we only do
38f2fd
that at the end of qemuDomainAttachHostPCIDevice(). Work around
38f2fd
the issue by adding the hostdev before adjusting the locked memory
38f2fd
limit and removing it immediately afterwards.
38f2fd
38f2fd
(cherry picked from commit 79b8c97e995d2e8bc04fb9a3972e1875fad01e6d)
38f2fd
38f2fd
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1283924
38f2fd
38f2fd
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
38f2fd
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
38f2fd
---
38f2fd
 src/qemu/qemu_hotplug.c | 23 ++++++++++++++++-------
38f2fd
 1 file changed, 16 insertions(+), 7 deletions(-)
38f2fd
38f2fd
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
38f2fd
index 785423a..003b614 100644
38f2fd
--- a/src/qemu/qemu_hotplug.c
38f2fd
+++ b/src/qemu/qemu_hotplug.c
38f2fd
@@ -1277,17 +1277,26 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
38f2fd
                              "supported by this version of qemu"));
38f2fd
             goto error;
38f2fd
         }
38f2fd
+        break;
38f2fd
 
38f2fd
-        /* setup memory locking limits, that are necessary for VFIO */
38f2fd
+    default:
38f2fd
+        break;
38f2fd
+    }
38f2fd
+
38f2fd
+    /* Temporarily add the hostdev to the domain definition. This is needed
38f2fd
+     * because qemuDomainRequiresMlock() and qemuDomainGetMlockLimitBytes()
38f2fd
+     * require the hostdev to be already part of the domain definition, but
38f2fd
+     * other functions like qemuAssignDeviceHostdevAlias() used below expect
38f2fd
+     * it *not* to be there. A better way to handle this would be nice */
38f2fd
+    vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
38f2fd
+    if (qemuDomainRequiresMlock(vm->def)) {
38f2fd
         if (virProcessSetMaxMemLock(vm->pid,
38f2fd
-                                    qemuDomainGetMlockLimitBytes(vm->def)) < 0)
38f2fd
+                                    qemuDomainGetMlockLimitBytes(vm->def)) < 0) {
38f2fd
+            vm->def->hostdevs[--(vm->def->nhostdevs)] = NULL;
38f2fd
             goto error;
38f2fd
-
38f2fd
-        break;
38f2fd
-
38f2fd
-    default:
38f2fd
-        break;
38f2fd
+        }
38f2fd
     }
38f2fd
+    vm->def->hostdevs[--(vm->def->nhostdevs)] = NULL;
38f2fd
 
38f2fd
     if (qemuSetupHostdevCGroup(vm, hostdev) < 0)
38f2fd
         goto error;
38f2fd
-- 
38f2fd
2.6.3
38f2fd