* [PATCH] btrfs: handle failure of add_pending_csums
@ 2017-12-05 11:51 Nikolay Borisov
2018-01-05 16:44 ` David Sterba
0 siblings, 1 reply; 4+ messages in thread
From: Nikolay Borisov @ 2017-12-05 11:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: Nikolay Borisov
add_pending_csums was added as part of the new data=ordered implementation in
e6dcd2dc9c48 ("Btrfs: New data=ordered implementation"). Even back then it
called the btrfs_csum_file_blocks which can fail but it never bothered handling
the failure. In ENOMEM situation this could lead to the filesystem failing to
write the checksums for a particular extent and not detect this. On read this
could lead to the filesystem erroring out due to crc mismatch. Fix it by
propagating failure from add_pending_csums and handling them
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
fs/btrfs/inode.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index e87ec11c0986..432bffdbb02f 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2039,11 +2039,14 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
struct inode *inode, struct list_head *list)
{
struct btrfs_ordered_sum *sum;
+ int ret;
list_for_each_entry(sum, list, list) {
trans->adding_csums = true;
- btrfs_csum_file_blocks(trans,
+ ret = btrfs_csum_file_blocks(trans,
BTRFS_I(inode)->root->fs_info->csum_root, sum);
+ if (ret)
+ return ret;
trans->adding_csums = false;
}
return 0;
@@ -3051,7 +3054,11 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
goto out;
}
- add_pending_csums(trans, inode, &ordered_extent->list);
+ ret = add_pending_csums(trans, inode, &ordered_extent->list);
+ if (ret) {
+ btrfs_abort_transaction(trans, ret);
+ goto out;
+ }
btrfs_ordered_update_i_size(inode, 0, ordered_extent);
ret = btrfs_update_inode_fallback(trans, root, inode);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: handle failure of add_pending_csums
2017-12-05 11:51 [PATCH] btrfs: handle failure of add_pending_csums Nikolay Borisov
@ 2018-01-05 16:44 ` David Sterba
2018-01-08 8:59 ` [PATCH v2] " Nikolay Borisov
0 siblings, 1 reply; 4+ messages in thread
From: David Sterba @ 2018-01-05 16:44 UTC (permalink / raw)
To: Nikolay Borisov; +Cc: linux-btrfs
On Tue, Dec 05, 2017 at 01:51:43PM +0200, Nikolay Borisov wrote:
> add_pending_csums was added as part of the new data=ordered implementation in
> e6dcd2dc9c48 ("Btrfs: New data=ordered implementation"). Even back then it
> called the btrfs_csum_file_blocks which can fail but it never bothered handling
> the failure. In ENOMEM situation this could lead to the filesystem failing to
> write the checksums for a particular extent and not detect this. On read this
> could lead to the filesystem erroring out due to crc mismatch. Fix it by
> propagating failure from add_pending_csums and handling them
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
> fs/btrfs/inode.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index e87ec11c0986..432bffdbb02f 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -2039,11 +2039,14 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
> struct inode *inode, struct list_head *list)
> {
> struct btrfs_ordered_sum *sum;
> + int ret;
>
> list_for_each_entry(sum, list, list) {
> trans->adding_csums = true;
> - btrfs_csum_file_blocks(trans,
> + ret = btrfs_csum_file_blocks(trans,
> BTRFS_I(inode)->root->fs_info->csum_root, sum);
> + if (ret)
> + return ret;
The return should come after the line below, otherwise the transaction
will be left in the "adding csums".
> trans->adding_csums = false;
...
> }
> return 0;
> @@ -3051,7 +3054,11 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
> goto out;
> }
>
> - add_pending_csums(trans, inode, &ordered_extent->list);
> + ret = add_pending_csums(trans, inode, &ordered_extent->list);
> + if (ret) {
> + btrfs_abort_transaction(trans, ret);
Ok, we can't do better here, this is too late and
add_pending_csums -> btrfs_csum_file_blocks modifies too much of the
state to be rolled back safely.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] btrfs: handle failure of add_pending_csums
2018-01-05 16:44 ` David Sterba
@ 2018-01-08 8:59 ` Nikolay Borisov
2018-01-26 14:28 ` Josef Bacik
0 siblings, 1 reply; 4+ messages in thread
From: Nikolay Borisov @ 2018-01-08 8:59 UTC (permalink / raw)
To: dsterba; +Cc: linux-btrfs, Nikolay Borisov
add_pending_csums was added as part of the new data=ordered implementation in
e6dcd2dc9c48 ("Btrfs: New data=ordered implementation"). Even back then it
called the btrfs_csum_file_blocks which can fail but it never bothered handling
the failure. In ENOMEM situation this could lead to the filesystem failing to
write the checksums for a particular extent and not detect this. On read this
could lead to the filesystem erroring out due to crc mismatch. Fix it by
propagating failure from add_pending_csums and handling them
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
V2:
Moves the if/ret part after setting ->adding_csums to false.
fs/btrfs/inode.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index eebfe2615428..029399593049 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2039,12 +2039,15 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
struct inode *inode, struct list_head *list)
{
struct btrfs_ordered_sum *sum;
+ int ret;
list_for_each_entry(sum, list, list) {
trans->adding_csums = true;
- btrfs_csum_file_blocks(trans,
+ ret = btrfs_csum_file_blocks(trans,
BTRFS_I(inode)->root->fs_info->csum_root, sum);
trans->adding_csums = false;
+ if (ret)
+ return ret;
}
return 0;
}
@@ -3058,7 +3061,11 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
goto out;
}
- add_pending_csums(trans, inode, &ordered_extent->list);
+ ret = add_pending_csums(trans, inode, &ordered_extent->list);
+ if (ret) {
+ btrfs_abort_transaction(trans, ret);
+ goto out;
+ }
btrfs_ordered_update_i_size(inode, 0, ordered_extent);
ret = btrfs_update_inode_fallback(trans, root, inode);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] btrfs: handle failure of add_pending_csums
2018-01-08 8:59 ` [PATCH v2] " Nikolay Borisov
@ 2018-01-26 14:28 ` Josef Bacik
0 siblings, 0 replies; 4+ messages in thread
From: Josef Bacik @ 2018-01-26 14:28 UTC (permalink / raw)
To: Nikolay Borisov; +Cc: dsterba, linux-btrfs
On Mon, Jan 08, 2018 at 10:59:43AM +0200, Nikolay Borisov wrote:
> add_pending_csums was added as part of the new data=ordered implementation in
> e6dcd2dc9c48 ("Btrfs: New data=ordered implementation"). Even back then it
> called the btrfs_csum_file_blocks which can fail but it never bothered handling
> the failure. In ENOMEM situation this could lead to the filesystem failing to
> write the checksums for a particular extent and not detect this. On read this
> could lead to the filesystem erroring out due to crc mismatch. Fix it by
> propagating failure from add_pending_csums and handling them
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-01-26 14:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-05 11:51 [PATCH] btrfs: handle failure of add_pending_csums Nikolay Borisov
2018-01-05 16:44 ` David Sterba
2018-01-08 8:59 ` [PATCH v2] " Nikolay Borisov
2018-01-26 14:28 ` Josef Bacik
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).