Skip to contentSkip to conversation

Btrfs: fix mount failure when qgroup rescan is in progress

PATCH In review [email protected] 3 participants 6 messages Jun 27, 2018 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: fix mount failure when qgroup rescan is in progress

From: Filipe Manana <[email protected]>

If a power failure happens while the qgroup rescan kthread is running, the next mount operation will always fail. This is because of a recent regression that makes qgroup_rescan_init() incorrectly return -EINVAL when we are mounting the filesystem (through btrfs_read_qgroup_config()). This causes the -EINVAL error to be returned regardless of any qgroup flags being set instead of returning the error only when neither of the flags BTRFS_QGROUP_STATUS_FLAG_RESCAN nor BTRFS_QGROUP_STATUS_FLAG_ON are set.

A test case for fstests follows up soon.

Fixes 9593bf49675e ("btrfs: qgroup: show more meaningful qgroup_rescan_init error message")
---
 fs/btrfs/qgroup.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +10 -3
index 1874a6d2e6f5..d4171de93087 100644
@@ -2784,13 +2784,20 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
 
 	if (!init_flags) {
 		/* we're resuming qgroup rescan at mount time */
-		if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN))
+		if (!(fs_info->qgroup_flags &
+		      BTRFS_QGROUP_STATUS_FLAG_RESCAN)) {
 			btrfs_warn(fs_info,
 			"qgroup rescan init failed, qgroup is not enabled");
-		else if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_ON))
+			ret = -EINVAL;
+		} else if (!(fs_info->qgroup_flags &
+			     BTRFS_QGROUP_STATUS_FLAG_ON)) {
 			btrfs_warn(fs_info,
 			"qgroup rescan init failed, qgroup rescan is not queued");
-		return -EINVAL;
+			ret = -EINVAL;
+		}
+
+		if (ret)
+			return ret;
 	}
 
 	mutex_lock(&fs_info->qgroup_rescan_lock);
Signature · 1 line
2.11.0
#1 lore raw
Quoted 34 lines · On 27.06.2018 02:43, [email protected] wrote:

From: Filipe Manana <[email protected]>

If a power failure happens while the qgroup rescan kthread is running, the next mount operation will always fail. This is because of a recent regression that makes qgroup_rescan_init() incorrectly return -EINVAL when we are mounting the filesystem (through btrfs_read_qgroup_config()). This causes the -EINVAL error to be returned regardless of any qgroup flags being set instead of returning the error only when neither of the flags BTRFS_QGROUP_STATUS_FLAG_RESCAN nor BTRFS_QGROUP_STATUS_FLAG_ON are set.

A test case for fstests follows up soon.

Fixes 9593bf49675e ("btrfs: qgroup: show more meaningful qgroup_rescan_init error message")
---
 fs/btrfs/qgroup.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +3 -2
index 1874a6d2e6f5..d4171de93087 100644
@@ -2784,13 +2784,20 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
 
 	if (!init_flags) {
 		/* we're resuming qgroup rescan at mount time */
-		if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN))
+		if (!(fs_info->qgroup_flags &
+		      BTRFS_QGROUP_STATUS_FLAG_RESCAN)) {
 			btrfs_warn(fs_info,
 			"qgroup rescan init failed, qgroup is not enabled");
-		else if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_ON))
+			ret = -EINVAL;

fs/btrfs/qgroup.c qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid, · line 2800

Quoted 10 lines
fs/btrfs/qgroup.c +7 -1
+		} else if (!(fs_info->qgroup_flags &
+			     BTRFS_QGROUP_STATUS_FLAG_ON)) {
 			btrfs_warn(fs_info,
 			"qgroup rescan init failed, qgroup rescan is not queued");
-		return -EINVAL;
+			ret = -EINVAL;
+		}
+
+		if (ret)
+			return ret;

How is this patch functionally different than the old code. In both cases if either of those 2 is not set a warn is printed and -EINVAL is returned?

