btrfs-progs: add command group info strings
[platform/upstream/btrfs-progs.git] / cmds-balance.c
1 /*
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.
5  *
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.
10  *
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.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <getopt.h>
22 #include <sys/ioctl.h>
23 #include <errno.h>
24
25 #include "kerncompat.h"
26 #include "ctree.h"
27 #include "ioctl.h"
28 #include "volumes.h"
29
30 #include "commands.h"
31 #include "utils.h"
32
33 static const char * const balance_cmd_group_usage[] = {
34         "btrfs balance <command> [options] <path>",
35         "btrfs balance <path>",
36         NULL
37 };
38
39 static int parse_one_profile(const char *profile, u64 *flags)
40 {
41         if (!strcmp(profile, "raid0")) {
42                 *flags |= BTRFS_BLOCK_GROUP_RAID0;
43         } else if (!strcmp(profile, "raid1")) {
44                 *flags |= BTRFS_BLOCK_GROUP_RAID1;
45         } else if (!strcmp(profile, "raid10")) {
46                 *flags |= BTRFS_BLOCK_GROUP_RAID10;
47         } else if (!strcmp(profile, "raid5")) {
48                 *flags |= BTRFS_BLOCK_GROUP_RAID5;
49         } else if (!strcmp(profile, "raid6")) {
50                 *flags |= BTRFS_BLOCK_GROUP_RAID6;
51         } else if (!strcmp(profile, "dup")) {
52                 *flags |= BTRFS_BLOCK_GROUP_DUP;
53         } else if (!strcmp(profile, "single")) {
54                 *flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
55         } else {
56                 fprintf(stderr, "Unknown profile '%s'\n", profile);
57                 return 1;
58         }
59
60         return 0;
61 }
62
63 static int parse_profiles(char *profiles, u64 *flags)
64 {
65         char *this_char;
66         char *save_ptr = NULL; /* Satisfy static checkers */
67
68         for (this_char = strtok_r(profiles, "|", &save_ptr);
69              this_char != NULL;
70              this_char = strtok_r(NULL, "|", &save_ptr)) {
71                 if (parse_one_profile(this_char, flags))
72                         return 1;
73         }
74
75         return 0;
76 }
77
78 static int parse_u64(const char *str, u64 *result)
79 {
80         char *endptr;
81         u64 val;
82
83         val = strtoull(str, &endptr, 10);
84         if (*endptr)
85                 return 1;
86
87         *result = val;
88         return 0;
89 }
90
91 static int parse_range(const char *range, u64 *start, u64 *end)
92 {
93         char *dots;
94
95         dots = strstr(range, "..");
96         if (dots) {
97                 const char *rest = dots + 2;
98                 int skipped = 0;
99
100                 *dots = 0;
101
102                 if (!*rest) {
103                         *end = (u64)-1;
104                         skipped++;
105                 } else {
106                         if (parse_u64(rest, end))
107                                 return 1;
108                 }
109                 if (dots == range) {
110                         *start = 0;
111                         skipped++;
112                 } else {
113                         if (parse_u64(range, start))
114                                 return 1;
115                 }
116
117                 if (*start >= *end) {
118                         fprintf(stderr, "Range %llu..%llu doesn't make "
119                                 "sense\n", (unsigned long long)*start,
120                                 (unsigned long long)*end);
121                         return 1;
122                 }
123
124                 if (skipped <= 1)
125                         return 0;
126         }
127
128         return 1;
129 }
130
131 static int parse_filters(char *filters, struct btrfs_balance_args *args)
132 {
133         char *this_char;
134         char *value;
135         char *save_ptr = NULL; /* Satisfy static checkers */
136
137         if (!filters)
138                 return 0;
139
140         for (this_char = strtok_r(filters, ",", &save_ptr);
141              this_char != NULL;
142              this_char = strtok_r(NULL, ",", &save_ptr)) {
143                 if ((value = strchr(this_char, '=')) != NULL)
144                         *value++ = 0;
145                 if (!strcmp(this_char, "profiles")) {
146                         if (!value || !*value) {
147                                 fprintf(stderr, "the profiles filter requires "
148                                        "an argument\n");
149                                 return 1;
150                         }
151                         if (parse_profiles(value, &args->profiles)) {
152                                 fprintf(stderr, "Invalid profiles argument\n");
153                                 return 1;
154                         }
155                         args->flags |= BTRFS_BALANCE_ARGS_PROFILES;
156                 } else if (!strcmp(this_char, "usage")) {
157                         if (!value || !*value) {
158                                 fprintf(stderr, "the usage filter requires "
159                                        "an argument\n");
160                                 return 1;
161                         }
162                         if (parse_u64(value, &args->usage) ||
163                             args->usage > 100) {
164                                 fprintf(stderr, "Invalid usage argument: %s\n",
165                                        value);
166                                 return 1;
167                         }
168                         args->flags |= BTRFS_BALANCE_ARGS_USAGE;
169                 } else if (!strcmp(this_char, "devid")) {
170                         if (!value || !*value) {
171                                 fprintf(stderr, "the devid filter requires "
172                                        "an argument\n");
173                                 return 1;
174                         }
175                         if (parse_u64(value, &args->devid) ||
176                             args->devid == 0) {
177                                 fprintf(stderr, "Invalid devid argument: %s\n",
178                                        value);
179                                 return 1;
180                         }
181                         args->flags |= BTRFS_BALANCE_ARGS_DEVID;
182                 } else if (!strcmp(this_char, "drange")) {
183                         if (!value || !*value) {
184                                 fprintf(stderr, "the drange filter requires "
185                                        "an argument\n");
186                                 return 1;
187                         }
188                         if (parse_range(value, &args->pstart, &args->pend)) {
189                                 fprintf(stderr, "Invalid drange argument\n");
190                                 return 1;
191                         }
192                         args->flags |= BTRFS_BALANCE_ARGS_DRANGE;
193                 } else if (!strcmp(this_char, "vrange")) {
194                         if (!value || !*value) {
195                                 fprintf(stderr, "the vrange filter requires "
196                                        "an argument\n");
197                                 return 1;
198                         }
199                         if (parse_range(value, &args->vstart, &args->vend)) {
200                                 fprintf(stderr, "Invalid vrange argument\n");
201                                 return 1;
202                         }
203                         args->flags |= BTRFS_BALANCE_ARGS_VRANGE;
204                 } else if (!strcmp(this_char, "convert")) {
205                         if (!value || !*value) {
206                                 fprintf(stderr, "the convert option requires "
207                                        "an argument\n");
208                                 return 1;
209                         }
210                         if (parse_one_profile(value, &args->target)) {
211                                 fprintf(stderr, "Invalid convert argument\n");
212                                 return 1;
213                         }
214                         args->flags |= BTRFS_BALANCE_ARGS_CONVERT;
215                 } else if (!strcmp(this_char, "soft")) {
216                         args->flags |= BTRFS_BALANCE_ARGS_SOFT;
217                 } else if (!strcmp(this_char, "limit")) {
218                         if (!value || !*value) {
219                                 fprintf(stderr,
220                                         "the limit filter requires an argument\n");
221                                 return 1;
222                         }
223                         if (parse_u64(value, &args->limit)) {
224                                 fprintf(stderr, "Invalid limit argument: %s\n",
225                                        value);
226                                 return 1;
227                         }
228                         args->flags |= BTRFS_BALANCE_ARGS_LIMIT;
229                 } else {
230                         fprintf(stderr, "Unrecognized balance option '%s'\n",
231                                 this_char);
232                         return 1;
233                 }
234         }
235
236         return 0;
237 }
238
239 static void dump_balance_args(struct btrfs_balance_args *args)
240 {
241         if (args->flags & BTRFS_BALANCE_ARGS_CONVERT) {
242                 printf("converting, target=%llu, soft is %s",
243                        (unsigned long long)args->target,
244                        (args->flags & BTRFS_BALANCE_ARGS_SOFT) ? "on" : "off");
245         } else {
246                 printf("balancing");
247         }
248
249         if (args->flags & BTRFS_BALANCE_ARGS_PROFILES)
250                 printf(", profiles=%llu", (unsigned long long)args->profiles);
251         if (args->flags & BTRFS_BALANCE_ARGS_USAGE)
252                 printf(", usage=%llu", (unsigned long long)args->usage);
253         if (args->flags & BTRFS_BALANCE_ARGS_DEVID)
254                 printf(", devid=%llu", (unsigned long long)args->devid);
255         if (args->flags & BTRFS_BALANCE_ARGS_DRANGE)
256                 printf(", drange=%llu..%llu",
257                        (unsigned long long)args->pstart,
258                        (unsigned long long)args->pend);
259         if (args->flags & BTRFS_BALANCE_ARGS_VRANGE)
260                 printf(", vrange=%llu..%llu",
261                        (unsigned long long)args->vstart,
262                        (unsigned long long)args->vend);
263         if (args->flags & BTRFS_BALANCE_ARGS_LIMIT)
264                 printf(", limit=%llu", (unsigned long long)args->limit);
265
266         printf("\n");
267 }
268
269 static void dump_ioctl_balance_args(struct btrfs_ioctl_balance_args *args)
270 {
271         printf("Dumping filters: flags 0x%llx, state 0x%llx, force is %s\n",
272                (unsigned long long)args->flags, (unsigned long long)args->state,
273                (args->flags & BTRFS_BALANCE_FORCE) ? "on" : "off");
274         if (args->flags & BTRFS_BALANCE_DATA) {
275                 printf("  DATA (flags 0x%llx): ",
276                        (unsigned long long)args->data.flags);
277                 dump_balance_args(&args->data);
278         }
279         if (args->flags & BTRFS_BALANCE_METADATA) {
280                 printf("  METADATA (flags 0x%llx): ",
281                        (unsigned long long)args->meta.flags);
282                 dump_balance_args(&args->meta);
283         }
284         if (args->flags & BTRFS_BALANCE_SYSTEM) {
285                 printf("  SYSTEM (flags 0x%llx): ",
286                        (unsigned long long)args->sys.flags);
287                 dump_balance_args(&args->sys);
288         }
289 }
290
291 static int do_balance_v1(int fd)
292 {
293         struct btrfs_ioctl_vol_args args;
294         int ret;
295
296         memset(&args, 0, sizeof(args));
297         ret = ioctl(fd, BTRFS_IOC_BALANCE, &args);
298         return ret;
299 }
300
301 static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
302                       int nofilters)
303 {
304         int fd;
305         int ret;
306         int e;
307         DIR *dirstream = NULL;
308
309         fd = open_file_or_dir(path, &dirstream);
310         if (fd < 0) {
311                 fprintf(stderr, "ERROR: can't access '%s'\n", path);
312                 return 1;
313         }
314
315         ret = ioctl(fd, BTRFS_IOC_BALANCE_V2, args);
316         e = errno;
317
318         if (ret < 0) {
319                 /*
320                  * older kernels don't have the new balance ioctl, try the
321                  * old one.  But, the old one doesn't know any filters, so
322                  * don't fall back if they tried to use the fancy new things
323                  */
324                 if (e == ENOTTY && nofilters) {
325                         ret = do_balance_v1(fd);
326                         if (ret == 0)
327                                 goto out;
328                         e = errno;
329                 }
330
331                 if (e == ECANCELED) {
332                         if (args->state & BTRFS_BALANCE_STATE_PAUSE_REQ)
333                                 fprintf(stderr, "balance paused by user\n");
334                         if (args->state & BTRFS_BALANCE_STATE_CANCEL_REQ)
335                                 fprintf(stderr, "balance canceled by user\n");
336                         ret = 0;
337                 } else {
338                         fprintf(stderr, "ERROR: error during balancing '%s' "
339                                 "- %s\n", path, strerror(e));
340                         if (e != EINPROGRESS)
341                                 fprintf(stderr, "There may be more info in "
342                                         "syslog - try dmesg | tail\n");
343                         ret = 1;
344                 }
345         } else {
346                 printf("Done, had to relocate %llu out of %llu chunks\n",
347                        (unsigned long long)args->stat.completed,
348                        (unsigned long long)args->stat.considered);
349                 ret = 0;
350         }
351
352 out:
353         close_file_or_dir(fd, dirstream);
354         return ret;
355 }
356
357 static const char * const cmd_balance_start_usage[] = {
358         "btrfs balance start [options] <path>",
359         "Balance chunks across the devices",
360         "Balance and/or convert (change allocation profile of) chunks that",
361         "passed all filters in a comma-separated list of filters for a",
362         "particular chunk type.  If filter list is not given balance all",
363         "chunks of that type.  In case none of the -d, -m or -s options is",
364         "given balance all chunks in a filesystem.",
365         "",
366         "-d[filters]    act on data chunks",
367         "-m[filters]    act on metadata chunks",
368         "-s[filters]    act on system chunks (only under -f)",
369         "-v             be verbose",
370         "-f             force reducing of metadata integrity",
371         NULL
372 };
373
374 static int cmd_balance_start(int argc, char **argv)
375 {
376         struct btrfs_ioctl_balance_args args;
377         struct btrfs_balance_args *ptrs[] = { &args.data, &args.sys,
378                                                 &args.meta, NULL };
379         int force = 0;
380         int verbose = 0;
381         int nofilters = 1;
382         int i;
383
384         memset(&args, 0, sizeof(args));
385
386         optind = 1;
387         while (1) {
388                 static const struct option longopts[] = {
389                         { "data", optional_argument, NULL, 'd'},
390                         { "metadata", optional_argument, NULL, 'm' },
391                         { "system", optional_argument, NULL, 's' },
392                         { "force", no_argument, NULL, 'f' },
393                         { "verbose", no_argument, NULL, 'v' },
394                         { NULL, 0, NULL, 0 }
395                 };
396
397                 int opt = getopt_long(argc, argv, "d::s::m::fv", longopts, NULL);
398                 if (opt < 0)
399                         break;
400
401                 switch (opt) {
402                 case 'd':
403                         nofilters = 0;
404                         args.flags |= BTRFS_BALANCE_DATA;
405
406                         if (parse_filters(optarg, &args.data))
407                                 return 1;
408                         break;
409                 case 's':
410                         nofilters = 0;
411                         args.flags |= BTRFS_BALANCE_SYSTEM;
412
413                         if (parse_filters(optarg, &args.sys))
414                                 return 1;
415                         break;
416                 case 'm':
417                         nofilters = 0;
418                         args.flags |= BTRFS_BALANCE_METADATA;
419
420                         if (parse_filters(optarg, &args.meta))
421                                 return 1;
422                         break;
423                 case 'f':
424                         force = 1;
425                         break;
426                 case 'v':
427                         verbose = 1;
428                         break;
429                 default:
430                         usage(cmd_balance_start_usage);
431                 }
432         }
433
434         if (check_argc_exact(argc - optind, 1))
435                 usage(cmd_balance_start_usage);
436
437         /*
438          * allow -s only under --force, otherwise do with system chunks
439          * the same thing we were ordered to do with meta chunks
440          */
441         if (args.flags & BTRFS_BALANCE_SYSTEM) {
442                 if (!force) {
443                         fprintf(stderr,
444 "Refusing to explicitly operate on system chunks.\n"
445 "Pass --force if you really want to do that.\n");
446                         return 1;
447                 }
448         } else if (args.flags & BTRFS_BALANCE_METADATA) {
449                 args.flags |= BTRFS_BALANCE_SYSTEM;
450                 memcpy(&args.sys, &args.meta,
451                         sizeof(struct btrfs_balance_args));
452         }
453
454         if (nofilters) {
455                 /* relocate everything - no filters */
456                 args.flags |= BTRFS_BALANCE_TYPE_MASK;
457         }
458
459         /* drange makes sense only when devid is set */
460         for (i = 0; ptrs[i]; i++) {
461                 if ((ptrs[i]->flags & BTRFS_BALANCE_ARGS_DRANGE) &&
462                     !(ptrs[i]->flags & BTRFS_BALANCE_ARGS_DEVID)) {
463                         fprintf(stderr, "drange filter can be used only if "
464                                 "devid filter is used\n");
465                         return 1;
466                 }
467         }
468
469         /* soft makes sense only when convert for corresponding type is set */
470         for (i = 0; ptrs[i]; i++) {
471                 if ((ptrs[i]->flags & BTRFS_BALANCE_ARGS_SOFT) &&
472                     !(ptrs[i]->flags & BTRFS_BALANCE_ARGS_CONVERT)) {
473                         fprintf(stderr, "'soft' option can be used only if "
474                                 "changing profiles\n");
475                         return 1;
476                 }
477         }
478
479         if (force)
480                 args.flags |= BTRFS_BALANCE_FORCE;
481         if (verbose)
482                 dump_ioctl_balance_args(&args);
483
484         return do_balance(argv[optind], &args, nofilters);
485 }
486
487 static const char * const cmd_balance_pause_usage[] = {
488         "btrfs balance pause <path>",
489         "Pause running balance",
490         NULL
491 };
492
493 static int cmd_balance_pause(int argc, char **argv)
494 {
495         const char *path;
496         int fd;
497         int ret;
498         int e;
499         DIR *dirstream = NULL;
500
501         if (check_argc_exact(argc, 2))
502                 usage(cmd_balance_pause_usage);
503
504         path = argv[1];
505
506         fd = open_file_or_dir(path, &dirstream);
507         if (fd < 0) {
508                 fprintf(stderr, "ERROR: can't access '%s'\n", path);
509                 return 1;
510         }
511
512         ret = ioctl(fd, BTRFS_IOC_BALANCE_CTL, BTRFS_BALANCE_CTL_PAUSE);
513         e = errno;
514         close_file_or_dir(fd, dirstream);
515
516         if (ret < 0) {
517                 fprintf(stderr, "ERROR: balance pause on '%s' failed - %s\n",
518                         path, (e == ENOTCONN) ? "Not running" : strerror(e));
519                 if (e == ENOTCONN)
520                         return 2;
521                 else
522                         return 1;
523         }
524
525         return 0;
526 }
527
528 static const char * const cmd_balance_cancel_usage[] = {
529         "btrfs balance cancel <path>",
530         "Cancel running or paused balance",
531         NULL
532 };
533
534 static int cmd_balance_cancel(int argc, char **argv)
535 {
536         const char *path;
537         int fd;
538         int ret;
539         int e;
540         DIR *dirstream = NULL;
541
542         if (check_argc_exact(argc, 2))
543                 usage(cmd_balance_cancel_usage);
544
545         path = argv[1];
546
547         fd = open_file_or_dir(path, &dirstream);
548         if (fd < 0) {
549                 fprintf(stderr, "ERROR: can't access '%s'\n", path);
550                 return 1;
551         }
552
553         ret = ioctl(fd, BTRFS_IOC_BALANCE_CTL, BTRFS_BALANCE_CTL_CANCEL);
554         e = errno;
555         close_file_or_dir(fd, dirstream);
556
557         if (ret < 0) {
558                 fprintf(stderr, "ERROR: balance cancel on '%s' failed - %s\n",
559                         path, (e == ENOTCONN) ? "Not in progress" : strerror(e));
560                 if (e == ENOTCONN)
561                         return 2;
562                 else
563                         return 1;
564         }
565
566         return 0;
567 }
568
569 static const char * const cmd_balance_resume_usage[] = {
570         "btrfs balance resume <path>",
571         "Resume interrupted balance",
572         NULL
573 };
574
575 static int cmd_balance_resume(int argc, char **argv)
576 {
577         struct btrfs_ioctl_balance_args args;
578         const char *path;
579         DIR *dirstream = NULL;
580         int fd;
581         int ret;
582         int e;
583
584         if (check_argc_exact(argc, 2))
585                 usage(cmd_balance_resume_usage);
586
587         path = argv[1];
588
589         fd = open_file_or_dir(path, &dirstream);
590         if (fd < 0) {
591                 fprintf(stderr, "ERROR: can't access '%s'\n", path);
592                 return 1;
593         }
594
595         memset(&args, 0, sizeof(args));
596         args.flags |= BTRFS_BALANCE_RESUME;
597
598         ret = ioctl(fd, BTRFS_IOC_BALANCE_V2, &args);
599         e = errno;
600         close_file_or_dir(fd, dirstream);
601
602         if (ret < 0) {
603                 if (e == ECANCELED) {
604                         if (args.state & BTRFS_BALANCE_STATE_PAUSE_REQ)
605                                 fprintf(stderr, "balance paused by user\n");
606                         if (args.state & BTRFS_BALANCE_STATE_CANCEL_REQ)
607                                 fprintf(stderr, "balance canceled by user\n");
608                 } else if (e == ENOTCONN || e == EINPROGRESS) {
609                         fprintf(stderr, "ERROR: balance resume on '%s' "
610                                 "failed - %s\n", path,
611                                 (e == ENOTCONN) ? "Not in progress" :
612                                                   "Already running");
613                         if (e == ENOTCONN)
614                                 return 2;
615                         else
616                                 return 1;
617                 } else {
618                         fprintf(stderr,
619 "ERROR: error during balancing '%s' - %s\n"
620 "There may be more info in syslog - try dmesg | tail\n", path, strerror(e));
621                         return 1;
622                 }
623         } else {
624                 printf("Done, had to relocate %llu out of %llu chunks\n",
625                        (unsigned long long)args.stat.completed,
626                        (unsigned long long)args.stat.considered);
627         }
628
629         return 0;
630 }
631
632 static const char * const cmd_balance_status_usage[] = {
633         "btrfs balance status [-v] <path>",
634         "Show status of running or paused balance",
635         "",
636         "-v     be verbose",
637         NULL
638 };
639
640 /* Checks the status of the balance if any
641  * return codes:
642  *   2 : Error failed to know if there is any pending balance
643  *   1 : Successful to know status of a pending balance
644  *   0 : When there is no pending balance or completed
645  */
646 static int cmd_balance_status(int argc, char **argv)
647 {
648         struct btrfs_ioctl_balance_args args;
649         const char *path;
650         DIR *dirstream = NULL;
651         int fd;
652         int verbose = 0;
653         int ret;
654         int e;
655
656         optind = 1;
657         while (1) {
658                 int opt;
659                 static const struct option longopts[] = {
660                         { "verbose", no_argument, NULL, 'v' },
661                         { NULL, 0, NULL, 0 }
662                 };
663
664                 opt = getopt_long(argc, argv, "v", longopts, NULL);
665                 if (opt < 0)
666                         break;
667
668                 switch (opt) {
669                 case 'v':
670                         verbose = 1;
671                         break;
672                 default:
673                         usage(cmd_balance_status_usage);
674                 }
675         }
676
677         if (check_argc_exact(argc - optind, 1))
678                 usage(cmd_balance_status_usage);
679
680         path = argv[optind];
681
682         fd = open_file_or_dir(path, &dirstream);
683         if (fd < 0) {
684                 fprintf(stderr, "ERROR: can't access '%s'\n", path);
685                 return 2;
686         }
687
688         ret = ioctl(fd, BTRFS_IOC_BALANCE_PROGRESS, &args);
689         e = errno;
690         close_file_or_dir(fd, dirstream);
691
692         if (ret < 0) {
693                 if (e == ENOTCONN) {
694                         printf("No balance found on '%s'\n", path);
695                         return 0;
696                 }
697                 fprintf(stderr, "ERROR: balance status on '%s' failed - %s\n",
698                         path, strerror(e));
699                 return 2;
700         }
701
702         if (args.state & BTRFS_BALANCE_STATE_RUNNING) {
703                 printf("Balance on '%s' is running", path);
704                 if (args.state & BTRFS_BALANCE_STATE_CANCEL_REQ)
705                         printf(", cancel requested\n");
706                 else if (args.state & BTRFS_BALANCE_STATE_PAUSE_REQ)
707                         printf(", pause requested\n");
708                 else
709                         printf("\n");
710         } else {
711                 printf("Balance on '%s' is paused\n", path);
712         }
713
714         printf("%llu out of about %llu chunks balanced (%llu considered), "
715                "%3.f%% left\n", (unsigned long long)args.stat.completed,
716                (unsigned long long)args.stat.expected,
717                (unsigned long long)args.stat.considered,
718                100 * (1 - (float)args.stat.completed/args.stat.expected));
719
720         if (verbose)
721                 dump_ioctl_balance_args(&args);
722
723         return 1;
724 }
725
726 static const char balance_cmd_group_info[] =
727 "balance data accross devices, or change block groups using filters";
728
729 const struct cmd_group balance_cmd_group = {
730         balance_cmd_group_usage, balance_cmd_group_info, {
731                 { "start", cmd_balance_start, cmd_balance_start_usage, NULL, 0 },
732                 { "pause", cmd_balance_pause, cmd_balance_pause_usage, NULL, 0 },
733                 { "cancel", cmd_balance_cancel, cmd_balance_cancel_usage, NULL, 0 },
734                 { "resume", cmd_balance_resume, cmd_balance_resume_usage, NULL, 0 },
735                 { "status", cmd_balance_status, cmd_balance_status_usage, NULL, 0 },
736                 NULL_CMD_STRUCT
737         }
738 };
739
740 int cmd_balance(int argc, char **argv)
741 {
742         if (argc == 2) {
743                 /* old 'btrfs filesystem balance <path>' syntax */
744                 struct btrfs_ioctl_balance_args args;
745
746                 memset(&args, 0, sizeof(args));
747                 args.flags |= BTRFS_BALANCE_TYPE_MASK;
748
749                 return do_balance(argv[1], &args, 1);
750         }
751
752         return handle_command_group(&balance_cmd_group, argc, argv);
753 }