Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Daniel Vacek <neelx@suse.com>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>
Cc: Daniel Vacek <neelx@suse.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v6 4/8] btrfs: add orig_logical to btrfs_bio
Date: Wed, 12 Nov 2025 20:36:04 +0100	[thread overview]
Message-ID: <20251112193611.2536093-5-neelx@suse.com> (raw)
In-Reply-To: <20251112193611.2536093-1-neelx@suse.com>

From: Josef Bacik <josef@toxicpanda.com>

When checksumming the encrypted bio on writes we need to know which
logical address this checksum is for.  At the point where we get the
encrypted bio the bi_sector is the physical location on the target disk,
so we need to save the original logical offset in the btrfs_bio.  Then
we can use this when csum'ing the bio instead of the
bio->iter.bi_sector.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
No code changes other than context since v5.
---
 fs/btrfs/bio.c       | 10 ++++++++++
 fs/btrfs/bio.h       |  2 ++
 fs/btrfs/file-item.c |  2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
index a69174b2b6b6..aba452dd9904 100644
--- a/fs/btrfs/bio.c
+++ b/fs/btrfs/bio.c
@@ -94,6 +94,8 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info,
 	if (bbio_has_ordered_extent(bbio)) {
 		refcount_inc(&orig_bbio->ordered->refs);
 		bbio->ordered = orig_bbio->ordered;
+		bbio->orig_logical = orig_bbio->orig_logical;
+		orig_bbio->orig_logical += map_length;
 	}
 	bbio->csum_search_commit_root = orig_bbio->csum_search_commit_root;
 	atomic_inc(&orig_bbio->pending_ios);
@@ -726,6 +728,14 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
 		goto end_bbio;
 	}
 
+	/*
+	 * For fscrypt writes we will get the encrypted bio after we've
+	 * remapped our bio to the physical disk location, so we need to
+	 * save the original bytenr so we know what we're checksumming.
+	 */
+	if (bio_op(bio) == REQ_OP_WRITE && is_data_bbio(bbio))
+		bbio->orig_logical = logical;
+
 	map_length = min(map_length, length);
 	if (use_append)
 		map_length = btrfs_append_map_length(bbio, map_length);
diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h
index c5a6c66d51a0..5015e327dbd9 100644
--- a/fs/btrfs/bio.h
+++ b/fs/btrfs/bio.h
@@ -52,6 +52,7 @@ struct btrfs_bio {
 		 * - pointer to the checksums for this bio
 		 * - original physical address from the allocator
 		 *   (for zone append only)
+		 * - original logical address, used for checksumming fscrypt bios.
 		 */
 		struct {
 			struct btrfs_ordered_extent *ordered;
@@ -61,6 +62,7 @@ struct btrfs_bio {
 			struct bio *csum_bio;
 			struct bvec_iter csum_saved_iter;
 			u64 orig_physical;
+			u64 orig_logical;
 		};
 
 		/* For metadata reads: parentness verification. */
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 474949074da8..d2ecd26727ac 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -812,7 +812,7 @@ int btrfs_csum_one_bio(struct btrfs_bio *bbio, struct bio *bio, bool async)
 	if (!sums)
 		return -ENOMEM;
 
-	sums->logical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
+	sums->logical = bbio->orig_logical;
 	sums->len = bio->bi_iter.bi_size;
 	INIT_LIST_HEAD(&sums->list);
 	bbio->sums = sums;
-- 
2.51.0


  parent reply	other threads:[~2025-11-12 19:36 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-12 19:36 [PATCH v6 0/8] btrfs: add fscrypt support, PART 1 Daniel Vacek
2025-11-12 19:36 ` [PATCH v6 1/8] btrfs: disable various operations on encrypted inodes Daniel Vacek
2025-11-12 21:10   ` Qu Wenruo
2025-11-13 10:22     ` David Sterba
2025-11-12 19:36 ` [PATCH v6 2/8] btrfs: disable verity " Daniel Vacek
2025-11-13 10:25   ` David Sterba
2025-11-12 19:36 ` [PATCH v6 3/8] btrfs: add a bio argument to btrfs_csum_one_bio Daniel Vacek
2025-11-12 21:02   ` Qu Wenruo
2025-11-13 19:07     ` Daniel Vacek
2025-11-13 20:16       ` Qu Wenruo
2025-11-18 14:05         ` Daniel Vacek
2025-11-18 15:08           ` Christoph Hellwig
2025-11-18 15:45             ` Daniel Vacek
2025-11-18 21:05           ` Qu Wenruo
2025-11-19  7:34             ` Daniel Vacek
2025-11-19  8:16               ` Qu Wenruo
2025-11-19  8:22               ` Christoph Hellwig
2025-11-19  9:28                 ` Daniel Vacek
2025-11-19  9:32                   ` Christoph Hellwig
2025-11-19  9:48                     ` Daniel Vacek
2025-11-12 19:36 ` Daniel Vacek [this message]
2025-11-12 21:07   ` [PATCH v6 4/8] btrfs: add orig_logical to btrfs_bio Qu Wenruo
2025-11-13 19:16     ` Daniel Vacek
2025-11-12 19:36 ` [PATCH v6 5/8] btrfs: don't rewrite ret from inode_permission Daniel Vacek
2025-11-12 19:36 ` [PATCH v6 6/8] btrfs: move inode_to_path higher in backref.c Daniel Vacek
2025-11-12 19:36 ` [PATCH v6 7/8] btrfs: don't search back for dir inode item in INO_LOOKUP_USER Daniel Vacek
2025-11-12 19:36 ` [PATCH v6 8/8] btrfs: set the appropriate free space settings in reconfigure Daniel Vacek
2025-11-13 10:32   ` David Sterba
2025-11-13 11:24     ` Daniel Vacek
2025-11-18 12:10       ` David Sterba
2025-11-18 15:04 ` [PATCH v6 0/8] btrfs: add fscrypt support, PART 1 David Sterba
2025-11-18 16:14   ` Daniel Vacek

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=20251112193611.2536093-5-neelx@suse.com \
    --to=neelx@suse.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@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