Skip to contentSkip to conversation

Remove balance v1 ioctl

PATCH In review Nikolay Borisov 3 participants 6 messages Mar 30, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover Remove balance v1 ioctl

It was slated for removal in 5.18. So here are the patches which remove the relevant bits (patch 1 and 2). As a result of this simplification code can be juggled around a bit so further simplify btrfs_ioctl_balance(patch 3).

Nikolay Borisov (3):
btrfs: remove balance v1 ioctl
btrfs: remove checks for arg argument in btrfs_ioctl_balance
btrfs: simplify codeflow in btrfs_ioctl_balance

 fs/btrfs/ioctl.c | 69 ++++++++++++++++++------------------------------
 1 file changed, 25 insertions(+), 44 deletions(-)

--
2.25.1

#1 lore raw

PATCH 1/3 btrfs: remove balance v1 ioctl

It was scheduled for removal in kernel v5.18 thus its time has come.

---
 fs/btrfs/ioctl.c | 2 --
 1 file changed, 2 deletions(-)
fs/btrfs/ioctl.c +0 -2
index 9e81c8c5000c..fe00dd88c281 100644
@@ -5459,8 +5459,6 @@ long btrfs_ioctl(struct file *file, unsigned int
 		return btrfs_ioctl_fs_info(fs_info, argp);
 	case BTRFS_IOC_DEV_INFO:
 		return btrfs_ioctl_dev_info(fs_info, argp);
-	case BTRFS_IOC_BALANCE:
-		return btrfs_ioctl_balance(file, NULL);
 	case BTRFS_IOC_TREE_SEARCH:
 		return btrfs_ioctl_tree_search(inode, argp);
 	case BTRFS_IOC_TREE_SEARCH_V2:
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/3 btrfs: remove checks for arg argument in btrfs_ioctl_balance

In reply to Nikolay Borisov

With the removal of balance v1 ioctl the 'arg' argument is guaranteed to be present so simply remove all conditional code which checks for its presence.

---
 fs/btrfs/ioctl.c | 55 ++++++++++++++++++------------------------------
 1 file changed, 21 insertions(+), 34 deletions(-)
fs/btrfs/ioctl.c +21 -34
index fe00dd88c281..95e47e6f8d41 100644
@@ -4346,10 +4346,6 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
 	bool need_unlock; /* for mut. excl. ops lock */
 	int ret;
 
-	if (!arg)
-		btrfs_warn(fs_info,
-	"IOC_BALANCE ioctl (v1) is deprecated and will be removed in kernel 5.18");
-
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
@@ -4405,29 +4401,25 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
 
 locked:
 
-	if (arg) {
-		bargs = memdup_user(arg, sizeof(*bargs));
-		if (IS_ERR(bargs)) {
-			ret = PTR_ERR(bargs);
-			goto out_unlock;
-		}
+	bargs = memdup_user(arg, sizeof(*bargs));
+	if (IS_ERR(bargs)) {
+		ret = PTR_ERR(bargs);
+		goto out_unlock;
+	}
 
-		if (bargs->flags & BTRFS_BALANCE_RESUME) {
-			if (!fs_info->balance_ctl) {
-				ret = -ENOTCONN;
-				goto out_bargs;
-			}
+	if (bargs->flags & BTRFS_BALANCE_RESUME) {
+		if (!fs_info->balance_ctl) {
+			ret = -ENOTCONN;
+			goto out_bargs;
+		}
 
-			bctl = fs_info->balance_ctl;
-			spin_lock(&fs_info->balance_lock);
-			bctl->flags |= BTRFS_BALANCE_RESUME;
-			spin_unlock(&fs_info->balance_lock);
-			btrfs_exclop_balance(fs_info, BTRFS_EXCLOP_BALANCE);
+		bctl = fs_info->balance_ctl;
+		spin_lock(&fs_info->balance_lock);
+		bctl->flags |= BTRFS_BALANCE_RESUME;
+		spin_unlock(&fs_info->balance_lock);
+		btrfs_exclop_balance(fs_info, BTRFS_EXCLOP_BALANCE);
 
-			goto do_balance;
-		}
-	} else {
-		bargs = NULL;
+		goto do_balance;
 	}
 
 	if (fs_info->balance_ctl) {
@@ -4441,16 +4433,11 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
 		goto out_bargs;
 	}
 
-	if (arg) {
-		memcpy(&bctl->data, &bargs->data, sizeof(bctl->data));
-		memcpy(&bctl->meta, &bargs->meta, sizeof(bctl->meta));
-		memcpy(&bctl->sys, &bargs->sys, sizeof(bctl->sys));
+	memcpy(&bctl->data, &bargs->data, sizeof(bctl->data));
+	memcpy(&bctl->meta, &bargs->meta, sizeof(bctl->meta));
+	memcpy(&bctl->sys, &bargs->sys, sizeof(bctl->sys));
 
-		bctl->flags = bargs->flags;
-	} else {
-		/* balance everything - no filters */
-		bctl->flags |= BTRFS_BALANCE_TYPE_MASK;
-	}
+	bctl->flags = bargs->flags;
 
 	if (bctl->flags & ~(BTRFS_BALANCE_ARGS_MASK | BTRFS_BALANCE_TYPE_MASK)) {
 		ret = -EINVAL;
@@ -4469,7 +4456,7 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
 	ret = btrfs_balance(fs_info, bctl, bargs);
 	bctl = NULL;
 
-	if ((ret == 0 || ret == -ECANCELED) && arg) {
+	if (ret == 0 || ret == -ECANCELED) {
 		if (copy_to_user(arg, bargs, sizeof(*bargs)))
 			ret = -EFAULT;
 	}
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/3 btrfs: simplify codeflow in btrfs_ioctl_balance

In reply to Nikolay Borisov

Move code in btrfs_ioctl_balance to simplify its code flow. This is possible thanks to the removal of balance v1 ioctl and ensuring 'arg' argument is always present. First move the code duplicating the userspace arg to the kernel 'barg'. This makes the out_unlock label redundant. Secondly, check the validity of bargs::flags before copying to the dynamically allocated 'bctl'. This removes the need for the out_bctl label.

---
 fs/btrfs/ioctl.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)
fs/btrfs/ioctl.c +11 -15
index 95e47e6f8d41..a5484a098b92 100644
@@ -4353,6 +4353,12 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
 	if (ret)
 		return ret;
 
+	bargs = memdup_user(arg, sizeof(*bargs));
+	if (IS_ERR(bargs)) {
+		ret = PTR_ERR(bargs);
+		goto out;
+	}
+
 again:
 	if (btrfs_exclop_start(fs_info, BTRFS_EXCLOP_BALANCE)) {
 		mutex_lock(&fs_info->balance_mutex);
@@ -4400,13 +4406,6 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
 	}
 
 locked:
-
-	bargs = memdup_user(arg, sizeof(*bargs));
-	if (IS_ERR(bargs)) {
-		ret = PTR_ERR(bargs);
-		goto out_unlock;
-	}
-
 	if (bargs->flags & BTRFS_BALANCE_RESUME) {
 		if (!fs_info->balance_ctl) {
 			ret = -ENOTCONN;
@@ -4422,6 +4421,11 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
 		goto do_balance;
 	}
 
+	if (bargs->flags & ~(BTRFS_BALANCE_ARGS_MASK | BTRFS_BALANCE_TYPE_MASK)) {
+		ret = -EINVAL;
+		goto out_bargs;
+	}
+
 	if (fs_info->balance_ctl) {
 		ret = -EINPROGRESS;
 		goto out_bargs;
@@ -4438,12 +4442,6 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
 	memcpy(&bctl->sys, &bargs->sys, sizeof(bctl->sys));
 
 	bctl->flags = bargs->flags;
-
-	if (bctl->flags & ~(BTRFS_BALANCE_ARGS_MASK | BTRFS_BALANCE_TYPE_MASK)) {
-		ret = -EINVAL;
-		goto out_bctl;
-	}
-
 do_balance:
 	/*
 	 * Ownership of bctl and exclusive operation goes to btrfs_balance.
@@ -4461,11 +4459,9 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
 			ret = -EFAULT;
 	}
 
-out_bctl:
 	kfree(bctl);
 out_bargs:
 	kfree(bargs);
-out_unlock:
 	mutex_unlock(&fs_info->balance_mutex);
 	if (need_unlock)
 		btrfs_exclop_finish(fs_info);
Signature · 1 line
2.25.1
Reviewed-by on the v1 series
#4 lore raw
In reply to Nikolay Borisov
Quoted 11 lines · Nikolay Borisov

It was slated for removal in 5.18. So here are the patches which remove the relevant bits (patch 1 and 2). As a result of this simplification code can be juggled around a bit so further simplify btrfs_ioctl_balance(patch 3).

Nikolay Borisov (3):
btrfs: remove balance v1 ioctl
btrfs: remove checks for arg argument in btrfs_ioctl_balance
btrfs: simplify codeflow in btrfs_ioctl_balance

Quoted 5 lines
  fs/btrfs/ioctl.c | 69 ++++++++++++++++++------------------------------
  1 file changed, 25 insertions(+), 44 deletions(-)

--
2.25.1

#5 lore raw
In reply to Nikolay Borisov
Quoted 8 lines · Nikolay Borisov

It was slated for removal in 5.18. So here are the patches which remove the relevant bits (patch 1 and 2). As a result of this simplification code can be juggled around a bit so further simplify btrfs_ioctl_balance(patch 3).

Nikolay Borisov (3):
btrfs: remove balance v1 ioctl
btrfs: remove checks for arg argument in btrfs_ioctl_balance
btrfs: simplify codeflow in btrfs_ioctl_balance

Added to misc-next, thanks. The first patch will go to 5.18 queue so we adhere to the scheduled removal.