static int zfs_do_unload_key(int argc, char **argv);
static int zfs_do_change_key(int argc, char **argv);
static int zfs_do_project(int argc, char **argv);
+static int zfs_do_version(int argc, char **argv);
/*
* Enable a reasonable set of defaults for libumem debugging on DEBUG builds.
HELP_LOAD_KEY,
HELP_UNLOAD_KEY,
HELP_CHANGE_KEY,
+ HELP_VERSION
} zfs_help_t;
typedef struct zfs_command {
* the generic usage message.
*/
static zfs_command_t command_table[] = {
+ { "version", zfs_do_version, HELP_VERSION },
+ { NULL },
{ "create", zfs_do_create, HELP_CREATE },
{ "destroy", zfs_do_destroy, HELP_DESTROY },
{ NULL },
"\t [-o keylocation=<value>] [-o pbkfd2iters=<value>]\n"
"\t <filesystem|volume>\n"
"\tchange-key -i [-l] <filesystem|volume>\n"));
+ case HELP_VERSION:
+ return (gettext("\tversion\n"));
}
abort();
return (ret);
}
+/*
+ * Display version message
+ */
+static int
+zfs_do_version(int argc, char **argv)
+{
+ if (zfs_version_print() == -1)
+ return (1);
+
+ return (0);
+}
+
int
main(int argc, char **argv)
{
(strcmp(cmdname, "--help") == 0))
usage(B_TRUE);
+ /*
+ * Special case '-V|--version'
+ */
+ if ((strcmp(cmdname, "-V") == 0) || (strcmp(cmdname, "--version") == 0))
+ return (zfs_do_version(argc, argv));
+
if ((g_zfs = libzfs_init()) == NULL) {
(void) fprintf(stderr, "%s", libzfs_error_init(errno));
return (1);
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.
HELP_SPLIT,
HELP_SYNC,
HELP_REGUID,
- HELP_REOPEN
+ HELP_REOPEN,
+ HELP_VERSION
} zpool_help_t;
* 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 },
return (gettext("\treguid <pool>\n"));
case HELP_SYNC:
return (gettext("\tsync [pool] ...\n"));
+ case HELP_VERSION:
+ return (gettext("\tversion\n"));
}
abort();
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)
{
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);
int libzfs_envvar_is_set(char *envvar);
+/*
+ * Utility functions for zfs version
+ */
+extern void zfs_version_userland(char *, int);
+extern int zfs_version_kernel(char *, int);
+extern int zfs_version_print(void);
+
/*
* Given a device or file, determine if it is part of a pool.
*/
#include "zfeature_common.h"
#include <zfs_fletcher.h>
#include <libzutil.h>
+#include <sys/zfs_sysfs.h>
int
libzfs_errno(libzfs_handle_t *hdl)
{
return (zprop_iter_common(func, cb, show_all, ordered, type));
}
+
+/*
+ * Fill given version buffer with zfs userland version
+ */
+void
+zfs_version_userland(char *version, int len)
+{
+ (void) strlcpy(version, ZFS_META_ALIAS, len);
+}
+
+/*
+ * Fill given version buffer with zfs kernel version read from ZFS_SYSFS_DIR
+ * Returns 0 on success, and -1 on error (with errno set)
+ */
+int
+zfs_version_kernel(char *version, int len)
+{
+ int _errno;
+ int fd;
+ int rlen;
+
+ if ((fd = open(ZFS_SYSFS_DIR "/version", O_RDONLY)) == -1)
+ return (-1);
+
+ if ((rlen = read(fd, version, len)) == -1) {
+ version[0] = '\0';
+ _errno = errno;
+ (void) close(fd);
+ errno = _errno;
+ return (-1);
+ }
+
+ version[rlen-1] = '\0'; /* discard '\n' */
+
+ if (close(fd) == -1)
+ return (-1);
+
+ return (0);
+}
+
+/*
+ * Prints both zfs userland and kernel versions
+ * Returns 0 on success, and -1 on error (with errno set)
+ */
+int
+zfs_version_print(void)
+{
+ char zver_userland[128];
+ char zver_kernel[128];
+
+ if (zfs_version_kernel(zver_kernel, sizeof (zver_kernel)) == -1) {
+ fprintf(stderr, "zfs_version_kernel() failed: %s\n",
+ strerror(errno));
+ return (-1);
+ }
+
+ zfs_version_userland(zver_userland, sizeof (zver_userland));
+
+ (void) printf("%s\n", zver_userland);
+ (void) printf("zfs-kmod-%s\n", zver_kernel);
+
+ return (0);
+}
.Nd configures ZFS file systems
.Sh SYNOPSIS
.Nm
-.Fl ?
+.Fl ?V
.Nm
.Cm create
.Op Fl p
.Fl i
.Op Fl l
.Ar filesystem
+.Nm
+.Cm version
.Sh DESCRIPTION
The
.Nm
Displays a help message.
.It Xo
.Nm
+.Fl V, -version
+.Xc
+An alias for the
+.Nm zfs Cm version
+subcommand.
+.It Xo
+.Nm
.Cm create
.Op Fl p
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
inherit the key of its parent. Note that this command can only be run on an
encryption root that has an encrypted parent.
.El
+.It Xo
+.Nm
+.Cm version
+.Xc
+Displays the software version of the
+.Nm
+userland utility and the zfs kernel module.
.El
.Sh EXIT STATUS
The
.Nd configure ZFS storage pools
.Sh SYNOPSIS
.Nm
-.Fl ?
+.Fl ?V
.Nm
.Cm add
.Op Fl fgLnP
.Cm upgrade
.Op Fl V Ar version
.Fl a Ns | Ns Ar pool Ns ...
+.Nm
+.Cm version
.Sh DESCRIPTION
The
.Nm
Displays a help message.
.It Xo
.Nm
+.Fl V, -version
+.Xc
+An alias for the
+.Nm zpool Cm version
+subcommand.
+.It Xo
+.Nm
.Cm add
.Op Fl fgLnP
.Oo Fl o Ar property Ns = Ns Ar value Oc
This option can only be used to increase the version number up to the last
supported legacy version number.
.El
+.It Xo
+.Nm
+.Cm version
+.Xc
+Displays the software version of the
+.Nm
+userland utility and the zfs kernel module.
.El
.Sh EXIT STATUS
The following exit values are returned: