From patchwork Mon Sep 11 06:36:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9946703 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 9CCAB603F3 for ; Mon, 11 Sep 2017 06:36:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 911C126B41 for ; Mon, 11 Sep 2017 06:36:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8608528AE7; Mon, 11 Sep 2017 06:36:33 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_HI 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 36E0D26B41 for ; Mon, 11 Sep 2017 06:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750996AbdIKGga (ORCPT ); Mon, 11 Sep 2017 02:36:30 -0400 Received: from mout.gmx.net ([212.227.15.18]:55554 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750926AbdIKGg2 (ORCPT ); Mon, 11 Sep 2017 02:36:28 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0M86PB-1dVnL63hc9-00vc3T; Mon, 11 Sep 2017 08:36:26 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v2 6/7] btrfs-progs: mkfs: Workaround BUG_ON caused by rootdir option Date: Mon, 11 Sep 2017 15:36:11 +0900 Message-Id: <20170911063612.32114-7-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170911063612.32114-1-quwenruo.btrfs@gmx.com> References: <20170911063612.32114-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:mdKJGhMny2+qEVh7qPmHo0tI2tK14BJFjDVr6K6I+9+5uMAVHMs du3VFXKXxVmAXeXxzHtitZfi25o8ehjKIzuHSajmnJbjq6qABip4rW7jjeVpwrUkAv8lkcl FrpoBQcP6/pFy5HIoonlTmd7H+bsQKufbyqTLLEt7oRV36lMDnoF4kASyJ1RnCShEXQis+n lO6+UfOMurpHPnH2M2V9Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:PEAmsbX5QW4=:G/6hSMDQ5i0YRyD0efM3vd ZMxq/MjmtjuU7KpjIjy4I9VozD1a6KzMw/jFz7+90Uty+UEa50Qj+5xVwLEOLEU6Wr3rb0L6C 3bRT+U+CsjgGiXYkaSqU9rFt5N0PVnXdXWqB3g305/C7hp9VKbH9FzanSVjsVjHnHH+6MRRbT YD747SIXyazvNAEAqWbuiOTKHXjY8AU8lnueotZHreNPqMTrf7U+YlGNQpJ/2qOvVFrmC1Fkk izHsBo8mEhhsSAFr/C+h3K1WaPu0Vq6n1UOmCvbSm0xOyzj36awBwsG+WDGIQ79gtV2gSZCeY z+D9M6oPVwtzImxU/Q7oEcJvX23QmWxdmycZSeTZUQANOX+mMY3KIcBc4ffdGlwalk7MTteEc zDWjPfLYfDNfycTKWngrUr+3R0dJxT95YAy5grTN2qRRENS6XbOzeOiDfaCFlXlLFelKpenQE WMYCNwop+fqwSWwG7+50w7JBCd2684ajEECA7j3hZYTpeE/6BoVut9B8jpaP2Ddd8/0LNansQ NgkggTcE+5Jq4ofFtxL0JwsvocgfJYSl/HYnU1sLf9oTOKaFTlvurqE70YUdkbfx4OI8MScKN 5RahjSRVy+5C5p9T14i44PKA8gxCXF07hd2IwGT+06uYTnIxVvz07NPdgle837Di9tSluP4rD Dv5D1hgageyZ/f+BC1Hn4SggBx3HUcyj4NQAV+mALsnUU5Joz84GJA8r6KnyNo7R+5ayhSvxG ZWQaqnIxFKUacZ2K5cF0dM6clJEuFdO9h6CEDk1j+PECAoWseDx0LcNUWnPbOxv2lJZkfHZg4 BjwSiOhIpFKLfhbe3QkPCxj9zKEgA== 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);