btrfs: fixes for missing error reporting when attaching to a transaction
cover btrfs: fixes for missing error reporting when attaching to a transaction
From: Filipe Manana <[email protected]>
These fix missing error checks and returns when attaching to a transaction in barrier mode, and waiting for a transaction to commit and finish. These can make things like an fsync that fallbacks to a transaction commit to report success to user space when a transaction was aborted and the inode changes were therefore not persisted. More details on the change logs.
Filipe Manana (2):
btrfs: check if the transaction was aborted at btrfs_wait_for_commit()
btrfs: check for commit error at btrfs_attach_transaction_barrier()
fs/btrfs/transaction.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 btrfs: check if the transaction was aborted at btrfs_wait_for_commit()
From: Filipe Manana <[email protected]>
At btrfs_wait_for_commit() we wait for a transaction to finish and then always return 0 (success) without checking if it was aborted, in which case the transaction didn't happen due to some critical error. Fix this by checking if the transaction was aborted.
--- fs/btrfs/transaction.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/transaction.c +1 -0
@@ -931,6 +931,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid) }wait_for_commit (cur_trans,TRANS_STATE_COMPLETED ); + ret = cur_trans->aborted;btrfs_put_transaction (cur_trans); out:return ret;
Signature · 1 line
2.34.1
PATCH 2/2 btrfs: check for commit error at btrfs_attach_transaction_barrier()
In reply to [email protected]From: Filipe Manana <[email protected]>
btrfs_attach_transaction_barrier() is used to get a handle pointing to the current running transaction if the transaction has not started its commit yet (its state is < TRANS_STATE_COMMIT_START). If the transaction commit has started, then we wait for the transaction to commit and finish before returning - however we completely ignore if the transaction was aborted due to some error during its commit, we simply return ERR_PT(-ENOENT), which makes the caller assume everything is fine and no errors happened.
This could make an fsync return success (0) to user space when in fact we had a transaction abort and the target inode changes were therefore not persisted.
Fix this by checking for the return value from btrfs_wait_for_commit(), and if it returned an error, return it back to the caller.
--- fs/btrfs/transaction.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/btrfs/transaction.c +7 -2
@@ -826,8 +826,13 @@ btrfs_attach_transaction_barrier(struct btrfs_root *root) trans =start_transaction (root,0 ,TRANS_ATTACH ,BTRFS_RESERVE_NO_FLUSH , true); -if (trans ==ERR_PTR (-ENOENT )) -btrfs_wait_for_commit (root->fs_info,0 ); +if (trans ==ERR_PTR (-ENOENT )) { +int ret; + + ret =btrfs_wait_for_commit (root->fs_info,0 ); +if (ret) +return ERR_PTR (ret); + }return trans; }
Signature · 1 line
2.34.1
Re: [PATCH 2/2] btrfs: check for commit error at btrfs_attach_transaction_barrier()
Quoted 14 lines · On 2023/7/21 17:49, [email protected] wrote:
From: Filipe Manana <[email protected]>
btrfs_attach_transaction_barrier()is used to get a handle pointing to the current running transaction if the transaction has not started its commit yet (its state is <TRANS_STATE_COMMIT_START). If the transaction commit has started, then we wait for the transaction to commit and finish before returning - however we completely ignore if the transaction was aborted due to some error during its commit, we simply returnERR_PT(-ENOENT), which makes the caller assume everything is fine and no errors happened.This could make an fsync return success (0) to user space when in fact we had a transaction abort and the target inode changes were therefore not persisted.
Quoted 5 lines
Fix this by checking for the return value from
btrfs_wait_for_commit(), and if it returned an error, return it back to the caller.Fixes d4edf39bd5db ("Btrfs: fix uncompleted transaction")Signed-off-by Filipe Manana <[email protected]>
Thanks,
Qu
Quoted 24 lines
--- fs/btrfs/transaction.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)fs/btrfs/transaction.c +7
-2@@ -826,8 +826,13 @@ btrfs_attach_transaction_barrier(struct btrfs_root *root) trans =start_transaction (root,0 ,TRANS_ATTACH ,BTRFS_RESERVE_NO_FLUSH , true); -if (trans ==ERR_PTR (-ENOENT )) -btrfs_wait_for_commit (root->fs_info,0 ); +if (trans ==ERR_PTR (-ENOENT )) { +int ret; + + ret =btrfs_wait_for_commit (root->fs_info,0 ); +if (ret) +return ERR_PTR (ret); + }return trans; }
Re: [PATCH 1/2] btrfs: check if the transaction was aborted at btrfs_wait_for_commit()
In reply to [email protected]Quoted 9 lines · On 2023/7/21 17:49, [email protected] wrote:
From: Filipe Manana <[email protected]>
At
btrfs_wait_for_commit()we wait for a transaction to finish and then always return 0 (success) without checking if it was aborted, in which case the transaction didn't happen due to some critical error. Fix this by checking if the transaction was aborted.Fixes 462045928bda ("Btrfs: add START_SYNC, WAIT_SYNC ioctls")Signed-off-by Filipe Manana <[email protected]>
Thanks,
Qu
Quoted 16 lines
--- fs/btrfs/transaction.c | 1 + 1 file changed, 1 insertion(+)fs/btrfs/transaction.c +1
-0@@ -931,6 +931,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid) }wait_for_commit (cur_trans,TRANS_STATE_COMPLETED ); + ret = cur_trans->aborted;btrfs_put_transaction (cur_trans); out:return ret;
Quoted 11 lines · On Fri, Jul 21, 2023 at 10:49:19AM +0100, [email protected] wrote:
From: Filipe Manana <[email protected]>
These fix missing error checks and returns when attaching to a transaction in barrier mode, and waiting for a transaction to commit and finish. These can make things like an fsync that fallbacks to a transaction commit to report success to user space when a transaction was aborted and the inode changes were therefore not persisted. More details on the change logs.
Filipe Manana (2):
btrfs: check if the transaction was aborted atbtrfs_wait_for_commit()
btrfs: check for commit error atbtrfs_attach_transaction_barrier()
Added to misc-next, thanks.