Whamcloud - gitweb
LU-2740 utils: Add support for --version option 14/11014/6
authorJames Nunez <james.a.nunez@intel.com>
Tue, 8 Jul 2014 19:37:50 +0000 (13:37 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 15 Jul 2014 03:59:11 +0000 (03:59 +0000)
For mount.lustre, mkfs.lustre, lfs, and lctl, a
--version option was added that will print the
LUSTRE_VERSION_STRING.

lctl has an option called lustre_build_version that prints
both the Lustre version and the lctl version, which is
BUILD_VERSION. Printing the lctl version was removed from
the 'lctl lustre_build_version' output since
BUILD_VERSION and LUSTRE_VERSION_STRING are very different
strings and this could be confusing to the user.

Also, mount.lustre and mkfs.lustre prints the version number
when printing help/usage. This was removed to make all
Lustre utilities have a more uniform output.

The lctl, lfs and mkfs.lustre man pages were updated to include
the --version option.

Signed-off-by: James Nunez <james.a.nunez@intel.com>
Change-Id: I301258562f51640f041dd7ac6aa695450270c385
Reviewed-on: http://review.whamcloud.com/11014
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
libcfs/include/libcfs/util/parser.h
libcfs/libcfs/util/parser.c
lustre/doc/lctl.8
lustre/doc/lfs.1
lustre/doc/mkfs.lustre.8
lustre/utils/lctl.c
lustre/utils/lfs.c
lustre/utils/mkfs_lustre.c
lustre/utils/mount_lustre.c
lustre/utils/obd.c

index 3b831f4..ff0d160 100644 (file)
@@ -68,7 +68,8 @@ typedef struct network {
        int     port;
 } network_t;
 
-int  Parser_quit(int argc, char **argv);
+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 */
index cca8e97..391db19 100644 (file)
@@ -18,6 +18,7 @@
  *
  */
 
+#include <lustre_ver.h>
 #include <libcfs/libcfsutil.h>
 
 static command_t * top_level;           /* Top level of commands, initialized by
@@ -767,3 +768,10 @@ int Parser_quit(int argc, char **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;
+}
index dc71f4a..4cd0e09 100644 (file)
@@ -420,6 +420,18 @@ number. See
 .TP
 .B --ignore_errors | ignore_errors 
 Ignore errors during script processing
+.TP
+.B lustre_build_version
+Output the build version of the Lustre kernel modules
+.TP
+.B --version
+Output the build version of the lctl utility
+.TP
+.B help
+Provides brief help on the various arguments
+.TP
+.B exit/quit
+Quit the interactive lctl session
 
 .SH EXAMPLES
 # lctl
index 1d5d9fb..2face13 100644 (file)
@@ -44,7 +44,7 @@ lfs \- Lustre utility to create a file with specific striping pattern, find the
 .B lfs osts
 .RB [ path ]
 .br
-.B path2fid <path> ...
+.B lfs path2fid <path> ...
 .br
 .B lfs pool_list <filesystem>[.<pool>] | <pathname>
 .br
@@ -84,12 +84,14 @@ lfs \- Lustre utility to create a file with specific striping pattern, find the
 .br
 .B lfs data_version [-n] \fB<filename>\fR
 .br
+.B lfs --version
+.br
 .B lfs help
 .SH DESCRIPTION
 .B lfs
 can be used to create a new file with a specific striping pattern, determine the default striping pattern, gather the extended attributes (object numbers and location) for a specific file. It can be invoked interactively without any arguments or in a non-interactive mode with one of the arguements supported. 
 .SH OPTIONS
-The various options supported by lctl are listed and explained below:
+The various options supported by lfs are listed and explained below:
 .TP
 .B changelog
 Show the metadata changes on an MDT.  Start and end points are optional.  The --follow option will block on new changes; this option is only valid when run direclty on the MDT node.
@@ -284,6 +286,9 @@ MDT0000. This is restricted to avoid creating directory trees that have
 intermediate path components on a series different MDTs and become unavailable
 if any of the intermediate MDTs are offline.
 .TP
+.B --version
+Output the build version of the lfs utility. Use "lctl lustre_build_version" to get the version of the Lustre kernel modules
+.TP
 .B help 
 Provides brief help on the various arguments
 .TP
index 317cd51..a9a879f 100644 (file)
@@ -144,6 +144,9 @@ Used for optizing MDT inode size
 .TP
 .BI \--verbose
 Print more information.
+.TP
+.BI \--version
+Output build version of the mkfs.lustre utiltiy.
 
 .SH EXAMPLES
 .TP
index 261da54..1da619c 100644 (file)
 #include <libcfs/libcfsutil.h>
 #include <lustre/lustre_idl.h>
 
-static int jt_quit(int argc, char **argv) {
-        Parser_quit(argc, argv);
-        return 0;
-}
-
 static int jt_noop(int argc, char **argv) {
         return 0;
 }
@@ -80,11 +75,13 @@ command_t cmdlist[] = {
         {"lustre_build_version", jt_get_version, 0,
          "print the build version of lustre\n"
          "usage: lustre_build_version"},
-        {"exit", jt_quit, 0, "quit"},
-        {"quit", jt_quit, 0, "quit"},
+       {"exit", Parser_quit, 0, "quit"},
+       {"quit", Parser_quit, 0, "quit"},
+       {"--version", Parser_version, 0,
+        "output build version of the utility and exit"},
 
-        /* Network configuration commands */
-        {"===== network config =====", jt_noop, 0, "network config"},
+       /* Network configuration commands */
+       {"===== network config =====", jt_noop, 0, "network config"},
         {"--net", jt_opt_net, 0,"run <command> after setting network to <net>\n"
          "usage: --net <tcp/elan/o2ib/...> <command>"},
         {"network", jt_ptl_network, 0, "configure LNET"
@@ -464,7 +461,7 @@ int lctl_main(int argc, char **argv)
         if (dbg_initialize(argc, argv) < 0)
                 exit(3);
 
-        Parser_init("lctl > ", cmdlist);
+       Parser_init("lctl > ", cmdlist);
 
         if (argc > 1) {
                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
index 512d770..7ca4a7e 100644 (file)
@@ -340,6 +340,8 @@ command_t cmdlist[] = {
        {"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"},
        { 0, 0, 0, NULL }
 };
 
@@ -3862,7 +3864,7 @@ int main(int argc, char **argv)
 
         setlinebuf(stdout);
 
-        Parser_init("lfs > ", cmdlist);
+       Parser_init("lfs > ", cmdlist);
 
         if (argc > 1) {
                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
index ceed41d..5310276 100644 (file)
@@ -76,6 +76,7 @@
 
 char *progname;
 int verbose = 1;
+int version;
 static int print_only = 0;
 
 #ifdef HAVE_LDISKFS_OSD
@@ -103,7 +104,6 @@ static int print_only = 0;
 
 void usage(FILE *out)
 {
-       fprintf(out, "%s v"LUSTRE_VERSION_STRING"\n", progname);
        fprintf(out, "usage: %s <target type> [--backfstype="FSLIST"] "
                "--fsname=<filesystem name>\n"
                "\t--index=<target index> [options] <device>\n", progname);
@@ -162,6 +162,8 @@ void usage(FILE *out)
                "\t\t--comment=<user comment>: arbitrary string (%d bytes)\n"
                "\t\t--dryrun: report what we would do; don't write to disk\n"
                "\t\t--verbose: e.g. show mkfs progress\n"
+               "\t\t-V|--version: output build version of the utility and\n"
+               "\t\t\texit\n"
                "\t\t--quiet\n",
                (int)sizeof(((struct lustre_disk_data *)0)->ldd_userdata));
        return;
@@ -304,10 +306,11 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                { "servicenode",        required_argument,      NULL, 's' },
                { "network",            required_argument,      NULL, 't' },
                { "verbose",            no_argument,            NULL, 'v' },
+               { "version",            no_argument,            NULL, 'V' },
                { "writeconf",          no_argument,            NULL, 'w' },
                { 0,                    0,                      NULL,  0  }
        };
-       char *optstring = "b:c:C:d:ef:Ghi:k:L:m:MnNo:Op:PqrRs:t:Uu:vw";
+       char *optstring = "b:c:C:d:ef:Ghi:k:L:m:MnNo:Op:PqrRs:t:Uu:vVw";
        int opt;
        int rc, longidx;
        int failnode_set = 0, servicenode_set = 0;
@@ -498,12 +501,17 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                         strscpy(mop->mo_ldd.ldd_userdata, optarg,
                                 sizeof(mop->mo_ldd.ldd_userdata));
                         break;
-                case 'v':
-                        verbose++;
-                        break;
-                case 'w':
-                        mop->mo_ldd.ldd_flags |= LDD_F_WRITECONF;
-                        break;
+               case 'v':
+                       verbose++;
+                       break;
+               case 'V':
+                       ++version;
+                       fprintf(stdout, "%s %s\n", progname,
+                               LUSTRE_VERSION_STRING);
+                       return 0;
+               case 'w':
+                       mop->mo_ldd.ldd_flags |= LDD_F_WRITECONF;
+                       break;
                case 'Q':
                        mop->mo_flags |= MO_QUOTA;
                        break;
@@ -603,16 +611,16 @@ int main(int argc, char *const argv[])
                mop.mo_ldd.ldd_flags |= LDD_F_WRITECONF;
        }
 
-        if (strstr(mop.mo_ldd.ldd_params, PARAM_MGSNODE))
-            mop.mo_mgs_failnodes++;
+       if (strstr(mop.mo_ldd.ldd_params, PARAM_MGSNODE))
+               mop.mo_mgs_failnodes++;
 
-        if (verbose > 0)
-                print_ldd("Read previous values", &(mop.mo_ldd));
+       if (verbose > 0)
+               print_ldd("Read previous values", &(mop.mo_ldd));
 #endif
 
-        ret = parse_opts(argc, argv, &mop, &mountopts);
-        if (ret)
-                goto out;
+       ret = parse_opts(argc, argv, &mop, &mountopts);
+       if (ret || version)
+               goto out;
 
         ldd = &mop.mo_ldd;
 
index 7671da3..13b56c7 100644 (file)
 #define MAXOPT 4096
 #define MAX_RETRIES 99
 
-int          verbose = 0;
-char         *progname = NULL;
+int    verbose;
+int    version;
+char   *progname;
 
 void usage(FILE *out)
 {
-        fprintf(out, "%s v"LUSTRE_VERSION_STRING"\n", progname);
-        fprintf(out, "\nThis mount helper should only be invoked via the "
-                "mount (8) command,\ne.g. mount -t lustre dev dir\n\n");
-        fprintf(out, "usage: %s [-fhnv] [-o <mntopt>] <device> <mountpt>\n",
-                progname);
-        fprintf(out,
-                "\t<device>: the disk device, or for a client:\n"
-                "\t\t<mgmtnid>[:<altmgtnid>...]:/<filesystem>-client\n"
-                "\t<filesystem>: name of the Lustre filesystem (e.g. lustre1)\n"
-                "\t<mountpt>: filesystem mountpoint (e.g. /mnt/lustre)\n"
-                "\t-f|--fake: fake mount (updates /etc/mtab)\n"
-                "\t-o force|--force: force mount even if already in /etc/mtab\n"
-                "\t-h|--help: print this usage message\n"
-                "\t-n|--nomtab: do not update /etc/mtab after mount\n"
-                "\t-v|--verbose: print verbose config settings\n"
-                "\t<mntopt>: one or more comma separated of:\n"
-                "\t\t(no)flock,(no)user_xattr,(no)acl\n"
-                "\t\tabort_recov: abort server recovery handling\n"
-                "\t\tnosvc: only start MGC/MGS obds\n"
-                "\t\tnomgs: only start target obds, using existing MGS\n"
-                "\t\texclude=<ostname>[:<ostname>] : colon-separated list of "
-                "inactive OSTs (e.g. lustre-OST0001)\n"
-                "\t\tretry=<num>: number of times mount is retried by client\n"
-                "\t\tmd_stripe_cache_size=<num>: set the raid stripe cache "
-                "size for the underlying raid if present\n"
-                );
-        exit((out != stdout) ? EINVAL : 0);
+       fprintf(out, "\nThis mount helper should only be invoked via the "
+               "mount (8) command,\ne.g. mount -t lustre dev dir\n\n");
+       fprintf(out, "usage: %s [-fhnvV] [-o <mntopt>] <device> <mountpt>\n",
+               progname);
+       fprintf(out,
+               "\t<device>: the disk device, or for a client:\n"
+               "\t\t<mgmtnid>[:<altmgtnid>...]:/<filesystem>-client\n"
+               "\t<filesystem>: name of the Lustre filesystem (e.g. lustre1)\n"
+               "\t<mountpt>: filesystem mountpoint (e.g. /mnt/lustre)\n"
+               "\t-f|--fake: fake mount (updates /etc/mtab)\n"
+               "\t-o force|--force: force mount even if already in /etc/mtab\n"
+               "\t-h|--help: print this usage message\n"
+               "\t-n|--nomtab: do not update /etc/mtab after mount\n"
+               "\t-v|--verbose: print verbose config settings\n"
+               "\t-V|--version: output build version of the utility and exit\n"
+               "\t<mntopt>: one or more comma separated of:\n"
+               "\t\t(no)flock,(no)user_xattr,(no)acl\n"
+               "\t\tabort_recov: abort server recovery handling\n"
+               "\t\tnosvc: only start MGC/MGS obds\n"
+               "\t\tnomgs: only start target obds, using existing MGS\n"
+               "\t\texclude=<ostname>[:<ostname>] : colon-separated list of "
+               "inactive OSTs (e.g. lustre-OST0001)\n"
+               "\t\tretry=<num>: number of times mount is retried by client\n"
+               "\t\tmd_stripe_cache_size=<num>: set the raid stripe cache "
+               "size for the underlying raid if present\n");
+       exit((out != stdout) ? EINVAL : 0);
 }
 
 /* Get rid of symbolic hostnames for tcp, since kernel can't do lookups */
@@ -508,6 +508,7 @@ static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
                {"nomtab", 0, 0, 'n'},
                {"options", 1, 0, 'o'},
                {"verbose", 0, 0, 'v'},
+               {"version", 0, 0, 'V'},
                {0, 0, 0, 0}
        };
        char real_path[PATH_MAX] = {'\0'};
@@ -517,7 +518,7 @@ static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
        char *ptr;
        int opt, rc;
 
-       while ((opt = getopt_long(argc, argv, "fhno:v",
+       while ((opt = getopt_long(argc, argv, "fhno:vV",
                                  long_opt, NULL)) != EOF){
                switch (opt) {
                case 1:
@@ -541,6 +542,11 @@ static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
                case 'v':
                        ++verbose;
                        break;
+               case 'V':
+                       ++version;
+                       fprintf(stdout, "%s %s\n", progname,
+                               LUSTRE_VERSION_STRING);
+                       return 0;
                default:
                        fprintf(stderr, "%s: unknown option '%c'\n",
                                        progname, opt);
@@ -614,7 +620,7 @@ int main(int argc, char *const argv[])
                return rc;
 
        rc = parse_opts(argc, argv, &mop);
-       if (rc)
+       if (rc || version)
                return rc;
 
         if (verbose) {
index 9bac523..235e785 100644 (file)
@@ -932,11 +932,10 @@ int jt_get_version(int argc, char **argv)
         if (rc)
                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
                         strerror(-rc));
-        else
-                printf("Lustre version: %s\n", version);
+       else
+               printf("Lustre version: %s\n", version);
 
-        printf("lctl   version: %s\n", BUILD_VERSION);
-        return rc;
+       return rc;
 }
 
 static void print_obd_line(char *s)