[libvirt] [PATCH 4/5] qemu: Implement virDomainDetachDeviceAlias
Peter Krempa
pkrempa at redhat.com
Tue May 22 06:33:04 UTC 2018
On Mon, May 21, 2018 at 18:08:01 +0200, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
> src/qemu/qemu_driver.c | 41 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 0e0c0ce53e..fee152d202 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -8808,6 +8808,46 @@ qemuDomainDetachDeviceFlags(virDomainPtr dom,
> return ret;
> }
>
> +
> +static int
> +qemuDomainDetachDeviceAlias(virDomainPtr dom,
> + const char *alias,
> + unsigned int flags)
> +{
> + virQEMUDriverPtr driver = dom->conn->privateData;
> + virDomainObjPtr vm = NULL;
> + virDomainDeviceDef dev;
> + int ret = -1;
> +
> + if (!(vm = qemuDomObjFromDomain(dom)))
> + goto cleanup;
> +
> + if (virDomainDetachDeviceAliasEnsureACL(dom->conn, vm->def, flags) < 0)
> + goto cleanup;
> +
> + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
> + goto cleanup;
> +
> + if (virDomainDefFindDevice(vm->def, alias, &dev, true) < 0)
> + goto endjob;
This reports an 'internal error' if the alias is not found which is not
great to present to users.
Additionally this does not deal with the active/inactive flag which is
wrong since you e.g. can't properly use this if you have a different
persistent configuration (which uses user-aliases). In that case you
can't refer to a alias in that configuration, since only vm->def is
inspected.
> +
> + if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
> + goto endjob;
> +
> + if (qemuDomainDetachDeviceLiveAndConfig(driver, vm, &dev, flags) < 0)
> + goto endjob;
Since you pass in 'dev' containing a device definition which gets freed
by this function it may become tricky. At least you will need to
document that this is happening in this function.
Note that I did not inspect all the functions called by
qemuDomainDetachDeviceLiveAndConfig to ensure that there isn't an actual
problem.
> +
> + ret = 0;
> +
> + endjob:
> + qemuDomainObjEndJob(driver, vm);
> +
> + cleanup:
> + virDomainObjEndAPI(&vm);
> + return ret;
> +}
> +
> +
> static int qemuDomainDetachDevice(virDomainPtr dom, const char *xml)
> {
> return qemuDomainDetachDeviceFlags(dom, xml,
> @@ -21303,6 +21343,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
> .domainDetachDevice = qemuDomainDetachDevice, /* 0.5.0 */
> .domainDetachDeviceFlags = qemuDomainDetachDeviceFlags, /* 0.7.7 */
> .domainUpdateDeviceFlags = qemuDomainUpdateDeviceFlags, /* 0.8.0 */
> + .domainDetachDeviceAlias = qemuDomainDetachDeviceAlias, /* 4.4.0 */
> .domainGetAutostart = qemuDomainGetAutostart, /* 0.2.1 */
> .domainSetAutostart = qemuDomainSetAutostart, /* 0.2.1 */
> .domainGetSchedulerType = qemuDomainGetSchedulerType, /* 0.7.0 */
> --
> 2.16.1
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180522/dc4f17b9/attachment-0001.sig>
More information about the libvir-list
mailing list