Skip to content

Commit

Permalink
Linux 4.11 compat: iops.getattr and friends
Browse files Browse the repository at this point in the history
In torvalds/linux@a528d35, there are several changes to the getattr
family of functions, struct kstat, and the interface of inode_operations
.getattr.

The inode_operations .getattr interface changed to:

int (*getattr) (const struct path *, struct dentry *, struct kstat *,
    u32 request_mask, unsigned int query_flags)

The request_mask argument indicates which field(s) the caller intends to use.
Fields the caller has not specified via request_mask may be set in he returned
struct anyway, but their values may be approximate.

The query_flags argument indicates whether the filesystem must update
the attributes from the backing store.

Currently both fields are ignored.

struct kstat includes new fields:
u32               result_mask;  /* What fields the user got */
u64               attributes;   /* See STATX_ATTR_* flags */
struct timespec   btime;        /* File creation time */

XXX result_mask is set but may be incorrect.  attributes and btime
are not set by zfs, may need to be.

The interface to simple_getattr() has changed to:

int simple_getattr(const struct path *, struct kstat *, u32,
    unsigned int);

Requires-spl: refs/pull/608/head
Requires-builders: distro

Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
  • Loading branch information
ofaaland committed Mar 14, 2017
1 parent 09ec770 commit b4ae79f
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 6 deletions.
67 changes: 67 additions & 0 deletions config/kernel-inode-getattr.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
dnl #
dnl # Linux 4.11 API
dnl # See torvalds/linux@a528d35
dnl #
AC_DEFUN([ZFS_AC_4ARGS_KERNEL_IOPS_GETATTR], [
AC_MSG_CHECKING([whether iops->getattr() takes 4 arguments])
ZFS_LINUX_TRY_COMPILE([
#include <linux/fs.h>
int test_getattr(
const struct path *p, struct kstat *k,
u32 request_mask, unsigned int query_flags)
{ return 0; }
static const struct inode_operations
iops __attribute__ ((unused)) = {
.getattr = test_getattr,
};
],[
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_4ARGS_IOPS_GETATTR, 1,
[iops->getattr() takes 4 arguments])
],[
AC_MSG_RESULT(no)
])
])



dnl #
dnl # Linux 3.9 - 4.10 API
dnl #
AC_DEFUN([ZFS_AC_3ARGS_KERNEL_IOPS_GETATTR], [
AC_MSG_CHECKING([whether iops->getattr() takes 3 arguments])
ZFS_LINUX_TRY_COMPILE([
#include <linux/fs.h>
int test_getattr(
struct vfsmount *mnt, struct dentry *d,
struct kstat *k)
{ return 0; }
static const struct inode_operations
iops __attribute__ ((unused)) = {
.getattr = test_getattr,
};
],[
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_3ARGS_IOPS_GETATTR, 1,
[iops->getattr() takes 3 arguments])
],[
AC_MSG_RESULT(no)
])
])


dnl #
dnl # The interface of the getattr callback from the inode_operations
dnl # structure changed. Also, the interface of the simple_getattr()
dnl # function provided by the kernel changed.
dnl #
AC_DEFUN([ZFS_AC_KERNEL_INODE_OPERATIONS_GETATTR], [
ZFS_AC_4ARGS_KERNEL_IOPS_GETATTR
ZFS_AC_3ARGS_KERNEL_IOPS_GETATTR
])
1 change: 1 addition & 0 deletions config/kernel.m4
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
ZFS_AC_KERNEL_INODE_OPERATIONS_CHECK_ACL_WITH_FLAGS
ZFS_AC_KERNEL_INODE_OPERATIONS_GET_ACL
ZFS_AC_KERNEL_INODE_OPERATIONS_SET_ACL
ZFS_AC_KERNEL_INODE_OPERATIONS_GETATTR
ZFS_AC_KERNEL_INODE_SET_FLAGS
ZFS_AC_KERNEL_GET_ACL_HANDLE_CACHE
ZFS_AC_KERNEL_SHOW_OPTIONS
Expand Down
54 changes: 49 additions & 5 deletions module/zfs/zpl_ctldir.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,31 @@ zpl_root_readdir(struct file *filp, void *dirent, filldir_t filldir)
* Get root directory attributes.
*/
/* ARGSUSED */

#if defined(HAVE_3ARGS_IOPS_GETATTR)
static int
zpl_root_getattr(struct vfsmount *mnt, struct dentry *dentry,
struct kstat *stat)
{
error = simple_getattr(mnt, dentry, stat);
stat->atime = CURRENT_TIME;

return (error);
}
#elif defined(HAVE_4ARGS_IOPS_GETATTR)
static int
zpl_root_getattr(const struct path *path, struct kstat *stat, u32 request_mask,
unsigned int query_flags)
{
int error;

error = simple_getattr(mnt, dentry, stat);
error = simple_getattr(path, stat, request_mask, query_flags);
stat->atime = CURRENT_TIME;

return (error);
}
#endif /* defined(HAVE_4ARGS_IOPS_GETATTR) */


static struct dentry *
#ifdef HAVE_LOOKUP_NAMEIDATA
Expand Down Expand Up @@ -375,14 +389,29 @@ zpl_snapdir_mkdir(struct inode *dip, struct dentry *dentry, zpl_umode_t mode)
*/
/* ARGSUSED */
static int
zpl_snapdir_getattr(struct vfsmount *mnt, struct dentry *dentry,
struct kstat *stat)
zpl_snapdir_getattr(
#if defined(HAVE_3ARGS_IOPS_GETATTR)
struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
#elif defined(HAVE_4ARGS_IOPS_GETATTR)
const struct path *path, struct kstat *stat, u32 request_mask,
unsigned int query_flags
#endif /* defined(HAVE_4ARGS_IOPS_GETATTR) */
)
{
#if defined(HAVE_3ARGS_IOPS_GETATTR)
zfsvfs_t *zfsvfs = ITOZSB(dentry->d_inode);
#elif defined(HAVE_4ARGS_IOPS_GETATTR)
zfsvfs_t *zfsvfs = ITOZSB(path->dentry->d_inode);
#endif /* defined(HAVE_4ARGS_IOPS_GETATTR) */
int error;

ZFS_ENTER(zfsvfs);
#if defined(HAVE_3ARGS_IOPS_GETATTR)
error = simple_getattr(mnt, dentry, stat);
#elif defined(HAVE_4ARGS_IOPS_GETATTR)
error = simple_getattr(path, stat, request_mask, query_flags);
#endif /* defined(HAVE_4ARGS_IOPS_GETATTR) */

stat->nlink = stat->size = 2;
stat->ctime = stat->mtime = dmu_objset_snap_cmtime(zfsvfs->z_os);
stat->atime = CURRENT_TIME;
Expand Down Expand Up @@ -509,18 +538,33 @@ zpl_shares_readdir(struct file *filp, void *dirent, filldir_t filldir)

/* ARGSUSED */
static int
zpl_shares_getattr(struct vfsmount *mnt, struct dentry *dentry,
struct kstat *stat)
zpl_shares_getattr(
#if defined(HAVE_3ARGS_IOPS_GETATTR)
struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
#elif defined(HAVE_4ARGS_IOPS_GETATTR)
const struct path *path, struct kstat *stat, u32 request_mask,
unsigned int query_flags
#endif /* defined(HAVE_4ARGS_IOPS_GETATTR) */
)
{
#if defined(HAVE_3ARGS_IOPS_GETATTR)
struct inode *ip = dentry->d_inode;
#elif defined(HAVE_4ARGS_IOPS_GETATTR)
struct inode *ip = path->dentry->d_inode;
#endif /* defined(HAVE_4ARGS_IOPS_GETATTR) */
zfsvfs_t *zfsvfs = ITOZSB(ip);
znode_t *dzp;
int error;

ZFS_ENTER(zfsvfs);

if (zfsvfs->z_shares_dir == 0) {
#if defined(HAVE_3ARGS_IOPS_GETATTR)
error = simple_getattr(mnt, dentry, stat);
#elif defined(HAVE_4ARGS_IOPS_GETATTR)
error = simple_getattr(path, stat, request_mask,
query_flags);
#endif /* defined(HAVE_4ARGS_IOPS_GETATTR) */
stat->nlink = stat->size = 2;
stat->atime = CURRENT_TIME;
ZFS_EXIT(zfsvfs);
Expand Down
24 changes: 23 additions & 1 deletion module/zfs/zpl_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,35 @@ zpl_rmdir(struct inode *dir, struct dentry *dentry)
}

static int
zpl_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
zpl_getattr(
#if defined(HAVE_3ARGS_IOPS_GETATTR)
struct vfsmount *mnt,
struct dentry *dentry,
struct kstat *stat
#elif defined(HAVE_4ARGS_IOPS_GETATTR)
const struct path *path,
struct kstat *stat,
u32 request_mask,
unsigned int query_flags
#endif /* defined(HAVE_4ARGS_IOPS_GETATTR) */
)
{
int error;
fstrans_cookie_t cookie;

cookie = spl_fstrans_mark();
#if defined(HAVE_3ARGS_IOPS_GETATTR)
error = -zfs_getattr_fast(dentry->d_inode, stat);
#elif defined(HAVE_4ARGS_IOPS_GETATTR)
/*
* zfs_getattr_fast()->generic_fillattr() does not
* set stat->result_mask except to toggle a couple of
* individual bits. So set it to BASIC_STATS first
* and then result should be correct.
*/
stat->result_mask = STATX_BASIC_STATS;
error = -zfs_getattr_fast(path->dentry->d_inode, stat);
#endif /* defined(HAVE_4ARGS_IOPS_GETATTR) */
spl_fstrans_unmark(cookie);
ASSERT3S(error, <=, 0);

Expand Down

0 comments on commit b4ae79f

Please sign in to comment.