This is a note to let you know that I've just added the patch titled xfs: evict all inodes involved with log redo item to the 4.9-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: xfs-evict-all-inodes-involved-with-log-redo-item.patch and it can be found in the queue-4.9 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Mon Sep 18 10:16:36 CEST 2017 From: Christoph Hellwig <hch@xxxxxx> Date: Sun, 17 Sep 2017 14:06:57 -0700 Subject: xfs: evict all inodes involved with log redo item To: stable@xxxxxxxxxxxxxxx Cc: linux-xfs@xxxxxxxxxxxxxxx, "Darrick J. Wong" <darrick.wong@xxxxxxxxxx>, viro@xxxxxxxxxxxxxxxxxx Message-ID: <20170917210712.10804-33-hch@xxxxxx> From: "Darrick J. Wong" <darrick.wong@xxxxxxxxxx> 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@xxxxxxxxxx> Cc: viro@xxxxxxxxxxxxxxxxxx Reviewed-by: Brian Foster <bfoster@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/inode.c | 1 + fs/internal.h | 1 - fs/xfs/xfs_log.c | 12 ++++++++++++ include/linux/fs.h | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) --- a/fs/inode.c +++ b/fs/inode.c @@ -637,6 +637,7 @@ again: dispose_list(&dispose); } +EXPORT_SYMBOL_GPL(evict_inodes); /** * invalidate_inodes - attempt to free all inodes on a superblock --- a/fs/internal.h +++ b/fs/internal.h @@ -136,7 +136,6 @@ extern bool atime_needs_update_rcu(const 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); /* --- a/fs/xfs/xfs_log.c +++ b/fs/xfs/xfs_log.c @@ -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; --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2760,6 +2760,7 @@ static inline void lockdep_annotate_inod #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 *); Patches currently in stable-queue which might be from hch@xxxxxx are queue-4.9/xfs-open-code-xfs_buf_item_dirty.patch queue-4.9/xfs-properly-retry-failed-inode-items-in-case-of-error-during-buffer-writeback.patch queue-4.9/xfs-use-kmem_free-to-free-return-value-of-kmem_zalloc.patch queue-4.9/xfs-fix-inobt-inode-allocation-search-optimization.patch queue-4.9/xfs-add-infrastructure-needed-for-error-propagation-during-buffer-io-failure.patch queue-4.9/xfs-try-to-avoid-blowing-out-the-transaction-reservation-when-bunmaping-a-shared-extent.patch queue-4.9/xfs-don-t-set-v3-xflags-for-v2-inodes.patch queue-4.9/xfs-free-cowblocks-and-retry-on-buffered-write-enospc.patch queue-4.9/xfs-add-log-recovery-tracepoint-for-head-tail.patch queue-4.9/xfs-toggle-readonly-state-around-xfs_log_mount_finish.patch queue-4.9/xfs-fix-log-recovery-corruption-error-due-to-tail-overwrite.patch queue-4.9/xfs-move-bmbt-owner-change-to-last-step-of-extent-swap.patch queue-4.9/xfs-set-firstfsb-to-nullfsblock-before-feeding-it-to-_bmapi_write.patch queue-4.9/xfs-fix-quotacheck-dquot-id-overflow-infinite-loop.patch queue-4.9/xfs-remove-bli-from-ail-before-release-on-transaction-abort.patch queue-4.9/xfs-check-_btree_check_block-value.patch queue-4.9/xfs-check-for-race-with-xfs_reclaim_inode-in-xfs_ifree_cluster.patch queue-4.9/xfs-always-verify-the-log-tail-during-recovery.patch queue-4.9/xfs-open-code-end_buffer_async_write-in-xfs_finish_page_writeback.patch queue-4.9/xfs-relog-dirty-buffers-during-swapext-bmbt-owner-change.patch queue-4.9/xfs-don-t-allow-bmap-on-rt-files.patch queue-4.9/xfs-disable-per-inode-dax-flag.patch queue-4.9/xfs-refactor-buffer-logging-into-buffer-dirtying-helper.patch queue-4.9/xfs-fix-recovery-failure-when-log-record-header-wraps-log-end.patch queue-4.9/xfs-free-uncommitted-transactions-during-log-recovery.patch queue-4.9/xfs-skip-bmbt-block-ino-validation-during-owner-change.patch queue-4.9/xfs-don-t-log-dirty-ranges-for-ordered-buffers.patch queue-4.9/xfs-stop-searching-for-free-slots-in-an-inode-chunk-when-there-are-none.patch queue-4.9/xfs-fix-incorrect-log_flushed-on-fsync.patch queue-4.9/xfs-evict-all-inodes-involved-with-log-redo-item.patch queue-4.9/xfs-write-unmount-record-for-ro-mounts.patch queue-4.9/xfs-clear-ms_active-after-finishing-log-recovery.patch queue-4.9/xfs-don-t-crash-on-unexpected-holes-in-dir-attr-btrees.patch queue-4.9/xfs-fix-spurious-spin_is_locked-assert-failures-on-non-smp-kernels.patch queue-4.9/xfs-fix-per-inode-dax-flag-inheritance.patch queue-4.9/xfs-fix-multi-ag-deadlock-in-xfs_bunmapi.patch queue-4.9/xfs-remove-unnecessary-dirty-bli-format-check-for-ordered-bufs.patch queue-4.9/xfs-disallow-marking-previously-dirty-buffers-as-ordered.patch queue-4.9/xfs-handle-efscorrupted-during-head-tail-verification.patch queue-4.9/xfs-release-bli-from-transaction-properly-on-fs-shutdown.patch queue-4.9/iomap-fix-integer-truncation-issues-in-the-zeroing-and-dirtying-helpers.patch queue-4.9/xfs-don-t-leak-quotacheck-dquots-when-cow-recovery.patch queue-4.9/xfs-ordered-buffer-log-items-are-never-formatted.patch queue-4.9/xfs-check-_alloc_read_agf-buffer-pointer-before-using.patch queue-4.9/xfs-remove-xfs_trans_ail_delete_bulk.patch