Skip to content

Commit b444451

Browse files
jeffmahoneykdave
authored andcommitted
btrfs-progs: pass cmd_struct to command callback function
This patch passes the cmd_struct to the command callback function. This has several purposes: It allows the command callback to identify which command was used to call it. It also gives us direct access to the usage associated with that command. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 82d4846 commit b444451

22 files changed

+143
-93
lines changed

btrfs.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static const char * const cmd_help_usage[] = {
148148
NULL
149149
};
150150

151-
static int cmd_help(int argc, char **argv)
151+
static int cmd_help(const struct cmd_struct *unused, int argc, char **argv)
152152
{
153153
help_command_group(&btrfs_cmd_group, argc, argv);
154154
return 0;
@@ -162,7 +162,7 @@ static const char * const cmd_version_usage[] = {
162162
NULL
163163
};
164164

165-
static int cmd_version(int argc, char **argv)
165+
static int cmd_version(const struct cmd_struct *unused, int argc, char **argv)
166166
{
167167
printf("%s\n", PACKAGE_STRING);
168168
return 0;
@@ -231,13 +231,13 @@ static void handle_special_globals(int shift, int argc, char **argv)
231231
if (has_full)
232232
usage_command_group(&btrfs_cmd_group, true, false);
233233
else
234-
cmd_help(argc, argv);
234+
cmd_execute(&cmd_struct_help, argc, argv);
235235
exit(0);
236236
}
237237

238238
for (i = 0; i < shift; i++)
239239
if (strcmp(argv[i], "--version") == 0) {
240-
cmd_version(argc, argv);
240+
cmd_execute(&cmd_struct_version, argc, argv);
241241
exit(0);
242242
}
243243
}

check/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -9869,7 +9869,7 @@ static const char * const cmd_check_usage[] = {
98699869
NULL
98709870
};
98719871

9872-
static int cmd_check(int argc, char **argv)
9872+
static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
98739873
{
98749874
struct cache_tree root_cache;
98759875
struct btrfs_root *root;

cmds-balance.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ static const char * const cmd_balance_start_usage[] = {
516516
NULL
517517
};
518518

519-
static int cmd_balance_start(int argc, char **argv)
519+
static int cmd_balance_start(const struct cmd_struct *cmd,
520+
int argc, char **argv)
520521
{
521522
struct btrfs_ioctl_balance_args args;
522523
struct btrfs_balance_args *ptrs[] = { &args.data, &args.sys,
@@ -682,7 +683,8 @@ static const char * const cmd_balance_pause_usage[] = {
682683
NULL
683684
};
684685

685-
static int cmd_balance_pause(int argc, char **argv)
686+
static int cmd_balance_pause(const struct cmd_struct *cmd,
687+
int argc, char **argv)
686688
{
687689
const char *path;
688690
int fd;
@@ -721,7 +723,8 @@ static const char * const cmd_balance_cancel_usage[] = {
721723
NULL
722724
};
723725

724-
static int cmd_balance_cancel(int argc, char **argv)
726+
static int cmd_balance_cancel(const struct cmd_struct *cmd,
727+
int argc, char **argv)
725728
{
726729
const char *path;
727730
int fd;
@@ -760,7 +763,8 @@ static const char * const cmd_balance_resume_usage[] = {
760763
NULL
761764
};
762765

763-
static int cmd_balance_resume(int argc, char **argv)
766+
static int cmd_balance_resume(const struct cmd_struct *cmd,
767+
int argc, char **argv)
764768
{
765769
struct btrfs_ioctl_balance_args args;
766770
const char *path;
@@ -828,7 +832,8 @@ static const char * const cmd_balance_status_usage[] = {
828832
* 1 : Successful to know status of a pending balance
829833
* 0 : When there is no pending balance or completed
830834
*/
831-
static int cmd_balance_status(int argc, char **argv)
835+
static int cmd_balance_status(const struct cmd_struct *cmd,
836+
int argc, char **argv)
832837
{
833838
struct btrfs_ioctl_balance_args args;
834839
const char *path;
@@ -907,7 +912,7 @@ static int cmd_balance_status(int argc, char **argv)
907912
}
908913
static DEFINE_SIMPLE_COMMAND(balance_status, "status");
909914

910-
static int cmd_balance_full(int argc, char **argv)
915+
static int cmd_balance_full(const struct cmd_struct *cmd, int argc, char **argv)
911916
{
912917
struct btrfs_ioctl_balance_args args;
913918

@@ -934,7 +939,7 @@ static const struct cmd_group balance_cmd_group = {
934939
}
935940
};
936941

937-
static int cmd_balance(int argc, char **argv)
942+
static int cmd_balance(const struct cmd_struct *unused, int argc, char **argv)
938943
{
939944
if (argc == 2 && strcmp("start", argv[1]) != 0) {
940945
/* old 'btrfs filesystem balance <path>' syntax */

cmds-device.c

+18-15
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ static const char * const cmd_device_add_usage[] = {
4949
NULL
5050
};
5151

52-
static int cmd_device_add(int argc, char **argv)
52+
static int cmd_device_add(const struct cmd_struct *cmd,
53+
int argc, char **argv)
5354
{
5455
char *mntpnt;
5556
int i, fdmnt, ret = 0;
@@ -144,14 +145,14 @@ static int cmd_device_add(int argc, char **argv)
144145
}
145146
static DEFINE_SIMPLE_COMMAND(device_add, "add");
146147

147-
static int _cmd_device_remove(int argc, char **argv,
148-
const char * const *usagestr)
148+
static int _cmd_device_remove(const struct cmd_struct *cmd,
149+
int argc, char **argv)
149150
{
150151
char *mntpnt;
151152
int i, fdmnt, ret = 0;
152153
DIR *dirstream = NULL;
153154

154-
clean_args_no_options(argc, argv, usagestr);
155+
clean_args_no_options(argc, argv, cmd->usagestr);
155156

156157
if (check_argc_min(argc - optind, 2))
157158
return 1;
@@ -241,9 +242,10 @@ static const char * const cmd_device_remove_usage[] = {
241242
NULL
242243
};
243244

244-
static int cmd_device_remove(int argc, char **argv)
245+
static int cmd_device_remove(const struct cmd_struct *cmd,
246+
int argc, char **argv)
245247
{
246-
return _cmd_device_remove(argc, argv, cmd_device_remove_usage);
248+
return _cmd_device_remove(cmd, argc, argv);
247249
}
248250
static DEFINE_SIMPLE_COMMAND(device_remove, "remove");
249251

@@ -255,9 +257,10 @@ static const char * const cmd_device_delete_usage[] = {
255257
NULL
256258
};
257259

258-
static int cmd_device_delete(int argc, char **argv)
260+
static int cmd_device_delete(const struct cmd_struct *cmd,
261+
int argc, char **argv)
259262
{
260-
return _cmd_device_remove(argc, argv, cmd_device_delete_usage);
263+
return _cmd_device_remove(cmd, argc, argv);
261264
}
262265
static DEFINE_COMMAND(device_delete, "delete", cmd_device_delete,
263266
cmd_device_delete_usage, NULL, CMD_ALIAS);
@@ -300,7 +303,7 @@ static const char * const cmd_device_scan_usage[] = {
300303
NULL
301304
};
302305

303-
static int cmd_device_scan(int argc, char **argv)
306+
static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
304307
{
305308
int i;
306309
int devstart;
@@ -400,14 +403,14 @@ static const char * const cmd_device_ready_usage[] = {
400403
NULL
401404
};
402405

403-
static int cmd_device_ready(int argc, char **argv)
406+
static int cmd_device_ready(const struct cmd_struct *cmd, int argc, char **argv)
404407
{
405408
struct btrfs_ioctl_vol_args args;
406409
int fd;
407410
int ret;
408411
char *path;
409412

410-
clean_args_no_options(argc, argv, cmd_device_ready_usage);
413+
clean_args_no_options(argc, argv, cmd->usagestr);
411414

412415
if (check_argc_exact(argc - optind, 1))
413416
return 1;
@@ -459,7 +462,7 @@ static const char * const cmd_device_stats_usage[] = {
459462
NULL
460463
};
461464

462-
static int cmd_device_stats(int argc, char **argv)
465+
static int cmd_device_stats(const struct cmd_struct *cmd, int argc, char **argv)
463466
{
464467
char *dev_path;
465468
struct btrfs_ioctl_fs_info_args fi_args;
@@ -625,15 +628,15 @@ static int _cmd_device_usage(int fd, const char *path, unsigned unit_mode)
625628
return ret;
626629
}
627630

628-
static int cmd_device_usage(int argc, char **argv)
631+
static int cmd_device_usage(const struct cmd_struct *cmd, int argc, char **argv)
629632
{
630633
unsigned unit_mode;
631634
int ret = 0;
632635
int i;
633636

634637
unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
635638

636-
clean_args_no_options(argc, argv, cmd_device_usage_usage);
639+
clean_args_no_options(argc, argv, cmd->usagestr);
637640

638641
if (check_argc_min(argc - optind, 1))
639642
return 1;
@@ -678,7 +681,7 @@ static const struct cmd_group device_cmd_group = {
678681
}
679682
};
680683

681-
static int cmd_device(int argc, char **argv)
684+
static int cmd_device(const struct cmd_struct *unused, int argc, char **argv)
682685
{
683686
return handle_command_group(&device_cmd_group, argc, argv);
684687
}

cmds-fi-du.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ static const char * const cmd_filesystem_du_usage[] = {
558558
NULL
559559
};
560560

561-
static int cmd_filesystem_du(int argc, char **argv)
561+
static int cmd_filesystem_du(const struct cmd_struct *cmd,
562+
int argc, char **argv)
562563
{
563564
int ret = 0, err = 0;
564565
int i;

cmds-fi-usage.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,8 @@ static const char * const cmd_filesystem_usage_usage[] = {
964964
NULL
965965
};
966966

967-
static int cmd_filesystem_usage(int argc, char **argv)
967+
static int cmd_filesystem_usage(const struct cmd_struct *cmd,
968+
int argc, char **argv)
968969
{
969970
int ret = 0;
970971
unsigned unit_mode;

cmds-filesystem.c

+16-8
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ static void print_df(struct btrfs_ioctl_space_args *sargs, unsigned unit_mode)
120120
}
121121
}
122122

123-
static int cmd_filesystem_df(int argc, char **argv)
123+
static int cmd_filesystem_df(const struct cmd_struct *cmd,
124+
int argc, char **argv)
124125
{
125126
struct btrfs_ioctl_space_args *sargs = NULL;
126127
int ret;
@@ -674,7 +675,8 @@ static const char * const cmd_filesystem_show_usage[] = {
674675
NULL
675676
};
676677

677-
static int cmd_filesystem_show(int argc, char **argv)
678+
static int cmd_filesystem_show(const struct cmd_struct *cmd,
679+
int argc, char **argv)
678680
{
679681
LIST_HEAD(all_uuids);
680682
struct btrfs_fs_devices *fs_devices;
@@ -833,7 +835,8 @@ static const char * const cmd_filesystem_sync_usage[] = {
833835
NULL
834836
};
835837

836-
static int cmd_filesystem_sync(int argc, char **argv)
838+
static int cmd_filesystem_sync(const struct cmd_struct *cmd,
839+
int argc, char **argv)
837840
{
838841
enum btrfs_util_error err;
839842

@@ -921,7 +924,8 @@ static int defrag_callback(const char *fpath, const struct stat *sb,
921924
return 0;
922925
}
923926

924-
static int cmd_filesystem_defrag(int argc, char **argv)
927+
static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
928+
int argc, char **argv)
925929
{
926930
int fd;
927931
int flush = 0;
@@ -1108,7 +1112,8 @@ static const char * const cmd_filesystem_resize_usage[] = {
11081112
NULL
11091113
};
11101114

1111-
static int cmd_filesystem_resize(int argc, char **argv)
1115+
static int cmd_filesystem_resize(const struct cmd_struct *cmd,
1116+
int argc, char **argv)
11121117
{
11131118
struct btrfs_ioctl_vol_args args;
11141119
int fd, res, len, e;
@@ -1186,7 +1191,8 @@ static const char * const cmd_filesystem_label_usage[] = {
11861191
NULL
11871192
};
11881193

1189-
static int cmd_filesystem_label(int argc, char **argv)
1194+
static int cmd_filesystem_label(const struct cmd_struct *cmd,
1195+
int argc, char **argv)
11901196
{
11911197
clean_args_no_options(argc, argv, cmd_filesystem_label_usage);
11921198

@@ -1215,7 +1221,8 @@ static const char * const cmd_filesystem_balance_usage[] = {
12151221
NULL
12161222
};
12171223

1218-
static int cmd_filesystem_balance(int argc, char **argv)
1224+
static int cmd_filesystem_balance(const struct cmd_struct *unused,
1225+
int argc, char **argv)
12191226
{
12201227
return cmd_execute(&cmd_struct_balance, argc, argv);
12211228
}
@@ -1247,7 +1254,8 @@ static const struct cmd_group filesystem_cmd_group = {
12471254
}
12481255
};
12491256

1250-
static int cmd_filesystem(int argc, char **argv)
1257+
static int cmd_filesystem(const struct cmd_struct *unused,
1258+
int argc, char **argv)
12511259
{
12521260
return handle_command_group(&filesystem_cmd_group, argc, argv);
12531261
}

cmds-inspect-dump-super.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ static const char * const cmd_inspect_dump_super_usage[] = {
523523
NULL
524524
};
525525

526-
static int cmd_inspect_dump_super(int argc, char **argv)
526+
static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
527+
int argc, char **argv)
527528
{
528529
int all = 0;
529530
int full = 0;

cmds-inspect-dump-tree.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ static int dump_print_tree_blocks(struct btrfs_fs_info *fs_info,
284284
return ret;
285285
}
286286

287-
static int cmd_inspect_dump_tree(int argc, char **argv)
287+
static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,
288+
int argc, char **argv)
288289
{
289290
struct btrfs_root *root;
290291
struct btrfs_fs_info *info;

cmds-inspect-tree-stats.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ static const char * const cmd_inspect_tree_stats_usage[] = {
427427
NULL
428428
};
429429

430-
static int cmd_inspect_tree_stats(int argc, char **argv)
430+
static int cmd_inspect_tree_stats(const struct cmd_struct *cmd,
431+
int argc, char **argv)
431432
{
432433
struct btrfs_key key;
433434
struct btrfs_root *root;

0 commit comments

Comments
 (0)