Move zfs_version_kernel to platform code

Linux uses sysfs to determine the module version, FreeBSD uses a
different method.

Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #9978
This commit is contained in:
Ryan Moeller 2020-02-12 16:00:19 -05:00 committed by GitHub
parent 1bbeb6d755
commit e7be5c47bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 31 deletions

View File

@ -54,7 +54,6 @@
#include "zfeature_common.h"
#include <zfs_fletcher.h>
#include <libzutil.h>
#include <sys/zfs_sysfs.h>
int
@ -1833,36 +1832,6 @@ 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)

View File

@ -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);
}