From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNA0u-0000lS-Ns for qemu-devel@nongnu.org; Tue, 12 Jul 2016 22:35:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNA0q-0002Lw-Gs for qemu-devel@nongnu.org; Tue, 12 Jul 2016 22:35:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNA0q-0002Lr-Al for qemu-devel@nongnu.org; Tue, 12 Jul 2016 22:35:00 -0400 References: <1468315413-22846-1-git-send-email-pbonzini@redhat.com> From: Jason Wang Message-ID: <5785A8CF.6010301@redhat.com> Date: Wed, 13 Jul 2016 10:34:55 +0800 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] slirp: use exit notifier for slirp_smb_cleanup List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , Paolo Bonzini Cc: QEMU On 2016=E5=B9=B407=E6=9C=8812=E6=97=A5 18:15, Marc-Andr=C3=A9 Lureau wrot= e: > Hi > > On Tue, Jul 12, 2016 at 11:23 AM, Paolo Bonzini w= rote: >> 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 > Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Jason Wang > > > >> --- >> 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 =3D container_of(n, SlirpState, exit_notifier); >> + slirp_smb_cleanup(s); >> +} >> + >> static void net_slirp_cleanup(NetClientState *nc) >> { >> SlirpState *s =3D 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, co= nst char *model, >> } >> #endif >> >> + s->exit_notifier.notify =3D slirp_smb_exit; >> + qemu_add_exit_notifier(&s->exit_notifier); >> return 0; >> >> error: >> -- >> 2.7.4 >> >> > >