Btrfs: do not abort transaction when failing to insert hole extent
PATCH 1/1 Btrfs: do not abort transaction when failing to insert hole extent
This is running in a typical write path, not inside a critical path where we have to abort the running transaction, so it's OK to return errors to callers and eventually to userspace.
--- fs/btrfs/inode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
fs/btrfs/inode.c +1 -4
@@ -4939,16 +4939,13 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, ret =btrfs_drop_extents (trans, root, inode, offset, offset + len,1 );if (ret) { -btrfs_abort_transaction (trans, ret);btrfs_end_transaction (trans);return ret; } ret =btrfs_insert_file_extent (trans, root,btrfs_ino (BTRFS_I (inode)), offset,0 ,0 , len,0 , len,0 ,0 ,0 ); -if (ret) -btrfs_abort_transaction (trans, ret); -else +if (!ret)btrfs_update_inode (trans, root, inode);btrfs_end_transaction (trans);return ret;
Signature · 1 line
1.8.3.1
Quoted 3 lines · Liu Bo
This is running in a typical write path, not inside a critical path where we have to abort the running transaction, so it's OK to return errors to callers and eventually to userspace.
I'm not sure this is entierly correct, several other places do not abort after btrfs_drop_extents as there's nothing that would leave the structres in some half-state.
Quoted 10 lines
Signed-off-by Liu Bo <[email protected]>--- fs/btrfs/inode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)fs/btrfs/inode.c +0
-0
fs/btrfs/inode.c static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, · line 4947
Quoted 10 lines
fs/btrfs/inode.c +0
-1@@ -4939,16 +4939,13 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, ret =btrfs_drop_extents (trans, root, inode, offset, offset + len,1 );if (ret) { -btrfs_abort_transaction (trans, ret);btrfs_end_transaction (trans);return ret; } ret =btrfs_insert_file_extent (trans, root,btrfs_ino (BTRFS_I (inode)), offset,0 ,0 , len,0 , len,0 ,0 ,0 );
But here the extents have been already dropped and missing to insert the items does not seem to lead to a consistent state.
It's possible that I'm missing something. In a call path that can be safely rolled back even with a started transaction, we don't need to abort in all cases. But if the rollback requires some non-trivial modifications, I don't see options how to avoid the abort.
__btrfs_drop_extents does a lot of state changes and can itself fail in the middle of dropping the range, aborting looks like the safest option.
Quoted 7 lines
fs/btrfs/inode.c +1
-3-if (ret) -btrfs_abort_transaction (trans, ret); -else +if (!ret)btrfs_update_inode (trans, root, inode);btrfs_end_transaction (trans);return ret;
Quoted 33 lines · David Sterba
Quoted 3 lines · Liu Bo
This is running in a typical write path, not inside a critical path where we have to abort the running transaction, so it's OK to return errors to callers and eventually to userspace.
I'm not sure this is entierly correct, several other places do not abort after
btrfs_drop_extentsas there's nothing that would leave the structres in some half-state.Quoted 10 lines
Signed-off-by Liu Bo <[email protected]>--- fs/btrfs/inode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)fs/btrfs/inode.c +0
-0fs/btrfs/inode.c static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, · line 4947
Quoted 10 lines
fs/btrfs/inode.c +0
-1@@ -4939,16 +4939,13 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, ret =btrfs_drop_extents (trans, root, inode, offset, offset + len,1 );if (ret) { -btrfs_abort_transaction (trans, ret);btrfs_end_transaction (trans);return ret; } ret =btrfs_insert_file_extent (trans, root,btrfs_ino (BTRFS_I (inode)), offset,0 ,0 , len,0 , len,0 ,0 ,0 );But here the extents have been already dropped and missing to insert the items does not seem to lead to a consistent state.
Quoted 9 lines
It's possible that I'm missing something. In a call path that can be safely rolled back even with a started transaction, we don't need to abort in all cases. But if the rollback requires some non-trivial modifications, I don't see options how to avoid the abort.
__btrfs_drop_extentsdoes a lot of state changes and can itself fail in the middle of dropping the range, aborting looks like the safest option.
As maybe_insert_hole is only called by btrfs_cont_expand here, which means it's a really hole, I don't expect drop_extents would drop anything, we can remove this drop_extents and put an assert after btrfs_insert_file_extent for checking EEXIST.
It's different from punch hole where we need to explicitly drop an actual extent and replace it with a hole range.
thanks,
liubo
Quoted 11 lines
fs/btrfs/inode.c static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, · line 4951
Quoted 7 lines
fs/btrfs/inode.c +1
-3-if (ret) -btrfs_abort_transaction (trans, ret); -else +if (!ret)btrfs_update_inode (trans, root, inode);btrfs_end_transaction (trans);return ret;--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 44 lines · Liu Bo
Quoted 33 lines · David Sterba
Quoted 3 lines · Liu Bo
This is running in a typical write path, not inside a critical path where we have to abort the running transaction, so it's OK to return errors to callers and eventually to userspace.
I'm not sure this is entierly correct, several other places do not abort after
btrfs_drop_extentsas there's nothing that would leave the structres in some half-state.Quoted 10 lines
Signed-off-by Liu Bo <[email protected]>--- fs/btrfs/inode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)fs/btrfs/inode.c +0
-0fs/btrfs/inode.c static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, · line 4947
Quoted 10 lines
fs/btrfs/inode.c +0
-1@@ -4939,16 +4939,13 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, ret =btrfs_drop_extents (trans, root, inode, offset, offset + len,1 );if (ret) { -btrfs_abort_transaction (trans, ret);btrfs_end_transaction (trans);return ret; } ret =btrfs_insert_file_extent (trans, root,btrfs_ino (BTRFS_I (inode)), offset,0 ,0 , len,0 , len,0 ,0 ,0 );But here the extents have been already dropped and missing to insert the items does not seem to lead to a consistent state.
Quoted 9 lines
It's possible that I'm missing something. In a call path that can be safely rolled back even with a started transaction, we don't need to abort in all cases. But if the rollback requires some non-trivial modifications, I don't see options how to avoid the abort.
__btrfs_drop_extentsdoes a lot of state changes and can itself fail in the middle of dropping the range, aborting looks like the safest option.
Quoted 4 lines
As
maybe_insert_holeis only called bybtrfs_cont_expandhere, which means it's a really hole, I don't expectdrop_extentswould drop anything, we can remove thisdrop_extentsand put an assert afterbtrfs_insert_file_extentfor checking EEXIST.
Sounds good.
Quoted 2 lines
It's different from punch hole where we need to explicitly drop an actual extent and replace it with a hole range.
Right, that's what I didn't see at first.
Quoted 45 lines · David Sterba
Quoted 44 lines · Liu Bo
Quoted 42 lines · David Sterba
Quoted 3 lines · Liu Bo
This is running in a typical write path, not inside a critical path where we have to abort the running transaction, so it's OK to return errors to callers and eventually to userspace.
I'm not sure this is entierly correct, several other places do not abort after
btrfs_drop_extentsas there's nothing that would leave the structres in some half-state.Quoted 10 lines
Signed-off-by Liu Bo <[email protected]>--- fs/btrfs/inode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)fs/btrfs/inode.c +0
-0fs/btrfs/inode.c static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, · line 4947
Quoted 10 lines
fs/btrfs/inode.c +0
-1@@ -4939,16 +4939,13 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, ret =btrfs_drop_extents (trans, root, inode, offset, offset + len,1 );if (ret) { -btrfs_abort_transaction (trans, ret);btrfs_end_transaction (trans);return ret; } ret =btrfs_insert_file_extent (trans, root,btrfs_ino (BTRFS_I (inode)), offset,0 ,0 , len,0 , len,0 ,0 ,0 );But here the extents have been already dropped and missing to insert the items does not seem to lead to a consistent state.
It's possible that I'm missing something. In a call path that can be safely rolled back even with a started transaction, we don't need to abort in all cases. But if the rollback requires some non-trivial modifications, I don't see options how to avoid the abort.
__btrfs_drop_extentsdoes a lot of state changes and can itself fail in the middle of dropping the range, aborting looks like the safest option.
Quoted 7 lines
Quoted 4 lines
As
maybe_insert_holeis only called bybtrfs_cont_expandhere, which means it's a really hole, I don't expectdrop_extentswould drop anything, we can remove thisdrop_extentsand put an assert afterbtrfs_insert_file_extentfor checking EEXIST.Sounds good.
Let me make a v2 and have a fstests run.
thanks,
liubo
Quoted 4 lines
Quoted 2 lines
It's different from punch hole where we need to explicitly drop an actual extent and replace it with a hole range.
Right, that's what I didn't see at first.
Quoted 51 lines · Liu Bo
Quoted 50 lines · David Sterba
Quoted 48 lines · Liu Bo
Quoted 33 lines · David Sterba
Quoted 3 lines · Liu Bo
This is running in a typical write path, not inside a critical path where we have to abort the running transaction, so it's OK to return errors to callers and eventually to userspace.
I'm not sure this is entierly correct, several other places do not abort after
btrfs_drop_extentsas there's nothing that would leave the structres in some half-state.Quoted 10 lines
Signed-off-by Liu Bo <[email protected]>--- fs/btrfs/inode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)fs/btrfs/inode.c +0
-0fs/btrfs/inode.c static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, · line 4947
Quoted 10 lines
fs/btrfs/inode.c +0
-1@@ -4939,16 +4939,13 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode, ret =btrfs_drop_extents (trans, root, inode, offset, offset + len,1 );if (ret) { -btrfs_abort_transaction (trans, ret);btrfs_end_transaction (trans);return ret; } ret =btrfs_insert_file_extent (trans, root,btrfs_ino (BTRFS_I (inode)), offset,0 ,0 , len,0 , len,0 ,0 ,0 );But here the extents have been already dropped and missing to insert the items does not seem to lead to a consistent state.
Quoted 9 lines
It's possible that I'm missing something. In a call path that can be safely rolled back even with a started transaction, we don't need to abort in all cases. But if the rollback requires some non-trivial modifications, I don't see options how to avoid the abort.
__btrfs_drop_extentsdoes a lot of state changes and can itself fail in the middle of dropping the range, aborting looks like the safest option.As
maybe_insert_holeis only called bybtrfs_cont_expandhere, which means it's a really hole, I don't expectdrop_extentswould drop anything, we can remove thisdrop_extentsand put an assert afterbtrfs_insert_file_extentfor checking EEXIST.
Quoted 5 lines
Quoted 2 lines
Sounds good.
Let me make a v2 and have a fstests run.
It turns out that the btrfs_drop_extents() here is quite necessary since fallocate(2) has a FALLOC_FL_KEEP_SIZE option, and when that happens, a hole extent would be appended between the EOF and fallocate range's start, then a later truncate up would have to drop these hole extents in order to expand with a new hole...
As I don't see a way to gracefully solve this except keeping drop_extents(), lets drop this patch instead.
thanks,
liubo
Quoted 7 lines
thanks,
liuboQuoted 4 lines
Quoted 2 lines
It's different from punch hole where we need to explicitly drop an actual extent and replace it with a hole range.
Right, that's what I didn't see at first.
Quoted 11 lines · Liu Bo
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
As
maybe_insert_holeis only called bybtrfs_cont_expandhere, which means it's a really hole, I don't expectdrop_extentswould drop anything, we can remove thisdrop_extentsand put an assert afterbtrfs_insert_file_extentfor checking EEXIST.Sounds good.
Let me make a v2 and have a fstests run.
It turns out that the
btrfs_drop_extents()here is quite necessary since fallocate(2) has aFALLOC_FL_KEEP_SIZEoption, and when that happens, a hole extent would be appended between the EOF and fallocate range's start, then a later truncate up would have to drop these hole extents in order to expand with a new hole...
Would it make sense to split the cases where FALLOC_FL_KEEP_SIZE is and is not used? Either passing an argument or 2 functions where one could avoid the drop. I've looked at the code only briefly, so this may be a nonsense in the end.
Quoted 2 lines
As I don't see a way to gracefully solve this except keeping
drop_extents(), lets drop this patch instead.
Understood.
Quoted 13 lines · David Sterba
Quoted 11 lines · Liu Bo
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
As
maybe_insert_holeis only called bybtrfs_cont_expandhere, which means it's a really hole, I don't expectdrop_extentswould drop anything, we can remove thisdrop_extentsand put an assert afterbtrfs_insert_file_extentfor checking EEXIST.Sounds good.
Let me make a v2 and have a fstests run.
It turns out that the
btrfs_drop_extents()here is quite necessary since fallocate(2) has aFALLOC_FL_KEEP_SIZEoption, and when that happens, a hole extent would be appended between the EOF and fallocate range's start, then a later truncate up would have to drop these hole extents in order to expand with a new hole...
Quoted 5 lines
Would it make sense to split the cases where
FALLOC_FL_KEEP_SIZEis and is not used? Either passing an argument or 2 functions where one could avoid the drop. I've looked at the code only briefly, so this may be a nonsense in the end.
I'm afraid that It won't work as there is no way I could think of to know whether an inode has been fallocate with KEEP_SIZE, IOW, seems that we have to do a search to check if there are extra extents beyond EOF.
thanks,
liubo
Quoted 4 lines
Quoted 2 lines
As I don't see a way to gracefully solve this except keeping
drop_extents(), lets drop this patch instead.Understood.