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