On 9/3/19 5:09 PM, Eric Farman wrote:
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 <far...@linux.ibm.com>
---

Reviewed-by: Daniel Henrique Barboza <danielhb...@gmail.com>

  src/qemu/qemu_domain.c  | 30 ++++++++++++++++++++++++++++++
  src/qemu/qemu_domain.h  |  2 ++
  src/qemu/qemu_hotplug.c | 11 +----------
  3 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c7eb0b5e9a..a63a035328 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11723,6 +11723,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
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index d097f23342..456c623336 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -931,6 +931,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,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 63acb9c451..24e75e49be 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1508,17 +1508,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;

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to