From patchwork Mon Sep 18 07:21:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9955611 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 354F560385 for ; Mon, 18 Sep 2017 07:22:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25D0128A52 for ; Mon, 18 Sep 2017 07:22:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1ABB928AF5; Mon, 18 Sep 2017 07:22:27 +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.4 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE78728A52 for ; Mon, 18 Sep 2017 07:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752516AbdIRHWY (ORCPT ); Mon, 18 Sep 2017 03:22:24 -0400 Received: from mout.gmx.net ([212.227.17.22]:55029 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751832AbdIRHVz (ORCPT ); Mon, 18 Sep 2017 03:21:55 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MVsUW-1dvvrc3J9M-00X2He; Mon, 18 Sep 2017 09:21:53 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v3 06/14] btrfs-progs: mkfs: Workaround BUG_ON caused by rootdir option Date: Mon, 18 Sep 2017 16:21:31 +0900 Message-Id: <20170918072139.6300-7-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170918072139.6300-1-quwenruo.btrfs@gmx.com> References: <20170918072139.6300-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:y8mlmvLXCmCcW1UzDI/LjbX5QxlFBKIu07wmojAor2TXczIPfx1 Pf0vNhWUWNqZZCmeiVI/Wuefq9AkqOn/D/zrELmAPNYgPHsaZIOm6wLkVDqPgV9pvIPsGHw jlAyb+0GC+Cw/GYCRcOcIeWYXT/xhghRexgySTP39UmKkIDqTKKTiaBRNHHRkLpQDNAc/4m t+FCSq3SbEYehmp5pw5fg== X-UI-Out-Filterresults: notjunk:1; V01:K0:N5GyBmmk/Ro=:eAQy5ba4y5v74jzig8m/Ck RG/1AYEUcyePxSq8NeCiL0pZ3OiVZo+iydPbMhV4ITqQwWx4yEcWEzQemz7CzyeAfojp7/SUU 52Bo6wS0BCwXqPSo6b9xSBQFgmvsqfbUrEUvyRwpKcrrzSPIMKduUkDKbxjmto1LdDHKwm3Rl LkjXFfev/B3rUjOBEEvgq8gHjrwDCsBHb344D3YW6x0VGFhTiAnPcrsypqei7p1pWuRhGPzFo TLAMrmAFHt9NHrpqjdLdvuY5AuiH1Qy3dyup8BK+/5LjekUZ3ngUMWeyZBFmvh7Fiaj49Pe1D qVYBc+4Vo1Sa4XHXkVO/PjEnM7IkBICeVrPuIcm7KkH64p0dPWnOdbGigxM8B7mICimDxIBIu /Muo2NKk1W26juj+DFMZrr10G8WnIAvsgYs8aO+PF8Uculz9kksTFEC/bOEdXSG91+ZZQ8JO0 gYq6vjiGTOLbWLuDLnNyQjkpu5eRsliiBQSzjx7frcWl5VD3P4d7wD8WMpNHrx42jsTaTC35u D+izfYulyDJT3fcSyLJaUBoB+HbzEdP37LhCFVh64Wt6BdiL4+G/V7viPdhCsnnIQtd7x74ZE Z+h3Uyq7dNFnh8ElPJ42EuDVLC+u0DrWz/IDvmU9fksYlLhrMYd2sP3x61Hg0Z3KKXbo94/ww GI4/Rx169RSZrbYv2E3udtP3TG3u2xftCCfBb+cUWg9Cp8RIZxXvJGDBDja4RMu1yF+rjTRUz HZfJKd7m2lmo4vmRc1zVOPJYQ8bgw7VX8v7IU2d6yuI7gY4Oj/+NDOU8n50OfKhKpltPqxo3l 1qO5dteBp4MW04KutKjRP6wG1I5Bw== Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP --rootdir option will start a transaction to fill the fs, however if something goes wrong, from ENOSPC to lack of permission, we won't commit transaction and cause BUG_ON trigger by uncommitted transaction: ------ extent buffer leak: start 29392896 len 16384 extent_io.c:579: free_extent_buffer: BUG_ON `eb->flags & EXTENT_DIRTY` triggered, value 1 ------ The root fix is to introduce btrfs_abort_transaction() in btrfs-progs, however in this particular case, we can workaround it by force committing the transaction. Since during mkfs, the magic of btrfs is set to an invalid one, without setting fs_info->finalize_on_close() the fs is never able to be mounted. So even we force to commit wrong transaction we won't screw up things worse. Signed-off-by: Qu Wenruo --- mkfs/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mkfs/main.c b/mkfs/main.c index 6561ac52..f78c24ce 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -1025,6 +1025,18 @@ static int make_image(const char *source_dir, struct btrfs_root *root) printf("Making image is completed.\n"); return 0; fail: + /* + * XXX: + * To avoid BUG_ON() triggered by uncommitted transaction, + * here we must commit transaction before we have proper + * btrfs_abort_transaction() in btrfs-progs. + * + * Don't worry, the magic number is not valid so the fs can't be + * mounted by kernel even we commit the trans. + * And we don't want to pollute the original error, so we ignore + * the return value from btrfs_commit_transaction(). + */ + btrfs_commit_transaction(trans, root); while (!list_empty(&dir_head.list)) { dir_entry = list_entry(dir_head.list.next, struct directory_name_entry, list);