From f6e22561d21af6700a1180ecaedc93049614b307 Mon Sep 17 00:00:00 2001 From: Coleman Kane Date: Thu, 2 Dec 2021 23:25:08 -0500 Subject: [PATCH] Linux 5.16: type member of iov_iter renamed iter_type The iov_iter->type member was renamed iov_iter->iter_type. However, while looking into this, realized that in 2018 a iov_iter_type(*iov) accessor function was introduced. So if that is present, use it, otherwise fall back to trying the existing behavior of directly accessing type from iov_iter. Reviewed-by: Tony Hutter Reviewed-by: Brian Behlendorf Signed-off-by: Coleman Kane Closes #12819 --- config/kernel-vfs-iov_iter.m4 | 22 ++++++++++++++++++++++ module/os/linux/zfs/zpl_file.c | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/config/kernel-vfs-iov_iter.m4 b/config/kernel-vfs-iov_iter.m4 index bee6d0be9..ecdda939f 100644 --- a/config/kernel-vfs-iov_iter.m4 +++ b/config/kernel-vfs-iov_iter.m4 @@ -74,6 +74,14 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_VFS_IOV_ITER], [ bytes = copy_from_iter((void *)&buf, size, &iter); ]) + + ZFS_LINUX_TEST_SRC([iov_iter_type], [ + #include + #include + ],[ + struct iov_iter iter = { 0 }; + __attribute__((unused)) enum iter_type i = iov_iter_type(&iter); + ]) ]) AC_DEFUN([ZFS_AC_KERNEL_VFS_IOV_ITER], [ @@ -149,6 +157,20 @@ AC_DEFUN([ZFS_AC_KERNEL_VFS_IOV_ITER], [ enable_vfs_iov_iter="no" ]) + dnl # + dnl # This checks for iov_iter_type() in linux/uio.h. It is not + dnl # required, however, and the module will compiled without it + dnl # using direct access of the member attribute + dnl # + AC_MSG_CHECKING([whether iov_iter_type() is available]) + ZFS_LINUX_TEST_RESULT([iov_iter_type], [ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_IOV_ITER_TYPE, 1, + [iov_iter_type() is available]) + ],[ + AC_MSG_RESULT(no) + ]) + dnl # dnl # As of the 4.9 kernel support is provided for iovecs, kvecs, dnl # bvecs and pipes in the iov_iter structure. As long as the diff --git a/module/os/linux/zfs/zpl_file.c b/module/os/linux/zfs/zpl_file.c index 63002fe3b..7e88eae33 100644 --- a/module/os/linux/zfs/zpl_file.c +++ b/module/os/linux/zfs/zpl_file.c @@ -250,11 +250,17 @@ zpl_uio_init(zfs_uio_t *uio, struct kiocb *kiocb, struct iov_iter *to, { #if defined(HAVE_VFS_IOV_ITER) zfs_uio_iov_iter_init(uio, to, pos, count, skip); +#else +#ifdef HAVE_IOV_ITER_TYPE + zfs_uio_iovec_init(uio, to->iov, to->nr_segs, pos, + iov_iter_type(to) & ITER_KVEC ? UIO_SYSSPACE : UIO_USERSPACE, + count, skip); #else zfs_uio_iovec_init(uio, to->iov, to->nr_segs, pos, to->type & ITER_KVEC ? UIO_SYSSPACE : UIO_USERSPACE, count, skip); #endif +#endif } static ssize_t