Skip to content

Commit 12c7752

Browse files
jankaraMark Fasheh
authored andcommitted
quota: Implement function for scanning active dquots
OCFS2 needs to scan all active dquots once in a while and sync quota information among cluster nodes. Provide a helper function for it so that it does not have to reimplement internally a list which VFS already has. Moreover this function is probably going to be useful for other clustered filesystems if they decide to use VFS quotas. Signed-off-by: Jan Kara <[email protected]> Signed-off-by: Mark Fasheh <[email protected]>
1 parent 3d9ea25 commit 12c7752

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

fs/dquot.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,41 @@ static void invalidate_dquots(struct super_block *sb, int type)
476476
spin_unlock(&dq_list_lock);
477477
}
478478

479+
/* Call callback for every active dquot on given filesystem */
480+
int dquot_scan_active(struct super_block *sb,
481+
int (*fn)(struct dquot *dquot, unsigned long priv),
482+
unsigned long priv)
483+
{
484+
struct dquot *dquot, *old_dquot = NULL;
485+
int ret = 0;
486+
487+
mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
488+
spin_lock(&dq_list_lock);
489+
list_for_each_entry(dquot, &inuse_list, dq_inuse) {
490+
if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags))
491+
continue;
492+
if (dquot->dq_sb != sb)
493+
continue;
494+
/* Now we have active dquot so we can just increase use count */
495+
atomic_inc(&dquot->dq_count);
496+
dqstats.lookups++;
497+
spin_unlock(&dq_list_lock);
498+
dqput(old_dquot);
499+
old_dquot = dquot;
500+
ret = fn(dquot, priv);
501+
if (ret < 0)
502+
goto out;
503+
spin_lock(&dq_list_lock);
504+
/* We are safe to continue now because our dquot could not
505+
* be moved out of the inuse list while we hold the reference */
506+
}
507+
spin_unlock(&dq_list_lock);
508+
out:
509+
dqput(old_dquot);
510+
mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
511+
return ret;
512+
}
513+
479514
int vfs_quota_sync(struct super_block *sb, int type)
480515
{
481516
struct list_head *dirty;
@@ -2318,6 +2353,7 @@ EXPORT_SYMBOL(vfs_quota_on_path);
23182353
EXPORT_SYMBOL(vfs_quota_on_mount);
23192354
EXPORT_SYMBOL(vfs_quota_disable);
23202355
EXPORT_SYMBOL(vfs_quota_off);
2356+
EXPORT_SYMBOL(dquot_scan_active);
23212357
EXPORT_SYMBOL(vfs_quota_sync);
23222358
EXPORT_SYMBOL(vfs_get_dqinfo);
23232359
EXPORT_SYMBOL(vfs_set_dqinfo);

include/linux/quotaops.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ int dquot_drop_locked(struct inode *inode);
2828
struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
2929
void dqput(struct dquot *dquot);
3030
int dquot_is_cached(struct super_block *sb, unsigned int id, int type);
31+
int dquot_scan_active(struct super_block *sb,
32+
int (*fn)(struct dquot *dquot, unsigned long priv),
33+
unsigned long priv);
3134

3235
int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
3336
int dquot_alloc_inode(const struct inode *inode, qsize_t number);

0 commit comments

Comments
 (0)