* [PATCH] btrfs: reject encoded write if inode has nodatasum flag set
@ 2024-02-02 12:22 fdmanana
2024-02-02 12:38 ` Johannes Thumshirn
2024-02-05 15:37 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: fdmanana @ 2024-02-02 12:22 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
Currently we allow an encoded write against inodes that have the NODATASUM
flag set, either because they are NOCOW files or they were created while
the filesystem was mounted with "-o nodatasum". This results in having
compressed extents without corresponding checksums, which is a filesystem
inconsistency reported by 'btrfs check'.
For example, running btrfs/281 with MOUNT_OPTIONS="-o nodatacow" triggers
this and 'btrfs check' errors out with:
[1/7] checking root items
[2/7] checking extents
[3/7] checking free space tree
[4/7] checking fs roots
root 256 inode 257 errors 1040, bad file extent, some csum missing
root 256 inode 258 errors 1040, bad file extent, some csum missing
ERROR: errors found in fs roots
(...)
So reject encoded writes if the target inode has NODATASUM set.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/inode.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 50aea888d977..2329bff33d4b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -10289,6 +10289,13 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
if (encoded->encryption != BTRFS_ENCODED_IO_ENCRYPTION_NONE)
return -EINVAL;
+ /*
+ * Compressed extents should always have checksums, so error out if we
+ * have a NOCOW file or inode was created while mounted with NODATASUM.
+ */
+ if (inode->flags & BTRFS_INODE_NODATASUM)
+ return -EINVAL;
+
orig_count = iov_iter_count(from);
/* The extent size must be sane. */
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: reject encoded write if inode has nodatasum flag set
2024-02-02 12:22 [PATCH] btrfs: reject encoded write if inode has nodatasum flag set fdmanana
@ 2024-02-02 12:38 ` Johannes Thumshirn
2024-02-05 15:37 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2024-02-02 12:38 UTC (permalink / raw)
To: fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: reject encoded write if inode has nodatasum flag set
2024-02-02 12:22 [PATCH] btrfs: reject encoded write if inode has nodatasum flag set fdmanana
2024-02-02 12:38 ` Johannes Thumshirn
@ 2024-02-05 15:37 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2024-02-05 15:37 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Fri, Feb 02, 2024 at 12:22:53PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> Currently we allow an encoded write against inodes that have the NODATASUM
> flag set, either because they are NOCOW files or they were created while
> the filesystem was mounted with "-o nodatasum". This results in having
> compressed extents without corresponding checksums, which is a filesystem
> inconsistency reported by 'btrfs check'.
>
> For example, running btrfs/281 with MOUNT_OPTIONS="-o nodatacow" triggers
> this and 'btrfs check' errors out with:
>
> [1/7] checking root items
> [2/7] checking extents
> [3/7] checking free space tree
> [4/7] checking fs roots
> root 256 inode 257 errors 1040, bad file extent, some csum missing
> root 256 inode 258 errors 1040, bad file extent, some csum missing
> ERROR: errors found in fs roots
> (...)
>
> So reject encoded writes if the target inode has NODATASUM set.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-02-05 15:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-02 12:22 [PATCH] btrfs: reject encoded write if inode has nodatasum flag set fdmanana
2024-02-02 12:38 ` Johannes Thumshirn
2024-02-05 15:37 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox