diff options
author | Jeff Mahoney <jeffm@suse.com> | 2016-08-15 12:10:33 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2016-08-25 06:58:19 -0400 |
commit | d2c609b834d62f1e91f1635a27dca29f7806d3d6 (patch) | |
tree | 446eb20c30b212f1ad9def7dc95cb156fd3a2951 | |
parent | eecba891d38051ebf7f4af6394d188a5fd151a6a (diff) |
btrfs: properly track when rescan worker is running
The qgroup_flags field is overloaded such that it reflects the on-disk
status of qgroups and the runtime state. The BTRFS_QGROUP_STATUS_FLAG_RESCAN
flag is used to indicate that a rescan operation is in progress, but if
the file system is unmounted while a rescan is running, the rescan
operation is paused. If the file system is then mounted read-only,
the flag will still be present but the rescan operation will not have
been resumed. When we go to umount, btrfs_qgroup_wait_for_completion
will see the flag and interpret it to mean that the rescan worker is
still running and will wait for a completion that will never come.
This patch uses a separate flag to indicate when the worker is
running. The locking and state surrounding the qgroup rescan worker
needs a lot of attention beyond this patch but this is enough to
avoid a hung umount.
Cc: <stable@vger.kernel.org> # v4.4+
Signed-off-by; Jeff Mahoney <jeffm@suse.com>
Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r-- | fs/btrfs/ctree.h | 1 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 1 | ||||
-rw-r--r-- | fs/btrfs/qgroup.c | 9 |
3 files changed, 10 insertions, 1 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index f66a0ba9a2a9..acc6850a118f 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -1028,6 +1028,7 @@ struct btrfs_fs_info { | |||
1028 | struct btrfs_workqueue *qgroup_rescan_workers; | 1028 | struct btrfs_workqueue *qgroup_rescan_workers; |
1029 | struct completion qgroup_rescan_completion; | 1029 | struct completion qgroup_rescan_completion; |
1030 | struct btrfs_work qgroup_rescan_work; | 1030 | struct btrfs_work qgroup_rescan_work; |
1031 | bool qgroup_rescan_running; /* protected by qgroup_rescan_lock */ | ||
1031 | 1032 | ||
1032 | /* filesystem state */ | 1033 | /* filesystem state */ |
1033 | unsigned long fs_state; | 1034 | unsigned long fs_state; |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 4a34c9fcc1a7..f5b2a7fb4575 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -2304,6 +2304,7 @@ static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info) | |||
2304 | fs_info->quota_enabled = 0; | 2304 | fs_info->quota_enabled = 0; |
2305 | fs_info->pending_quota_state = 0; | 2305 | fs_info->pending_quota_state = 0; |
2306 | fs_info->qgroup_ulist = NULL; | 2306 | fs_info->qgroup_ulist = NULL; |
2307 | fs_info->qgroup_rescan_running = false; | ||
2307 | mutex_init(&fs_info->qgroup_rescan_lock); | 2308 | mutex_init(&fs_info->qgroup_rescan_lock); |
2308 | } | 2309 | } |
2309 | 2310 | ||
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 93ee1c18ef9d..3fe295e2c84a 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c | |||
@@ -2303,6 +2303,10 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work) | |||
2303 | int err = -ENOMEM; | 2303 | int err = -ENOMEM; |
2304 | int ret = 0; | 2304 | int ret = 0; |
2305 | 2305 | ||
2306 | mutex_lock(&fs_info->qgroup_rescan_lock); | ||
2307 | fs_info->qgroup_rescan_running = true; | ||
2308 | mutex_unlock(&fs_info->qgroup_rescan_lock); | ||
2309 | |||
2306 | path = btrfs_alloc_path(); | 2310 | path = btrfs_alloc_path(); |
2307 | if (!path) | 2311 | if (!path) |
2308 | goto out; | 2312 | goto out; |
@@ -2369,6 +2373,9 @@ out: | |||
2369 | } | 2373 | } |
2370 | 2374 | ||
2371 | done: | 2375 | done: |
2376 | mutex_lock(&fs_info->qgroup_rescan_lock); | ||
2377 | fs_info->qgroup_rescan_running = false; | ||
2378 | mutex_unlock(&fs_info->qgroup_rescan_lock); | ||
2372 | complete_all(&fs_info->qgroup_rescan_completion); | 2379 | complete_all(&fs_info->qgroup_rescan_completion); |
2373 | } | 2380 | } |
2374 | 2381 | ||
@@ -2494,7 +2501,7 @@ int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info) | |||
2494 | 2501 | ||
2495 | mutex_lock(&fs_info->qgroup_rescan_lock); | 2502 | mutex_lock(&fs_info->qgroup_rescan_lock); |
2496 | spin_lock(&fs_info->qgroup_lock); | 2503 | spin_lock(&fs_info->qgroup_lock); |
2497 | running = fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN; | 2504 | running = fs_info->qgroup_rescan_running; |
2498 | spin_unlock(&fs_info->qgroup_lock); | 2505 | spin_unlock(&fs_info->qgroup_lock); |
2499 | mutex_unlock(&fs_info->qgroup_rescan_lock); | 2506 | mutex_unlock(&fs_info->qgroup_rescan_lock); |
2500 | 2507 | ||