diff mbox

[05/10] Btrfs: don't release reserve or decrement orphan count if orphan item already existed

Message ID ea8803dda4166f74f674385d81f96c6b0e8256f5.1525932796.git.osandov@fb.com (mailing list archive)
State New, archived
Headers show

Commit Message

Omar Sandoval May 10, 2018, 6:21 a.m. UTC
From: Omar Sandoval <osandov@fb.com>

Currently, if btrfs_insert_orphan_item() fails, we release the reserved
space and decrement root->orphan_inodes. However, we also ignore -EEXIST
errors, so we still want the space reservation for when we delete the
item, and we still need to count the orphan because we're still going to
decrement root->orphan_inodes from btrfs_orphan_del() later.

Fixes: 4ef31a45a009 ("Btrfs: fix the error handling wrt orphan items")
Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 fs/btrfs/inode.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Nikolay Borisov May 10, 2018, 8:23 a.m. UTC | #1
On 10.05.2018 09:21, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> Currently, if btrfs_insert_orphan_item() fails, we release the reserved
> space and decrement root->orphan_inodes. However, we also ignore -EEXIST
> errors, so we still want the space reservation for when we delete the
> item, and we still need to count the orphan because we're still going to
> decrement root->orphan_inodes from btrfs_orphan_del() later.
> 
> Fixes: 4ef31a45a009 ("Btrfs: fix the error handling wrt orphan items")
> Signed-off-by: Omar Sandoval <osandov@fb.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  fs/btrfs/inode.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 1460823951d7..e77df96de642 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -3408,7 +3408,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans,
>  	/* insert an orphan item to track this unlinked file */
>  	if (insert) {
>  		ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode));
> -		if (ret) {
> +		if (ret && ret != -EEXIST) {
>  			if (reserve) {
>  				clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
>  					  &inode->runtime_flags);
> @@ -3420,14 +3420,11 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans,
>  			 * decrease ->orphan_inodes after everything is done.
>  			 */
>  			atomic_dec(&root->orphan_inodes);
> -			if (ret != -EEXIST) {
> -				clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
> -					  &inode->runtime_flags);
> -				btrfs_abort_transaction(trans, ret);
> -				return ret;
> -			}
> +			clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
> +				  &inode->runtime_flags);
> +			btrfs_abort_transaction(trans, ret);
> +			return ret;
>  		}
> -		ret = 0;
>  	}
>  
>  	return 0;
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 1460823951d7..e77df96de642 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3408,7 +3408,7 @@  int btrfs_orphan_add(struct btrfs_trans_handle *trans,
 	/* insert an orphan item to track this unlinked file */
 	if (insert) {
 		ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode));
-		if (ret) {
+		if (ret && ret != -EEXIST) {
 			if (reserve) {
 				clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
 					  &inode->runtime_flags);
@@ -3420,14 +3420,11 @@  int btrfs_orphan_add(struct btrfs_trans_handle *trans,
 			 * decrease ->orphan_inodes after everything is done.
 			 */
 			atomic_dec(&root->orphan_inodes);
-			if (ret != -EEXIST) {
-				clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
-					  &inode->runtime_flags);
-				btrfs_abort_transaction(trans, ret);
-				return ret;
-			}
+			clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
+				  &inode->runtime_flags);
+			btrfs_abort_transaction(trans, ret);
+			return ret;
 		}
-		ret = 0;
 	}
 
 	return 0;