Quoted 4 lines
fs/btrfs/qgroup.c +0 -0
 	}
 
 	mutex_lock(&fs_info->qgroup_rescan_lock);
#2 lore raw
Quoted 44 lines · Nikolay Borisov
Quoted 41 lines · On 27.06.2018 02:43, [email protected] wrote:

From: Filipe Manana <[email protected]>

If a power failure happens while the qgroup rescan kthread is running, the next mount operation will always fail. This is because of a recent regression that makes qgroup_rescan_init() incorrectly return -EINVAL when we are mounting the filesystem (through btrfs_read_qgroup_config()). This causes the -EINVAL error to be returned regardless of any qgroup flags being set instead of returning the error only when neither of the flags BTRFS_QGROUP_STATUS_FLAG_RESCAN nor BTRFS_QGROUP_STATUS_FLAG_ON are set.

A test case for fstests follows up soon.

Fixes 9593bf49675e ("btrfs: qgroup: show more meaningful qgroup_rescan_init error message")
---
 fs/btrfs/qgroup.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +7 -3
index 1874a6d2e6f5..d4171de93087 100644
@@ -2784,13 +2784,20 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
 
      if (!init_flags) {
              /* we're resuming qgroup rescan at mount time */
-             if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN))
+             if (!(fs_info->qgroup_flags &
+                   BTRFS_QGROUP_STATUS_FLAG_RESCAN)) {
                      btrfs_warn(fs_info,
                      "qgroup rescan init failed, qgroup is not enabled");
-             else if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_ON))
+                     ret = -EINVAL;
+             } else if (!(fs_info->qgroup_flags &
+                          BTRFS_QGROUP_STATUS_FLAG_ON)) {
                      btrfs_warn(fs_info,
                      "qgroup rescan init failed, qgroup rescan is not queued");
-             return -EINVAL;
+                     ret = -EINVAL;
+             }
Quoted 8 lines

fs/btrfs/qgroup.c qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid, · line 2800

Quoted 3 lines
fs/btrfs/qgroup.c +3 -0
+
+             if (ret)
+                     return ret;

How is this patch functionally different than the old code. In both cases if either of those 2 is not set a warn is printed and -EINVAL is returned?

It is explained in the changelog:

"This is because of a recent
regression that makes qgroup_rescan_init() incorrectly return -EINVAL when we are mounting the filesystem (through btrfs_read_qgroup_config()). This causes the -EINVAL error to be returned regardless of any qgroup flags being set instead of returning the error only when neither of the flags BTRFS_QGROUP_STATUS_FLAG_RESCAN nor BTRFS_QGROUP_STATUS_FLAG_ON are set."

If you can't understand it, try the test case...

Quoted 5 lines
Quoted 5 lines
fs/btrfs/qgroup.c +0 -0
      }
 
      mutex_lock(&fs_info->qgroup_rescan_lock);
#3 lore raw
Quoted 54 lines · Filipe Manana
Quoted 44 lines · Nikolay Borisov
Quoted 41 lines · On 27.06.2018 02:43, [email protected] wrote:

From: Filipe Manana <[email protected]>

If a power failure happens while the qgroup rescan kthread is running, the next mount operation will always fail. This is because of a recent regression that makes qgroup_rescan_init() incorrectly return -EINVAL when we are mounting the filesystem (through btrfs_read_qgroup_config()). This causes the -EINVAL error to be returned regardless of any qgroup flags being set instead of returning the error only when neither of the flags BTRFS_QGROUP_STATUS_FLAG_RESCAN nor BTRFS_QGROUP_STATUS_FLAG_ON are set.

A test case for fstests follows up soon.

Fixes 9593bf49675e ("btrfs: qgroup: show more meaningful qgroup_rescan_init error message")
---
 fs/btrfs/qgroup.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +7 -3
index 1874a6d2e6f5..d4171de93087 100644
@@ -2784,13 +2784,20 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
 
      if (!init_flags) {
              /* we're resuming qgroup rescan at mount time */
-             if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN))
+             if (!(fs_info->qgroup_flags &
+                   BTRFS_QGROUP_STATUS_FLAG_RESCAN)) {
                      btrfs_warn(fs_info,
                      "qgroup rescan init failed, qgroup is not enabled");
-             else if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_ON))
+                     ret = -EINVAL;
+             } else if (!(fs_info->qgroup_flags &
+                          BTRFS_QGROUP_STATUS_FLAG_ON)) {
                      btrfs_warn(fs_info,
                      "qgroup rescan init failed, qgroup rescan is not queued");
-             return -EINVAL;
+                     ret = -EINVAL;
+             }
Quoted 8 lines

fs/btrfs/qgroup.c qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid, · line 2800

Quoted 3 lines
fs/btrfs/qgroup.c +3 -0
+
+             if (ret)
+                     return ret;

How is this patch functionally different than the old code. In both cases if either of those 2 is not set a warn is printed and -EINVAL is returned?

Quoted 1 line

It is explained in the changelog:

No need to be snide

Quoted 10 lines

"This is because of a recent
regression that makes qgroup_rescan_init() incorrectly return -EINVAL when we are mounting the filesystem (through btrfs_read_qgroup_config()). This causes the -EINVAL error to be returned regardless of any qgroup flags being set instead of returning the error only when neither of the flags BTRFS_QGROUP_STATUS_FLAG_RESCAN nor BTRFS_QGROUP_STATUS_FLAG_ON are set."

If you can't understand it, try the test case...

Ok I see it now, however your description contradicts the code. Currently -EINVAL will be returned when either of the 2 flags is unset i.e

!BTRFS_QGROUP_STATUS_FLAG_RESCAN && BTRFS_QGROUP_STATUS_FLAG_ON !BTRFS_QGROUP_STATUS_FLAG_ON && BTRFS_QGROUP_STATUS_FLAG_RESCAN

and in your description you refer to neither that is the 2 flags being unset. Perhaps those combinations are invalid due to some other reasons which are not visible in the code but in this case the changelog should be expanded to cover why those 2 combinations are impossible (because if they are -EINVAL is still likely ) ?

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
fs/btrfs/qgroup.c +0 -0
      }
 
      mutex_lock(&fs_info->qgroup_rescan_lock);
#4 lore raw
Quoted 57 lines · Nikolay Borisov
Quoted 54 lines · Filipe Manana
Quoted 52 lines · Nikolay Borisov
Quoted 34 lines · On 27.06.2018 02:43, [email protected] wrote:

From: Filipe Manana <[email protected]>

If a power failure happens while the qgroup rescan kthread is running, the next mount operation will always fail. This is because of a recent regression that makes qgroup_rescan_init() incorrectly return -EINVAL when we are mounting the filesystem (through btrfs_read_qgroup_config()). This causes the -EINVAL error to be returned regardless of any qgroup flags being set instead of returning the error only when neither of the flags BTRFS_QGROUP_STATUS_FLAG_RESCAN nor BTRFS_QGROUP_STATUS_FLAG_ON are set.

A test case for fstests follows up soon.

Fixes 9593bf49675e ("btrfs: qgroup: show more meaningful qgroup_rescan_init error message")
---
 fs/btrfs/qgroup.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +3 -2
index 1874a6d2e6f5..d4171de93087 100644
@@ -2784,13 +2784,20 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
 
      if (!init_flags) {
              /* we're resuming qgroup rescan at mount time */
-             if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN))
+             if (!(fs_info->qgroup_flags &
+                   BTRFS_QGROUP_STATUS_FLAG_RESCAN)) {
                      btrfs_warn(fs_info,
                      "qgroup rescan init failed, qgroup is not enabled");
-             else if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_ON))
+                     ret = -EINVAL;

fs/btrfs/qgroup.c qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid, · line 2800

Quoted 10 lines
fs/btrfs/qgroup.c +7 -1
+             } else if (!(fs_info->qgroup_flags &
+                          BTRFS_QGROUP_STATUS_FLAG_ON)) {
                      btrfs_warn(fs_info,
                      "qgroup rescan init failed, qgroup rescan is not queued");
-             return -EINVAL;
+                     ret = -EINVAL;
+             }
+
+             if (ret)
+                     return ret;

How is this patch functionally different than the old code. In both cases if either of those 2 is not set a warn is printed and -EINVAL is returned?

Quoted 3 lines
Quoted 1 line

It is explained in the changelog:

No need to be snide

No one's being snide. Simply, I can't see how the changelog doesn't explain (what is already quite easy to notice from the code).

Quoted 15 lines
Quoted 11 lines

"This is because of a recent
regression that makes qgroup_rescan_init() incorrectly return -EINVAL when we are mounting the filesystem (through btrfs_read_qgroup_config()). This causes the -EINVAL error to be returned regardless of any qgroup flags being set instead of returning the error only when neither of the flags BTRFS_QGROUP_STATUS_FLAG_RESCAN nor BTRFS_QGROUP_STATUS_FLAG_ON are set."

If you can't understand it, try the test case...

Ok I see it now, however your description contradicts the code. Currently -EINVAL will be returned when either of the 2 flags is unset i.e

Quoted 8 lines

!BTRFS_QGROUP_STATUS_FLAG_RESCAN && BTRFS_QGROUP_STATUS_FLAG_ON !BTRFS_QGROUP_STATUS_FLAG_ON && BTRFS_QGROUP_STATUS_FLAG_RESCAN

and in your description you refer to neither that is the 2 flags being unset. Perhaps those combinations are invalid due to some other reasons which are not visible in the code but in this case the changelog should be expanded to cover why those 2 combinations are impossible (because if they are -EINVAL is still likely ) ?

I don't think the changelog is contradictory.
It says that -EINVAL is always returned, independently of which qgroup flags are set/missing.
Further it says that the error should be returned only when one of those 2 qgroup flags is not set (or both are not set).

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
fs/btrfs/qgroup.c +0 -0
      }
 
      mutex_lock(&fs_info->qgroup_rescan_lock);
Reviewed-by on v1 1/1
#5 lore raw
In reply to [email protected]
Quoted 10 lines · On 2018年06月27日 07:43, [email protected] wrote:

From: Filipe Manana <[email protected]>

If a power failure happens while the qgroup rescan kthread is running, the next mount operation will always fail. This is because of a recent regression that makes qgroup_rescan_init() incorrectly return -EINVAL when we are mounting the filesystem (through btrfs_read_qgroup_config()). This causes the -EINVAL error to be returned regardless of any qgroup flags being set instead of returning the error only when neither of the flags BTRFS_QGROUP_STATUS_FLAG_RESCAN nor BTRFS_QGROUP_STATUS_FLAG_ON are set.

My fault.

Quoted 5 lines

A test case for fstests follows up soon.

Fixes 9593bf49675e ("btrfs: qgroup: show more meaningful qgroup_rescan_init error message")

Thanks,
Qu

Quoted 33 lines
---
 fs/btrfs/qgroup.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +10 -3
index 1874a6d2e6f5..d4171de93087 100644
@@ -2784,13 +2784,20 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
 
 	if (!init_flags) {
 		/* we're resuming qgroup rescan at mount time */
-		if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN))
+		if (!(fs_info->qgroup_flags &
+		      BTRFS_QGROUP_STATUS_FLAG_RESCAN)) {
 			btrfs_warn(fs_info,
 			"qgroup rescan init failed, qgroup is not enabled");
-		else if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_ON))
+			ret = -EINVAL;
+		} else if (!(fs_info->qgroup_flags &
+			     BTRFS_QGROUP_STATUS_FLAG_ON)) {
 			btrfs_warn(fs_info,
 			"qgroup rescan init failed, qgroup rescan is not queued");
-		return -EINVAL;
+			ret = -EINVAL;
+		}
+
+		if (ret)
+			return ret;
 	}
 
 	mutex_lock(&fs_info->qgroup_rescan_lock);