]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Refactor the max memlock routine
authorEric Farman <farman@linux.ibm.com>
Tue, 3 Sep 2019 20:09:46 +0000 (22:09 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 9 Sep 2019 14:39:52 +0000 (16:39 +0200)
Let's pull this hunk out into a function, so it can be reused
in another codepath that needs to do the same thing.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_hotplug.c

index 28fd930df2b60f236007b7d10ce0cea53e3b7252..bd247628cb3cdbfef4cce388dbc03261cda7c684 100644 (file)
@@ -11968,6 +11968,36 @@ qemuDomainAdjustMaxMemLock(virDomainObjPtr vm)
      return ret;
 }
 
+
+/**
+ * qemuDomainAdjustMaxMemLockHostdev:
+ * @vm: domain
+ * @hostdev: device
+ *
+ * Temporarily add the hostdev to the domain definition. This is needed
+ * because qemuDomainAdjustMaxMemLock() requires the hostdev to be already
+ * part of the domain definition, but other functions like
+ * qemuAssignDeviceHostdevAlias() expect it *not* to be there.
+ * A better way to handle this would be nice
+ *
+ * Returns: 0 on success, <0 on failure
+ */
+int
+qemuDomainAdjustMaxMemLockHostdev(virDomainObjPtr vm,
+                                  virDomainHostdevDefPtr hostdev)
+{
+    int ret = 0;
+
+    vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
+    if (qemuDomainAdjustMaxMemLock(vm) < 0)
+        ret = -1;
+
+    vm->def->hostdevs[--(vm->def->nhostdevs)] = NULL;
+
+    return ret;
+}
+
+
 /**
  * qemuDomainHasVcpuPids:
  * @vm: Domain object
index bc88580a65139fb2b82e2eb5f1a7393e2fb63c74..3e87e75c3a46be2d7c4819779d5e49022856b4af 100644 (file)
@@ -952,6 +952,8 @@ void qemuDomainUpdateCurrentMemorySize(virDomainObjPtr vm);
 
 unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def);
 int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
+int qemuDomainAdjustMaxMemLockHostdev(virDomainObjPtr vm,
+                                      virDomainHostdevDefPtr hostdev);
 
 int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                        virQEMUCapsPtr qemuCaps,
index 7d31b712fb7a0846cf40498a27ab6126a190e2eb..20f3bfa2ff88f4be9786303904ed40458e61f22a 100644 (file)
@@ -1621,17 +1621,8 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
         break;
     }
 
-    /* Temporarily add the hostdev to the domain definition. This is needed
-     * because qemuDomainAdjustMaxMemLock() requires the hostdev to be already
-     * part of the domain definition, but other functions like
-     * qemuAssignDeviceHostdevAlias() used below expect it *not* to be there.
-     * A better way to handle this would be nice */
-    vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
-    if (qemuDomainAdjustMaxMemLock(vm) < 0) {
-        vm->def->hostdevs[--(vm->def->nhostdevs)] = NULL;
+    if (qemuDomainAdjustMaxMemLockHostdev(vm, hostdev) < 0)
         goto error;
-    }
-    vm->def->hostdevs[--(vm->def->nhostdevs)] = NULL;
 
     if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0)
         goto error;