2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public
4 * License v2 as published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * General Public License for more details.
11 * You should have received a copy of the GNU General Public
12 * License along with this program; if not, write to the
13 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 * Boston, MA 021110-1307, USA.
21 #include <sys/ioctl.h>
24 #include "kerncompat.h"
31 static const char balance_cmd_group_usage[] =
32 "btrfs [filesystem] balance [<command>] [options] <path>";
34 static const char balance_cmd_group_info[] =
35 "'btrfs filesystem balance' command is deprecated, please use\n"
36 "'btrfs balance start' command instead.";
38 static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args)
44 fd = open_file_or_dir(path);
46 fprintf(stderr, "ERROR: can't access to '%s'\n", path);
50 ret = ioctl(fd, BTRFS_IOC_BALANCE_V2, args);
56 if (args->state & BTRFS_BALANCE_STATE_PAUSE_REQ)
57 fprintf(stderr, "balance paused by user\n");
58 if (args->state & BTRFS_BALANCE_STATE_CANCEL_REQ)
59 fprintf(stderr, "balance canceled by user\n");
61 fprintf(stderr, "ERROR: error during balancing '%s' "
62 "- %s\n", path, strerror(e));
64 fprintf(stderr, "There may be more info in "
65 "syslog - try dmesg | tail\n");
69 printf("Done, had to relocate %llu out of %llu chunks\n",
70 (unsigned long long)args->stat.completed,
71 (unsigned long long)args->stat.considered);
77 const struct cmd_group balance_cmd_group = {
78 balance_cmd_group_usage, balance_cmd_group_info, {
83 int cmd_balance(int argc, char **argv)
86 /* old 'btrfs filesystem balance <path>' syntax */
87 struct btrfs_ioctl_balance_args args;
89 memset(&args, 0, sizeof(args));
90 args.flags |= BTRFS_BALANCE_TYPE_MASK;
92 return do_balance(argv[1], &args);
95 return handle_command_group(&balance_cmd_group, argc, argv);