[PATCH v3 09/11] fs/quota: convert add_dquot_ref() to super_iter_inodes()
From: Huang Shijie
Date: Thu Nov 19 2026 - 22:14:55 EST
Convert add_dquot_ref() to super_iter_inodes()
No functional change.
Signed-off-by: Huang Shijie <huangsj@xxxxxxxx>
---
fs/quota/dquot.c | 71 +++++++++++++++++++-----------------------------
1 file changed, 28 insertions(+), 43 deletions(-)
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 9aaf2cfa9e1b..6453949c8af6 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -1066,56 +1066,41 @@ 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 bool add_dquot_ref_eligible(struct inode *inode, void *priv)
{
- struct inode *inode, *old_inode = NULL;
-#ifdef CONFIG_QUOTA_DEBUG
- int reserved = 0;
-#endif
- int err = 0;
+ struct dquot_ref_data *ref = priv;
- 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);
- spin_unlock(&inode->i_lock);
- spin_unlock(&sb->s_inode_list_lock);
+ return atomic_read(&inode->i_writecount) &&
+ dqinit_needed(inode, ref->type);
+}
+
+static int add_dquot_ref_fn(struct inode *inode, void *priv)
+{
+ struct dquot_ref_data *ref = priv;
+ int ret;
#ifdef CONFIG_QUOTA_DEBUG
- if (unlikely(inode_get_rsv_space(inode) > 0))
- reserved = 1;
+ if (unlikely(inode_get_rsv_space(inode) > 0))
+ ref->reserved++;
#endif
- iput(old_inode);
- err = __dquot_initialize(inode, type);
- if (err) {
- iput(inode);
- goto out;
- }
+ ret = __dquot_initialize(inode, ref->type);
+ if (ret)
+ return ret;
+ return INO_ITER_RET_NEXT;
+}
- /*
- * 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:
+/* This routine is guarded by s_umount semaphore */
+static int add_dquot_ref(struct super_block *sb, int type)
+{
+ struct dquot_ref_data ref = {
+ .type = type,
+ };
+ int err;
+
+ err = super_iter_inodes(sb, add_dquot_ref_fn,
+ add_dquot_ref_eligible, &ref, 0);
#ifdef CONFIG_QUOTA_DEBUG
- if (reserved) {
+ if (ref.reserved) {
quota_error(sb, "Writes happened before quota was turned on "
"thus quota information is probably inconsistent. "
"Please run quotacheck(8)");
--
2.53.0