]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
xfs: mark reclaimed inodes invalid earlier
authorDave Chinner <dchinner@redhat.com>
Wed, 18 May 2016 04:09:12 +0000 (14:09 +1000)
committerDave Chinner <david@fromorbit.com>
Wed, 18 May 2016 04:09:12 +0000 (14:09 +1000)
commit8a17d7ddedb4d9031f046ae0e97c40b46aa69db5
tree36509f042caa361bc2254ae12fe70f5fe32aa77c
parent1f2dcfe89edac4e3bf5b76c56f745191f921fd2a
xfs: mark reclaimed inodes invalid earlier

The last thing we do before using call_rcu() on an xfs_inode to be
freed is mark it as invalid. This means there is a window between
when we know for certain that the inode is going to be freed and
when we do actually mark it as "freed".

This is important in the context of RCU lookups - we can look up the
inode, find that it is valid, and then use it as such not realising
that it is in the final stages of being freed.

As such, mark the inode as being invalid the moment we know it is
going to be reclaimed. This can be done while we still hold the
XFS_ILOCK_EXCL and the flush lock in xfs_inode_reclaim, meaning that
it occurs well before we remove it from the radix tree, and that
the i_flags_lock, the XFS_ILOCK and the inode flush lock all act as
synchronisation points for detecting that an inode is about to go
away.

For defensive purposes, this allows us to add a further check to
xfs_iflush_cluster to ensure we skip inodes that are being freed
after we grab the XFS_ILOCK_SHARED and the flush lock - we know that
if the inode number if valid while we have these locks held we know
that it has not progressed through reclaim to the point where it is
clean and is about to be freed.

[bfoster: fixed __xfs_inode_clear_reclaim() using ip->i_ino after it
  had already been zeroed.]

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/xfs/xfs_icache.c
fs/xfs/xfs_inode.c