From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz
Subject: [PATCH 3/5] btrfs-progs: mkfs: Error out gracefully for --rootdir
Date: Wed, 18 Oct 2017 16:00:52 +0800 [thread overview]
Message-ID: <20171018080054.25509-4-wqu@suse.com> (raw)
In-Reply-To: <20171018080054.25509-1-wqu@suse.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 <wqu@suse.com>
---
mkfs/main.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/mkfs/main.c b/mkfs/main.c
index 5817f114c1a1..8c332aa1e12a 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1073,6 +1073,19 @@ static int make_image(const char *source_dir, struct btrfs_root *root)
printf("Making image is completed.\n");
return 0;
fail:
+ /*
+ * Since we don't have btrfs_abort_transaction() yet, uncommitted trans
+ * will trigger a BUG_ON().
+ *
+ * However before mkfs is fully finished, the magic number is invalid,
+ * so even we commit transaction here, the fs still can't be mounted.
+ *
+ * To do a graceful error out, here we commit transaction as a
+ * workaround.
+ * Since we have already hit some problem, the return value doesn't
+ * matter now.
+ */
+ 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.2
next prev parent reply other threads:[~2017-10-18 8:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-18 8:00 [PATCH 0/5] Rootdir refactor and small bug fixes Qu Wenruo
2017-10-18 8:00 ` [PATCH 1/5] btrfs-progs: Avoid BUG_ON for chunk allocation when ENOSPC happens Qu Wenruo
2017-10-18 8:00 ` [PATCH 2/5] btrfs-progs: mkfs: Fix overwritten return value for mkfs Qu Wenruo
2017-10-18 8:00 ` Qu Wenruo [this message]
2017-10-18 8:00 ` [PATCH 4/5] btrfs-progs: mkfs: Move image creation of rootdir to its own files Qu Wenruo
2017-10-18 8:00 ` [PATCH 5/5] btrfs-progs: mkfs: Move source dir size calculation " Qu Wenruo
2017-10-18 12:23 ` [PATCH 0/5] Rootdir refactor and small bug fixes Nikolay Borisov
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=20171018080054.25509-4-wqu@suse.com \
--to=wqu@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).