-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.gnu.org/licenses/gpl-2.0.html
- *
- * GPL HEADER END
- */
+// SPDX-License-Identifier: GPL-2.0
+
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 2014, 2017, Intel Corporation.
+ *
*/
+
/*
* This file is part of Lustre, http://www.lustre.org/
*
#ifndef _PARSER_H_
#define _PARSER_H_
-#define HISTORY 100 /* Don't let history grow unbounded */
+#define HISTORY 100
#define MAXARGS 512
#define CMD_COMPLETE 0
int port;
} network_t;
-int Parser_quit(int argc, char **argv);
-int Parser_version(int argc, char **argv);
-void Parser_init(char *, command_t *); /* Set prompt and load command list */
-int Parser_commands(void); /* Start the command parser */
-void Parser_qhelp(int, char **); /* Quick help routine */
-int Parser_help(int, char **); /* Detailed help routine */
-void Parser_ignore_errors(int ignore); /* Set the ignore errors flag */
-void Parser_printhelp(char *); /* Detailed help routine */
-void Parser_exit(int, char **); /* Shuts down command parser */
-int Parser_execarg(int argc, char **argv, command_t cmds[]);
-int Parser_list_commands(const command_t *cmdlist, int line_len,
- int col_num);
-
-/* Converts a string to an integer */
-int Parser_int(char *, int *);
-
-/* Prompts for a string, with default values and a maximum length */
-char *Parser_getstr(const char *prompt, const char *deft, char *res,
- size_t len);
-
-/* Prompts for an integer, with minimum, maximum and default values and base */
-int Parser_getint(const char *prompt, long min, long max, long deft,
- int base);
-
-/* Prompts for a yes/no, with default */
-int Parser_getbool(const char *prompt, int deft);
-
-/* Extracts an integer from a string, or prompts if it cannot get one */
-long Parser_intarg(const char *inp, const char *prompt, int deft,
- int min, int max, int base);
-
-/* Extracts a word from the input, or propmts if it cannot get one */
-char *Parser_strarg(char *inp, const char *prompt, const char *deft,
- char *answer, int len);
-
-/* Extracts an integer from a string with a base */
-int Parser_arg2int(const char *inp, long *result, int base);
-
-/* Convert human readable size string to and int; "1k" -> 1000 */
-int Parser_size(unsigned long *sizep, char *str);
-
-/* Convert a string boolean to an int; "enable" -> 1 */
-int Parser_bool(int *b, char *str);
+int cfs_parser(int argc, char **argv, command_t cmds[]);
#endif
int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res);
int cfs_str2num_check(char *str, int nob, unsigned *num,
unsigned min, unsigned max);
+int cfs_human_readable2long(unsigned long *sizep, char *str);
int cfs_expr2str(struct list_head *list, char *str, size_t size);
int cfs_expr_list_match(__u32 value, struct cfs_expr_list *expr_list);
int cfs_expr_list_print(char *buffer, int count,
+// SPDX-License-Identifier: GPL-2.0
+
/*
* Copyright (C) 2001 Cluster File Systems, Inc.
*
* Copyright (c) 2014, 2017, Intel Corporation.
*
- * This file is part of Lustre, http://www.sf.net/projects/lustre/
- *
- * Lustre is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ */
+
+/*
+ * This file is part of Lustre, http://www.lustre.org/
*
- * Lustre is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * libcfs/libcfs/parser.c
*
- * You should have received a copy of the GNU General Public License
- * along with Lustre; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * A command line parser.
*
*/
#include <libcfs/util/parser.h>
#include <linux/lustre/lustre_ver.h>
-/* Top level of commands, initialized by InitParser */
+/* Top level of commands */
static command_t *top_level;
-/* Parser prompt, set by InitParser */
-static char *parser_prompt;
/* Set to 1 if user types exit or quit */
static int done;
/*
*/
static int ignore_errors;
-/* static functions */
static char *skipwhitespace(char *s);
static char *skiptowhitespace(char *s);
static command_t *find_cmd(char *name, command_t cmds[], char **next);
static int process(char *s, char **next, command_t *lookup, command_t **result,
char **prev);
+static int line2args(char *line, char **argv, int maxargs);
+static int cfs_parser_commands(command_t *cmds);
+static int cfs_parser_execarg(int argc, char **argv, command_t cmds[]);
+static int cfs_parser_list_commands(const command_t *cmdlist, int line_len,
+ int col_num);
+static int cfs_parser_list(int argc, char **argv);
+static int cfs_parser_help(int argc, char **argv);
+static int cfs_parser_quit(int argc, char **argv);
+static int cfs_parser_version(int argc, char **argv);
+static int cfs_parser_ignore_errors(int argc, char **argv);
+
+command_t override_cmdlist[] = {
+ { .pc_name = "quit", .pc_func = cfs_parser_quit, .pc_help = "quit" },
+ { .pc_name = "exit", .pc_func = cfs_parser_quit, .pc_help = "exit" },
+ { .pc_name = "help", .pc_func = cfs_parser_help, .pc_help = "help" },
+ { .pc_name = "--help", .pc_func = cfs_parser_help, .pc_help = "help" },
+ { .pc_name = "version", .pc_func = cfs_parser_version,
+ .pc_help = "version" },
+ { .pc_name = "--version", .pc_func = cfs_parser_version,
+ .pc_help = "version" },
+ { .pc_name = "list-commands", .pc_func = cfs_parser_list,
+ .pc_help = "list" },
+ { .pc_name = "--list-commands", .pc_func = cfs_parser_list,
+ .pc_help = "list" },
+ { .pc_name = "--ignore_errors", .pc_func = cfs_parser_ignore_errors,
+ .pc_help = "ignore errors that occur during script processing\n"
+ "--ignore_errors"},
+ { .pc_name = "ignore_errors", .pc_func = cfs_parser_ignore_errors,
+ .pc_help = "ignore errors that occur during script processing\n"
+ "ignore_errors"},
+ { .pc_name = 0, .pc_func = NULL, .pc_help = 0 }
+};
static char *skipwhitespace(char *s)
{
}
/* find a command -- return it if unique otherwise print alternatives */
-static command_t *Parser_findargcmd(char *name, command_t cmds[])
+static command_t *cfs_parser_findargcmd(char *name, command_t cmds[])
{
command_t *cmd;
return NULL;
}
-void Parser_ignore_errors(int ignore)
+static int cfs_parser_ignore_errors(int argc, char **argv)
+{
+ (void) argc;
+ (void) argv;
+
+ ignore_errors = 1;
+
+ return 0;
+}
+
+int cfs_parser(int argc, char **argv, command_t cmds[])
{
- ignore_errors = ignore;
+ int rc = 0;
+
+ done = 0;
+ top_level = cmds;
+
+ if (argc > 1)
+ rc = cfs_parser_execarg(argc - 1, argv + 1, cmds);
+ else
+ rc = cfs_parser_commands(cmds);
+
+ return rc;
}
-int Parser_execarg(int argc, char **argv, command_t cmds[])
+static int cfs_parser_execarg(int argc, char **argv, command_t cmds[])
{
command_t *cmd;
- cmd = Parser_findargcmd(argv[0], cmds);
+ cmd = cfs_parser_findargcmd(argv[0], override_cmdlist);
+
+ if (!cmd)
+ cmd = cfs_parser_findargcmd(argv[0], cmds);
+
if (cmd && cmd->pc_func) {
int rc = cmd->pc_func(argc, argv);
}
return rc;
}
- /*
- * handle --help here as a synonym of --list-commands so that it can be
- * applied to all commands without needing to individually add a --help
- * option to each command.
- * This does not apply to lctl which has its own --help option because
- * `lctl --list-commands` uses a unique format.
- */
- if (strcmp(argv[0], "--help") == 0) {
- Parser_list_commands(cmds, 80, 4);
- return 0;
- }
+
fprintf(stderr,
"%s: '%s' is not a valid command. See '%s --list-commands'.\n",
program_invocation_short_name, argv[0],
if (len == 0)
return NULL;
+ for (i = 0; override_cmdlist[i].pc_name; i++) {
+ if (strncasecmp(name, override_cmdlist[i].pc_name, len) == 0) {
+ *next = skipwhitespace(*next);
+ return &override_cmdlist[i];
+ }
+ }
for (i = 0; cmds[i].pc_name; i++) {
if (strncasecmp(name, cmds[i].pc_name, len) == 0) {
*next = skipwhitespace(*next);
#endif
/* this is the command execution machine */
-int Parser_commands(void)
+static int cfs_parser_commands(command_t *cmds)
{
char *line, *s;
int rc = 0, save_error = 0;
interactive = init_input();
while (!done) {
- line = readline(interactive ? parser_prompt : NULL);
+ line = readline(interactive ? "> " : NULL);
if (!line)
break;
return rc;
}
-/* sets the parser prompt */
-void Parser_init(char *prompt, command_t *cmds)
-{
- done = 0;
- top_level = cmds;
- if (parser_prompt)
- free(parser_prompt);
- parser_prompt = strdup(prompt);
-}
-
-/* frees the parser prompt */
-void Parser_exit(int argc, char *argv[])
-{
- done = 1;
- free(parser_prompt);
- parser_prompt = NULL;
-}
-
-/* convert a string to an integer */
-int Parser_int(char *s, int *val)
-{
- int ret;
-
- if (*s != '0') {
- ret = sscanf(s, "%d", val);
- } else if (*(s + 1) != 'x') {
- ret = sscanf(s, "%o", val);
- } else {
- s++;
- ret = sscanf(++s, "%x", val);
- }
-
- return ret;
-}
-
-void Parser_qhelp(int argc, char *argv[])
-{
- printf("usage: %s [COMMAND] [OPTIONS]... [ARGS]\n",
- program_invocation_short_name);
- printf("Without any parameters, interactive mode is invoked\n");
-
- printf("Try '%s help <COMMAND>', or '%s --list-commands' for a list of commands.\n",
- program_invocation_short_name, program_invocation_short_name);
-}
-
-int Parser_help(int argc, char **argv)
+static int cfs_parser_help(int argc, char **argv)
{
char line[1024];
char *next, *prev, *tmp;
int i;
if (argc == 1) {
- Parser_qhelp(argc, argv);
+ printf("usage: %s [COMMAND] [OPTIONS]... [ARGS]\n",
+ program_invocation_short_name);
+ printf("Without any parameters, interactive mode is invoked\n");
+ printf("Try '%s help <COMMAND>', or '%s --list-commands' for a list of commands.\n",
+ program_invocation_short_name,
+ program_invocation_short_name);
return 0;
}
return 0;
}
-void Parser_printhelp(char *cmd)
-{
- char *argv[] = { "help", cmd };
-
- Parser_help(2, argv);
-}
-
-/* COMMANDS */
-
/**
- * Parser_list_commands() - Output a list of the supported commands.
+ * cfs_parser_list_commands() - Output a list of the supported commands.
* @cmdlist: Array of structures describing the commands.
* @line_len: Length of output line.
* @col_num: The number of commands printed in a single row.
*
* Return: The number of items that were printed.
*/
-int Parser_list_commands(const command_t *cmdlist, int line_len,
- int col_num)
+static int cfs_parser_list_commands(const command_t *cmdlist, int line_len,
+ int col_num)
{
int char_max;
int count = 0;
return count;
}
-char *Parser_getstr(const char *prompt, const char *deft, char *res,
- size_t len)
+static int cfs_parser_quit(int argc, char **argv)
{
- char *line = NULL;
- int size = strlen(prompt) + strlen(deft) + 8;
- char *theprompt;
-
- theprompt = malloc(size);
- assert(theprompt);
-
- snprintf(theprompt, size, "%s [%s]: ", prompt, deft);
-
- line = readline(theprompt);
- free(theprompt);
-
- /*
- * The function strlcpy() cannot be used here because of
- * this function is used in LNet utils that is not linked
- * with libcfs.a.
- */
- if (!line || *line == '\0')
- strncpy(res, deft, len);
- else
- strncpy(res, line, len);
- res[len - 1] = '\0';
-
- if (line) {
- free(line);
- return res;
- }
- return NULL;
-}
-
-/* get integer from prompt, loop forever to get it */
-int Parser_getint(const char *prompt, long min, long max, long deft, int base)
-{
- int rc;
- long result;
- char *line;
- int size = strlen(prompt) + 40;
- char *theprompt = malloc(size);
-
- assert(theprompt);
- snprintf(theprompt, size, "%s [%ld, (0x%lx)]: ", prompt, deft, deft);
- fflush(stdout);
-
- do {
- line = NULL;
- line = readline(theprompt);
- if (!line) {
- fprintf(stdout, "Please enter an integer.\n");
- fflush(stdout);
- continue;
- }
- if (*line == '\0') {
- free(line);
- result = deft;
- break;
- }
- rc = Parser_arg2int(line, &result, base);
- free(line);
- if (rc != 0) {
- fprintf(stdout, "Invalid string.\n");
- fflush(stdout);
- } else if (result > max || result < min) {
- fprintf(stdout,
- "Error: response must lie between %ld and %ld.\n",
- min, max);
- fflush(stdout);
- } else {
- break;
- }
- } while (1);
-
- if (theprompt)
- free(theprompt);
- return result;
-}
-
-/* get boolean (starting with YyNn; loop forever */
-int Parser_getbool(const char *prompt, int deft)
-{
- int result = 0;
- char *line;
- int size = strlen(prompt) + 8;
- char *theprompt = malloc(size);
-
- assert(theprompt);
- fflush(stdout);
-
- if (deft != 0 && deft != 1) {
- fprintf(stderr, "Error: Parser_getbool given bad default %d\n",
- deft);
- assert(0);
- }
- snprintf(theprompt, size, "%s [%s]: ", prompt, (deft == 0) ? "N" : "Y");
-
- do {
- line = NULL;
- line = readline(theprompt);
- if (!line) {
- result = deft;
- break;
- }
- if (*line == '\0') {
- result = deft;
- break;
- }
- if (*line == 'y' || *line == 'Y') {
- result = 1;
- break;
- }
- if (*line == 'n' || *line == 'N') {
- result = 0;
- break;
- }
- if (line)
- free(line);
- fprintf(stdout, "Invalid string. Must start with yY or nN\n");
- fflush(stdout);
- } while (1);
+ (void) argc;
+ (void) argv;
- if (line)
- free(line);
- if (theprompt)
- free(theprompt);
+ done = 1;
- return result;
+ return 0;
}
-/* parse int out of a string or prompt for it */
-long Parser_intarg(const char *inp, const char *prompt, int deft,
- int min, int max, int base)
+static int cfs_parser_version(int argc, char **argv)
{
- long result;
- int rc;
+ (void) argc;
+ (void) argv;
- rc = Parser_arg2int(inp, &result, base);
- if (rc == 0)
- return result;
- else
- return Parser_getint(prompt, deft, min, max, base);
-}
+ fprintf(stdout, "%s %s\n", program_invocation_short_name,
+ LUSTRE_VERSION_STRING);
-/* parse int out of a string or prompt for it */
-char *Parser_strarg(char *inp, const char *prompt, const char *deft,
- char *answer, int len)
-{
- if (!inp || *inp == '\0')
- return Parser_getstr(prompt, deft, answer, len);
- else
- return inp;
+ return 0;
}
-/*
- * change a string into a number: return 0 on success. No invalid characters
- * allowed. The processing of base and validity follows strtol(3)
- */
-int Parser_arg2int(const char *inp, long *result, int base)
+static int cfs_parser_list(int argc, char **argv)
{
- char *endptr;
-
- if ((base != 0) && (base < 2 || base > 36))
- return 1;
-
- *result = strtol(inp, &endptr, base);
+ command_t *cmd;
+ int num_cmds_listed;
- if (*inp != '\0' && *endptr == '\0')
- return 0;
- else
- return 1;
-}
+ (void) argc;
+ (void) argv;
-/* Convert human readable size string to and int; "1k" -> 1000 */
-int Parser_size(unsigned long *sizep, char *str)
-{
- unsigned long size;
- char mod[32];
-
- switch (sscanf(str, "%lu%1[gGmMkK]", &size, mod)) {
- default:
- return -1;
- case 1:
- *sizep = size;
- return 0;
- case 2:
- switch (*mod) {
- case 'g':
- case 'G':
- *sizep = size << 30;
- return 0;
- case 'm':
- case 'M':
- *sizep = size << 20;
- return 0;
- case 'k':
- case 'K':
- *sizep = size << 10;
- return 0;
- default:
- *sizep = size;
- return 0;
+ cmd = top_level;
+ while (cmd->pc_name != NULL) {
+ if (!cmd->pc_func) {
+ /*
+ * print the command category
+ */
+ printf("\n%s\n", cmd->pc_name);
+ cmd++;
}
+ num_cmds_listed = cfs_parser_list_commands(cmd, 80, 4);
+ cmd += num_cmds_listed;
}
-}
-/* Convert a string boolean to an int; "enable" -> 1 */
-int Parser_bool(int *b, char *str)
-{
- if (!strcasecmp(str, "no") || !strcasecmp(str, "n") ||
- !strcasecmp(str, "off") || !strcasecmp(str, "down") ||
- !strcasecmp(str, "disable")) {
- *b = 0;
- return 0;
- }
-
- if (!strcasecmp(str, "yes") || !strcasecmp(str, "y") ||
- !strcasecmp(str, "on") || !strcasecmp(str, "up") ||
- !strcasecmp(str, "enable")) {
- *b = 1;
- return 0;
- }
-
- return -1;
-}
-
-int Parser_quit(int argc, char **argv)
-{
- (void) argc;
- (void) argv;
- done = 1;
- return 0;
-}
-
-int Parser_version(int argc, char **argv)
-{
- fprintf(stdout, "%s %s\n", program_invocation_short_name,
- LUSTRE_VERSION_STRING);
return 0;
}
static int jt_add_udsp(int argc, char **argv);
static int jt_del_udsp(int argc, char **argv);
/*static int jt_show_peer(int argc, char **argv);*/
-static int lnetctl_list_commands(int argc, char **argv);
static int jt_import(int argc, char **argv);
static int jt_export(int argc, char **argv);
static int jt_ping(int argc, char **argv);
{"cpt-of-nid", jt_calc_cpt_of_nid, 0, "Calculate the CPT associated with NID\n"
"\t--nid: NID to calculate the CPT of\n"
"\t--ncpt: Number of CPTs to consider in the calculation\n"},
- {"help", Parser_help, 0, "help"},
- {"exit", Parser_quit, 0, "quit"},
- {"quit", Parser_quit, 0, "quit"},
- {"--list-commands", lnetctl_list_commands, 0, "list commands"},
{ 0, 0, 0, NULL }
};
if (rc)
return rc;
- return Parser_execarg(argc - 1, &argv[1], lnet_cmds);
+ return cfs_parser(argc, argv, lnet_cmds);
}
static int jt_route(int argc, char **argv)
if (rc)
return rc;
- return Parser_execarg(argc - 1, &argv[1], route_cmds);
+ return cfs_parser(argc, argv, route_cmds);
}
static int jt_net(int argc, char **argv)
if (rc)
return rc;
- return Parser_execarg(argc - 1, &argv[1], net_cmds);
+ return cfs_parser(argc, argv, net_cmds);
}
static int jt_routing(int argc, char **argv)
if (rc)
return rc;
- return Parser_execarg(argc - 1, &argv[1], routing_cmds);
+ return cfs_parser(argc, argv, routing_cmds);
}
static int jt_stats(int argc, char **argv)
if (rc)
return rc;
- return Parser_execarg(argc - 1, &argv[1], stats_cmds);
+ return cfs_parser(argc, argv, stats_cmds);
}
static int jt_debug(int argc, char **argv)
if (rc)
return rc;
- return Parser_execarg(argc - 1, &argv[1], debug_cmds);
+ return cfs_parser(argc, argv, debug_cmds);
}
static int jt_global(int argc, char **argv)
if (rc)
return rc;
- return Parser_execarg(argc - 1, &argv[1], global_cmds);
+ return cfs_parser(argc, argv, global_cmds);
}
static int jt_peers(int argc, char **argv)
if (rc)
return rc;
- return Parser_execarg(argc - 1, &argv[1], peer_cmds);
+ return cfs_parser(argc, argv, peer_cmds);
}
static int jt_set(int argc, char **argv)
if (rc)
return rc;
- return Parser_execarg(argc - 1, &argv[1], set_cmds);
+ return cfs_parser(argc, argv, set_cmds);
}
static int jt_udsp(int argc, char **argv)
if (rc)
return rc;
- return Parser_execarg(argc - 1, &argv[1], udsp_cmds);
+ return cfs_parser(argc, argv, udsp_cmds);
}
static int jt_import(int argc, char **argv)
return rc;
}
-static int lnetctl_list_commands(int argc, char **argv)
-{
- Parser_list_commands(cmd_list, 80, 4);
-
- return 0;
-}
-
int main(int argc, char **argv)
{
int rc = 0;
return rc;
}
- Parser_init("lnetctl > ", cmd_list);
- if (argc > 1) {
- rc = Parser_execarg(argc - 1, &argv[1], cmd_list);
- goto errorout;
- }
-
- Parser_commands();
-
-errorout:
- return rc;
+ return cfs_parser(argc, argv, cmd_list);
}
struct lst_sid LST_INVALID_SID = { .ses_nid = LNET_NID_ANY, .ses_stamp = -1 };
static unsigned int session_key;
-static int lst_list_commands(int argc, char **argv);
/* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
static unsigned int session_features = LST_FEATS_MASK;
void
lst_print_usage(char *cmd)
{
- Parser_printhelp(cmd);
+ char *argv[] = { "help", cmd };
+
+ cfs_parser(2, argv, NULL);
}
void
{"add_test", jt_lst_add_test, NULL,
"Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
" [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
- {"help", Parser_help, 0, "help" },
- {"--list-commands", lst_list_commands, 0, "list commands" },
{0, 0, 0, NULL }
};
return 0;
}
-static int lst_list_commands(int argc, char **argv)
-{
- Parser_list_commands(lst_cmdlist, 80, 4);
-
- return 0;
-}
-
-int
-main(int argc, char **argv)
+int main(int argc, char **argv)
{
- int rc = 0;
+ int rc = 0;
- setlinebuf(stdout);
+ setlinebuf(stdout);
- rc = lst_initialize();
- if (rc < 0)
- goto errorout;
+ rc = lst_initialize();
+ if (rc < 0)
+ goto errorout;
rc = lustre_lnet_config_lib_init();
if (rc < 0)
goto errorout;
- Parser_init("lst > ", lst_cmdlist);
-
- if (argc != 1) {
- rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);
- goto errorout;
- }
-
- Parser_commands();
+ rc = cfs_parser(argc, argv, lst_cmdlist);
errorout:
- return rc;
+ return rc;
}
#include <linux/lustre/lustre_ver.h>
#include <lustre/lustreapi.h>
-static int lctl_list_commands(int argc, char **argv);
-
-static int jt_opt_ignore_errors(int argc, char **argv)
-{
- Parser_ignore_errors(1);
- return 0;
-}
-
-static int jt_pcc_list_commands(int argc, char **argv);
static int jt_pcc(int argc, char **argv);
/**
{ .pc_name = "list", .pc_func = jt_pcc_list,
.pc_help = "List all PCC backends on a client.\n"
"usage: lctl pcc list <mntpath>\n" },
- { .pc_name = "--list-commands", .pc_func = jt_pcc_list_commands,
- .pc_help = "list commands supported by lctl pcc"},
- { .pc_name = "help", .pc_func = Parser_help, .pc_help = "help" },
- { .pc_name = "exit", .pc_func = Parser_quit, .pc_help = "quit" },
- { .pc_name = "quit", .pc_func = Parser_quit, .pc_help = "quit" },
{ .pc_help = NULL }
};
{"--device", jt_opt_device, 0,
"run <command> after connecting to device <devno>\n"
"--device <devno> <command [args ...]>"},
- {"--ignore_errors", jt_opt_ignore_errors, 0,
- "ignore errors that occur during script processing\n"
- "--ignore_errors"},
- {"ignore_errors", jt_opt_ignore_errors, 0,
- "ignore errors that occur during script processing\n"
- "ignore_errors"},
/* User interface commands */
{"======== control =========", NULL, 0, "control commands"},
- {"help", Parser_help, 0, "help"},
{"lustre_build_version", jt_get_version, 0,
"print version of Lustre modules\n"
"usage: lustre_build_version"},
- {"exit", Parser_quit, 0, "quit"},
- {"quit", Parser_quit, 0, "quit"},
- {"--version", Parser_version, 0,
- "print build version of this utility and exit"},
- {"--list-commands", lctl_list_commands, 0,
- "list commands supported by this utility and exit"},
- /* help is a synonym of --list-commands */
- {"--help", lctl_list_commands, 0,
- "list commands supported by this utility and exit"},
/* Network configuration commands */
{"===== network config =====", NULL, 0, "network config"},
};
/**
- * jt_pcc_list_commands() - List lctl pcc commands.
- * @argc: The count of command line arguments.
- * @argv: Array of strings for command line arguments.
- *
- * This function lists lctl pcc commands defined in pccdev_cmdlist[].
- *
- * Return: 0 on success.
- */
-static int jt_pcc_list_commands(int argc, char **argv)
-{
- Parser_list_commands(pccdev_cmdlist, 80, 4);
-
- return 0;
-}
-
-/**
* jt_pcc() - Parse and execute lctl pcc commands.
* @argc: The count of lctl pcc command line arguments.
* @argv: Array of strings for lctl pcc command line arguments.
setlinebuf(stdout);
- Parser_init("lctl-pcc > ", pccdev_cmdlist);
-
snprintf(cmd, sizeof(cmd), "%s %s", program_invocation_short_name,
argv[0]);
program_invocation_short_name = cmd;
- if (argc > 1)
- rc = Parser_execarg(argc - 1, argv + 1, pccdev_cmdlist);
- else
- rc = Parser_commands();
+ rc = cfs_parser(argc, argv, pccdev_cmdlist);
return rc < 0 ? -rc : rc;
}
if (dbg_initialize(argc, argv) < 0)
exit(3);
- Parser_init("lctl > ", cmdlist);
-
- if (argc > 1) {
- llapi_set_command_name(argv[1]);
- rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
- llapi_clear_command_name();
- } else {
- rc = Parser_commands();
- }
-
+ llapi_set_command_name(argv[1]);
+ rc = cfs_parser(argc, argv, cmdlist);
+ llapi_clear_command_name();
obd_finalize(argc, argv);
- Parser_exit(argc, argv);
- return rc < 0 ? -rc : rc;
-}
-static int lctl_list_commands(int argc, char **argv)
-{
- command_t *cmd;
- int rc;
-
- cmd = cmdlist;
- while (cmd->pc_name != NULL) {
- printf("\n%s\n", cmd->pc_name); /* Command category */
- cmd++;
- rc = Parser_list_commands(cmd, 80, 4);
- cmd += rc;
- }
-
- return 0;
+ return rc < 0 ? -rc : rc;
}
int main(int argc, char **argv)
static int lfs_heat_get(int argc, char **argv);
static int lfs_heat_set(int argc, char **argv);
static int lfs_mirror(int argc, char **argv);
-static int lfs_mirror_list_commands(int argc, char **argv);
-static int lfs_list_commands(int argc, char **argv);
static inline int lfs_mirror_resync(int argc, char **argv);
static inline int lfs_mirror_verify(int argc, char **argv);
static inline int lfs_mirror_read(int argc, char **argv);
static int lfs_pcc_detach_fid(int argc, char **argv);
static int lfs_pcc_state(int argc, char **argv);
static int lfs_pcc(int argc, char **argv);
-static int lfs_pcc_list_commands(int argc, char **argv);
enum stats_flag {
STATS_ON,
.pc_help = "Verify mirrored file(s).\n"
"usage: lfs mirror verify [--only MIRROR_ID[,...]]\n"
"\t\t[--verbose|-v] <mirrored_file> [<mirrored_file2> ...]\n" },
- { .pc_name = "--list-commands", .pc_func = lfs_mirror_list_commands,
- .pc_help = "list commands supported by lfs mirror"},
- { .pc_name = "help", .pc_func = Parser_help, .pc_help = "help" },
- { .pc_name = "exit", .pc_func = Parser_quit, .pc_help = "quit" },
- { .pc_name = "quit", .pc_func = Parser_quit, .pc_help = "quit" },
{ .pc_help = NULL }
};
{ .pc_name = "detach_fid", .pc_func = lfs_pcc_detach_fid,
.pc_help = "Detach given files from PCC by FID(s).\n"
"usage: lfs pcc detach_fid <mntpath> <fid>...\n" },
- { .pc_name = "--list-commands", .pc_func = lfs_pcc_list_commands,
- .pc_help = "list commands supported by lfs pcc"},
- { .pc_name = "help", .pc_func = Parser_help, .pc_help = "help" },
- { .pc_name = "exit", .pc_func = Parser_quit, .pc_help = "quit" },
- { .pc_name = "quit", .pc_func = Parser_quit, .pc_help = "quit" },
{ .pc_help = NULL }
};
"lfs pcc state - display the PCC state for given files\n"
"lfs pcc detach - detach given files from Persistent Client Cache\n"
"lfs pcc detach_fid - detach given files from PCC by FID(s)\n"},
- {"help", Parser_help, 0, "help"},
- {"exit", Parser_quit, 0, "quit"},
- {"quit", Parser_quit, 0, "quit"},
- {"--version", Parser_version, 0,
- "output build version of the utility and exit"},
- {"--list-commands", lfs_list_commands, 0,
- "list commands supported by the utility and exit"},
{ 0, 0, 0, NULL }
};
setlinebuf(stdout);
- Parser_init("lfs-mirror > ", mirror_cmdlist);
-
snprintf(cmd, sizeof(cmd), "%s %s", progname, argv[0]);
progname = cmd;
program_invocation_short_name = cmd;
- if (argc > 1)
- rc = Parser_execarg(argc - 1, argv + 1, mirror_cmdlist);
- else
- rc = Parser_commands();
+ rc = cfs_parser(argc, argv, mirror_cmdlist);
return rc < 0 ? -rc : rc;
}
return 0;
}
-/**
- * lfs_mirror_list_commands() - List lfs mirror commands.
- * @argc: The count of command line arguments.
- * @argv: Array of strings for command line arguments.
- *
- * This function lists lfs mirror commands defined in mirror_cmdlist[].
- *
- * Return: 0 on success.
- */
-static int lfs_mirror_list_commands(int argc, char **argv)
-{
- Parser_list_commands(mirror_cmdlist, 80, 4);
-
- return 0;
-}
-
static int lfs_pcc_attach(int argc, char **argv)
{
struct option long_opts[] = {
}
/**
- * lfs_pcc_list_commands() - List lfs pcc commands.
- * @argc: The count of command line arguments.
- * @argv: Array of strings for command line arguments.
- *
- * This function lists lfs pcc commands defined in pcc_cmdlist[].
- *
- * Return: 0 on success.
- */
-static int lfs_pcc_list_commands(int argc, char **argv)
-{
- Parser_list_commands(pcc_cmdlist, 80, 4);
-
- return 0;
-}
-
-/**
* lfs_pcc() - Parse and execute lfs pcc commands.
* @argc: The count of lfs pcc command line arguments.
* @argv: Array of strings for lfs pcc command line arguments.
setlinebuf(stdout);
- Parser_init("lfs-pcc > ", pcc_cmdlist);
-
snprintf(cmd, sizeof(cmd), "%s %s", progname, argv[0]);
progname = cmd;
program_invocation_short_name = cmd;
- if (argc > 1)
- rc = Parser_execarg(argc - 1, argv + 1, pcc_cmdlist);
- else
- rc = Parser_commands();
+ rc = cfs_parser(argc, argv, pcc_cmdlist);
return rc < 0 ? -rc : rc;
}
-static int lfs_list_commands(int argc, char **argv)
-{
- Parser_list_commands(cmdlist, 80, 4);
-
- return 0;
-}
-
int main(int argc, char **argv)
{
int rc;
setlinebuf(stdout);
opterr = 0;
- Parser_init("lfs > ", cmdlist);
-
progname = program_invocation_short_name; /* Used in error messages */
- if (argc > 1) {
- llapi_set_command_name(argv[1]);
- rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
- llapi_clear_command_name();
- } else {
- rc = Parser_commands();
- }
-
- Parser_exit(argc, argv);
+ llapi_set_command_name(argv[1]);
+ rc = cfs_parser(argc, argv, cmdlist);
+ llapi_clear_command_name();
return rc < 0 ? -rc : rc;
}
#include <linux/lustre/lustre_fid.h>
#include <libcfs/util/hash.h>
#include <libcfs/util/list.h>
-#include <libcfs/util/parser.h>
#define container_of(ptr, type, member) ({ \
const typeof(((type *) 0)->member) * __mptr = (ptr); \
#define CHLG_POLL_INTV 60
#define REC_MIN_AGE 600
#define DEF_CACHE_SIZE (256 * 1048576) /* 256MB */
+#define ONE_MB 0x100000
struct options {
const char *o_chlg_user;
int main(int argc, char **argv)
{
- int c;
- int rc;
- void *chglog_hdlr;
- struct changelog_rec *rec;
- bool stop = 0;
- int ret = 0;
- unsigned long cache_size = DEF_CACHE_SIZE;
- char fsname[MAX_OBD_NAME + 1];
+ int c;
+ int rc;
+ void *chglog_hdlr;
+ struct changelog_rec *rec;
+ bool stop = 0;
+ int ret = 0;
+ unsigned long long cache_size = DEF_CACHE_SIZE;
+ char fsname[MAX_OBD_NAME + 1];
+ unsigned long long unit;
static struct option options[] = {
{ "mdt", required_argument, NULL, 'm' },
{ "user", required_argument, 0, 'u'},
}
break;
case 'c':
- rc = Parser_size(&cache_size, optarg);
+ unit = ONE_MB;
+ rc = llapi_parse_size(optarg, &cache_size, &unit, 0);
if (rc < 0) {
rc = -EINVAL;
llapi_error(LLAPI_MSG_ERROR, rc,
*/
if (cache_size < 100)
cache_size = get_fid_cache_size(cache_size);
- llapi_printf(LLAPI_MSG_INFO, "Cache size: %lu\n",
+ llapi_printf(LLAPI_MSG_INFO, "Cache size: %llu\n",
cache_size);
break;
case 'v':
rc = do_device("device", argv[1]);
if (!rc)
- rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
+ rc = cfs_parser(argc - 1, argv + 1, cmdlist);
ret = do_disconnect(argv[0], 0);
if (!rc)
rc = jt_ptl_network(2, arg2);
if (!rc)
- rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
+ rc = cfs_parser(argc - 1, argv + 1, cmdlist);
return rc;
}