xfs: evict all inodes involved with log redo item
authorDarrick J. Wong <darrick.wong@oracle.com>
Sun, 17 Sep 2017 21:06:57 +0000 (14:06 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Sep 2017 06:20:01 +0000 (08:20 +0200)
commit 799ea9e9c59949008770aab4e1da87f10e99dbe4 upstream.

When we introduced the bmap redo log items, we set MS_ACTIVE on the
mountpoint and XFS_IRECOVERY on the inode to prevent unlinked inodes
from being truncated prematurely during log recovery.  This also had the
effect of putting linked inodes on the lru instead of evicting them.

Unfortunately, we neglected to find all those unreferenced lru inodes
and evict them after finishing log recovery, which means that we leak
them if anything goes wrong in the rest of xfs_mountfs, because the lru
is only cleaned out on unmount.

Therefore, evict unreferenced inodes in the lru list immediately
after clearing MS_ACTIVE.

Fixes: 17c12bcd30 ("xfs: when replaying bmap operations, don't let unlinked inodes get reaped")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Cc: viro@ZenIV.linux.org.uk
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/inode.c
fs/internal.h
fs/xfs/xfs_log.c
include/linux/fs.h

index 88110fd0b282e49246dc9cd93a1d6e173d951d7b..920aa0b1c6b033f820f0f7efca30ed1ad93dc587 100644 (file)
@@ -637,6 +637,7 @@ again:
 
        dispose_list(&dispose);
 }
+EXPORT_SYMBOL_GPL(evict_inodes);
 
 /**
  * invalidate_inodes   - attempt to free all inodes on a superblock
index f4da3341b4a37dd36564db16a8870efaec1f4e48..8b7143b0211ce7c9ac140ede8fddd10cda57cc56 100644 (file)
@@ -136,7 +136,6 @@ extern bool atime_needs_update_rcu(const struct path *, struct inode *);
 extern void inode_io_list_del(struct inode *inode);
 
 extern long get_nr_dirty_inodes(void);
-extern void evict_inodes(struct super_block *);
 extern int invalidate_inodes(struct super_block *, bool);
 
 /*
index ebe20f1591f1d263f0370d6160921c2157aaacbc..fe5f3df8b253af4f06475b75cac7378b27353a71 100644 (file)
@@ -761,12 +761,24 @@ xfs_log_mount_finish(
         * inodes.  Turn it off immediately after recovery finishes
         * so that we don't leak the quota inodes if subsequent mount
         * activities fail.
+        *
+        * We let all inodes involved in redo item processing end up on
+        * the LRU instead of being evicted immediately so that if we do
+        * something to an unlinked inode, the irele won't cause
+        * premature truncation and freeing of the inode, which results
+        * in log recovery failure.  We have to evict the unreferenced
+        * lru inodes after clearing MS_ACTIVE because we don't
+        * otherwise clean up the lru if there's a subsequent failure in
+        * xfs_mountfs, which leads to us leaking the inodes if nothing
+        * else (e.g. quotacheck) references the inodes before the
+        * mount failure occurs.
         */
        mp->m_super->s_flags |= MS_ACTIVE;
        error = xlog_recover_finish(mp->m_log);
        if (!error)
                xfs_log_work_queue(mp);
        mp->m_super->s_flags &= ~MS_ACTIVE;
+       evict_inodes(mp->m_super);
 
        if (readonly)
                mp->m_flags |= XFS_MOUNT_RDONLY;
index dd88ded27fc877af386492f5aca6d629bfb77b36..d705ae084edd099622e2f8026e3e991a9d0c4750 100644 (file)
@@ -2760,6 +2760,7 @@ static inline void lockdep_annotate_inode_mutex_key(struct inode *inode) { };
 #endif
 extern void unlock_new_inode(struct inode *);
 extern unsigned int get_next_ino(void);
+extern void evict_inodes(struct super_block *sb);
 
 extern void __iget(struct inode * inode);
 extern void iget_failed(struct inode *);