]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: hotplug: Simplify removal of managed PR infrastructure on unplug
authorPeter Krempa <pkrempa@redhat.com>
Wed, 11 Jul 2018 12:24:49 +0000 (14:24 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 20 Jul 2018 12:23:09 +0000 (14:23 +0200)
Extract the (possible) removal of the PR backend and daemon into a
separate helper which enters monitor on its own. This simplifies the
code and allows reuse of this function in the future e.g. for blockjobs
where removing a image with PR may result into PR not being necessary.

Since the PR is not used often the overhead of entering monitor again
should be negligible.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_hotplug.c

index 738c344167d40f66b76448bffc5686903d836e4c..d489e35732b2c99a9e72d01b236fee140220cd7f 100644 (file)
@@ -350,6 +350,41 @@ qemuDomainDiskAttachManagedPR(virDomainObjPtr vm,
 }
 
 
+/**
+ * qemuHotplugRemoveManagedPR:
+ * @driver: QEMU driver object
+ * @vm: domain object
+ * @asyncJob: asynchronous job identifier
+ *
+ * Removes the managed PR object from @vm if the configuration does not require
+ * it any more.
+ */
+static int
+qemuHotplugRemoveManagedPR(virQEMUDriverPtr driver,
+                           virDomainObjPtr vm,
+                           qemuDomainAsyncJob asyncJob)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virErrorPtr orig_err;
+    virErrorPreserveLast(&orig_err);
+
+    if (!priv->prDaemonRunning ||
+        virDomainDefHasManagedPR(vm->def))
+        return 0;
+
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+        return -1;
+    ignore_value(qemuMonitorDelObject(priv->mon, qemuDomainGetManagedPRAlias()));
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        return -1;
+
+    qemuProcessKillManagedPRDaemon(vm);
+    virErrorRestore(&orig_err);
+
+    return 0;
+}
+
+
 struct _qemuHotplugDiskSourceData {
     qemuBlockStorageSourceAttachDataPtr *backends;
     size_t nbackends;
@@ -3949,8 +3984,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
     virObjectEventPtr event;
     size_t i;
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    bool prManaged = priv->prDaemonRunning;
-    bool prUsed = false;
     int ret = -1;
 
     VIR_DEBUG("Removing disk %s from domain %p %s",
@@ -3966,16 +3999,10 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
         }
     }
 
-    /* check if the last disk with managed PR was just removed */
-    prUsed = virDomainDefHasManagedPR(vm->def);
-
     qemuDomainObjEnterMonitor(driver, vm);
 
     qemuHotplugDiskSourceRemove(priv->mon, diskbackend);
 
-    if (prManaged && !prUsed)
-        ignore_value(qemuMonitorDelObject(priv->mon, qemuDomainGetManagedPRAlias()));
-
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         goto cleanup;
 
@@ -3984,9 +4011,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
     event = virDomainEventDeviceRemovedNewFromObj(vm, disk->info.alias);
     virObjectEventStateQueue(driver->domainEventState, event);
 
-    if (prManaged && !prUsed)
-        qemuProcessKillManagedPRDaemon(vm);
-
     qemuDomainReleaseDeviceAddress(vm, &disk->info, virDomainDiskGetSource(disk));
 
     /* tear down disk security access */
@@ -3997,6 +4021,9 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
     ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name));
     virDomainUSBAddressRelease(priv->usbaddrs, &disk->info);
 
+    if (qemuHotplugRemoveManagedPR(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
+        goto cleanup;
+
     ret = 0;
 
  cleanup: