btrfs-progs: balance: check for full-balance before background fork

Move the full-balance warning to before the fork, so that the user can
see and react to it.

Notes on test:

- Don't use grep -q, as it causes a SIGPIPE during the countdown, and
  the balance thus doesn't start.

- The "balance cancel" is superfluous as the last command, but it
  provides some idempotence and allows adding more tests below it.

Issue: #168
Signed-off-by: Vladimir Panteleev <git@vladimir.panteleev.md>
Signed-off-by: David Sterba <dsterba@suse.com>
master
Vladimir Panteleev 2019-08-17 23:14:34 +00:00 committed by David Sterba
parent bbb18c990c
commit f972ef650b
2 changed files with 24 additions and 18 deletions

View File

@ -437,24 +437,6 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
if (fd < 0)
return 1;
if (!(flags & BALANCE_START_FILTERS) && !(flags & BALANCE_START_NOWARN)) {
int delay = 10;
printf("WARNING:\n\n");
printf("\tFull balance without filters requested. This operation is very\n");
printf("\tintense and takes potentially very long. It is recommended to\n");
printf("\tuse the balance filters to narrow down the scope of balance.\n");
printf("\tUse 'btrfs balance start --full-balance' option to skip this\n");
printf("\twarning. The operation will start in %d seconds.\n", delay);
printf("\tUse Ctrl-C to stop it.\n");
while (delay) {
printf("%2d", delay--);
fflush(stdout);
sleep(1);
}
printf("\nStarting balance without any filters.\n");
}
ret = ioctl(fd, BTRFS_IOC_BALANCE_V2, args);
if (ret < 0) {
/*
@ -634,6 +616,24 @@ static int cmd_balance_start(const struct cmd_struct *cmd,
}
}
if (!(start_flags & BALANCE_START_FILTERS) && !(start_flags & BALANCE_START_NOWARN)) {
int delay = 10;
printf("WARNING:\n\n");
printf("\tFull balance without filters requested. This operation is very\n");
printf("\tintense and takes potentially very long. It is recommended to\n");
printf("\tuse the balance filters to narrow down the scope of balance.\n");
printf("\tUse 'btrfs balance start --full-balance' option to skip this\n");
printf("\twarning. The operation will start in %d seconds.\n", delay);
printf("\tUse Ctrl-C to stop it.\n");
while (delay) {
printf("%2d", delay--);
fflush(stdout);
sleep(1);
}
printf("\nStarting balance without any filters.\n");
}
if (force)
args.flags |= BTRFS_BALANCE_FORCE;
if (verbose)

View File

@ -18,4 +18,10 @@ run_check $SUDO_HELPER "$TOP/btrfs" balance start "$TEST_MNT"
run_check $SUDO_HELPER "$TOP/btrfs" balance --full-balance "$TEST_MNT"
run_check $SUDO_HELPER "$TOP/btrfs" balance "$TEST_MNT"
# grep below can't use -q else this could lead to SIGPIPE
run_check_stdout $SUDO_HELPER "$TOP/btrfs" balance start --background "$TEST_MNT" |
grep -F "Full balance without filters requested." >/dev/null ||
_fail "full balance warning not in the output"
run_mayfail $SUDO_HELPER "$TOP/btrfs" balance cancel "$TEST_MNT"
run_check_umount_test_dev