From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiPQf-0007hn-Pj for qemu-devel@nongnu.org; Tue, 11 Dec 2012 07:59:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TiPQY-0007UR-6q for qemu-devel@nongnu.org; Tue, 11 Dec 2012 07:59:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25501) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiPQX-0007UL-Us for qemu-devel@nongnu.org; Tue, 11 Dec 2012 07:59:14 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBBCxCaZ030623 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 11 Dec 2012 07:59:12 -0500 Date: Tue, 11 Dec 2012 15:02:23 +0200 From: "Michael S. Tsirkin" Message-ID: <20121211130223.GE15435@redhat.com> References: <20121211055704.GA5080@t430s.nay.redhat.com> <20121211083843.GB23282@stefanha-thinkpad.muc.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20121211083843.GB23282@stefanha-thinkpad.muc.redhat.com> Subject: Re: [Qemu-devel] Network isn't clean when qemu exits List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Amos Kong , Qemu Devel Mail List On Tue, Dec 11, 2012 at 09:38:43AM +0100, Stefan Hajnoczi wrote: > On Tue, Dec 11, 2012 at 01:57:04PM +0800, Amos Kong wrote: > > In vl.c:main(), tap device would be created when net_init_clients() is called. > > "device" option is parsed after calling net_init_clients() by: > > # "qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) > > > > Qemu will exit if fails to parse device parameters without calling net_cleanup(). > > I touch a problem, the tap device which is created by qemu-ifup script > > could not be removed by qemu-ifdown script. > > > > I did a quick fix, the tap device should be removed. > > > > But there are many "exit(1)" after calling net_init_clients() in vl.c, > > it's ugly to call net_cleanup() before each exit. Not sure if we have > > other exit(1) in other sub-functions, which is also called after calling > > net_init_clients(). > > > > Any comments? > > > > ===== > > @@ -3882,8 +3889,11 @@ int main(int argc, char **argv, char **envp) > > } > > > > /* init generic devices */ > > - if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, > > NULL, 1) != 0) > > + if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, > > + NULL, 1) != 0) { > > + net_cleanup(); > > exit(1); > > + } > > How about qemu_add_exit_notifier() or atexit(3)? Several other places > in QEMU use this to clean up. > > Then you can also remove net_cleanup() from the end of vl.c:main() since > it gets called implicitly. > > Stefan Good idea, thanks a lot.