From patchwork Fri Jun 30 12:50:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9819531 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 A1F796035F for ; Fri, 30 Jun 2017 12:51:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 955CD1FFB9 for ; Fri, 30 Jun 2017 12:51:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8845F28630; Fri, 30 Jun 2017 12:51:47 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 077E71FFB9 for ; Fri, 30 Jun 2017 12:51:46 +0000 (UTC) Received: from localhost ([::1]:44413 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQvOj-0001wt-BF for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Jun 2017 08:51:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQvNl-0001ud-LP for qemu-devel@nongnu.org; Fri, 30 Jun 2017 08:50:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQvNg-0003Tj-Tw for qemu-devel@nongnu.org; Fri, 30 Jun 2017 08:50:45 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:9193) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQvNg-0003TV-OX for qemu-devel@nongnu.org; Fri, 30 Jun 2017 08:50:40 -0400 X-IronPort-AV: E=Sophos;i="5.40,286,1496102400"; d="scan'208";a="438451358" From: Ross Lagerwall To: Date: Fri, 30 Jun 2017 13:50:28 +0100 Message-ID: <20170630125028.30265-1-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.9.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Subject: [Qemu-devel] [PATCH v2] xen-platform: Cleanup network infrastructure when emulated NICs are unplugged 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: Stefano Stabellini , Eduardo Habkost , "Michael S. Tsirkin" , Ross Lagerwall , Anthony Perard , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When the guest unplugs the emulated NICs, cleanup the peer for each NIC as it is not needed anymore. Most importantly, this allows the tap interfaces which QEMU holds open to be closed and removed. Signed-off-by: Ross Lagerwall Acked-by: Anthony PERARD --- In v2: Don't call nic_cleanup(), just remove the peer of the NIC which will cleanup up the tap devices. This means that QEMU doesn't segv when shutting down. hw/i386/xen/xen_platform.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c index 1419fc9..f231558 100644 --- a/hw/i386/xen/xen_platform.c +++ b/hw/i386/xen/xen_platform.c @@ -102,8 +102,19 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o) } } +/* Remove the peer of the NIC device. Normally, this would be a tap device. */ +static void del_nic_peer(NICState *nic, void *opaque) +{ + NetClientState *nc; + + nc = qemu_get_queue(nic); + if (nc->peer) + qemu_del_net_client(nc->peer); +} + static void pci_unplug_nics(PCIBus *bus) { + qemu_foreach_nic(del_nic_peer, NULL); pci_for_each_device(bus, 0, unplug_nic, NULL); }