diff mbox series

[2/9] btrfs: clear defrag status of a root if starting transaction fails

Message ID 183259751d20f64fa45dab806b7083923e718ceb.1621961965.git.dsterba@suse.com (mailing list archive)
State New, archived
Headers show
Series Misc fixups and cleanups | expand

Commit Message

David Sterba May 25, 2021, 5:08 p.m. UTC
The defrag loop processes leaves in batches and starting transaction for
each. The whole defragmentation on a given root is protected by a bit
but in case the transaction fails, the bit is not cleared

In case the transaction fails the bit would prevent starting
defragmentation again, so make sure it's cleared.

CC: stable@vger.kernel.org # 4.4+
Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/transaction.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Qu Wenruo May 25, 2021, 11:49 p.m. UTC | #1
On 2021/5/26 上午1:08, David Sterba wrote:
> The defrag loop processes leaves in batches and starting transaction for
> each. The whole defragmentation on a given root is protected by a bit
> but in case the transaction fails, the bit is not cleared
>
> In case the transaction fails the bit would prevent starting
> defragmentation again, so make sure it's cleared.
>
> CC: stable@vger.kernel.org # 4.4+
> Signed-off-by: David Sterba <dsterba@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/transaction.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index e0a82aa7da89..22951621363f 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -1406,8 +1406,10 @@ int btrfs_defrag_root(struct btrfs_root *root)
>
>   	while (1) {
>   		trans = btrfs_start_transaction(root, 0);
> -		if (IS_ERR(trans))
> -			return PTR_ERR(trans);
> +		if (IS_ERR(trans)) {
> +			ret = PTR_ERR(trans);
> +			break;
> +		}
>
>   		ret = btrfs_defrag_leaves(trans, root);
>
>
Anand Jain May 26, 2021, 6:05 a.m. UTC | #2
On 26/05/2021 01:08, David Sterba wrote:
> The defrag loop processes leaves in batches and starting transaction for
> each. The whole defragmentation on a given root is protected by a bit
> but in case the transaction fails, the bit is not cleared
> 
> In case the transaction fails the bit would prevent starting
> defragmentation again, so make sure it's cleared.
> 
> CC: stable@vger.kernel.org # 4.4+
> Signed-off-by: David Sterba <dsterba@suse.com>

Reviewed-by: Anand Jain <anand.jain@oracle.com>

Thanks.

> ---
>   fs/btrfs/transaction.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index e0a82aa7da89..22951621363f 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -1406,8 +1406,10 @@ int btrfs_defrag_root(struct btrfs_root *root)
>   
>   	while (1) {
>   		trans = btrfs_start_transaction(root, 0);
> -		if (IS_ERR(trans))
> -			return PTR_ERR(trans);
> +		if (IS_ERR(trans)) {
> +			ret = PTR_ERR(trans);
> +			break;
> +		}
>   
>   		ret = btrfs_defrag_leaves(trans, root);
>   
>
diff mbox series

Patch

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index e0a82aa7da89..22951621363f 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1406,8 +1406,10 @@  int btrfs_defrag_root(struct btrfs_root *root)
 
 	while (1) {
 		trans = btrfs_start_transaction(root, 0);
-		if (IS_ERR(trans))
-			return PTR_ERR(trans);
+		if (IS_ERR(trans)) {
+			ret = PTR_ERR(trans);
+			break;
+		}
 
 		ret = btrfs_defrag_leaves(trans, root);