btrfs: introduce exclusive operation BALANCE_PAUSED state
[sfrench/cifs-2.6.git] / fs / btrfs / volumes.c
index 4f77268619f33716f7abd4c446d3f47f45285f52..9db9d66b54704c7567e30b2c3d165e55829b6597 100644 (file)
@@ -4394,8 +4394,10 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
        ret = __btrfs_balance(fs_info);
 
        mutex_lock(&fs_info->balance_mutex);
-       if (ret == -ECANCELED && atomic_read(&fs_info->balance_pause_req))
+       if (ret == -ECANCELED && atomic_read(&fs_info->balance_pause_req)) {
                btrfs_info(fs_info, "balance: paused");
+               btrfs_exclop_balance(fs_info, BTRFS_EXCLOP_BALANCE_PAUSED);
+       }
        /*
         * Balance can be canceled by:
         *
@@ -4471,6 +4473,10 @@ int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info)
                return 0;
        }
 
+       spin_lock(&fs_info->super_lock);
+       ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED);
+       fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE;
+       spin_unlock(&fs_info->super_lock);
        /*
         * A ro->rw remount sequence should continue with the paused balance
         * regardless of who pauses it, system or the user as of now, so set
@@ -4539,7 +4545,7 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
         * is in a paused state and must have fs_info::balance_ctl properly
         * set up.
         */
-       if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE))
+       if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE_PAUSED))
                btrfs_warn(fs_info,
        "balance: cannot set exclusive op status, resume manually");