]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfs: skip inode inactivation on a shut down mount
authorMikhail Lobanov <m.lobanov@rosa.ru>
Wed, 10 Jun 2026 19:19:03 +0000 (22:19 +0300)
committerCarlos Maiolino <cem@kernel.org>
Fri, 12 Jun 2026 07:57:02 +0000 (09:57 +0200)
XFS already declines to inactivate inodes on a shut down mount, but only
at queue time: xfs_inode_mark_reclaimable() calls
xfs_inode_needs_inactive(), which returns false when the mount is shut
down ("If the log isn't running, push inodes straight to reclaim"), and
then drops the dquots and marks the inode reclaimable directly.

An inode that was queued for background inactivation while the mount was
still live is not covered by that check: the inodegc worker still calls
xfs_inactive() on it even after the mount has been shut down in the
meantime.  Inactivation modifies persistent metadata and runs
transactions that cannot complete on a shut down mount, and it relies on
subsystems (e.g. quota) that a torn down, or never fully set up, mount
may not have available.

Honour the same invariant in xfs_inactive() itself: if the mount is shut
down, return early before doing any inactivation work.  The dquots
attached to the inode are released by the existing xfs_qm_dqdetach() at
the out: label, so references are not leaked, and the caller then makes
the inode reclaimable exactly as before.

On its own this is a consistency fix with the existing queue-time
behaviour; it is also a prerequisite for shutting the mount down in the
xfs_mountfs() failure path in the following patch.

Fixes: ab23a7768739 ("xfs: per-cpu deferred inode inactivation queues")
Signed-off-by: Mikhail Lobanov <m.lobanov@rosa.ru>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/xfs_inode.c

index b9f65cd638ad7e6d93ccc49295c689307dba9b71..0b7e3e9201d80d9c1e9fc4cc4f3d43f8bbd9b76c 100644 (file)
@@ -1380,7 +1380,7 @@ int
 xfs_inactive(
        xfs_inode_t     *ip)
 {
-       struct xfs_mount        *mp;
+       struct xfs_mount        *mp = ip->i_mount;
        int                     error = 0;
        int                     truncate = 0;
 
@@ -1393,7 +1393,20 @@ xfs_inactive(
                goto out;
        }
 
-       mp = ip->i_mount;
+       /*
+        * If the filesystem has been shut down - for example a mount that
+        * failed after background inactivation was enabled - do not
+        * inactivate the inode.  Inactivation modifies persistent metadata,
+        * its transactions cannot complete on a shut down mount, and the
+        * subsystems it relies on (e.g. quota, mp->m_quotainfo) may not be
+        * set up.  The attached dquots are dropped at the out: label and the
+        * inode then goes straight to reclaim, the same way
+        * xfs_inode_needs_inactive() already declines to inactivate on a shut
+        * down mount at queue time.
+        */
+       if (xfs_is_shutdown(mp))
+               goto out;
+
        ASSERT(!xfs_iflags_test(ip, XFS_IRECOVERY));
 
        xfs_inactive_health(ip);