From 2f8ef68b7c5f82ae9dead452acf927c71600cd7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 14 Jul 2016 20:58:01 +0200 Subject: [PATCH 19/27] slirp: use exit notifier for slirp_smb_cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RH-Author: Marc-André Lureau Message-id: <20160714205802.2896-4-marcandre.lureau@redhat.com> Patchwork-id: 71191 O-Subject: [RHEV-7.3 qemu-kvm-rhev PATCH 3/4] slirp: use exit notifier for slirp_smb_cleanup Bugzilla: 1354090 RH-Acked-by: Xiao Wang RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Paolo Bonzini RH-Acked-by: Laurent Vivier From: Paolo Bonzini 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. Reviewed-by: Marc-André Lureau Reviewed-by: Jason Wang Signed-off-by: Paolo Bonzini (cherry picked from commit f6c2e66ae8c8a03d3044dc9054aa7c16e7f817ee) Signed-off-by: Marc-André Lureau Signed-off-by: Miroslav Rezanina --- 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: -- 1.8.3.1