summaryrefslogtreecommitdiff
path: root/fs/xfs
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-03-25 13:37:03 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-03-25 17:08:23 -0700
commit5799c2fba9827f834f6cc1cd337317453cd80efc (patch)
treef9c30b4f2571975ab50c281b4b25e50c8061c327 /fs/xfs
parentb1519b1bbcaaeceded63c80b23e695fbb6b9b9b5 (diff)
xfs: create a polled function to force inode inactivation
Create a polled version of xfs_inactive_force so that we can force inactivation while holding a lock (usually the umount lock) without tripping over the softlockup timer. This is for callers that hold vfs locks while calling inactivation, which is currently unmount, iunlink processing during mount, and rw->ro remount. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/xfs_icache.c46
-rw-r--r--fs/xfs/xfs_icache.h1
-rw-r--r--fs/xfs/xfs_linux.h1
-rw-r--r--fs/xfs/xfs_mount.c2
-rw-r--r--fs/xfs/xfs_mount.h5
-rw-r--r--fs/xfs/xfs_super.c3
6 files changed, 55 insertions, 3 deletions
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index 7693965164a5..d45166066847 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -1901,9 +1901,13 @@ xfs_inodegc_free_space(
struct xfs_mount *mp,
struct xfs_eofblocks *eofb)
{
+ int error;
+
trace_xfs_inodegc_free_space(mp, eofb, _RET_IP_);
- return xfs_inode_walk(mp, XFS_ICI_INODEGC_TAG, eofb);
+ error = xfs_inode_walk(mp, XFS_ICI_INODEGC_TAG, eofb);
+ wake_up(&mp->m_inactive_wait);
+ return error;
}
/* Background inode inactivation worker. */
@@ -1945,6 +1949,46 @@ xfs_inodegc_flush(
flush_workqueue(mp->m_gc_workqueue);
}
+/*
+ * Force all queued inode inactivation work to run immediately, and poll
+ * until the work is complete. Callers should only use this function if they
+ * must inactivate inodes while holding VFS mutexes.
+ */
+void
+xfs_inodegc_flush_poll(
+ struct xfs_mount *mp)
+{
+ struct xfs_perag *pag;
+ xfs_agnumber_t agno;
+ bool queued = false;
+
+ /*
+ * Force to the foreground any inode inactivations that may happen
+ * while we're running our polling loop.
+ */
+ set_bit(XFS_OPFLAG_INACTIVATE_NOW_BIT, &mp->m_opflags);
+
+ for_each_perag_tag(mp, agno, pag, XFS_ICI_INODEGC_TAG) {
+ mod_delayed_work(mp->m_gc_workqueue, &pag->pag_inodegc_work, 0);
+ queued = true;
+ }
+ if (!queued)
+ goto clear;
+
+ /*
+ * Touch the softlockup watchdog every 1/10th of a second while there
+ * are still inactivation-tagged inodes in the filesystem.
+ */
+ while (!wait_event_timeout(mp->m_inactive_wait,
+ !radix_tree_tagged(&mp->m_perag_tree,
+ XFS_ICI_INODEGC_TAG),
+ HZ / 10)) {
+ touch_softlockup_watchdog();
+ }
+clear:
+ clear_bit(XFS_OPFLAG_INACTIVATE_NOW_BIT, &mp->m_opflags);
+}
+
/* Stop all queued inactivation work. */
void
xfs_inodegc_stop(
diff --git a/fs/xfs/xfs_icache.h b/fs/xfs/xfs_icache.h
index f43a3dad5652..a1230ebcea3e 100644
--- a/fs/xfs/xfs_icache.h
+++ b/fs/xfs/xfs_icache.h
@@ -76,6 +76,7 @@ void xfs_inew_wait(struct xfs_inode *ip);
void xfs_inodegc_worker(struct work_struct *work);
void xfs_inodegc_flush(struct xfs_mount *mp);
+void xfs_inodegc_flush_poll(struct xfs_mount *mp);
void xfs_inodegc_stop(struct xfs_mount *mp);
void xfs_inodegc_start(struct xfs_mount *mp);
int xfs_inodegc_free_space(struct xfs_mount *mp, struct xfs_eofblocks *eofb);
diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
index b4c5a2c71f43..b83a46619e8e 100644
--- a/fs/xfs/xfs_linux.h
+++ b/fs/xfs/xfs_linux.h
@@ -61,6 +61,7 @@ typedef __u32 xfs_nlink_t;
#include <linux/ratelimit.h>
#include <linux/rhashtable.h>
#include <linux/xattr.h>
+#include <linux/nmi.h>
#include <asm/page.h>
#include <asm/div64.h>
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 3762b1b7d5a9..06ae8557de94 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -1117,7 +1117,7 @@ xfs_unmountfs(
* Flush all the queued inode inactivation work to disk before tearing
* down rt metadata and quotas.
*/
- xfs_inodegc_flush(mp);
+ xfs_inodegc_flush_poll(mp);
xfs_blockgc_stop(mp);
xfs_fs_unreserve_ag_blocks(mp);
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index 513d2a52b60d..6477361bdadb 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -220,6 +220,11 @@ typedef struct xfs_mount {
struct xfs_kobj m_errortag_kobj;
#endif
struct ratelimit_state m_inodegc_ratelimit;
+ /*
+ * Use this to wait for the inode inactivation workqueue to finish
+ * inactivating all the inodes.
+ */
+ struct wait_queue_head m_inactive_wait;
} xfs_mount_t;
#define M_IGEO(mp) (&(mp)->m_ino_geo)
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index a3e0fe696d82..e529bca073e9 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -1782,7 +1782,7 @@ xfs_remount_ro(
* Since this can involve finobt updates, do it now before we lose the
* per-AG space reservations to guarantee that we won't fail there.
*/
- xfs_inodegc_flush(mp);
+ xfs_inodegc_flush_poll(mp);
/* Free the per-AG metadata reservation pool. */
error = xfs_fs_unreserve_ag_blocks(mp);
@@ -1908,6 +1908,7 @@ static int xfs_init_fs_context(
INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker);
INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
mp->m_kobj.kobject.kset = xfs_kset;
+ init_waitqueue_head(&mp->m_inactive_wait);
/*
* We don't create the finobt per-ag space reservation until after log
* recovery, so we must set this to true so that an ifree transaction