Commit

Yauhen Kharuzhy committed 834bebb

btrfs: Set mutually_exclusive_operation_running flag at auto replace start

At autoreplace start, set a fs_info->mutually_exclusive_operation_running
flag to prevent some race conditions and side effects as this done by
manual replace start routines.

Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>

Comments (0)

Files changed (1)

File fs/btrfs/dev-replace.c Modified

View file
  • Ignore whitespace
  • Hide word diff
 				struct btrfs_device *src_device)
 {
 	char *tgt_path;
-	int ret;
+	int ret = 0;
+
+	if (atomic_xchg(
+		&root->fs_info->mutually_exclusive_operation_running,
+			1)) {
+		btrfs_info(root->fs_info, "Autoreplace failed: FS is busy. Will try later\n");
+		return -EBUSY;
+	}
 
 	if (btrfs_get_spare_device(&tgt_path)) {
 		btrfs_err(root->fs_info,
 			"No spare device found/configured in the kernel");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto out;
 	}
 
 	ret = btrfs_dev_replace_start_v2(root, tgt_path, src_device);
 	if (ret)
 		btrfs_put_spare_device(tgt_path);
 
+
 	kfree(tgt_path);
 
-	return 0;
+out:
+	atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
+
+	return ret;
 }