Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport] 4.8, 5.16, and 5.17 compat patches #13058

Merged
merged 8 commits into from
Feb 4, 2022
26 changes: 26 additions & 0 deletions config/kernel-add-disk.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
dnl #
dnl # 5.16 API change
dnl # add_disk grew a must-check return code
dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_ADD_DISK], [

ZFS_LINUX_TEST_SRC([add_disk_ret], [
#include <linux/genhd.h>
], [
struct gendisk *disk = NULL;
int err = add_disk(disk);
err = err;
])

])
AC_DEFUN([ZFS_AC_KERNEL_ADD_DISK], [
AC_MSG_CHECKING([whether add_disk() returns int])
ZFS_LINUX_TEST_RESULT([add_disk_ret],
[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_ADD_DISK_RET, 1,
[add_disk() returns int])
], [
AC_MSG_RESULT(no)
])
])
17 changes: 17 additions & 0 deletions config/kernel-fallocate.m4
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ dnl # Linux 2.6.38 - 3.x API
dnl # The fallocate callback was moved from the inode_operations
dnl # structure to the file_operations structure.
dnl #
dnl #
dnl # Linux 3.15+
dnl # fallocate learned a new flag, FALLOC_FL_ZERO_RANGE
dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_FALLOCATE], [
ZFS_LINUX_TEST_SRC([file_fallocate], [
#include <linux/fs.h>
Expand All @@ -15,12 +19,25 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_FALLOCATE], [
.fallocate = test_fallocate,
};
], [])
ZFS_LINUX_TEST_SRC([falloc_fl_zero_range], [
#include <linux/falloc.h>
],[
int flags __attribute__ ((unused));
flags = FALLOC_FL_ZERO_RANGE;
])
])

AC_DEFUN([ZFS_AC_KERNEL_FALLOCATE], [
AC_MSG_CHECKING([whether fops->fallocate() exists])
ZFS_LINUX_TEST_RESULT([file_fallocate], [
AC_MSG_RESULT(yes)
AC_MSG_CHECKING([whether FALLOC_FL_ZERO_RANGE exists])
ZFS_LINUX_TEST_RESULT([falloc_fl_zero_range], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_FALLOC_FL_ZERO_RANGE, 1, [FALLOC_FL_ZERO_RANGE is defined])
],[
AC_MSG_RESULT(no)
])
],[
ZFS_LINUX_TEST_ERROR([file_fallocate])
])
Expand Down
1 change: 1 addition & 0 deletions config/kernel-kmem.m4
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_KVMALLOC], [
ZFS_LINUX_TEST_SRC([kvmalloc], [
#include <linux/mm.h>
#include <linux/slab.h>
],[
void *p __attribute__ ((unused));

Expand Down
68 changes: 68 additions & 0 deletions config/kernel-kthread.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
AC_DEFUN([ZFS_AC_KERNEL_KTHREAD_COMPLETE_AND_EXIT], [
dnl #
dnl # 5.17 API,
dnl # cead18552660702a4a46f58e65188fe5f36e9dfe ("exit: Rename complete_and_exit to kthread_complete_and_exit")
dnl #
dnl # Also moves the definition from include/linux/kernel.h to include/linux/kthread.h
dnl #
AC_MSG_CHECKING([whether kthread_complete_and_exit() is available])
ZFS_LINUX_TEST_RESULT([kthread_complete_and_exit], [
AC_MSG_RESULT(yes)
AC_DEFINE(SPL_KTHREAD_COMPLETE_AND_EXIT, kthread_complete_and_exit, [kthread_complete_and_exit() available])
], [
AC_MSG_RESULT(no)
AC_DEFINE(SPL_KTHREAD_COMPLETE_AND_EXIT, complete_and_exit, [using complete_and_exit() instead])
])
])

AC_DEFUN([ZFS_AC_KERNEL_KTHREAD_DEQUEUE_SIGNAL_4ARG], [
dnl #
dnl # 5.17 API: enum pid_type * as new 4th dequeue_signal() argument,
dnl # 5768d8906bc23d512b1a736c1e198aa833a6daa4 ("signal: Requeue signals in the appropriate queue")
dnl #
dnl # int dequeue_signal(struct task_struct *task, sigset_t *mask, kernel_siginfo_t *info);
dnl # int dequeue_signal(struct task_struct *task, sigset_t *mask, kernel_siginfo_t *info, enum pid_type *type);
dnl #
AC_MSG_CHECKING([whether dequeue_signal() takes 4 arguments])
ZFS_LINUX_TEST_RESULT([kthread_dequeue_signal], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_DEQUEUE_SIGNAL_4ARG, 1, [dequeue_signal() takes 4 arguments])
], [
AC_MSG_RESULT(no)
])
])

AC_DEFUN([ZFS_AC_KERNEL_SRC_KTHREAD_COMPLETE_AND_EXIT], [
ZFS_LINUX_TEST_SRC([kthread_complete_and_exit], [
#include <linux/kthread.h>
], [
struct completion *completion = NULL;
long code = 0;

kthread_complete_and_exit(completion, code);
])
])

AC_DEFUN([ZFS_AC_KERNEL_SRC_KTHREAD_DEQUEUE_SIGNAL_4ARG], [
ZFS_LINUX_TEST_SRC([kthread_dequeue_signal], [
#include <linux/sched/signal.h>
], [
struct task_struct *task = NULL;
sigset_t *mask = NULL;
kernel_siginfo_t *info = NULL;
enum pid_type *type = NULL;
int error __attribute__ ((unused));

error = dequeue_signal(task, mask, info, type);
])
])

AC_DEFUN([ZFS_AC_KERNEL_KTHREAD], [
ZFS_AC_KERNEL_KTHREAD_COMPLETE_AND_EXIT
ZFS_AC_KERNEL_KTHREAD_DEQUEUE_SIGNAL_4ARG
])

AC_DEFUN([ZFS_AC_KERNEL_SRC_KTHREAD], [
ZFS_AC_KERNEL_SRC_KTHREAD_COMPLETE_AND_EXIT
ZFS_AC_KERNEL_SRC_KTHREAD_DEQUEUE_SIGNAL_4ARG
])
16 changes: 9 additions & 7 deletions config/kernel-pde-data.m4
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
dnl #
dnl # 3.10 API change,
dnl # PDE is replaced by PDE_DATA
dnl # 5.17 API: PDE_DATA() renamed to pde_data(),
dnl # 359745d78351c6f5442435f81549f0207ece28aa ("proc: remove PDE_DATA() completely")
dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_PDE_DATA], [
ZFS_LINUX_TEST_SRC([pde_data], [
#include <linux/proc_fs.h>
], [
PDE_DATA(NULL);
pde_data(NULL);
])
])

AC_DEFUN([ZFS_AC_KERNEL_PDE_DATA], [
AC_MSG_CHECKING([whether PDE_DATA() is available])
ZFS_LINUX_TEST_RESULT_SYMBOL([pde_data], [PDE_DATA], [], [
AC_MSG_CHECKING([whether pde_data() is lowercase])
ZFS_LINUX_TEST_RESULT([pde_data], [
AC_MSG_RESULT(yes)
],[
ZFS_LINUX_TEST_ERROR([PDE_DATA])
AC_DEFINE(SPL_PDE_DATA, pde_data, [pde_data() is pde_data()])
], [
AC_MSG_RESULT(no)
AC_DEFINE(SPL_PDE_DATA, PDE_DATA, [pde_data() is PDE_DATA()])
])
])
22 changes: 20 additions & 2 deletions config/kernel-vfs-iov_iter.m4
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_VFS_IOV_ITER], [
error = iov_iter_fault_in_readable(&iter, size);
])

ZFS_LINUX_TEST_SRC([fault_in_iov_iter_readable], [
#include <linux/fs.h>
#include <linux/uio.h>
],[
struct iov_iter iter = { 0 };
size_t size = 512;
int error __attribute__ ((unused));

error = fault_in_iov_iter_readable(&iter, size);
])

ZFS_LINUX_TEST_SRC([iov_iter_count], [
#include <linux/fs.h>
#include <linux/uio.h>
Expand Down Expand Up @@ -123,8 +134,15 @@ AC_DEFUN([ZFS_AC_KERNEL_VFS_IOV_ITER], [
AC_DEFINE(HAVE_IOV_ITER_FAULT_IN_READABLE, 1,
[iov_iter_fault_in_readable() is available])
],[
AC_MSG_RESULT(no)
enable_vfs_iov_iter="no"
AC_MSG_CHECKING([whether fault_in_iov_iter_readable() is available])
ZFS_LINUX_TEST_RESULT([fault_in_iov_iter_readable], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_FAULT_IN_IOV_ITER_READABLE, 1,
[fault_in_iov_iter_readable() is available])
],[
AC_MSG_RESULT(no)
enable_vfs_iov_iter="no"
])
])

AC_MSG_CHECKING([whether iov_iter_count() is available])
Expand Down
4 changes: 4 additions & 0 deletions config/kernel.m4
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
ZFS_AC_KERNEL_SRC_VFS_SET_PAGE_DIRTY_NOBUFFERS
ZFS_AC_KERNEL_SRC_STANDALONE_LINUX_STDARG
ZFS_AC_KERNEL_SRC_PAGEMAP_FOLIO_WAIT_BIT
ZFS_AC_KERNEL_SRC_ADD_DISK
ZFS_AC_KERNEL_SRC_KTHREAD

AC_MSG_CHECKING([for available kernel interfaces])
ZFS_LINUX_TEST_COMPILE_ALL([kabi])
Expand Down Expand Up @@ -243,6 +245,8 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
ZFS_AC_KERNEL_VFS_SET_PAGE_DIRTY_NOBUFFERS
ZFS_AC_KERNEL_STANDALONE_LINUX_STDARG
ZFS_AC_KERNEL_PAGEMAP_FOLIO_WAIT_BIT
ZFS_AC_KERNEL_ADD_DISK
ZFS_AC_KERNEL_KTHREAD
])

dnl #
Expand Down
4 changes: 4 additions & 0 deletions include/os/linux/spl/sys/uio.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include <asm/uaccess.h>
#include <sys/types.h>

#if defined(HAVE_VFS_IOV_ITER) && defined(HAVE_FAULT_IN_IOV_ITER_READABLE)
#define iov_iter_fault_in_readable(a, b) fault_in_iov_iter_readable(a, b)
#endif

typedef struct iovec iovec_t;

typedef enum zfs_uio_rw {
Expand Down
2 changes: 1 addition & 1 deletion module/os/linux/spl/spl-kstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ proc_kstat_open(struct inode *inode, struct file *filp)
return (rc);

f = filp->private_data;
f->private = PDE_DATA(inode);
f->private = SPL_PDE_DATA(inode);

return (0);
}
Expand Down
2 changes: 1 addition & 1 deletion module/os/linux/spl/spl-procfs-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ procfs_list_open(struct inode *inode, struct file *filp)

struct seq_file *f = filp->private_data;
procfs_list_cursor_t *cursor = f->private;
cursor->procfs_list = PDE_DATA(inode);
cursor->procfs_list = SPL_PDE_DATA(inode);
cursor->cached_node = NULL;
cursor->cached_pos = 0;

Expand Down
7 changes: 6 additions & 1 deletion module/os/linux/spl/spl-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void
__thread_exit(void)
{
tsd_exit();
complete_and_exit(NULL, 0);
SPL_KTHREAD_COMPLETE_AND_EXIT(NULL, 0);
/* Unreachable */
}
EXPORT_SYMBOL(__thread_exit);
Expand Down Expand Up @@ -188,7 +188,12 @@ issig(int why)

spin_lock_irq(&task->sighand->siglock);
int ret;
#ifdef HAVE_DEQUEUE_SIGNAL_4ARG
enum pid_type __type;
if ((ret = dequeue_signal(task, &set, &__info, &__type)) != 0) {
#else
if ((ret = dequeue_signal(task, &set, &__info)) != 0) {
#endif
#ifdef HAVE_SIGNAL_STOP
spin_unlock_irq(&task->sighand->siglock);
kernel_signal_stop();
Expand Down
2 changes: 1 addition & 1 deletion module/os/linux/zfs/vdev_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ vdev_submit_bio_impl(struct bio *bio)
#ifdef HAVE_1ARG_SUBMIT_BIO
(void) submit_bio(bio);
#else
(void) submit_bio(0, bio);
(void) submit_bio(bio_data_dir(bio), bio);
#endif
}

Expand Down
9 changes: 7 additions & 2 deletions module/os/linux/zfs/zpl_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,12 @@ zpl_fallocate_common(struct inode *ip, int mode, loff_t offset, loff_t len)
fstrans_cookie_t cookie;
int error = 0;

if ((mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) != 0)
int test_mode = FALLOC_FL_PUNCH_HOLE;
#ifdef HAVE_FALLOC_FL_ZERO_RANGE
test_mode |= FALLOC_FL_ZERO_RANGE;
#endif

if ((mode & ~(FALLOC_FL_KEEP_SIZE | test_mode)) != 0)
return (-EOPNOTSUPP);

if (offset < 0 || len <= 0)
Expand All @@ -756,7 +761,7 @@ zpl_fallocate_common(struct inode *ip, int mode, loff_t offset, loff_t len)

crhold(cr);
cookie = spl_fstrans_mark();
if (mode & FALLOC_FL_PUNCH_HOLE) {
if (mode & (test_mode)) {
flock64_t bf;

if (offset > olen)
Expand Down
4 changes: 4 additions & 0 deletions module/os/linux/zfs/zvol_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,11 @@ zvol_os_create_minor(const char *name)
rw_enter(&zvol_state_lock, RW_WRITER);
zvol_insert(zv);
rw_exit(&zvol_state_lock);
#ifdef HAVE_ADD_DISK_RET
error = add_disk(zv->zv_zso->zvo_disk);
#else
add_disk(zv->zv_zso->zvo_disk);
#endif
} else {
ida_simple_remove(&zvol_ida, idx);
}
Expand Down