All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] slirp: use exit notifier for slirp_smb_cleanup
@ 2016-07-12  9:23 Paolo Bonzini
  2016-07-12 10:15 ` Marc-André Lureau
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2016-07-12  9:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: jasowang, marcandre.lureau

We would like to move back net_cleanup() at the end of main function,
like it used to be until f30dbae63a46f23116715dff8d130c, but minimum
cleanup is needed regardless at exit() time for slirp's SMB
functionality.  Use an exit notifier to call slirp_smb_cleanup.
If net_cleanup() is called first, then remove the exit notifier as it
will become a dangling pointer otherwise.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 net/slirp.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/net/slirp.c b/net/slirp.c
index 31630f0..28207b6 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -38,6 +38,7 @@
 #include "slirp/libslirp.h"
 #include "slirp/ip6.h"
 #include "sysemu/char.h"
+#include "sysemu/sysemu.h"
 #include "qemu/cutils.h"
 
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
@@ -76,6 +77,7 @@ typedef struct SlirpState {
     NetClientState nc;
     QTAILQ_ENTRY(SlirpState) entry;
     Slirp *slirp;
+    Notifier exit_notifier;
 #ifndef _WIN32
     char smb_dir[128];
 #endif
@@ -118,11 +120,18 @@ static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, size_t
     return size;
 }
 
+static void slirp_smb_exit(Notifier *n, void *data)
+{
+    SlirpState *s = container_of(n, SlirpState, exit_notifier);
+    slirp_smb_cleanup(s);
+}
+
 static void net_slirp_cleanup(NetClientState *nc)
 {
     SlirpState *s = DO_UPCAST(SlirpState, nc, nc);
 
     slirp_cleanup(s->slirp);
+    qemu_remove_exit_notifier(&s->exit_notifier);
     slirp_smb_cleanup(s);
     QTAILQ_REMOVE(&slirp_stacks, s, entry);
 }
@@ -349,6 +358,8 @@ static int net_slirp_init(NetClientState *peer, const char *model,
     }
 #endif
 
+    s->exit_notifier.notify = slirp_smb_exit;
+    qemu_add_exit_notifier(&s->exit_notifier);
     return 0;
 
 error:
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] slirp: use exit notifier for slirp_smb_cleanup
  2016-07-12  9:23 [Qemu-devel] [PATCH] slirp: use exit notifier for slirp_smb_cleanup Paolo Bonzini
@ 2016-07-12 10:15 ` Marc-André Lureau
  2016-07-13  2:34   ` Jason Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Marc-André Lureau @ 2016-07-12 10:15 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: QEMU, Jason Wang

Hi

On Tue, Jul 12, 2016 at 11:23 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> We would like to move back net_cleanup() at the end of main function,
> like it used to be until f30dbae63a46f23116715dff8d130c, but minimum
> cleanup is needed regardless at exit() time for slirp's SMB
> functionality.  Use an exit notifier to call slirp_smb_cleanup.
> If net_cleanup() is called first, then remove the exit notifier as it
> will become a dangling pointer otherwise.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>



> ---
>  net/slirp.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/net/slirp.c b/net/slirp.c
> index 31630f0..28207b6 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -38,6 +38,7 @@
>  #include "slirp/libslirp.h"
>  #include "slirp/ip6.h"
>  #include "sysemu/char.h"
> +#include "sysemu/sysemu.h"
>  #include "qemu/cutils.h"
>
>  static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
> @@ -76,6 +77,7 @@ typedef struct SlirpState {
>      NetClientState nc;
>      QTAILQ_ENTRY(SlirpState) entry;
>      Slirp *slirp;
> +    Notifier exit_notifier;

we may want to rename the notifier in my patch too, for consistency
(you did that already, probably)

>  #ifndef _WIN32
>      char smb_dir[128];
>  #endif
> @@ -118,11 +120,18 @@ static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, size_t
>      return size;
>  }
>
> +static void slirp_smb_exit(Notifier *n, void *data)
> +{
> +    SlirpState *s = container_of(n, SlirpState, exit_notifier);
> +    slirp_smb_cleanup(s);
> +}
> +
>  static void net_slirp_cleanup(NetClientState *nc)
>  {
>      SlirpState *s = DO_UPCAST(SlirpState, nc, nc);
>
>      slirp_cleanup(s->slirp);
> +    qemu_remove_exit_notifier(&s->exit_notifier);
>      slirp_smb_cleanup(s);
>      QTAILQ_REMOVE(&slirp_stacks, s, entry);
>  }
> @@ -349,6 +358,8 @@ static int net_slirp_init(NetClientState *peer, const char *model,
>      }
>  #endif
>
> +    s->exit_notifier.notify = slirp_smb_exit;
> +    qemu_add_exit_notifier(&s->exit_notifier);
>      return 0;
>
>  error:
> --
> 2.7.4
>
>



-- 
Marc-André Lureau

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] slirp: use exit notifier for slirp_smb_cleanup
  2016-07-12 10:15 ` Marc-André Lureau
