linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Thumshirn <jth@kernel.org>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [RFC 2/2] btrfs: insert dummy RAID stripe extents for preallocated data
Date: Wed, 18 Sep 2024 16:08:50 +0200	[thread overview]
Message-ID: <20240918140850.27261-3-jth@kernel.org> (raw)
In-Reply-To: <20240918140850.27261-1-jth@kernel.org>

From: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Preallocated extents are not backed by a RAID stripe-tree entry (in
case the filesystem is using the RAID stripe-tree), because there is
no real logical to physical mapping needed for them.

But for instance scrub is performing RAID stripe-tree lookups for all
extents in the extent-tree, even for preallocated ones, so
the stripe-tree lookup code will return -ENOENT for them. This is
causing scrub to mark these extents as I/O errors.

To solve this issue, add a dummy RAID stripe-tree entry for these
extents, so the block mapping performed for scrub operations doesn't fail.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/inode.c            | 47 +++++++++++++++++++++++++++++++++++++
 fs/btrfs/raid-stripe-tree.c |  4 ++++
 2 files changed, 51 insertions(+)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index edac499fd83d..a8e119809670 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -71,6 +71,7 @@
 #include "backref.h"
 #include "raid-stripe-tree.h"
 #include "fiemap.h"
+#include "volumes.h"
 
 struct btrfs_iget_args {
 	u64 ino;
@@ -8679,6 +8680,44 @@ static int btrfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
 	return err;
 }
 
+static int insert_prealloc_rst_entry(struct btrfs_fs_info *fs_info,
+				     struct btrfs_trans_handle *trans_in,
+				     u64 start, u64 len)
+{
+	struct btrfs_trans_handle *trans;
+	struct btrfs_chunk_map *map;
+	u64 map_type;
+	int ret;
+
+	if (!btrfs_fs_incompat(fs_info, RAID_STRIPE_TREE))
+		return 0;
+
+	if (trans_in)
+		trans = trans_in;
+	else
+		trans = btrfs_join_transaction(fs_info->stripe_root);
+
+	map = btrfs_find_chunk_map(fs_info, start, len);
+	if (!map)
+		return -ENOENT;
+
+	map_type = map->type;
+	btrfs_free_chunk_map(map);
+
+	if (!btrfs_need_stripe_tree_update(fs_info, map_type))
+		return 0;
+	ret = btrfs_insert_dummy_raid_extent(trans, start, len);
+	if (ret) {
+		btrfs_abort_transaction(trans, ret);
+		return ret;
+	}
+
+	if (trans != trans_in)
+		btrfs_end_transaction(trans);
+
+	return 0;
+}
+
 static struct btrfs_trans_handle *insert_prealloc_file_extent(
 				       struct btrfs_trans_handle *trans_in,
 				       struct btrfs_inode *inode,
@@ -8817,6 +8856,14 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
 			break;
 		}
 
+		ret = insert_prealloc_rst_entry(fs_info, trans, ins.objectid,
+						cur_offset);
+		if (ret) {
+			btrfs_free_reserved_extent(fs_info, ins.objectid,
+						   ins.offset, 0);
+			break;
+		}
+
 		em = alloc_extent_map();
 		if (!em) {
 			btrfs_drop_extent_map_range(BTRFS_I(inode), cur_offset,
diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c
index bbe0689b1d17..f559ea14976f 100644
--- a/fs/btrfs/raid-stripe-tree.c
+++ b/fs/btrfs/raid-stripe-tree.c
@@ -61,6 +61,9 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
 		trace_btrfs_raid_extent_delete(fs_info, start, end,
 					       found_start, found_end);
 
+		if (key.type == BTRFS_RAID_STRIPE_DUMMY_KEY)
+			goto delete;
+
 		if (found_start < start) {
 			struct btrfs_key prev;
 			u64 diff = start - found_start;
@@ -112,6 +115,7 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
 			break;
 		}
 
+delete:
 		ret = btrfs_del_item(trans, stripe_root, path);
 		if (ret)
 			break;
-- 
2.43.0


  parent reply	other threads:[~2024-09-18 14:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-12 14:33 [PATCH] btrfs: scrub: skip PREALLOC extents on RAID stripe-tree Johannes Thumshirn
2024-09-12 21:32 ` Qu Wenruo
2024-09-13  5:42   ` Johannes Thumshirn
2024-09-13  5:47     ` Qu Wenruo
2024-09-18 14:08       ` [RFC 0/2] Add dummy RAID stripe tree entries for PREALLOC data Johannes Thumshirn
2024-09-18 14:08         ` [RFC 1/2] btrfs: introduce dummy RAID stripes for preallocated data Johannes Thumshirn
2024-09-18 14:08         ` Johannes Thumshirn [this message]
2024-09-18 23:45         ` [RFC 0/2] Add dummy RAID stripe tree entries for PREALLOC data Qu Wenruo
2024-09-19 15:42           ` Johannes Thumshirn
2024-09-19 16:57         ` Gerhard Wiesinger
2024-09-20  9:50           ` Johannes Thumshirn
2024-09-23 15:27         ` Josef Bacik

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=20240918140850.27261-3-jth@kernel.org \
    --to=jth@kernel.org \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /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).