mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
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 <behlendorf1@llnl.gov> Reviewed-by: Matthew Ahrens <mahrens@delphix.com> Reviewed-by: Richard Laager <rlaager@wiktel.com> Signed-off-by: TerraTech <1118433+TerraTech@users.noreply.github.com> Closes #2501 Closes #8567
This commit is contained in:
committed by
Brian Behlendorf
parent
8750edf1f7
commit
50478c6dad
@@ -54,6 +54,7 @@
|
||||
#include "zfeature_common.h"
|
||||
#include <zfs_fletcher.h>
|
||||
#include <libzutil.h>
|
||||
#include <sys/zfs_sysfs.h>
|
||||
|
||||
int
|
||||
libzfs_errno(libzfs_handle_t *hdl)
|
||||
@@ -1940,3 +1941,66 @@ zprop_iter(zprop_func func, void *cb, boolean_t show_all, boolean_t ordered,
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user