From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 05/10] xfs: pass around xfs_inode_ag_walk iget/irele helper functions
Date: Tue, 31 Dec 2019 17:09:11 -0800 [thread overview]
Message-ID: <157784095105.1362752.6192279595180573182.stgit@magnolia> (raw)
In-Reply-To: <157784092020.1362752.15046503361741521784.stgit@magnolia>
From: Darrick J. Wong <darrick.wong@oracle.com>
Create an alternative version of xfs_ici_walk() that allow a caller to
pass in custom inode grab and inode release helper functions. Deferred
inode inactivation deals with xfs inodes that are still in memory but no
longer visible to the vfs, which means that it has to screen and process
those inodes differently.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
fs/xfs/xfs_icache.c | 82 +++++++++++++++++++++++++++++++++++++++------------
fs/xfs/xfs_icache.h | 6 ++--
2 files changed, 65 insertions(+), 23 deletions(-)
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index d9bfc78a1b85..01f5502d984a 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -792,20 +792,38 @@ xfs_inode_ag_walk_grab(
return false;
}
+struct xfs_ici_walk_ops {
+ /*
+ * Examine the given inode to decide if we want to pass it to the
+ * execute function. If so, this function should do whatever is needed
+ * to prevent others from grabbing it. If not, this function should
+ * release the inode.
+ */
+ bool (*igrab)(struct xfs_inode *ip, int iter_flags);
+
+ /* Do something with the given inode. */
+ xfs_ici_walk_fn iwalk;
+
+ /*
+ * Release an inode after the execution function runs. This function
+ * is optional.
+ */
+ void (*irele)(struct xfs_inode *ip);
+};
+
/*
* For a given per-AG structure @pag, @grab, @execute, and @rele all incore
* inodes with the given radix tree @tag.
*/
STATIC int
xfs_ici_walk_ag(
- struct xfs_mount *mp,
struct xfs_perag *pag,
- int (*execute)(struct xfs_inode *ip,
- struct xfs_perag *pag, void *args),
+ const struct xfs_ici_walk_ops *ops,
+ int iter_flags,
void *args,
- int tag,
- int iter_flags)
+ int tag)
{
+ struct xfs_mount *mp = pag->pag_mount;
uint32_t first_index;
int last_error = 0;
int skipped;
@@ -846,7 +864,7 @@ xfs_ici_walk_ag(
for (i = 0; i < nr_found; i++) {
struct xfs_inode *ip = batch[i];
- if (done || !xfs_inode_ag_walk_grab(ip, iter_flags))
+ if (done || !ops->igrab(ip, iter_flags))
batch[i] = NULL;
/*
@@ -877,8 +895,9 @@ xfs_ici_walk_ag(
if ((iter_flags & XFS_ICI_WALK_INEW_WAIT) &&
xfs_iflags_test(batch[i], XFS_INEW))
xfs_inew_wait(batch[i]);
- error = execute(batch[i], pag, args);
- xfs_irele(batch[i]);
+ error = ops->iwalk(batch[i], pag, args);
+ if (ops->irele)
+ ops->irele(batch[i]);
if (error == -EAGAIN) {
skipped++;
continue;
@@ -915,15 +934,14 @@ xfs_ici_walk_get_perag(
}
/*
- * Call the @execute function on all incore inodes matching the radix tree
- * @tag.
+ * Call the @grab, @execute, and @rele functions on all incore inodes matching
+ * the radix tree @tag.
*/
STATIC int
-xfs_ici_walk(
+xfs_ici_walk_fns(
struct xfs_mount *mp,
+ const struct xfs_ici_walk_ops *ops,
int iter_flags,
- int (*execute)(struct xfs_inode *ip,
- struct xfs_perag *pag, void *args),
void *args,
int tag)
{
@@ -935,8 +953,7 @@ xfs_ici_walk(
ag = 0;
while ((pag = xfs_ici_walk_get_perag(mp, ag, tag))) {
ag = pag->pag_agno + 1;
- error = xfs_ici_walk_ag(mp, pag, execute, args, tag,
- iter_flags);
+ error = xfs_ici_walk_ag(pag, ops, iter_flags, args, tag);
xfs_perag_put(pag);
if (error) {
last_error = error;
@@ -947,6 +964,27 @@ xfs_ici_walk(
return last_error;
}
+/*
+ * Call the @execute function on all incore inodes matching a given radix tree
+ * @tag.
+ */
+STATIC int
+xfs_ici_walk(
+ struct xfs_mount *mp,
+ int iter_flags,
+ xfs_ici_walk_fn iwalk,
+ void *args,
+ int tag)
+{
+ struct xfs_ici_walk_ops ops = {
+ .igrab = xfs_inode_ag_walk_grab,
+ .iwalk = iwalk,
+ .irele = xfs_irele,
+ };
+
+ return xfs_ici_walk_fns(mp, &ops, iter_flags, args, tag);
+}
+
/*
* Walk all incore inodes in the filesystem. Knowledge of radix tree tags
* is hidden and we always wait for INEW inodes.
@@ -954,11 +992,10 @@ xfs_ici_walk(
int
xfs_ici_walk_all(
struct xfs_mount *mp,
- int (*execute)(struct xfs_inode *ip,
- struct xfs_perag *pag, void *args),
+ xfs_ici_walk_fn iwalk,
void *args)
{
- return xfs_ici_walk(mp, XFS_ICI_WALK_INEW_WAIT, execute, args,
+ return xfs_ici_walk(mp, XFS_ICI_WALK_INEW_WAIT, iwalk, args,
XFS_ICI_NO_TAG);
}
@@ -1000,8 +1037,13 @@ xfs_blockgc_scan_pag(
struct xfs_perag *pag,
struct xfs_eofblocks *eofb)
{
- return xfs_ici_walk_ag(pag->pag_mount, pag, xfs_blockgc_scan_inode,
- eofb, XFS_ICI_BLOCK_GC_TAG, 0);
+ static const struct xfs_ici_walk_ops ops = {
+ .igrab = xfs_inode_ag_walk_grab,
+ .iwalk = xfs_blockgc_scan_inode,
+ .irele = xfs_irele,
+ };
+
+ return xfs_ici_walk_ag(pag, &ops, 0, eofb, XFS_ICI_BLOCK_GC_TAG);
}
/* Scan all incore inodes for block preallocations that we can remove. */
diff --git a/fs/xfs/xfs_icache.h b/fs/xfs/xfs_icache.h
index d7713eb0734d..3c34c0e2e266 100644
--- a/fs/xfs/xfs_icache.h
+++ b/fs/xfs/xfs_icache.h
@@ -69,9 +69,9 @@ void xfs_inode_set_cowblocks_tag(struct xfs_inode *ip);
void xfs_inode_clear_cowblocks_tag(struct xfs_inode *ip);
int xfs_icache_free_cowblocks(struct xfs_mount *, struct xfs_eofblocks *);
-int xfs_ici_walk_all(struct xfs_mount *mp,
- int (*execute)(struct xfs_inode *ip, struct xfs_perag *pag, void *args),
- void *args);
+typedef int (*xfs_ici_walk_fn)(struct xfs_inode *ip, struct xfs_perag *pag,
+ void *args);
+int xfs_ici_walk_all(struct xfs_mount *mp, xfs_ici_walk_fn iwalk, void *args);
int xfs_icache_inode_is_allocated(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_ino_t ino, bool *inuse);
next prev parent reply other threads:[~2020-01-01 1:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-01 1:08 [PATCH v2 00/10] xfs: deferred inode inactivation Darrick J. Wong
2020-01-01 1:08 ` [PATCH 01/10] xfs: decide if inode needs inactivation Darrick J. Wong
2020-01-01 1:08 ` [PATCH 02/10] xfs: track unlinked inactive inode fs summary counters Darrick J. Wong
2020-01-01 1:08 ` [PATCH 03/10] xfs: track unlinked inactive inode quota counters Darrick J. Wong
2020-01-01 1:09 ` [PATCH 04/10] xfs: pass per-ag structure to the xfs_ici_walk execute function Darrick J. Wong
2020-01-01 1:09 ` Darrick J. Wong [this message]
2020-01-01 1:09 ` [PATCH 06/10] xfs: deferred inode inactivation Darrick J. Wong
2020-01-01 1:09 ` [PATCH 07/10] xfs: force inode inactivation and retry fs writes when there isn't space Darrick J. Wong
2020-01-01 1:09 ` [PATCH 08/10] xfs: force inactivation before fallocate when space is low Darrick J. Wong
2020-01-01 1:09 ` [PATCH 09/10] xfs: parallelize inode inactivation Darrick J. Wong
2020-01-01 1:09 ` [PATCH 10/10] xfs: create a polled function to force " Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=157784095105.1362752.6192279595180573182.stgit@magnolia \
--to=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.