btrfs: abort the transaction to avoid half deleted qgroup relationship
PATCH 1/1 btrfs: abort the transaction to avoid half deleted qgroup relationship
In __del_qgroup_relation(), if the relationship item for (src, dst) was deleted successfully, but the item for (dst, src) failed to be deleted due to other reasons (EIO, ENOMEM etc), we just return the error without updating the in-memory relationship.
This can lead to minor inconsistency between in-memory structures and on-disk metadata.
E.g. the second deletion failed with ENOMEM, but the on-disk metadata has no such item. In this particular case we can continue deleting in-memory structure.
Fix it by aborting the transaction if the first deletion succeeded, and the second deletion failed for reasons other than ENOENT.
By this we still keep the best-effert deletion attempt. E.g if one relationship item is not found, we can still continue delete whatever left and remove the relationship completely.
--- fs/btrfs/qgroup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/btrfs/qgroup.c +8 -1
@@ -1688,8 +1688,15 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src,if (ret <0 && ret != -ENOENT )return ret; ret2 =del_qgroup_relation_item (trans, dst, src); -if (ret2 <0 && ret2 != -ENOENT ) +if (ret2 <0 && ret2 != -ENOENT ) { +/* +* Abort to avoid inconsistency caused by +* half deleted relationship. +*/ +if (unlikely (!ret)) +btrfs_abort_transaction (trans, ret2);return ret2; + }/* At least one deletion succeeded, return 0 */ if (!ret || !ret2)
Signature · 1 line
2.56.1