All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
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	[thread overview]
Message-ID: <20170918072139.6300-7-quwenruo.btrfs@gmx.com> (raw)
In-Reply-To: <20170918072139.6300-1-quwenruo.btrfs@gmx.com>

--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 <quwenruo.btrfs@gmx.com>
---
 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);
-- 
2.14.1


  parent reply	other threads:[~2017-09-18  7:21 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-18  7:21 [PATCH v3 00/14] Mkfs: Rework --rootdir to a more generic behavior Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 01/14] btrfs-progs: Refactor find_next_chunk() to get rid of parameter root and objectid Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 02/14] btrfs-progs: Fix one-byte overlap bug in free_block_group_cache Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 03/14] btrfs-progs: mkfs: Rework rootdir option to avoid custom chunk layout Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 04/14] btrfs-progs: mkfs: Update allocation info before verbose output Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 05/14] btrfs-progs: Avoid BUG_ON for chunk allocation when ENOSPC happens Qu Wenruo
2017-09-18  7:21 ` Qu Wenruo [this message]
2017-09-18  7:21 ` [PATCH v3 07/14] btrfs-progs: Doc/mkfs: Add extra condition for rootdir option Qu Wenruo
2017-09-22  9:24   ` Anand Jain
2017-09-22 10:39     ` Qu Wenruo
2017-09-22 11:38       ` Austin S. Hemmelgarn
2017-09-22 12:32         ` Qu Wenruo
2017-09-22 13:33           ` Austin S. Hemmelgarn
2017-09-22 15:07             ` Qu Wenruo
2017-09-24 10:10               ` Anand Jain
2017-09-24 14:08                 ` Goffredo Baroncelli
2017-09-25 11:15                   ` Austin S. Hemmelgarn
2017-09-27 16:20                     ` David Sterba
2017-09-28  0:00                       ` Qu Wenruo
2017-09-29 11:30                         ` Austin S. Hemmelgarn
2017-09-29 16:57                         ` Goffredo Baroncelli
2017-09-30  3:33                           ` Qu Wenruo
2017-10-02 11:47                             ` Austin S. Hemmelgarn
2017-10-02 18:47                               ` Goffredo Baroncelli
2017-09-25 11:53               ` Austin S. Hemmelgarn
2017-09-18  7:21 ` [PATCH v3 08/14] btrfs-progs: tests/common: Split user xattr into its own branch for generate_dataset Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 09/14] btrfs-progs: tests/common: Introduce optional parameter to specify destination directory " Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 10/14] btrfs-progs: tests/common: Make checksum, permission and acl check path independent Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 11/14] btrfs-progs: tests/mkfs: Add basic test case for rootdir parameter Qu Wenruo
2017-09-18  7:35   ` [PATCH v3.1 " Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 12/14] btrfs-progs: tests/common: Detect ungraceful failure case Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 13/14] btrfs-progs: mkfs: Fix overwritten return value for mkfs Qu Wenruo
2017-09-18  7:21 ` [PATCH v3 14/14] btrfs-progs: tests/mkfs: Check error handler for rootdir parameter Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170918072139.6300-7-quwenruo.btrfs@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.