mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemu: hotplug: Refactor/simplify PR managed addition to VM
Similarly to qemuDomainDiskRemoveManagedPR make it enter monitor on its own so that it can be reused. Future users will be in the snapshot code and in removable media change code. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
8498a1e222
commit
36e9b1ec50
@ -310,29 +310,31 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qemuDomainMaybeStartPRDaemon:
|
* qemuHotplugAttachManagedPR:
|
||||||
|
* @driver: QEMU driver object
|
||||||
* @vm: domain object
|
* @vm: domain object
|
||||||
* @disk: disk to hotplug
|
* @src: new disk source to be attached to @vm
|
||||||
* @retProps: properties of the managed pr-manager-helper object which needs
|
* @asyncJob: asynchronous job identifier
|
||||||
* to be added to the running vm
|
|
||||||
*
|
*
|
||||||
* Checks if it's needed to start qemu-pr-helper and add the corresponding
|
* Checks if it's needed to start qemu-pr-helper and add the corresponding
|
||||||
* pr-manager-helper object.
|
* pr-manager-helper object.
|
||||||
*
|
*
|
||||||
* Returns: 0 on success, -1 on error. If @retProps is populated the
|
* Returns: 0 on success, -1 on error.
|
||||||
* qemu-pr-helper daemon was started.
|
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
qemuDomainDiskAttachManagedPR(virDomainObjPtr vm,
|
qemuHotplugAttachManagedPR(virQEMUDriverPtr driver,
|
||||||
virDomainDiskDefPtr disk,
|
virDomainObjPtr vm,
|
||||||
virJSONValuePtr *retProps)
|
virStorageSourcePtr src,
|
||||||
|
qemuDomainAsyncJob asyncJob)
|
||||||
{
|
{
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virJSONValuePtr props = NULL;
|
virJSONValuePtr props = NULL;
|
||||||
|
bool daemonStarted = false;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if (priv->prDaemonRunning ||
|
if (priv->prDaemonRunning ||
|
||||||
!virStorageSourceChainHasManagedPR(disk->src))
|
!virStorageSourceChainHasManagedPR(src))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!(props = qemuBuildPRManagedManagerInfoProps(priv)))
|
if (!(props = qemuBuildPRManagedManagerInfoProps(priv)))
|
||||||
@ -341,10 +343,21 @@ qemuDomainDiskAttachManagedPR(virDomainObjPtr vm,
|
|||||||
if (qemuProcessStartManagedPRDaemon(vm) < 0)
|
if (qemuProcessStartManagedPRDaemon(vm) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_STEAL_PTR(*retProps, props);
|
daemonStarted = true;
|
||||||
|
|
||||||
|
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
rc = qemuMonitorAddObject(priv->mon, &props, NULL);
|
||||||
|
|
||||||
|
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (ret < 0 && daemonStarted)
|
||||||
|
qemuProcessKillManagedPRDaemon(vm);
|
||||||
virJSONValueFree(props);
|
virJSONValueFree(props);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -592,11 +605,8 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
qemuHotplugDiskSourceDataPtr diskdata = NULL;
|
qemuHotplugDiskSourceDataPtr diskdata = NULL;
|
||||||
virErrorPtr orig_err;
|
|
||||||
char *devstr = NULL;
|
char *devstr = NULL;
|
||||||
char *managedPrmgrAlias = NULL;
|
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
virJSONValuePtr managedPrmgrProps = NULL;
|
|
||||||
|
|
||||||
if (qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, false) < 0)
|
if (qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, false) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -607,9 +617,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
|||||||
if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0)
|
if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (qemuDomainDiskAttachManagedPR(vm, disk, &managedPrmgrProps) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(diskdata = qemuHotplugDiskSourceAttachPrepare(disk, priv->qemuCaps)))
|
if (!(diskdata = qemuHotplugDiskSourceAttachPrepare(disk, priv->qemuCaps)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -619,11 +626,10 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
|||||||
if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1) < 0)
|
if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
if (qemuHotplugAttachManagedPR(driver, vm, disk->src, QEMU_ASYNC_JOB_NONE) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (managedPrmgrProps &&
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
qemuMonitorAddObject(priv->mon, &managedPrmgrProps, &managedPrmgrAlias) < 0)
|
|
||||||
goto exit_monitor;
|
|
||||||
|
|
||||||
if (qemuHotplugDiskSourceAttach(priv->mon, diskdata) < 0)
|
if (qemuHotplugDiskSourceAttach(priv->mon, diskdata) < 0)
|
||||||
goto exit_monitor;
|
goto exit_monitor;
|
||||||
@ -643,9 +649,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
qemuHotplugDiskSourceDataFree(diskdata);
|
qemuHotplugDiskSourceDataFree(diskdata);
|
||||||
virJSONValueFree(managedPrmgrProps);
|
|
||||||
qemuDomainSecretDiskDestroy(disk);
|
qemuDomainSecretDiskDestroy(disk);
|
||||||
VIR_FREE(managedPrmgrAlias);
|
|
||||||
VIR_FREE(devstr);
|
VIR_FREE(devstr);
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
return ret;
|
return ret;
|
||||||
@ -653,20 +657,15 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
|||||||
exit_monitor:
|
exit_monitor:
|
||||||
qemuHotplugDiskSourceRemove(priv->mon, diskdata);
|
qemuHotplugDiskSourceRemove(priv->mon, diskdata);
|
||||||
|
|
||||||
virErrorPreserveLast(&orig_err);
|
|
||||||
if (managedPrmgrAlias)
|
|
||||||
ignore_value(qemuMonitorDelObject(priv->mon, managedPrmgrAlias));
|
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
ret = -2;
|
ret = -2;
|
||||||
virErrorRestore(&orig_err);
|
if (qemuHotplugRemoveManagedPR(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
|
||||||
|
ret = -2;
|
||||||
|
|
||||||
virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
|
virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true));
|
ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true));
|
||||||
if (priv->prDaemonRunning &&
|
|
||||||
!virDomainDefHasManagedPR(vm->def))
|
|
||||||
qemuProcessKillManagedPRDaemon(vm);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user