From patchwork Tue Oct 17 11:49:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 10011763 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 0BFCB600CC for ; Tue, 17 Oct 2017 11:49:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F03A92885C for ; Tue, 17 Oct 2017 11:49:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E36972886E; Tue, 17 Oct 2017 11:49:56 +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 669402886B for ; Tue, 17 Oct 2017 11:49:56 +0000 (UTC) Received: from localhost ([::1]:37885 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4QNf-0007wx-Nt for patchwork-qemu-devel@patchwork.kernel.org; Tue, 17 Oct 2017 07:49:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4QN2-0007wm-G3 for qemu-devel@nongnu.org; Tue, 17 Oct 2017 07:49:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4QMx-0008KP-KA for qemu-devel@nongnu.org; Tue, 17 Oct 2017 07:49:16 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:33094 helo=mx01.kamp.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e4QMx-0008JL-B1 for qemu-devel@nongnu.org; Tue, 17 Oct 2017 07:49:11 -0400 Received: (qmail 26686 invoked by uid 89); 17 Oct 2017 11:49:08 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/23958. avast: 1.2.2/17010300. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.029556 secs); 17 Oct 2017 11:49:08 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 17 Oct 2017 11:49:08 -0000 X-GL_Whitelist: yes Received: (qmail 7138 invoked from network); 17 Oct 2017 11:49:08 -0000 Received: from lieven-pc.kamp-intra.net (HELO ?172.21.12.60?) (pl@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES128-SHA encrypted) ESMTPA; 17 Oct 2017 11:49:08 -0000 To: Kevin Wolf References: <8e2160db-338f-f1dc-7f5e-8faa3dce7090@kamp.de> <20171017114625.GB7660@dhcp-200-186.str.redhat.com> From: Peter Lieven Message-ID: <02ff8cd2-3061-ca10-8235-c2295de58562@kamp.de> Date: Tue, 17 Oct 2017 13:49:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20171017114625.GB7660@dhcp-200-186.str.redhat.com> Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: Re: [Qemu-devel] [Qemu-block] Clean Block Driver Shutdown 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: "qemu-devel@nongnu.org" , qemu block , armbru@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Am 17.10.2017 um 13:46 schrieb Kevin Wolf: > Am 17.10.2017 um 12:33 hat Peter Lieven geschrieben: >> I noticed that Qemu quits at several points with an exit() if the >> supplied parameters in the commandline are incorrect. This at some >> stages happens after there have already been connections to storage >> backends established. > Maybe we need to come to the conclusion that exit() is always wrong, > even during the initialisation. > >> These connections are not cleanly shut down in this case. For posix >> file backends that doesn't matter, but for other backends this leads >> to errors. E.g. iSCSI Targets log an aborted iSCSI connection due to >> tcp reset. >> >> I wonder what is the best way to fix this. A simply call to >> bdrv_close_all() in an atexit handler seems to work. But is this a >> good solution? Maybe register this handler only until the VM starts. >> Or do we need an atexit handler in each block driver that requires a >> clean shutdown? > No, definitely not code in every single block driver. We need to make > sure to properly clean up what has been started. > > An atexit handler is probably relatively easy. I think it would be > cleaner to have proper error paths even in main(), like in every other > function. I'm not sure if this would be reasonably easy to achieve, > though. A clean error path would obviously be a good idea. However, the following seems to work: Peter diff --git a/vl.c b/vl.c index 0723835..bed512c 100644 --- a/vl.c +++ b/vl.c @@ -3197,6 +3197,7 @@ int main(int argc, char **argv, char **envp)      nb_nics = 0;      bdrv_init_with_whitelist(); +    atexit(bdrv_close_all);      autostart = 1;