Skip to content

Commit

Permalink
Linux: i_op: use .free_inode
Browse files Browse the repository at this point in the history
as per Documentation/filesystems/porting.rst:

quote:

**strongly recommended**

take the RCU-delayed parts of ->destroy_inode() into a new method -
->free_inode().  If ->destroy_inode() becomes empty - all the better,
just get rid of it.

endquote.

Signed-off-by: Pavel Snajdr <[email protected]>
  • Loading branch information
snajpa committed Nov 16, 2024
1 parent d928d85 commit 3741752
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
25 changes: 25 additions & 0 deletions config/kernel-inode-free.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
AC_DEFUN([ZFS_AC_KERNEL_SRC_INODE_FREE], [
ZFS_LINUX_TEST_SRC([inode_free], [
#include <linux/fs.h>
static void inode_free(struct inode *ip)
{ return; }
static const struct super_operations
iops __attribute__ ((unused)) = {
.free_inode = inode_free,
};
],[])
])

AC_DEFUN([ZFS_AC_KERNEL_INODE_FREE], [
AC_MSG_CHECKING([whether inode_free() is available])
ZFS_LINUX_TEST_RESULT([inode_free], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_INODE_FREE, 1,
[.inode_free() i_op exists])
],[
AC_MSG_RESULT(no)
])
])

2 changes: 2 additions & 0 deletions config/kernel.m4
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
ZFS_AC_KERNEL_SRC_INSERT_INODE_LOCKED
ZFS_AC_KERNEL_SRC_TRUNCATE_SETSIZE
ZFS_AC_KERNEL_SRC_SECURITY_INODE
ZFS_AC_KERNEL_SRC_INODE_FREE
ZFS_AC_KERNEL_SRC_FST_MOUNT
ZFS_AC_KERNEL_SRC_SET_NLINK
ZFS_AC_KERNEL_SRC_SGET
Expand Down Expand Up @@ -183,6 +184,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
ZFS_AC_KERNEL_INSERT_INODE_LOCKED
ZFS_AC_KERNEL_TRUNCATE_SETSIZE
ZFS_AC_KERNEL_SECURITY_INODE
ZFS_AC_KERNEL_INODE_FREE
ZFS_AC_KERNEL_FST_MOUNT
ZFS_AC_KERNEL_SET_NLINK
ZFS_AC_KERNEL_SGET
Expand Down
1 change: 1 addition & 0 deletions include/os/linux/zfs/sys/zfs_znode_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ struct znode;
extern int zfs_sync(struct super_block *, int, cred_t *);
extern int zfs_inode_alloc(struct super_block *, struct inode **ip);
extern void zfs_inode_destroy(struct inode *);
extern void zfs_inode_free(struct inode *);
extern void zfs_mark_inode_dirty(struct inode *);
extern boolean_t zfs_relatime_need_update(const struct inode *);
extern zil_replay_func_t *const zfs_replay_vector[TX_MAX_TYPE];
Expand Down
15 changes: 11 additions & 4 deletions module/os/linux/zfs/zfs_znode_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,14 @@ zfs_inode_alloc(struct super_block *sb, struct inode **ip)
return (0);
}

/*
* Called in multiple places when an inode should be destroyed.
*/
void
zfs_inode_free(struct inode *ip)
{
znode_t *zp = ITOZ(ip);

kmem_cache_free(znode_cache, zp);
}

void
zfs_inode_destroy(struct inode *ip)
{
Expand All @@ -395,7 +400,9 @@ zfs_inode_destroy(struct inode *ip)
zp->z_xattr_cached = NULL;
}

kmem_cache_free(znode_cache, zp);
#ifndef HAVE_INODE_FREE
zfs_inode_free(ip);
#endif
}

static void
Expand Down
13 changes: 13 additions & 0 deletions module/os/linux/zfs/zpl_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ zpl_inode_alloc(struct super_block *sb)
}

static void
zpl_inode_free(struct inode *ip)
{
zfs_inode_free(ip);
}

static void __maybe_unused
zpl_inode_destroy(struct inode *ip)
{
ASSERT(atomic_read(&ip->i_count) == 0);
Expand Down Expand Up @@ -89,6 +95,9 @@ zpl_evict_inode(struct inode *ip)
truncate_setsize(ip, 0);
clear_inode(ip);
zfs_inactive(ip);
#ifdef HAVE_INODE_FREE
zfs_inode_destroy(ip);
#endif
spl_fstrans_unmark(cookie);
}

Expand Down Expand Up @@ -384,7 +393,11 @@ zpl_prune_sb(uint64_t nr_to_scan, void *arg)

const struct super_operations zpl_super_operations = {
.alloc_inode = zpl_inode_alloc,
#ifdef HAVE_INODE_FREE
.free_inode = zpl_inode_free,
#else
.destroy_inode = zpl_inode_destroy,
#endif
.dirty_inode = zpl_dirty_inode,
.write_inode = NULL,
.evict_inode = zpl_evict_inode,
Expand Down

0 comments on commit 3741752

Please sign in to comment.