@ 2016-07-13  2:34   ` Jason Wang
  2016-07-13  7:40     ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Wang @ 2016-07-13  2:34 UTC (permalink / raw)
  To: Marc-André Lureau, Paolo Bonzini; +Cc: QEMU



On 2016年07月12日 18:15, Marc-André Lureau wrote:
> Hi
>
> On Tue, Jul 12, 2016 at 11:23 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> We would like to move back net_cleanup() at the end of main function,
>> like it used to be until f30dbae63a46f23116715dff8d130c, but minimum
>> cleanup is needed regardless at exit() time for slirp's SMB
>> functionality.  Use an exit notifier to call slirp_smb_cleanup.
>> If net_cleanup() is called first, then remove the exit notifier as it
>> will become a dangling pointer otherwise.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Jason Wang <jasowang@redhat.com>

>
>
>
>> ---
>>   net/slirp.c | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/net/slirp.c b/net/slirp.c
>> index 31630f0..28207b6 100644
>> --- a/net/slirp.c
>> +++ b/net/slirp.c
>> @@ -38,6 +38,7 @@
>>   #include "slirp/libslirp.h"
>>   #include "slirp/ip6.h"
>>   #include "sysemu/char.h"
>> +#include "sysemu/sysemu.h"
>>   #include "qemu/cutils.h"
>>
>>   static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
>> @@ -76,6 +77,7 @@ typedef struct SlirpState {
>>       NetClientState nc;
>>       QTAILQ_ENTRY(SlirpState) entry;
>>       Slirp *slirp;
>> +    Notifier exit_notifier;
> we may want to rename the notifier in my patch too, for consistency
> (you did that already, probably)
>
>>   #ifndef _WIN32
>>       char smb_dir[128];
>>   #endif
>> @@ -118,11 +120,18 @@ static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, size_t
>>       return size;
>>   }
>>
>> +static void slirp_smb_exit(Notifier *n, void *data)
>> +{
>> +    SlirpState *s = container_of(n, SlirpState, exit_notifier);
>> +    slirp_smb_cleanup(s);
>> +}
>> +
>>   static void net_slirp_cleanup(NetClientState *nc)
>>   {
>>       SlirpState *s = DO_UPCAST(SlirpState, nc, nc);
>>
>>       slirp_cleanup(s->slirp);
>> +    qemu_remove_exit_notifier(&s->exit_notifier);
>>       slirp_smb_cleanup(s);
>>       QTAILQ_REMOVE(&slirp_stacks, s, entry);
>>   }
>> @@ -349,6 +358,8 @@ static int net_slirp_init(NetClientState *peer, const char *model,
>>       }
>>   #endif
>>
>> +    s->exit_notifier.notify = slirp_smb_exit;
>> +    qemu_add_exit_notifier(&s->exit_notifier);
>>       return 0;
>>
>>   error:
>> --
>> 2.7.4
>>
>>
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] slirp: use exit notifier for slirp_smb_cleanup
  2016-07-13  2:34   ` Jason Wang
@ 2016-07-13  7:40     ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2016-07-13  7:40 UTC (permalink / raw)
  To: Jason Wang, Marc-André Lureau; +Cc: QEMU



On 13/07/2016 04:34, Jason Wang wrote:
> 
> 
> On 2016年07月12日 18:15, Marc-André Lureau wrote:
>> Hi
>>
>> On Tue, Jul 12, 2016 at 11:23 AM, Paolo Bonzini <pbonzini@redhat.com>
>> wrote:
>>> We would like to move back net_cleanup() at the end of main function,
>>> like it used to be until f30dbae63a46f23116715dff8d130c, but minimum
>>> cleanup is needed regardless at exit() time for slirp's SMB
>>> functionality.  Use an exit notifier to call slirp_smb_cleanup.
>>> If net_cleanup() is called first, then remove the exit notifier as it
>>> will become a dangling pointer otherwise.
>>>
>>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Reviewed-by: Jason Wang <jasowang@redhat.com>

Thanks!

Paolo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-13  7:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-12  9:23 [Qemu-devel] [PATCH] slirp: use exit notifier for slirp_smb_cleanup Paolo Bonzini
2016-07-12 10:15 ` Marc-André Lureau
2016-07-13  2:34   ` Jason Wang
2016-07-13  7:40     ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.