diff mbox series

[RFC,3/3] btrfs-progs: add '--background' option for '--full-balance'

Message ID 20200408131527.GD19101@jkm (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: balance --bg invocation | expand

Commit Message

Petr Janecek April 8, 2020, 1:15 p.m. UTC
Add the '--background' option to 'btrfs balance --full-balance'
(without the 'start').
---
 cmds/balance.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/cmds/balance.c b/cmds/balance.c
index 3d4deb27..506016ba 100644
--- a/cmds/balance.c
+++ b/cmds/balance.c
@@ -939,11 +939,38 @@  static DEFINE_SIMPLE_COMMAND(balance_status, "status");
 static int cmd_balance_full(const struct cmd_struct *cmd, int argc, char **argv)
 {
 	struct btrfs_ioctl_balance_args args;
+	unsigned start_flags = BALANCE_START_NOWARN;
 
 	memset(&args, 0, sizeof(args));
 	args.flags |= BTRFS_BALANCE_TYPE_MASK;
 
-	return do_balance(argv[1], &args, BALANCE_START_NOWARN);
+	optind = 0;
+	while (1) {
+		enum { GETOPT_VAL_BACKGROUND = 256 };
+		static const struct option longopts[] = {
+			{ "background", no_argument, NULL,
+				GETOPT_VAL_BACKGROUND },
+			{ "bg", no_argument, NULL, GETOPT_VAL_BACKGROUND },
+			{ NULL, 0, NULL, 0 }
+		};
+
+		int opt = getopt_long(argc, argv, "", longopts, NULL);
+		if (opt < 0)
+			break;
+
+		switch (opt) {
+		case GETOPT_VAL_BACKGROUND:
+			start_flags |= BALANCE_START_BACKGROUND;
+			break;
+		default:
+			usage_unknown_option(cmd, argv);
+		}
+	}
+
+	if (check_argc_exact(argc - optind, 1))
+		return 1;
+
+	return do_balance(argv[optind], &args, start_flags);
 }
 static DEFINE_COMMAND(balance_full, "--full-balance", cmd_balance_full,
 		      NULL, NULL, CMD_HIDDEN);