[libvirt] [PATCH v2 3/4] qemu: Remove character device backend only after frontend is gone

Peter Krempa pkrempa at redhat.com
Tue Jun 3 08:47:39 UTC 2014


On 06/03/14 10:22, Jiri Denemark wrote:
> In general, we should only remove a backend after seeing DEVICE_DELETED
> event for a corresponding frontend.
> 
> Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
> ---
> 
> Notes:
>     Version 2:
>     - return int and propagate errors
> 
>  src/qemu/qemu_hotplug.c | 33 ++++++++++++++++++++-------------
>  1 file changed, 20 insertions(+), 13 deletions(-)
> 
> diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> index 35099e4..fde46ad 100644
> --- a/src/qemu/qemu_hotplug.c
> +++ b/src/qemu/qemu_hotplug.c
> @@ -2742,22 +2742,38 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
>  }
>  
>  
> -static void
> +static int
>  qemuDomainRemoveChrDevice(virQEMUDriverPtr driver,
>                            virDomainObjPtr vm,
>                            virDomainChrDefPtr chr)
>  {
>      virObjectEventPtr event;
> +    char *charAlias = NULL;
> +    qemuDomainObjPrivatePtr priv = vm->privateData;
>  
>      VIR_DEBUG("Removing character device %s from domain %p %s",
>                chr->info.alias, vm, vm->def->name);
>  
> +    if (virAsprintf(&charAlias, "char%s", chr->info.alias) < 0)
> +        return -1;
> +
> +    qemuDomainObjEnterMonitor(driver, vm);
> +    if (qemuMonitorDetachCharDev(priv->mon, charAlias) < 0) {
> +        qemuDomainObjExitMonitor(driver, vm);
> +        goto cleanup;

You will return 0 even if qemuMonitorDetachCharDev fails which wouldn't
happen before as qemuDomainDetachChrDevice initializes ret to -1.

I think you need to add the "ret" variable to this function too.

> +    }
> +    qemuDomainObjExitMonitor(driver, vm);
> +
>      event = virDomainEventDeviceRemovedNewFromObj(vm, chr->info.alias);
>      if (event)
>          qemuDomainEventQueue(driver, event);
>  
>      qemuDomainChrRemove(vm->def, chr);
>      virDomainChrDefFree(chr);
> +
> + cleanup:
> +    VIR_FREE(charAlias);
> +    return 0;
>  }

ACK if you correctly propagate errors from qemuMonitorDetachCharDev.

Peter


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140603/0fc1c703/attachment-0001.sig>


More information about the libvir-list mailing list