Skip to contentSkip to conversation

btrfs: qgroup: exit the rescan worker during umount

PATCH Superseded Justin Maggard 3 participants 5 messages Sep 3, 2015 – Oct 8, 2015 Btrfs file system

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs: qgroup: exit the rescan worker during umount

v2: Fix stupid error while making formatting changes...

I was hitting a consistent NULL pointer dereference during shutdown that showed the trace running through end_workqueue_bio(). I traced it back to the endio_meta_workers workqueue being poked after it had already been destroyed.

Eventually I found that the root cause was a qgroup rescan that was still in progress while we were stopping all the btrfs workers.

Currently we explicitly pause balance and scrub operations in close_ctree(), but we do nothing to stop the qgroup rescan. We should probably be doing the same for qgroup rescan, but that's a much larger change. This small change is good enough to allow me to unmount without crashing.

---
 fs/btrfs/qgroup.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +6 -3
index d904ee1..5bfcee9 100644
@@ -2278,7 +2278,7 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
 		goto out;
 
 	err = 0;
-	while (!err) {
+	while (!err && !btrfs_fs_closing(fs_info)) {
 		trans = btrfs_start_transaction(fs_info->fs_root, 0);
 		if (IS_ERR(trans)) {
 			err = PTR_ERR(trans);
@@ -2301,7 +2301,8 @@ out:
 	btrfs_free_path(path);
 
 	mutex_lock(&fs_info->qgroup_rescan_lock);
-	fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
+	if (!btrfs_fs_closing(fs_info))
+		fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
 
 	if (err > 0 &&
 	    fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT) {
@@ -2330,7 +2331,9 @@ out:
 	}
 	btrfs_end_transaction(trans, fs_info->quota_root);
 
-	if (err >= 0) {
+	if (btrfs_fs_closing(fs_info)) {
+		btrfs_info(fs_info, "qgroup scan paused");
+	} else if (err >= 0) {
 		btrfs_info(fs_info, "qgroup scan completed%s",
 			err > 0 ? " (inconsistency flag cleared)" : "");
 	} else {
Signature · 1 line
2.5.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 1 line · Justin Maggard

v2: Fix stupid error while making formatting changes...

I haven't noticed any difference between the patches, what exactly did you change?

Quoted 8 lines

I was hitting a consistent NULL pointer dereference during shutdown that showed the trace running through end_workqueue_bio(). I traced it back to the endio_meta_workers workqueue being poked after it had already been destroyed.

Eventually I found that the root cause was a qgroup rescan that was still in progress while we were stopping all the btrfs workers.

Quoted 7 lines

Currently we explicitly pause balance and scrub operations in close_ctree(), but we do nothing to stop the qgroup rescan. We should probably be doing the same for qgroup rescan, but that's a much larger change. This small change is good enough to allow me to unmount without crashing.

Can you please submit the test you've used to trigger the crash to fstests?

#2 lore raw
Quoted 6 lines · David Sterba
Quoted 1 line · Justin Maggard

v2: Fix stupid error while making formatting changes...

I haven't noticed any difference between the patches, what exactly did you change?

I broke compiling while cleaning up some checkpatch.pl feedback. Here's what changed between v1 and v2:

- if (!btrfs_fs_closing(fs_info)) {
+ if (!btrfs_fs_closing(fs_info))

Quoted 14 lines
Quoted 14 lines

I was hitting a consistent NULL pointer dereference during shutdown that showed the trace running through end_workqueue_bio(). I traced it back to the endio_meta_workers workqueue being poked after it had already been destroyed.

Eventually I found that the root cause was a qgroup rescan that was still in progress while we were stopping all the btrfs workers.

Currently we explicitly pause balance and scrub operations in close_ctree(), but we do nothing to stop the qgroup rescan. We should probably be doing the same for qgroup rescan, but that's a much larger change. This small change is good enough to allow me to unmount without crashing.

Quoted 5 lines
Quoted 1 line

Can you please submit the test you've used to trigger the crash to fstests?

Sure, I've got a reproducer coded up for xfstests now. Should I just send that to this list, or is there a better place to send it?

-Justin

#3 lore raw
Quoted 29 lines · Justin Maggard
Quoted 6 lines · David Sterba
Quoted 1 line · Justin Maggard

v2: Fix stupid error while making formatting changes...

I haven't noticed any difference between the patches, what exactly did you change?

I broke compiling while cleaning up some checkpatch.pl feedback. Here's what changed between v1 and v2:

(quoted diff) +1 -1
-       if (!btrfs_fs_closing(fs_info)) {
+       if (!btrfs_fs_closing(fs_info))
Quoted 16 lines
Quoted 16 lines

I was hitting a consistent NULL pointer dereference during shutdown that showed the trace running through end_workqueue_bio(). I traced it back to the endio_meta_workers workqueue being poked after it had already been destroyed.

Eventually I found that the root cause was a qgroup rescan that was still in progress while we were stopping all the btrfs workers.

Currently we explicitly pause balance and scrub operations in close_ctree(), but we do nothing to stop the qgroup rescan. We should probably be doing the same for qgroup rescan, but that's a much larger change. This small change is good enough to allow me to unmount without crashing.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Can you please submit the test you've used to trigger the crash to fstests?

Sure, I've got a reproducer coded up for xfstests now. Should I just send that to this list, or is there a better place to send it?

Just send it to [email protected] with the btrfs mailing list on cc. If you take a look at test submission emails in the btrfs mailing list, you'll see how it's usually done.

thanks

Quoted 6 lines

-Justin
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 5 lines
Filipe David Manana,

"Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men."
#4 lore raw
In reply to Justin Maggard
Quoted 45 lines · Justin Maggard

v2: Fix stupid error while making formatting changes...

I was hitting a consistent NULL pointer dereference during shutdown that showed the trace running through end_workqueue_bio(). I traced it back to the endio_meta_workers workqueue being poked after it had already been destroyed.

Eventually I found that the root cause was a qgroup rescan that was still in progress while we were stopping all the btrfs workers.

Currently we explicitly pause balance and scrub operations in close_ctree(), but we do nothing to stop the qgroup rescan. We should probably be doing the same for qgroup rescan, but that's a much larger change. This small change is good enough to allow me to unmount without crashing.

---
 fs/btrfs/qgroup.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +3 -2
index d904ee1..5bfcee9 100644
@@ -2278,7 +2278,7 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
                goto out;
 
        err = 0;
-       while (!err) {
+       while (!err && !btrfs_fs_closing(fs_info)) {
                trans = btrfs_start_transaction(fs_info->fs_root, 0);
                if (IS_ERR(trans)) {
                        err = PTR_ERR(trans);
@@ -2301,7 +2301,8 @@ out:
        btrfs_free_path(path);
 
        mutex_lock(&fs_info->qgroup_rescan_lock);
-       fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
+       if (!btrfs_fs_closing(fs_info))
+               fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
 
        if (err > 0 &&
            fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT) {

fs/btrfs/qgroup.c out: · line 2339

Quoted 10 lines
fs/btrfs/qgroup.c +3 -1
@@ -2330,7 +2331,9 @@ out:
        }
        btrfs_end_transaction(trans, fs_info->quota_root);
 
-       if (err >= 0) {
+       if (btrfs_fs_closing(fs_info)) {
+               btrfs_info(fs_info, "qgroup scan paused");
+       } else if (err >= 0) {
                btrfs_info(fs_info, "qgroup scan completed%s",
                        err > 0 ? " (inconsistency flag cleared)" : "");
        } else {

Justin, this is still racy (however much less racy than before).

Once we leave the loop because of the condition btrfs_fs_closing(fs_info), we start a transaction and do some write operation on the quota btree. While or before we do such write operation, close_ctree() might have completed or be at a point where such write operation will result in another null pointer dereference, or accessing some dangling pointer, or leak a transaction that never gets committed (because close_ctree() already stopped the transaction kthread), etc, etc.

So in addition to what you did, you need to call btrfs_qgroup_wait_for_completion(fs_info) at disk-io.c:close_ctree() right after setting fs_info->closing to 1.

Otherwise it looks good.
Thanks.

Quoted 7 lines

--
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 5 lines
Filipe David Manana,

"Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men."