diff options
author | TerraTech <[email protected]> | 2019-04-10 00:43:28 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2019-04-16 12:24:06 -0700 |
commit | 50478c6dadc2accfab5bfe72d278ede17c2e13cf (patch) | |
tree | db8bacb6f2193e7c20b311780f7516549b24f798 /cmd/zpool | |
parent | 8750edf1f75e4f02c353be490309940f11115f23 (diff) |
Add option [-V|--version] to emit version string
Add the 'zfs version' and 'zpool version' subcommands to display
the version of the user space utilities and loaded zfs kernel
module. For example:
$ zfs version
zfs-0.8.0-rc3_169_g67e0366b88
zfs-kmod-0.8.0-rc3_169_g67e0366b88
The '-V' and '--version' aliases were added to support the
common convention of using 'zfs --version` to obtain the version
information.
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Matthew Ahrens <[email protected]>
Reviewed-by: Richard Laager <[email protected]>
Signed-off-by: TerraTech <[email protected]>
Closes #2501
Closes #8567
Diffstat (limited to 'cmd/zpool')
-rw-r--r-- | cmd/zpool/zpool_main.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index f4670fd62..c167324ce 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -115,6 +115,8 @@ static int zpool_do_set(int, char **); static int zpool_do_sync(int, char **); +static int zpool_do_version(int, char **); + /* * These libumem hooks provide a reasonable set of defaults for the allocator's * debugging facilities. @@ -164,7 +166,8 @@ typedef enum { HELP_SPLIT, HELP_SYNC, HELP_REGUID, - HELP_REOPEN + HELP_REOPEN, + HELP_VERSION } zpool_help_t; @@ -263,6 +266,8 @@ typedef struct zpool_command { * the generic usage message. */ static zpool_command_t command_table[] = { + { "version", zpool_do_version, HELP_VERSION }, + { NULL }, { "create", zpool_do_create, HELP_CREATE }, { "destroy", zpool_do_destroy, HELP_DESTROY }, { NULL }, @@ -404,6 +409,8 @@ get_usage(zpool_help_t idx) return (gettext("\treguid <pool>\n")); case HELP_SYNC: return (gettext("\tsync [pool] ...\n")); + case HELP_VERSION: + return (gettext("\tversion\n")); } abort(); @@ -9222,6 +9229,18 @@ find_command_idx(char *command, int *idx) return (1); } +/* + * Display version message + */ +static int +zpool_do_version(int argc, char **argv) +{ + if (zfs_version_print() == -1) + return (1); + + return (0); +} + int main(int argc, char **argv) { @@ -9252,6 +9271,12 @@ main(int argc, char **argv) if ((strcmp(cmdname, "-?") == 0) || strcmp(cmdname, "--help") == 0) usage(B_TRUE); + /* + * Special case '-V|--version' + */ + if ((strcmp(cmdname, "-V") == 0) || (strcmp(cmdname, "--version") == 0)) + return (zpool_do_version(argc, argv)); + if ((g_zfs = libzfs_init()) == NULL) { (void) fprintf(stderr, "%s", libzfs_error_init(errno)); return (1); |