linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 3/3] btrfs-progs: add '--background' option for '--full-balance'
@ 2020-04-08 13:15 Petr Janecek
  0 siblings, 0 replies; only message in thread
From: Petr Janecek @ 2020-04-08 13:15 UTC (permalink / raw)
  To: linux-btrfs

Add the '--background' option to 'btrfs balance --full-balance'
(without the 'start').
---
 cmds/balance.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

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);
-- 
2.26.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-08 13:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-08 13:15 [RFC PATCH 3/3] btrfs-progs: add '--background' option for '--full-balance' Petr Janecek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).