aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Moeller <[email protected]>2020-02-12 16:00:19 -0500
committerGitHub <[email protected]>2020-02-12 13:00:19 -0800
commite7be5c47bd8f824c79631b2747731ae169d6ae7a (patch)
tree092a00cad58f0482c578822d7647b15cb028d457
parent1bbeb6d755ba2aa72578faceb44183987c51b8d8 (diff)
Move zfs_version_kernel to platform code
Linux uses sysfs to determine the module version, FreeBSD uses a different method. Reviewed-by: Igor Kozhukhov <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #9978
-rw-r--r--lib/libzfs/libzfs_util.c31
-rw-r--r--lib/libzfs/os/linux/libzfs_util_os.c31
2 files changed, 31 insertions, 31 deletions
diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c
index 2ce3ad106..a8e9ac9cb 100644
--- a/lib/libzfs/libzfs_util.c
+++ b/lib/libzfs/libzfs_util.c
@@ -54,7 +54,6 @@
#include "zfeature_common.h"
#include <zfs_fletcher.h>
#include <libzutil.h>
-#include <sys/zfs_sysfs.h>
int
@@ -1834,36 +1833,6 @@ zfs_version_userland(char *version, int 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)
*/
diff --git a/lib/libzfs/os/linux/libzfs_util_os.c b/lib/libzfs/os/linux/libzfs_util_os.c
index c27dc91bc..918a43f7d 100644
--- a/lib/libzfs/os/linux/libzfs_util_os.c
+++ b/lib/libzfs/os/linux/libzfs_util_os.c
@@ -41,6 +41,7 @@
#include "libzfs_impl.h"
#include "zfs_prop.h"
#include <libzutil.h>
+#include <sys/zfs_sysfs.h>
#define ZDIFF_SHARESDIR "/.zfs/shares/"
@@ -182,3 +183,33 @@ find_shares_object(differ_info_t *di)
di->shares = (uint64_t)sb.st_ino;
return (0);
}
+
+/*
+ * 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);
+}