From: Julian Sun <sunjunchao@bytedance.com>
To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
gfs2@lists.linux.dev, linux-security-module@vger.kernel.org
Cc: jack@suse.cz, agruenba@redhat.com, mic@digikod.net,
gnoack@google.com, paul@paul-moore.com, jmorris@namei.org,
serge@hallyn.com, aleksa@amutable.com, legion@kernel.org,
djwong@kernel.org, ebiggers@kernel.org, sandeen@redhat.com
Subject: [PATCH 6/7] quota: use sb_for_each_inodes() in add_dquot_ref()
Date: Wed, 9 Sep 2026 17:01:11 +0800 [thread overview]
Message-ID: <20260909090112.790006-7-sunjunchao@bytedance.com> (raw)
In-Reply-To: <20260909090112.790006-1-sunjunchao@bytedance.com>
Convert add_dquot_ref() to sb_for_each_inodes(), passing the quota type
to the callback and propagating initialization errors. This removes the
old_inode reference used to preserve the walk position.
Leave remove_dquot_ref() unchanged to avoid adding per-inode locking to a
walk that never drops s_inode_list_lock.
Signed-off-by: Julian Sun <sunjunchao@bytedance.com>
---
fs/quota/dquot.c | 72 +++++++++++++++++++-----------------------------
1 file changed, 28 insertions(+), 44 deletions(-)
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 204afc5e984b..77c68149d4ae 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -1043,64 +1043,48 @@ static int dqinit_needed(struct inode *inode, int type)
return 0;
}
-/* This routine is guarded by s_umount semaphore */
-static int add_dquot_ref(struct super_block *sb, int type)
+static int add_dquot_ref_inode_iter_cb(struct inode *inode, void *data)
{
- struct inode *inode, *old_inode = NULL;
+ int type = *(int *)data;
+ int err = 0;
+ struct super_block *sb = inode->i_sb;
#ifdef CONFIG_QUOTA_DEBUG
int reserved = 0;
#endif
- int err = 0;
- spin_lock(&sb->s_inode_list_lock);
- list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
- spin_lock(&inode->i_lock);
- if ((inode_state_read(inode) & (I_FREEING | I_WILL_FREE | I_NEW)) ||
- !atomic_read(&inode->i_writecount) ||
- !dqinit_needed(inode, type)) {
- spin_unlock(&inode->i_lock);
- continue;
- }
- __iget(inode);
+ if (!atomic_read(&inode->i_writecount) ||
+ !dqinit_needed(inode, type)) {
spin_unlock(&inode->i_lock);
- spin_unlock(&sb->s_inode_list_lock);
+ return 0;
+ }
+
+ __iget(inode);
+ spin_unlock(&inode->i_lock);
+ spin_unlock(&sb->s_inode_list_lock);
#ifdef CONFIG_QUOTA_DEBUG
- if (unlikely(inode_get_rsv_space(inode) > 0))
- reserved = 1;
+ if (unlikely(inode_get_rsv_space(inode) > 0))
+ reserved = 1;
#endif
- iput(old_inode);
- err = __dquot_initialize(inode, type);
- if (err) {
- iput(inode);
- goto out;
- }
-
- /*
- * We hold a reference to 'inode' so it couldn't have been
- * removed from s_inodes list while we dropped the
- * s_inode_list_lock. We cannot iput the inode now as we can be
- * holding the last reference and we cannot iput it under
- * s_inode_list_lock. So we keep the reference and iput it
- * later.
- */
- old_inode = inode;
- cond_resched();
- spin_lock(&sb->s_inode_list_lock);
- }
- spin_unlock(&sb->s_inode_list_lock);
- iput(old_inode);
-out:
+ err = __dquot_initialize(inode, type);
#ifdef CONFIG_QUOTA_DEBUG
- if (reserved) {
- quota_error(sb, "Writes happened before quota was turned on "
- "thus quota information is probably inconsistent. "
- "Please run quotacheck(8)");
- }
+ if (reserved)
+ quota_error(sb, "Writes happened before quota was turned "
+ "on thus quota information is probably "
+ "inconsistent. Please run quotacheck(8)");
#endif
+ iput(inode);
+ spin_lock(&sb->s_inode_list_lock);
return err;
}
+/* This routine is guarded by s_umount semaphore */
+static int add_dquot_ref(struct super_block *sb, int type)
+{
+ return sb_for_each_inodes(sb, INODE_ITER_NORMAL,
+ add_dquot_ref_inode_iter_cb, &type);
+}
+
static void remove_dquot_ref(struct super_block *sb, int type)
{
struct inode *inode;
--
2.39.5
next prev parent reply other threads:[~2026-09-09 9:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 9:01 [PATCH 0/7] fs: preserve superblock inode walk positions across lock drops Julian Sun
2026-09-09 9:01 ` [PATCH 1/7] fs: remove trailing whitespace from include/linux/fs.h Julian Sun
2026-09-10 16:52 ` Jan Kara
2026-09-09 9:01 ` [PATCH 2/7] fs: introduce sb_for_each_inodes() Julian Sun
2026-09-10 17:47 ` Jan Kara
2026-09-11 3:34 ` [External] " Julian Sun
2026-09-11 3:35 ` Julian Sun
2026-09-09 9:01 ` [PATCH 3/7] block: use sb_for_each_inodes() in sync_bdevs() Julian Sun
2026-09-09 9:01 ` [PATCH 4/7] fs: use sb_for_each_inodes() API Julian Sun
2026-09-09 9:01 ` [PATCH 5/7] gfs2: use sb_for_each_inodes() for cooperative eviction Julian Sun
2026-09-09 9:01 ` Julian Sun [this message]
2026-09-09 9:01 ` [PATCH 7/7] landlock: use sb_for_each_inodes() when detaching a superblock Julian Sun
2026-09-09 12:49 ` [PATCH 0/7] fs: preserve superblock inode walk positions across lock drops Jan Kara
2026-09-09 13:08 ` [External] " Julian Sun
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=20260909090112.790006-7-sunjunchao@bytedance.com \
--to=sunjunchao@bytedance.com \
--cc=agruenba@redhat.com \
--cc=aleksa@amutable.com \
--cc=djwong@kernel.org \
--cc=ebiggers@kernel.org \
--cc=gfs2@lists.linux.dev \
--cc=gnoack@google.com \
--cc=jack@suse.cz \
--cc=jmorris@namei.org \
--cc=legion@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=paul@paul-moore.com \
--cc=sandeen@redhat.com \
--cc=serge@hallyn.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox