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 1/2] btrfs: introduce dummy RAID stripes for preallocated data
Date: Wed, 18 Sep 2024 16:08:49 +0200 [thread overview]
Message-ID: <20240918140850.27261-2-jth@kernel.org> (raw)
In-Reply-To: <20240918140850.27261-1-jth@kernel.org>
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Introduce BTRFS_RAID_STRIPE_DUMMY_KEY which describes a range in the
RAID stripe-tree that is backed by meta-data but no data. For instance
for preallocated extents.
On read, we can simply ignore the contents of the stripe_extent as
we're not interested in the physical address and device id of these
stripe_extents.
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
fs/btrfs/raid-stripe-tree.c | 43 +++++++++++++++++++++++++++++++++
fs/btrfs/raid-stripe-tree.h | 2 ++
include/uapi/linux/btrfs_tree.h | 1 +
3 files changed, 46 insertions(+)
diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c
index 075fecd08d87..bbe0689b1d17 100644
--- a/fs/btrfs/raid-stripe-tree.c
+++ b/fs/btrfs/raid-stripe-tree.c
@@ -158,6 +158,40 @@ static int update_raid_extent_item(struct btrfs_trans_handle *trans,
return ret;
}
+int btrfs_insert_dummy_raid_extent(struct btrfs_trans_handle *trans,
+ u64 logical, u64 length)
+{
+ struct btrfs_fs_info *fs_info = trans->fs_info;
+ struct btrfs_key stripe_key;
+ struct btrfs_root *stripe_root = fs_info->stripe_root;
+ struct btrfs_path *path;
+ int ret;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ stripe_key.objectid = logical;
+ stripe_key.type = BTRFS_RAID_STRIPE_DUMMY_KEY;
+ stripe_key.offset = length;
+
+ ret = btrfs_insert_empty_item(trans, stripe_root, path, &stripe_key, 0);
+ if (ret == -EEXIST) {
+ struct extent_buffer *leaf = path->nodes[0];
+ int slot = path->slots[0];
+ struct btrfs_key found_key;
+
+ btrfs_item_key_to_cpu(leaf, &found_key, slot);
+ found_key.objectid = logical;
+ found_key.offset = length;
+ btrfs_mark_buffer_dirty(trans, leaf);
+ ret = 0;
+ }
+ btrfs_free_path(path);
+
+ return ret;
+}
+
static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
struct btrfs_io_context *bioc)
{
@@ -305,6 +339,15 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
if (end > found_end)
*length -= end - found_end;
+ /*
+ * If we have a BTRFS_RAID_STRIPE_DUMMY_KEY it means we've hit
+ * an entry for a preallocated extent. Noone will ever check
+ * the physical, only logical and length, so we're good to
+ * bail out from here.
+ */
+ if (found_key.type == BTRFS_RAID_STRIPE_DUMMY_KEY)
+ goto out;
+
num_stripes = btrfs_num_raid_stripes(btrfs_item_size(leaf, slot));
stripe_extent = btrfs_item_ptr(leaf, slot, struct btrfs_stripe_extent);
diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h
index 1ac1c21aac2f..dbe52789f201 100644
--- a/fs/btrfs/raid-stripe-tree.h
+++ b/fs/btrfs/raid-stripe-tree.h
@@ -27,6 +27,8 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
u32 stripe_index, struct btrfs_io_stripe *stripe);
int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
struct btrfs_ordered_extent *ordered_extent);
+int btrfs_insert_dummy_raid_extent(struct btrfs_trans_handle *trans,
+ u64 logical, u64 length);
static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info,
u64 map_type)
diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
index fc29d273845d..76b18013b394 100644
--- a/include/uapi/linux/btrfs_tree.h
+++ b/include/uapi/linux/btrfs_tree.h
@@ -281,6 +281,7 @@
#define BTRFS_CHUNK_ITEM_KEY 228
#define BTRFS_RAID_STRIPE_KEY 230
+#define BTRFS_RAID_STRIPE_DUMMY_KEY 231
/*
* Records the overall state of the qgroups.
--
2.43.0
next prev 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 ` Johannes Thumshirn [this message]
2024-09-18 14:08 ` [RFC 2/2] btrfs: insert dummy RAID stripe extents for preallocated data Johannes Thumshirn
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-2-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).