From patchwork Tue Jul 12 09:23:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9224869 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2105360572 for ; Tue, 12 Jul 2016 09:23:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F0ED27C8F for ; Tue, 12 Jul 2016 09:23:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0274F27F7F; Tue, 12 Jul 2016 09:23:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8F30D27C8F for ; Tue, 12 Jul 2016 09:23:57 +0000 (UTC) Received: from localhost ([::1]:38612 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMtv2-0003A5-FQ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Jul 2016 05:23:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMtum-00039o-E8 for qemu-devel@nongnu.org; Tue, 12 Jul 2016 05:23:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMtuj-00075E-8i for qemu-devel@nongnu.org; Tue, 12 Jul 2016 05:23:40 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMtuj-00074t-2n for qemu-devel@nongnu.org; Tue, 12 Jul 2016 05:23:37 -0400 Received: by mail-wm0-x241.google.com with SMTP id i5so1481058wmg.2 for ; Tue, 12 Jul 2016 02:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=UDv0MvSN6q/Gyjy1msUOHr0NgbHYWrIgEPtTLdqZ27I=; b=DV+kDB3b+vWRdWUYOAF3DRLrgGeNSlUuLdcRnbuvxy+i2koklhNL0us/4jA5sQwLXS RLT1oK8yWMohGA02y0SIJ0yB8rRGUpJFFXo3F1qX9d1Q9DTPuMF3RiuKmPxVIG+ZcOqz 4k0NlZAX537IVGMNYZVDhPeUjTmywFk5HB+2AykjmfseVcVHkEamKWsvuHyMGk/hRf+o sOJTY9QZOuZrgeylWTQZjm+XWVpbahHG6lLtnuyEjguxVLPAJy1eiB6fqL8pwYUPU+I+ NtvS0IL/+48HqAfMYPNb+X8dkBkDmOTOAQkp6jDNyy4pXQhIM6l9WqwGcRUsECycMl1T zQzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=UDv0MvSN6q/Gyjy1msUOHr0NgbHYWrIgEPtTLdqZ27I=; b=F6dwau3FMYLzFDp+qMAdLgIHbEgMOLuvWsQqq/1j33bJoYrL9ekXScOuh1si1Lht/z FWJqVIVRtY1tjEOfySFsutGtY/2uSrNdgdNTWq6CJDbrgXXlTlsUXdijh6f7uWvF1FOx 6IvSxo/KSgQfB16exKGXUjwD2bvyhljmutDDh1iMylOqWrXveiV5Sw+5Uu5gb1F0PIfB SbohwMbl0b8wociuNWqw2vG+gvEGuW3fIJtUCAwjGt0gAL7Othydwk3SM20F4BtQI14j jmiUBwaxpw2tbVx0002H1BMOrUA1BLrYB9VKp4xopZ1ZPVkvQoashWOJwMK13+VFL1Ve u3Xw== X-Gm-Message-State: ALyK8tKeYsYebfC/iAQ9gAF76CeetN3MBGM1P0hPQDS08VZ8CtHNQH1MFJo6QFD+J/LOHA== X-Received: by 10.28.145.17 with SMTP id t17mr1972870wmd.14.1468315415936; Tue, 12 Jul 2016 02:23:35 -0700 (PDT) Received: from donizetti.lan (94-39-188-118.adsl-ull.clienti.tiscali.it. [94.39.188.118]) by smtp.gmail.com with ESMTPSA id v70sm302683wmf.18.2016.07.12.02.23.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2016 02:23:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 12 Jul 2016 11:23:33 +0200 Message-Id: <1468315413-22846-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH] slirp: use exit notifier for slirp_smb_cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, jasowang@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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é 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; #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: