diff mbox

[PULL,21/32] char: clean up remaining chardevs when leaving

Message ID 1467135242-874-22-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini June 28, 2016, 5:33 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

This helps to remove various chardev resources leaks when leaving qemu.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1466105332-10285-2-git-send-email-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-char.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Andrew Jones July 1, 2016, 12:34 p.m. UTC | #1
On Tue, Jun 28, 2016 at 07:33:51PM +0200, Paolo Bonzini wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> This helps to remove various chardev resources leaks when leaving qemu.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Message-Id: <1466105332-10285-2-git-send-email-marcandre.lureau@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  qemu-char.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/qemu-char.c b/qemu-char.c
> index 84f49ac..016badb 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -4549,6 +4549,15 @@ void qmp_chardev_remove(const char *id, Error **errp)
>      qemu_chr_delete(chr);
>  }
>  
> +static void qemu_chr_cleanup(void)
> +{
> +    CharDriverState *chr;
> +
> +    QTAILQ_FOREACH(chr, &chardevs, next) {
> +        qemu_chr_delete(chr);
> +    }
> +}
> +
>  static void register_types(void)
>  {
>      register_char_driver("null", CHARDEV_BACKEND_KIND_NULL, NULL,
> @@ -4595,6 +4604,8 @@ static void register_types(void)
>       * is specified
>       */
>      qemu_add_machine_init_done_notifier(&muxes_realize_notify);
> +
> +    atexit(qemu_chr_cleanup);
>  }
>  
>  type_init(register_types);
> -- 
> 2.7.4
> 
> 
>

With this patch, I now get

 qemu: qemu_mutex_destroy: Device or resource busy

and a SIGABRT when my arm tcg kvm-unit-tests guest exits
(I haven't tried any other guest types yet)

Thanks,
drew
Paolo Bonzini July 1, 2016, 3:18 p.m. UTC | #2
On 01/07/2016 14:34, Andrew Jones wrote:
>> >
> With this patch, I now get
> 
>  qemu: qemu_mutex_destroy: Device or resource busy
> 
> and a SIGABRT when my arm tcg kvm-unit-tests guest exits
> (I haven't tried any other guest types yet)

Eric, Laszlo, is it POSIX compliant to fail destruction of a taken mutex?

Paolo
Laszlo Ersek July 1, 2016, 3:29 p.m. UTC | #3
On 07/01/16 17:18, Paolo Bonzini wrote:
> 
> 
> On 01/07/2016 14:34, Andrew Jones wrote:
>>>>
>> With this patch, I now get
>>
>>  qemu: qemu_mutex_destroy: Device or resource busy
>>
>> and a SIGABRT when my arm tcg kvm-unit-tests guest exits
>> (I haven't tried any other guest types yet)
> 
> Eric, Laszlo, is it POSIX compliant to fail destruction of a taken mutex?

http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_destroy.html

    [...] Attempting to destroy a locked mutex or a mutex that is
    referenced (for example, while being used in a
    pthread_cond_timedwait() or pthread_cond_wait()) by another thread
    results in undefined behavior.

Thus EBUSY is POSIX compliant, because just the attempt is undefined
behavior.

Thanks
Laszlo
diff mbox

Patch

diff --git a/qemu-char.c b/qemu-char.c
index 84f49ac..016badb 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -4549,6 +4549,15 @@  void qmp_chardev_remove(const char *id, Error **errp)
     qemu_chr_delete(chr);
 }
 
+static void qemu_chr_cleanup(void)
+{
+    CharDriverState *chr;
+
+    QTAILQ_FOREACH(chr, &chardevs, next) {
+        qemu_chr_delete(chr);
+    }
+}
+
 static void register_types(void)
 {
     register_char_driver("null", CHARDEV_BACKEND_KIND_NULL, NULL,
@@ -4595,6 +4604,8 @@  static void register_types(void)
      * is specified
      */
     qemu_add_machine_init_done_notifier(&muxes_realize_notify);
+
+    atexit(qemu_chr_cleanup);
 }
 
 type_init(register_types);