]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/zpl_file.c
Kernel 4.9 compat: file_operations->aio_fsync removal
[mirror_zfs.git] / module / zfs / zpl_file.c
index 3737bb51911dc2a207c8f31c5cf3677bd8dce7b4..a225220285af2b1c454478bcb5e72d1da2556ad9 100644 (file)
  */
 /*
  * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
+ * Copyright (c) 2015 by Chunwei Chen. All rights reserved.
  */
 
 
+#ifdef CONFIG_COMPAT
+#include <linux/compat.h>
+#endif
 #include <sys/dmu_objset.h>
 #include <sys/zfs_vfsops.h>
 #include <sys/zfs_vnops.h>
@@ -35,13 +39,16 @@ zpl_open(struct inode *ip, struct file *filp)
 {
        cred_t *cr = CRED();
        int error;
+       fstrans_cookie_t cookie;
 
        error = generic_file_open(ip, filp);
        if (error)
                return (error);
 
        crhold(cr);
+       cookie = spl_fstrans_mark();
        error = -zfs_open(ip, filp->f_mode, filp->f_flags, cr);
+       spl_fstrans_unmark(cookie);
        crfree(cr);
        ASSERT3S(error, <=, 0);
 
@@ -53,12 +60,15 @@ zpl_release(struct inode *ip, struct file *filp)
 {
        cred_t *cr = CRED();
        int error;
+       fstrans_cookie_t cookie;
 
+       cookie = spl_fstrans_mark();
        if (ITOZ(ip)->z_atime_dirty)
-               mark_inode_dirty(ip);
+               zfs_mark_inode_dirty(ip);
 
        crhold(cr);
        error = -zfs_close(ip, filp->f_flags, cr);
+       spl_fstrans_unmark(cookie);
        crfree(cr);
        ASSERT3S(error, <=, 0);
 
@@ -68,19 +78,21 @@ zpl_release(struct inode *ip, struct file *filp)
 static int
 zpl_iterate(struct file *filp, struct dir_context *ctx)
 {
-       struct dentry *dentry = filp->f_path.dentry;
        cred_t *cr = CRED();
        int error;
+       fstrans_cookie_t cookie;
 
        crhold(cr);
-       error = -zfs_readdir(dentry->d_inode, ctx, cr);
+       cookie = spl_fstrans_mark();
+       error = -zfs_readdir(file_inode(filp), ctx, cr);
+       spl_fstrans_unmark(cookie);
        crfree(cr);
        ASSERT3S(error, <=, 0);
 
        return (error);
 }
 
-#if !defined(HAVE_VFS_ITERATE)
+#if !defined(HAVE_VFS_ITERATE) && !defined(HAVE_VFS_ITERATE_SHARED)
 static int
 zpl_readdir(struct file *filp, void *dirent, filldir_t filldir)
 {
@@ -106,15 +118,27 @@ zpl_fsync(struct file *filp, struct dentry *dentry, int datasync)
 {
        cred_t *cr = CRED();
        int error;
+       fstrans_cookie_t cookie;
 
        crhold(cr);
+       cookie = spl_fstrans_mark();
        error = -zfs_fsync(dentry->d_inode, datasync, cr);
+       spl_fstrans_unmark(cookie);
        crfree(cr);
        ASSERT3S(error, <=, 0);
 
        return (error);
 }
 
+#ifdef HAVE_FILE_AIO_FSYNC
+static int
+zpl_aio_fsync(struct kiocb *kiocb, int datasync)
+{
+       struct file *filp = kiocb->ki_filp;
+       return (zpl_fsync(filp, file_dentry(filp), datasync));
+}
+#endif
+
 #elif defined(HAVE_FSYNC_WITHOUT_DENTRY)
 /*
  * Linux 2.6.35 - 3.0 API,
@@ -128,15 +152,26 @@ zpl_fsync(struct file *filp, int datasync)
        struct inode *inode = filp->f_mapping->host;
        cred_t *cr = CRED();
        int error;
+       fstrans_cookie_t cookie;
 
        crhold(cr);
+       cookie = spl_fstrans_mark();
        error = -zfs_fsync(inode, datasync, cr);
+       spl_fstrans_unmark(cookie);
        crfree(cr);
        ASSERT3S(error, <=, 0);
 
        return (error);
 }
 
+#ifdef HAVE_FILE_AIO_FSYNC
+static int
+zpl_aio_fsync(struct kiocb *kiocb, int datasync)
+{
+       return (zpl_fsync(kiocb->ki_filp, datasync));
+}
+#endif
+
 #elif defined(HAVE_FSYNC_RANGE)
 /*
  * Linux 3.1 - 3.x API,
@@ -151,51 +186,78 @@ zpl_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
        struct inode *inode = filp->f_mapping->host;
        cred_t *cr = CRED();
        int error;
+       fstrans_cookie_t cookie;
 
        error = filemap_write_and_wait_range(inode->i_mapping, start, end);
        if (error)
                return (error);
 
        crhold(cr);
+       cookie = spl_fstrans_mark();
        error = -zfs_fsync(inode, datasync, cr);
+       spl_fstrans_unmark(cookie);
        crfree(cr);
        ASSERT3S(error, <=, 0);
 
        return (error);
 }
+
+#ifdef HAVE_FILE_AIO_FSYNC
+static int
+zpl_aio_fsync(struct kiocb *kiocb, int datasync)
+{
+       return (zpl_fsync(kiocb->ki_filp, kiocb->ki_pos, -1, datasync));
+}
+#endif
+
 #else
 #error "Unsupported fops->fsync() implementation"
 #endif
 
-ssize_t
-zpl_read_common(struct inode *ip, const char *buf, size_t len, loff_t pos,
-    uio_seg_t segment, int flags, cred_t *cr)
+static ssize_t
+zpl_read_common_iovec(struct inode *ip, const struct iovec *iovp, size_t count,
+    unsigned long nr_segs, loff_t *ppos, uio_seg_t segment, int flags,
+    cred_t *cr, size_t skip)
 {
-       int error;
        ssize_t read;
-       struct iovec iov;
        uio_t uio;
+       int error;
+       fstrans_cookie_t cookie;
 
-       iov.iov_base = (void *)buf;
-       iov.iov_len = len;
-
-       uio.uio_iov = &iov;
-       uio.uio_resid = len;
-       uio.uio_iovcnt = 1;
-       uio.uio_loffset = pos;
+       uio.uio_iov = iovp;
+       uio.uio_skip = skip;
+       uio.uio_resid = count;
+       uio.uio_iovcnt = nr_segs;
+       uio.uio_loffset = *ppos;
        uio.uio_limit = MAXOFFSET_T;
        uio.uio_segflg = segment;
 
+       cookie = spl_fstrans_mark();
        error = -zfs_read(ip, &uio, flags, cr);
+       spl_fstrans_unmark(cookie);
        if (error < 0)
                return (error);
 
-       read = len - uio.uio_resid;
+       read = count - uio.uio_resid;
+       *ppos += read;
        task_io_account_read(read);
 
        return (read);
 }
 
+inline ssize_t
+zpl_read_common(struct inode *ip, const char *buf, size_t len, loff_t *ppos,
+    uio_seg_t segment, int flags, cred_t *cr)
+{
+       struct iovec iov;
+
+       iov.iov_base = (void *)buf;
+       iov.iov_len = len;
+
+       return (zpl_read_common_iovec(ip, &iov, len, 1, ppos, segment,
+           flags, cr, 0));
+}
+
 static ssize_t
 zpl_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
 {
@@ -203,45 +265,102 @@ zpl_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
        ssize_t read;
 
        crhold(cr);
-       read = zpl_read_common(filp->f_mapping->host, buf, len, *ppos,
+       read = zpl_read_common(filp->f_mapping->host, buf, len, ppos,
            UIO_USERSPACE, filp->f_flags, cr);
        crfree(cr);
 
-       if (read < 0)
-               return (read);
+       file_accessed(filp);
+       return (read);
+}
 
-       *ppos += read;
+static ssize_t
+zpl_iter_read_common(struct kiocb *kiocb, const struct iovec *iovp,
+    unsigned long nr_segs, size_t count, uio_seg_t seg, size_t skip)
+{
+       cred_t *cr = CRED();
+       struct file *filp = kiocb->ki_filp;
+       ssize_t read;
+
+       crhold(cr);
+       read = zpl_read_common_iovec(filp->f_mapping->host, iovp, count,
+           nr_segs, &kiocb->ki_pos, seg, filp->f_flags, cr, skip);
+       crfree(cr);
+
+       file_accessed(filp);
        return (read);
 }
 
-ssize_t
-zpl_write_common(struct inode *ip, const char *buf, size_t len, loff_t pos,
-    uio_seg_t segment, int flags, cred_t *cr)
+#if defined(HAVE_VFS_RW_ITERATE)
+static ssize_t
+zpl_iter_read(struct kiocb *kiocb, struct iov_iter *to)
+{
+       ssize_t ret;
+       uio_seg_t seg = UIO_USERSPACE;
+       if (to->type & ITER_KVEC)
+               seg = UIO_SYSSPACE;
+       if (to->type & ITER_BVEC)
+               seg = UIO_BVEC;
+       ret = zpl_iter_read_common(kiocb, to->iov, to->nr_segs,
+           iov_iter_count(to), seg, to->iov_offset);
+       if (ret > 0)
+               iov_iter_advance(to, ret);
+       return (ret);
+}
+#else
+static ssize_t
+zpl_aio_read(struct kiocb *kiocb, const struct iovec *iovp,
+    unsigned long nr_segs, loff_t pos)
+{
+       return (zpl_iter_read_common(kiocb, iovp, nr_segs, kiocb->ki_nbytes,
+           UIO_USERSPACE, 0));
+}
+#endif /* HAVE_VFS_RW_ITERATE */
+
+static ssize_t
+zpl_write_common_iovec(struct inode *ip, const struct iovec *iovp, size_t count,
+    unsigned long nr_segs, loff_t *ppos, uio_seg_t segment, int flags,
+    cred_t *cr, size_t skip)
 {
-       int error;
        ssize_t wrote;
-       struct iovec iov;
        uio_t uio;
+       int error;
+       fstrans_cookie_t cookie;
 
-       iov.iov_base = (void *)buf;
-       iov.iov_len = len;
+       if (flags & O_APPEND)
+               *ppos = i_size_read(ip);
 
-       uio.uio_iov = &iov;
-       uio.uio_resid = len,
-       uio.uio_iovcnt = 1;
-       uio.uio_loffset = pos;
+       uio.uio_iov = iovp;
+       uio.uio_skip = skip;
+       uio.uio_resid = count;
+       uio.uio_iovcnt = nr_segs;
+       uio.uio_loffset = *ppos;
        uio.uio_limit = MAXOFFSET_T;
        uio.uio_segflg = segment;
 
+       cookie = spl_fstrans_mark();
        error = -zfs_write(ip, &uio, flags, cr);
+       spl_fstrans_unmark(cookie);
        if (error < 0)
                return (error);
 
-       wrote = len - uio.uio_resid;
+       wrote = count - uio.uio_resid;
+       *ppos += wrote;
        task_io_account_write(wrote);
 
        return (wrote);
 }
+inline ssize_t
+zpl_write_common(struct inode *ip, const char *buf, size_t len, loff_t *ppos,
+    uio_seg_t segment, int flags, cred_t *cr)
+{
+       struct iovec iov;
+
+       iov.iov_base = (void *)buf;
+       iov.iov_len = len;
+
+       return (zpl_write_common_iovec(ip, &iov, len, 1, ppos, segment,
+           flags, cr, 0));
+}
 
 static ssize_t
 zpl_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
@@ -250,31 +369,73 @@ zpl_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
        ssize_t wrote;
 
        crhold(cr);
-       wrote = zpl_write_common(filp->f_mapping->host, buf, len, *ppos,
+       wrote = zpl_write_common(filp->f_mapping->host, buf, len, ppos,
            UIO_USERSPACE, filp->f_flags, cr);
        crfree(cr);
 
-       if (wrote < 0)
-               return (wrote);
+       return (wrote);
+}
+
+static ssize_t
+zpl_iter_write_common(struct kiocb *kiocb, const struct iovec *iovp,
+    unsigned long nr_segs, size_t count, uio_seg_t seg, size_t skip)
+{
+       cred_t *cr = CRED();
+       struct file *filp = kiocb->ki_filp;
+       ssize_t wrote;
+
+       crhold(cr);
+       wrote = zpl_write_common_iovec(filp->f_mapping->host, iovp, count,
+           nr_segs, &kiocb->ki_pos, seg, filp->f_flags, cr, skip);
+       crfree(cr);
 
-       *ppos += wrote;
        return (wrote);
 }
 
+#if defined(HAVE_VFS_RW_ITERATE)
+static ssize_t
+zpl_iter_write(struct kiocb *kiocb, struct iov_iter *from)
+{
+       ssize_t ret;
+       uio_seg_t seg = UIO_USERSPACE;
+       if (from->type & ITER_KVEC)
+               seg = UIO_SYSSPACE;
+       if (from->type & ITER_BVEC)
+               seg = UIO_BVEC;
+       ret = zpl_iter_write_common(kiocb, from->iov, from->nr_segs,
+           iov_iter_count(from), seg, from->iov_offset);
+       if (ret > 0)
+               iov_iter_advance(from, ret);
+       return (ret);
+}
+#else
+static ssize_t
+zpl_aio_write(struct kiocb *kiocb, const struct iovec *iovp,
+    unsigned long nr_segs, loff_t pos)
+{
+       return (zpl_iter_write_common(kiocb, iovp, nr_segs, kiocb->ki_nbytes,
+           UIO_USERSPACE, 0));
+}
+#endif /* HAVE_VFS_RW_ITERATE */
+
 static loff_t
 zpl_llseek(struct file *filp, loff_t offset, int whence)
 {
 #if defined(SEEK_HOLE) && defined(SEEK_DATA)
+       fstrans_cookie_t cookie;
+
        if (whence == SEEK_DATA || whence == SEEK_HOLE) {
                struct inode *ip = filp->f_mapping->host;
                loff_t maxbytes = ip->i_sb->s_maxbytes;
                loff_t error;
 
-               spl_inode_lock(ip);
+               spl_inode_lock_shared(ip);
+               cookie = spl_fstrans_mark();
                error = -zfs_holey(ip, whence, &offset);
+               spl_fstrans_unmark(cookie);
                if (error == 0)
                        error = lseek_execute(filp, ip, offset, maxbytes);
-               spl_inode_unlock(ip);
+               spl_inode_unlock_shared(ip);
 
                return (error);
        }
@@ -332,9 +493,12 @@ zpl_mmap(struct file *filp, struct vm_area_struct *vma)
        struct inode *ip = filp->f_mapping->host;
        znode_t *zp = ITOZ(ip);
        int error;
+       fstrans_cookie_t cookie;
 
+       cookie = spl_fstrans_mark();
        error = -zfs_map(ip, vma->vm_pgoff, (caddr_t *)vma->vm_start,
            (size_t)(vma->vm_end - vma->vm_start), vma->vm_flags);
+       spl_fstrans_unmark(cookie);
        if (error)
                return (error);
 
@@ -364,12 +528,15 @@ zpl_readpage(struct file *filp, struct page *pp)
        struct inode *ip;
        struct page *pl[1];
        int error = 0;
+       fstrans_cookie_t cookie;
 
        ASSERT(PageLocked(pp));
        ip = pp->mapping->host;
        pl[0] = pp;
 
+       cookie = spl_fstrans_mark();
        error = -zfs_getpage(ip, pl, 1);
+       spl_fstrans_unmark(cookie);
 
        if (error) {
                SetPageError(pp);
@@ -402,19 +569,14 @@ int
 zpl_putpage(struct page *pp, struct writeback_control *wbc, void *data)
 {
        struct address_space *mapping = data;
+       fstrans_cookie_t cookie;
 
        ASSERT(PageLocked(pp));
        ASSERT(!PageWriteback(pp));
-       ASSERT(!(current->flags & PF_NOFS));
 
-       /*
-        * Annotate this call path with a flag that indicates that it is
-        * unsafe to use KM_SLEEP during memory allocations due to the
-        * potential for a deadlock.  KM_PUSHPAGE should be used instead.
-        */
-       current->flags |= PF_NOFS;
+       cookie = spl_fstrans_mark();
        (void) zfs_putpage(mapping->host, pp, wbc);
-       current->flags &= ~PF_NOFS;
+       spl_fstrans_unmark(cookie);
 
        return (0);
 }
@@ -445,7 +607,8 @@ zpl_writepages(struct address_space *mapping, struct writeback_control *wbc)
        if (sync_mode != wbc->sync_mode) {
                ZFS_ENTER(zsb);
                ZFS_VERIFY_ZP(zp);
-               zil_commit(zsb->z_log, zp->z_id);
+               if (zsb->z_log != NULL)
+                       zil_commit(zsb->z_log, zp->z_id);
                ZFS_EXIT(zsb);
 
                /*
@@ -478,55 +641,166 @@ zpl_writepage(struct page *pp, struct writeback_control *wbc)
 
 /*
  * The only flag combination which matches the behavior of zfs_space()
- * is FALLOC_FL_PUNCH_HOLE.  This flag was introduced in the 2.6.38 kernel.
+ * is FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE.  The FALLOC_FL_PUNCH_HOLE
+ * flag was introduced in the 2.6.38 kernel.
  */
+#if defined(HAVE_FILE_FALLOCATE) || defined(HAVE_INODE_FALLOCATE)
 long
 zpl_fallocate_common(struct inode *ip, int mode, loff_t offset, loff_t len)
 {
-       cred_t *cr = CRED();
        int error = -EOPNOTSUPP;
 
-       if (mode & FALLOC_FL_KEEP_SIZE)
-               return (-EOPNOTSUPP);
+#if defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE)
+       cred_t *cr = CRED();
+       flock64_t bf;
+       loff_t olen;
+       fstrans_cookie_t cookie;
 
-       crhold(cr);
+       if (mode != (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
+               return (error);
 
-#ifdef FALLOC_FL_PUNCH_HOLE
-       if (mode & FALLOC_FL_PUNCH_HOLE) {
-               flock64_t bf;
+       if (offset < 0 || len <= 0)
+               return (-EINVAL);
 
-               bf.l_type = F_WRLCK;
-               bf.l_whence = 0;
-               bf.l_start = offset;
-               bf.l_len = len;
-               bf.l_pid = 0;
+       spl_inode_lock(ip);
+       olen = i_size_read(ip);
 
-               error = -zfs_space(ip, F_FREESP, &bf, FWRITE, offset, cr);
+       if (offset > olen) {
+               spl_inode_unlock(ip);
+               return (0);
        }
-#endif /* FALLOC_FL_PUNCH_HOLE */
+       if (offset + len > olen)
+               len = olen - offset;
+       bf.l_type = F_WRLCK;
+       bf.l_whence = 0;
+       bf.l_start = offset;
+       bf.l_len = len;
+       bf.l_pid = 0;
+
+       crhold(cr);
+       cookie = spl_fstrans_mark();
+       error = -zfs_space(ip, F_FREESP, &bf, FWRITE, offset, cr);
+       spl_fstrans_unmark(cookie);
+       spl_inode_unlock(ip);
 
        crfree(cr);
+#endif /* defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE) */
 
        ASSERT3S(error, <=, 0);
        return (error);
 }
+#endif /* defined(HAVE_FILE_FALLOCATE) || defined(HAVE_INODE_FALLOCATE) */
 
 #ifdef HAVE_FILE_FALLOCATE
 static long
 zpl_fallocate(struct file *filp, int mode, loff_t offset, loff_t len)
 {
-       return zpl_fallocate_common(filp->f_path.dentry->d_inode,
+       return zpl_fallocate_common(file_inode(filp),
            mode, offset, len);
 }
 #endif /* HAVE_FILE_FALLOCATE */
 
+/*
+ * Map zfs file z_pflags (xvattr_t) to linux file attributes. Only file
+ * attributes common to both Linux and Solaris are mapped.
+ */
+static int
+zpl_ioctl_getflags(struct file *filp, void __user *arg)
+{
+       struct inode *ip = file_inode(filp);
+       unsigned int ioctl_flags = 0;
+       uint64_t zfs_flags = ITOZ(ip)->z_pflags;
+       int error;
+
+       if (zfs_flags & ZFS_IMMUTABLE)
+               ioctl_flags |= FS_IMMUTABLE_FL;
+
+       if (zfs_flags & ZFS_APPENDONLY)
+               ioctl_flags |= FS_APPEND_FL;
+
+       if (zfs_flags & ZFS_NODUMP)
+               ioctl_flags |= FS_NODUMP_FL;
+
+       ioctl_flags &= FS_FL_USER_VISIBLE;
+
+       error = copy_to_user(arg, &ioctl_flags, sizeof (ioctl_flags));
+
+       return (error);
+}
+
+/*
+ * fchange() is a helper macro to detect if we have been asked to change a
+ * flag. This is ugly, but the requirement that we do this is a consequence of
+ * how the Linux file attribute interface was designed. Another consequence is
+ * that concurrent modification of files suffers from a TOCTOU race. Neither
+ * are things we can fix without modifying the kernel-userland interface, which
+ * is outside of our jurisdiction.
+ */
+
+#define        fchange(f0, f1, b0, b1) ((((f0) & (b0)) == (b0)) != \
+       (((b1) & (f1)) == (f1)))
+
+static int
+zpl_ioctl_setflags(struct file *filp, void __user *arg)
+{
+       struct inode    *ip = file_inode(filp);
+       uint64_t        zfs_flags = ITOZ(ip)->z_pflags;
+       unsigned int    ioctl_flags;
+       cred_t          *cr = CRED();
+       xvattr_t        xva;
+       xoptattr_t      *xoap;
+       int             error;
+       fstrans_cookie_t cookie;
+
+       if (copy_from_user(&ioctl_flags, arg, sizeof (ioctl_flags)))
+               return (-EFAULT);
+
+       if ((ioctl_flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL)))
+               return (-EOPNOTSUPP);
+
+       if ((ioctl_flags & ~(FS_FL_USER_MODIFIABLE)))
+               return (-EACCES);
+
+       if ((fchange(ioctl_flags, zfs_flags, FS_IMMUTABLE_FL, ZFS_IMMUTABLE) ||
+           fchange(ioctl_flags, zfs_flags, FS_APPEND_FL, ZFS_APPENDONLY)) &&
+           !capable(CAP_LINUX_IMMUTABLE))
+               return (-EACCES);
+
+       if (!zpl_inode_owner_or_capable(ip))
+               return (-EACCES);
+
+       xva_init(&xva);
+       xoap = xva_getxoptattr(&xva);
+
+       XVA_SET_REQ(&xva, XAT_IMMUTABLE);
+       if (ioctl_flags & FS_IMMUTABLE_FL)
+               xoap->xoa_immutable = B_TRUE;
+
+       XVA_SET_REQ(&xva, XAT_APPENDONLY);
+       if (ioctl_flags & FS_APPEND_FL)
+               xoap->xoa_appendonly = B_TRUE;
+
+       XVA_SET_REQ(&xva, XAT_NODUMP);
+       if (ioctl_flags & FS_NODUMP_FL)
+               xoap->xoa_nodump = B_TRUE;
+
+       crhold(cr);
+       cookie = spl_fstrans_mark();
+       error = -zfs_setattr(ip, (vattr_t *)&xva, 0, cr);
+       spl_fstrans_unmark(cookie);
+       crfree(cr);
+
+       return (error);
+}
+
 static long
 zpl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
        switch (cmd) {
-       case ZFS_IOC_GETFLAGS:
-       case ZFS_IOC_SETFLAGS:
-               return (-EOPNOTSUPP);
+       case FS_IOC_GETFLAGS:
+               return (zpl_ioctl_getflags(filp, (void *)arg));
+       case FS_IOC_SETFLAGS:
+               return (zpl_ioctl_setflags(filp, (void *)arg));
        default:
                return (-ENOTTY);
        }
@@ -536,7 +810,17 @@ zpl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 static long
 zpl_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
-       return (zpl_ioctl(filp, cmd, arg));
+       switch (cmd) {
+       case FS_IOC32_GETFLAGS:
+               cmd = FS_IOC_GETFLAGS;
+               break;
+       case FS_IOC32_SETFLAGS:
+               cmd = FS_IOC_SETFLAGS;
+               break;
+       default:
+               return (-ENOTTY);
+       }
+       return (zpl_ioctl(filp, cmd, (unsigned long)compat_ptr(arg)));
 }
 #endif /* CONFIG_COMPAT */
 
@@ -554,8 +838,18 @@ const struct file_operations zpl_file_operations = {
        .llseek         = zpl_llseek,
        .read           = zpl_read,
        .write          = zpl_write,
+#ifdef HAVE_VFS_RW_ITERATE
+       .read_iter      = zpl_iter_read,
+       .write_iter     = zpl_iter_write,
+#else
+       .aio_read       = zpl_aio_read,
+       .aio_write      = zpl_aio_write,
+#endif
        .mmap           = zpl_mmap,
        .fsync          = zpl_fsync,
+#ifdef HAVE_FILE_AIO_FSYNC
+       .aio_fsync      = zpl_aio_fsync,
+#endif
 #ifdef HAVE_FILE_FALLOCATE
        .fallocate      = zpl_fallocate,
 #endif /* HAVE_FILE_FALLOCATE */
@@ -568,7 +862,9 @@ const struct file_operations zpl_file_operations = {
 const struct file_operations zpl_dir_file_operations = {
        .llseek         = generic_file_llseek,
        .read           = generic_read_dir,
-#ifdef HAVE_VFS_ITERATE
+#ifdef HAVE_VFS_ITERATE_SHARED
+       .iterate_shared = zpl_iterate,
+#elif defined(HAVE_VFS_ITERATE)
        .iterate        = zpl_iterate,
 #else
        .readdir        = zpl_readdir,