Whamcloud - gitweb
LU-13090 utils: fix lfs_migrate -p for file with pool
[fs/lustre-release.git] / libcfs / libcfs / util / parser.c
1 /*
2  * Copyright (C) 2001 Cluster File Systems, Inc.
3  *
4  * Copyright (c) 2014, 2017, Intel Corporation.
5  *
6  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #include <stddef.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <assert.h>
27 #include <ctype.h>
28 #include <errno.h>
29 #include <getopt.h>
30 #include <malloc.h>
31 #ifdef HAVE_LIBREADLINE
32 # include <readline/history.h>
33 # include <readline/readline.h>
34 #endif /* HAVE_LIBREADLINE */
35 #include <string.h>
36 #include <unistd.h>
37
38 #include <libcfs/util/parser.h>
39 #include <linux/lustre/lustre_ver.h>
40
41 /* Top level of commands, initialized by InitParser */
42 static command_t *top_level;
43 /* Parser prompt, set by InitParser */
44 static char *parser_prompt;
45 /* Set to 1 if user types exit or quit */
46 static int done;
47 /*
48  * Normally, the parser will quit when an error occurs in non-interacive
49  * mode. Setting this to non-zero will force it to keep buggering on.
50  */
51 static int ignore_errors;
52
53 /* static functions */
54 static char *skipwhitespace(char *s);
55 static char *skiptowhitespace(char *s);
56 static command_t *find_cmd(char *name, command_t cmds[], char **next);
57 static int process(char *s, char **next, command_t *lookup, command_t **result,
58                    char **prev);
59
60 static char *skipwhitespace(char *s)
61 {
62         char *t;
63         int len;
64
65         len = (int)strlen(s);
66         for (t = s; t <= s + len && isspace(*t); t++)
67                 ;
68         return t;
69 }
70
71 static char *skiptowhitespace(char *s)
72 {
73         char *t;
74
75         for (t = s; *t && !isspace(*t); t++)
76                 ;
77         return t;
78 }
79
80 static int line2args(char *line, char **argv, int maxargs)
81 {
82         char *arg;
83         int i = 0;
84
85         arg = strtok(line, " \t");
86         if (!arg || maxargs < 1)
87                 return 0;
88
89         argv[i++] = arg;
90         while ((arg = strtok(NULL, " \t")) != NULL && i < maxargs)
91                 argv[i++] = arg;
92         return i;
93 }
94
95 /* find a command -- return it if unique otherwise print alternatives */
96 static command_t *Parser_findargcmd(char *name, command_t cmds[])
97 {
98         command_t *cmd;
99
100         for (cmd = cmds; cmd->pc_name; cmd++) {
101                 if (strcmp(name, cmd->pc_name) == 0)
102                         return cmd;
103         }
104         return NULL;
105 }
106
107 void Parser_ignore_errors(int ignore)
108 {
109         ignore_errors = ignore;
110 }
111
112 int Parser_execarg(int argc, char **argv, command_t cmds[])
113 {
114         command_t *cmd;
115
116         cmd = Parser_findargcmd(argv[0], cmds);
117         if (cmd && cmd->pc_func) {
118                 int rc = cmd->pc_func(argc, argv);
119
120                 if (rc == CMD_HELP)
121                         fprintf(stderr, "%s\n", cmd->pc_help);
122                 return rc;
123         }
124         printf("Try interactive use without arguments or use one of:\n");
125         for (cmd = cmds; cmd->pc_name; cmd++)
126                 printf("\"%s\"\n", cmd->pc_name);
127         printf("as argument.\n");
128
129         return -1;
130 }
131
132 /*
133  * Returns the command_t * (NULL if not found) corresponding to a
134  * _partial_ match with the first token in name.  It sets *next to
135  * point to the following token. Does not modify *name.
136  */
137 static command_t *find_cmd(char *name, command_t cmds[], char **next)
138 {
139         int i, len;
140
141         if (!cmds || !name)
142                 return NULL;
143
144         /*
145          * This sets name to point to the first non-white space character,
146          * and next to the first whitespace after name, len to the length: do
147          * this with strtok
148          */
149         name = skipwhitespace(name);
150         *next = skiptowhitespace(name);
151         len = (int)(*next - name);
152         if (len == 0)
153                 return NULL;
154
155         for (i = 0; cmds[i].pc_name; i++) {
156                 if (strncasecmp(name, cmds[i].pc_name, len) == 0) {
157                         *next = skipwhitespace(*next);
158                         return &cmds[i];
159                 }
160         }
161         return NULL;
162 }
163
164 /*
165  * Recursively process a command line string s and find the command
166  * corresponding to it. This can be ambiguous, full, incomplete,
167  * non-existent.
168  */
169 static int process(char *s, char **next, command_t *lookup,
170                    command_t **result, char **prev)
171 {
172         *result = find_cmd(s, lookup, next);
173         *prev = s;
174
175         /* non existent */
176         if (!*result)
177                 return CMD_NONE;
178
179         /*
180          * found entry: is it ambigous, i.e. not exact command name and
181          * more than one command in the list matches.  Note that find_cmd
182          * points to the first ambiguous entry
183          */
184         if (strncasecmp(s, (*result)->pc_name, strlen((*result)->pc_name))) {
185                 char *another_next;
186                 int found_another = 0;
187
188                 command_t *another_result = find_cmd(s, (*result) + 1,
189                                                      &another_next);
190                 while (another_result) {
191                         if (strncasecmp(s, another_result->pc_name,
192                                         strlen(another_result->pc_name)) == 0) {
193                                 *result = another_result;
194                                 *next = another_next;
195                                 goto got_it;
196                         }
197                         another_result = find_cmd(s, another_result + 1,
198                                                   &another_next);
199                         found_another = 1;
200                 }
201                 if (found_another)
202                         return CMD_AMBIG;
203         }
204
205 got_it:
206         /* found a unique command: component or full? */
207         if ((*result)->pc_func)
208                 return CMD_COMPLETE;
209
210         if (**next == '\0')
211                 return CMD_INCOMPLETE;
212         return process(*next, next, (*result)->pc_sub_cmd,
213                        result, prev);
214 }
215
216 #ifdef HAVE_LIBREADLINE
217 static command_t *match_tbl; /* Command completion against this table */
218 static char *command_generator(const char *text, int state)
219 {
220         static int index, len;
221         char *name;
222
223         /* Do we have a match table? */
224         if (!match_tbl)
225                 return NULL;
226
227         /* If this is the first time called on this word, state is 0 */
228         if (!state) {
229                 index = 0;
230                 len = (int)strlen(text);
231         }
232
233         /* Return next name in the command list that paritally matches test */
234         while ((name = (match_tbl + index)->pc_name)) {
235                 index++;
236
237                 if (strncasecmp(name, text, len) == 0)
238                         return strdup(name);
239         }
240
241         /* No more matches */
242         return NULL;
243 }
244
245 /* probably called by readline */
246 static char **command_completion(const char *text, int start, int end)
247 {
248         command_t *table;
249         char *pos;
250
251         match_tbl = top_level;
252
253         for (table = find_cmd(rl_line_buffer, match_tbl, &pos);
254              table; table = find_cmd(pos, match_tbl, &pos)) {
255                 if (*(pos - 1) == ' ')
256                         match_tbl = table->pc_sub_cmd;
257         }
258
259         return rl_completion_matches(text, command_generator);
260 }
261 #endif
262
263 /* take a string and execute the function or print help */
264 int execute_line(char *line)
265 {
266         command_t *cmd, *ambig;
267         char *prev;
268         char *next, *tmp;
269         char *argv[MAXARGS];
270         int i;
271         int rc = 0;
272
273         switch (process(line, &next, top_level, &cmd, &prev)) {
274         case CMD_AMBIG:
275                 fprintf(stderr, "Ambiguous command \'%s\'\nOptions: ", line);
276                 while ((ambig = find_cmd(prev, cmd, &tmp))) {
277                         fprintf(stderr, "%s ", ambig->pc_name);
278                         cmd = ambig + 1;
279                 }
280                 fprintf(stderr, "\n");
281                 break;
282         case CMD_NONE:
283                 fprintf(stderr, "No such command, type help\n");
284                 break;
285         case CMD_INCOMPLETE:
286                 fprintf(stderr,
287                         "'%s' incomplete command.  Use '%s x' where x is one of:\n",
288                         line, line);
289                 fprintf(stderr, "\t");
290                 for (i = 0; cmd->pc_sub_cmd[i].pc_name; i++)
291                         fprintf(stderr, "%s ", cmd->pc_sub_cmd[i].pc_name);
292                 fprintf(stderr, "\n");
293                 break;
294         case CMD_COMPLETE:
295                 optind = 0;
296                 i = line2args(line, argv, MAXARGS);
297                 rc = cmd->pc_func(i, argv);
298
299                 if (rc == CMD_HELP)
300                         fprintf(stderr, "%s\n", cmd->pc_help);
301
302                 break;
303         }
304
305         return rc;
306 }
307
308 #ifdef HAVE_LIBREADLINE
309 static void noop_int_fn(int unused) { }
310 static void noop_void_fn(void) { }
311 #endif
312
313 /*
314  * just in case you're ever in an airplane and discover you
315  * forgot to install readline-dev. :)
316  */
317 static int init_input(void)
318 {
319         int interactive = isatty(fileno(stdin));
320
321 #ifdef HAVE_LIBREADLINE
322         using_history();
323         stifle_history(HISTORY);
324
325         if (!interactive) {
326                 rl_prep_term_function = noop_int_fn;
327                 rl_deprep_term_function = noop_void_fn;
328         }
329
330         rl_attempted_completion_function = command_completion;
331         rl_completion_entry_function = command_generator;
332 #endif
333         return interactive;
334 }
335
336 #ifndef HAVE_LIBREADLINE
337 #define add_history(s)
338 char *readline(char *prompt)
339 {
340         int size = 2048;
341         char *line = malloc(size);
342         char *ptr = line;
343         int c;
344         int eof = 0;
345
346         if (!line)
347                 return NULL;
348         if (prompt)
349                 printf("%s", prompt);
350
351         while (1) {
352                 if ((c = fgetc(stdin)) != EOF) {
353                         if (c == '\n')
354                                 goto out;
355                         *ptr++ = (char)c;
356
357                         if (ptr - line >= size - 1) {
358                                 char *tmp;
359
360                                 size *= 2;
361                                 tmp = malloc(size);
362                                 if (!tmp)
363                                         goto outfree;
364                                 memcpy(tmp, line, ptr - line);
365                                 ptr = tmp + (ptr - line);
366                                 free(line);
367                                 line = tmp;
368                         }
369                 } else {
370                         eof = 1;
371                         if (ferror(stdin) || feof(stdin))
372                                 goto outfree;
373                         goto out;
374                 }
375         }
376 out:
377         *ptr = 0;
378         if (eof && (strlen(line) == 0)) {
379                 free(line);
380                 line = NULL;
381         }
382         return line;
383 outfree:
384         free(line);
385         return NULL;
386 }
387 #endif
388
389 /* this is the command execution machine */
390 int Parser_commands(void)
391 {
392         char *line, *s;
393         int rc = 0, save_error = 0;
394         int interactive;
395
396         interactive = init_input();
397
398         while (!done) {
399                 line = readline(interactive ? parser_prompt : NULL);
400
401                 if (!line)
402                         break;
403
404                 s = skipwhitespace(line);
405
406                 if (*s) {
407                         add_history(s);
408                         rc = execute_line(s);
409                 }
410                 /* stop on error if not-interactive */
411                 if (rc != 0 && !interactive) {
412                         if (save_error == 0)
413                                 save_error = rc;
414                         if (!ignore_errors)
415                                 done = 1;
416                 }
417                 free(line);
418         }
419
420         if (save_error)
421                 rc = save_error;
422
423         return rc;
424 }
425
426 /* sets the parser prompt */
427 void Parser_init(char *prompt, command_t *cmds)
428 {
429         done = 0;
430         top_level = cmds;
431         if (parser_prompt)
432                 free(parser_prompt);
433         parser_prompt = strdup(prompt);
434 }
435
436 /* frees the parser prompt */
437 void Parser_exit(int argc, char *argv[])
438 {
439         done = 1;
440         free(parser_prompt);
441         parser_prompt = NULL;
442 }
443
444 /* convert a string to an integer */
445 int Parser_int(char *s, int *val)
446 {
447         int ret;
448
449         if (*s != '0') {
450                 ret = sscanf(s, "%d", val);
451         } else if (*(s + 1) != 'x') {
452                 ret = sscanf(s, "%o", val);
453         } else {
454                 s++;
455                 ret = sscanf(++s, "%x", val);
456         }
457
458         return ret;
459 }
460
461 void Parser_qhelp(int argc, char *argv[])
462 {
463         printf("usage: %s [COMMAND] [OPTIONS]... [ARGS]\n",
464                program_invocation_short_name);
465         printf("Without any parameters, interactive mode is invoked\n");
466
467         printf("Try '%s help <COMMAND>' or '%s --list-commands' for more information\n",
468                program_invocation_short_name, program_invocation_short_name);
469 }
470
471 int Parser_help(int argc, char **argv)
472 {
473         char line[1024];
474         char *next, *prev, *tmp;
475         command_t *result, *ambig;
476         int i;
477
478         if (argc == 1) {
479                 Parser_qhelp(argc, argv);
480                 return 0;
481         }
482
483         /*
484          * Joining command line arguments without space is not critical here
485          * because of this string is used for search a help topic and assume
486          * that only one argument will be (the name of topic). For example:
487          * lst > help ping run
488          * pingrun: Unknown command.
489          */
490         line[0] = '\0';
491         for (i = 1;  i < argc; i++) {
492                 if (strlen(argv[i]) >= sizeof(line) - strlen(line))
493                         return -E2BIG;
494                 /*
495                  * The function strlcat() cannot be used here because of
496                  * this function is used in LNet utils that is not linked
497                  * with libcfs.a.
498                  */
499                 strncat(line, argv[i], sizeof(line) - strlen(line));
500         }
501
502         switch (process(line, &next, top_level, &result, &prev)) {
503         case CMD_COMPLETE:
504                 fprintf(stderr, "%s: %s\n", line, result->pc_help);
505                 break;
506         case CMD_NONE:
507                 fprintf(stderr, "%s: Unknown command.\n", line);
508                 break;
509         case CMD_INCOMPLETE:
510                 fprintf(stderr,
511                         "'%s' incomplete command.  Use '%s x' where x is one of:\n",
512                         line, line);
513                 fprintf(stderr, "\t");
514                 for (i = 0; result->pc_sub_cmd[i].pc_name; i++)
515                         fprintf(stderr, "%s ", result->pc_sub_cmd[i].pc_name);
516                 fprintf(stderr, "\n");
517                 break;
518         case CMD_AMBIG:
519                 fprintf(stderr, "Ambiguous command \'%s\'\nOptions: ", line);
520                 while ((ambig = find_cmd(prev, result, &tmp))) {
521                         fprintf(stderr, "%s ", ambig->pc_name);
522                         result = ambig + 1;
523                 }
524                 fprintf(stderr, "\n");
525                 break;
526         }
527         return 0;
528 }
529
530 void Parser_printhelp(char *cmd)
531 {
532         char *argv[] = { "help", cmd };
533
534         Parser_help(2, argv);
535 }
536
537 /* COMMANDS */
538
539 /**
540  * Parser_list_commands() - Output a list of the supported commands.
541  * @cmdlist:      Array of structures describing the commands.
542  * @buffer:       String buffer used to temporarily store the output text.
543  * @buf_size:     Length of the string buffer.
544  * @parent_cmd:   When called recursively, contains the name of the parent cmd.
545  * @col_start:    Column where printing should begin.
546  * @col_num:      The number of commands printed in a single row.
547  *
548  * The commands and subcommands supported by the utility are printed, arranged
549  * into several columns for readability.  If a command supports subcommands, the
550  * function is called recursively, and the name of the parent command is
551  * supplied so that it can be prepended to the names of the subcommands.
552  *
553  * Return: The number of items that were printed.
554  */
555 int Parser_list_commands(const command_t *cmdlist, char *buffer,
556                          size_t buf_size, const char *parent_cmd,
557                          int col_start, int col_num)
558 {
559         int col = col_start;
560         int char_max;
561         int len;
562         int count = 0;
563         int rc;
564
565         if (col_start >= col_num)
566                 return 0;
567
568         char_max = (buf_size - 1) / col_num; /* Reserve 1 char for NUL */
569
570         for (; cmdlist->pc_name; cmdlist++) {
571                 if (!cmdlist->pc_func && !cmdlist->pc_sub_cmd)
572                         break;
573                 count++;
574                 if (parent_cmd)
575                         len = snprintf(&buffer[col * char_max],
576                                        char_max + 1, "%s %s", parent_cmd,
577                                        cmdlist->pc_name);
578                 else
579                         len = snprintf(&buffer[col * char_max],
580                                        char_max + 1, "%s", cmdlist->pc_name);
581
582                 /* Add trailing spaces to pad the entry to the column size */
583                 if (len < char_max) {
584                         snprintf(&buffer[col * char_max] + len,
585                                  char_max - len + 1, "%*s", char_max - len,
586                                  " ");
587                 } else {
588                         buffer[(col + 1) * char_max - 1] = ' ';
589                 }
590
591                 col++;
592                 if (col >= col_num) {
593                         fprintf(stdout, "%s\n", buffer);
594                         col = 0;
595                         buffer[0] = '\0';
596                 }
597
598                 if (cmdlist->pc_sub_cmd) {
599                         rc = Parser_list_commands(cmdlist->pc_sub_cmd, buffer,
600                                                   buf_size, cmdlist->pc_name,
601                                                   col, col_num);
602                         col = (col + rc) % col_num;
603                         count += rc;
604                 }
605         }
606         if (!parent_cmd && col != 0)
607                 fprintf(stdout, "%s\n", buffer);
608         return count;
609 }
610
611 char *Parser_getstr(const char *prompt, const char *deft, char *res,
612                     size_t len)
613 {
614         char *line = NULL;
615         int size = strlen(prompt) + strlen(deft) + 8;
616         char *theprompt;
617
618         theprompt = malloc(size);
619         assert(theprompt);
620
621         snprintf(theprompt, size, "%s [%s]: ", prompt, deft);
622
623         line  = readline(theprompt);
624         free(theprompt);
625
626         /*
627          * The function strlcpy() cannot be used here because of
628          * this function is used in LNet utils that is not linked
629          * with libcfs.a.
630          */
631         if (!line || *line == '\0')
632                 strncpy(res, deft, len);
633         else
634                 strncpy(res, line, len);
635         res[len - 1] = '\0';
636
637         if (line) {
638                 free(line);
639                 return res;
640         }
641         return NULL;
642 }
643
644 /* get integer from prompt, loop forever to get it */
645 int Parser_getint(const char *prompt, long min, long max, long deft, int base)
646 {
647         int rc;
648         long result;
649         char *line;
650         int size = strlen(prompt) + 40;
651         char *theprompt = malloc(size);
652
653         assert(theprompt);
654         snprintf(theprompt, size, "%s [%ld, (0x%lx)]: ", prompt, deft, deft);
655         fflush(stdout);
656
657         do {
658                 line = NULL;
659                 line = readline(theprompt);
660                 if (!line) {
661                         fprintf(stdout, "Please enter an integer.\n");
662                         fflush(stdout);
663                         continue;
664                 }
665                 if (*line == '\0') {
666                         free(line);
667                         result =  deft;
668                         break;
669                 }
670                 rc = Parser_arg2int(line, &result, base);
671                 free(line);
672                 if (rc != 0) {
673                         fprintf(stdout, "Invalid string.\n");
674                         fflush(stdout);
675                 } else if (result > max || result < min) {
676                         fprintf(stdout,
677                                 "Error: response must lie between %ld and %ld.\n",
678                                 min, max);
679                         fflush(stdout);
680                 } else {
681                         break;
682                 }
683         } while (1);
684
685         if (theprompt)
686                 free(theprompt);
687         return result;
688 }
689
690 /* get boolean (starting with YyNn; loop forever */
691 int Parser_getbool(const char *prompt, int deft)
692 {
693         int result = 0;
694         char *line;
695         int size = strlen(prompt) + 8;
696         char *theprompt = malloc(size);
697
698         assert(theprompt);
699         fflush(stdout);
700
701         if (deft != 0 && deft != 1) {
702                 fprintf(stderr, "Error: Parser_getbool given bad default %d\n",
703                         deft);
704                 assert(0);
705         }
706         snprintf(theprompt, size, "%s [%s]: ", prompt, (deft == 0) ? "N" : "Y");
707
708         do {
709                 line = NULL;
710                 line = readline(theprompt);
711                 if (!line) {
712                         result = deft;
713                         break;
714                 }
715                 if (*line == '\0') {
716                         result = deft;
717                         break;
718                 }
719                 if (*line == 'y' || *line == 'Y') {
720                         result = 1;
721                         break;
722                 }
723                 if (*line == 'n' || *line == 'N') {
724                         result = 0;
725                         break;
726                 }
727                 if (line)
728                         free(line);
729                 fprintf(stdout, "Invalid string. Must start with yY or nN\n");
730                 fflush(stdout);
731         } while (1);
732
733         if (line)
734                 free(line);
735         if (theprompt)
736                 free(theprompt);
737
738         return result;
739 }
740
741 /* parse int out of a string or prompt for it */
742 long Parser_intarg(const char *inp, const char *prompt, int deft,
743                    int min, int max, int base)
744 {
745         long result;
746         int rc;
747
748         rc = Parser_arg2int(inp, &result, base);
749         if (rc == 0)
750                 return result;
751         else
752                 return Parser_getint(prompt, deft, min, max, base);
753 }
754
755 /* parse int out of a string or prompt for it */
756 char *Parser_strarg(char *inp, const char *prompt, const char *deft,
757                     char *answer, int len)
758 {
759         if (!inp || *inp == '\0')
760                 return Parser_getstr(prompt, deft, answer, len);
761         else
762                 return inp;
763 }
764
765 /*
766  * change a string into a number: return 0 on success. No invalid characters
767  * allowed. The processing of base and validity follows strtol(3)
768  */
769 int Parser_arg2int(const char *inp, long *result, int base)
770 {
771         char *endptr;
772
773         if ((base != 0) && (base < 2 || base > 36))
774                 return 1;
775
776         *result = strtol(inp, &endptr, base);
777
778         if (*inp != '\0' && *endptr == '\0')
779                 return 0;
780         else
781                 return 1;
782 }
783
784 /* Convert human readable size string to and int; "1k" -> 1000 */
785 int Parser_size(unsigned long *sizep, char *str)
786 {
787         unsigned long size;
788         char mod[32];
789
790         switch (sscanf(str, "%lu%1[gGmMkK]", &size, mod)) {
791         default:
792                 return -1;
793         case 1:
794                 *sizep = size;
795                 return 0;
796         case 2:
797                 switch (*mod) {
798                 case 'g':
799                 case 'G':
800                         *sizep = size << 30;
801                         return 0;
802                 case 'm':
803                 case 'M':
804                         *sizep = size << 20;
805                         return 0;
806                 case 'k':
807                 case 'K':
808                         *sizep = size << 10;
809                         return 0;
810                 default:
811                         *sizep = size;
812                         return 0;
813                 }
814         }
815 }
816
817 /* Convert a string boolean to an int; "enable" -> 1 */
818 int Parser_bool(int *b, char *str)
819 {
820         if (!strcasecmp(str, "no") || !strcasecmp(str, "n") ||
821             !strcasecmp(str, "off") || !strcasecmp(str, "down") ||
822             !strcasecmp(str, "disable")) {
823                 *b = 0;
824                 return 0;
825         }
826
827         if (!strcasecmp(str, "yes") || !strcasecmp(str, "y") ||
828             !strcasecmp(str, "on") || !strcasecmp(str, "up") ||
829             !strcasecmp(str, "enable")) {
830                 *b = 1;
831                 return 0;
832         }
833
834         return -1;
835 }
836
837 int Parser_quit(int argc, char **argv)
838 {
839         argc = argc;
840         argv = argv;
841         done = 1;
842         return 0;
843 }
844
845 int Parser_version(int argc, char **argv)
846 {
847         fprintf(stdout, "%s %s\n", program_invocation_short_name,
848                 LUSTRE_VERSION_STRING);
849         return 0;
850 }