slirp: use exit notifier for slirp_smb_cleanup
PATCH 1/1 slirp: use exit notifier for slirp_smb_cleanup
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.
--- net/slirp.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/slirp.c +11 -0
@@ -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 _WIN32char smb_dir[128 ];#endif
@@ -118,11 +120,18 @@ static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, size_treturn 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:
Signature · 1 line
2.7.4
Hi
Quoted 8 lines · Paolo Bonzini
We would like to move back
net_cleanup()at the end of main function, like it used to be untilf30dbae63a46f23116715dff8d130c, but minimum cleanup is needed regardless atexit()time for slirp's SMB functionality. Use an exit notifier to callslirp_smb_cleanup. Ifnet_cleanup()is called first, then remove the exit notifier as it will become a dangling pointer otherwise.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 17 lines
--- net/slirp.c | 11 +++++++++++ 1 file changed, 11 insertions(+)net/slirp.c +1
-0@@ -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)
net/slirp.c typedef struct SlirpState { · line 80
Quoted 4 lines
net/slirp.c +1
-0@@ -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)
Quoted 35 lines
net/slirp.c +9
-1#ifndef _WIN32char smb_dir[128 ];#endif @@ -118,11 +120,18 @@ static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, size_treturn 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
Signature · 1 line
Marc-André Lureau
Jason Wang
Reviewed-byQuoted 10 lines · Marc-André Lureau
Hi
Quoted 7 lines · Paolo Bonzini
We would like to move back
net_cleanup()at the end of main function, like it used to be untilf30dbae63a46f23116715dff8d130c, but minimum cleanup is needed regardless atexit()time for slirp's SMB functionality. Use an exit notifier to callslirp_smb_cleanup. Ifnet_cleanup()is called first, then remove the exit notifier as it will become a dangling pointer otherwise.
Quoted 2 lines
Quoted 1 line
Signed-off-by Paolo Bonzini <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>
Quoted 64 lines
Quoted 20 lines
--- net/slirp.c | 11 +++++++++++ 1 file changed, 11 insertions(+)net/slirp.c +1
-0@@ -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)net/slirp.c typedef struct SlirpState { · line 80
Quoted 4 lines
net/slirp.c +1
-0@@ -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)
Quoted 35 lines
net/slirp.c +9
-1#ifndef _WIN32char smb_dir[128 ];#endif @@ -118,11 +120,18 @@ static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, size_treturn 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
Quoted 14 lines · Jason Wang
Quoted 11 lines · Marc-André Lureau
Hi
Quoted 7 lines · Paolo Bonzini
We would like to move back
net_cleanup()at the end of main function, like it used to be untilf30dbae63a46f23116715dff8d130c, but minimum cleanup is needed regardless atexit()time for slirp's SMB functionality. Use an exit notifier to callslirp_smb_cleanup. Ifnet_cleanup()is called first, then remove the exit notifier as it will become a dangling pointer otherwise.
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
Signed-off-by Paolo Bonzini <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>Reviewed-by Jason Wang <[email protected]>
Thanks!
Paolo