Skip to content

Commit 0241284

Browse files
LiBaokun96jankara
authored andcommitted
quota: factor out dquot_write_dquot()
Refactor out dquot_write_dquot() to reduce duplicate code. Signed-off-by: Baokun Li <libaokun1@huawei.com> Signed-off-by: Jan Kara <jack@suse.cz> Message-Id: <20230630110822.3881712-2-libaokun1@huawei.com>
1 parent 50607b5 commit 0241284

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

fs/quota/dquot.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,18 @@ int dquot_scan_active(struct super_block *sb,
628628
}
629629
EXPORT_SYMBOL(dquot_scan_active);
630630

631+
static inline int dquot_write_dquot(struct dquot *dquot)
632+
{
633+
int ret = dquot->dq_sb->dq_op->write_dquot(dquot);
634+
if (ret < 0) {
635+
quota_error(dquot->dq_sb, "Can't write quota structure "
636+
"(error %d). Quota may get out of sync!", ret);
637+
/* Clear dirty bit anyway to avoid infinite loop. */
638+
clear_dquot_dirty(dquot);
639+
}
640+
return ret;
641+
}
642+
631643
/* Write all dquot structures to quota files */
632644
int dquot_writeback_dquots(struct super_block *sb, int type)
633645
{
@@ -658,16 +670,9 @@ int dquot_writeback_dquots(struct super_block *sb, int type)
658670
* use count */
659671
dqgrab(dquot);
660672
spin_unlock(&dq_list_lock);
661-
err = sb->dq_op->write_dquot(dquot);
662-
if (err) {
663-
/*
664-
* Clear dirty bit anyway to avoid infinite
665-
* loop here.
666-
*/
667-
clear_dquot_dirty(dquot);
668-
if (!ret)
669-
ret = err;
670-
}
673+
err = dquot_write_dquot(dquot);
674+
if (err && !ret)
675+
ret = err;
671676
dqput(dquot);
672677
spin_lock(&dq_list_lock);
673678
}
@@ -765,8 +770,6 @@ static struct shrinker dqcache_shrinker = {
765770
*/
766771
void dqput(struct dquot *dquot)
767772
{
768-
int ret;
769-
770773
if (!dquot)
771774
return;
772775
#ifdef CONFIG_QUOTA_DEBUG
@@ -794,17 +797,7 @@ void dqput(struct dquot *dquot)
794797
if (dquot_dirty(dquot)) {
795798
spin_unlock(&dq_list_lock);
796799
/* Commit dquot before releasing */
797-
ret = dquot->dq_sb->dq_op->write_dquot(dquot);
798-
if (ret < 0) {
799-
quota_error(dquot->dq_sb, "Can't write quota structure"
800-
" (error %d). Quota may get out of sync!",
801-
ret);
802-
/*
803-
* We clear dirty bit anyway, so that we avoid
804-
* infinite loop here
805-
*/
806-
clear_dquot_dirty(dquot);
807-
}
800+
dquot_write_dquot(dquot);
808801
goto we_slept;
809802
}
810803
if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {

0 commit comments

Comments
 (0)