quota: Push dqio_sem down to ->write_file_info()
authorJan Kara <jack@suse.cz>
Fri, 9 Jun 2017 06:45:43 +0000 (08:45 +0200)
committerJan Kara <jack@suse.cz>
Thu, 17 Aug 2017 17:11:23 +0000 (19:11 +0200)
Push down acquisition of dqio_sem into ->write_file_info() callback.
Mostly for consistency with other operations.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/ocfs2/quota_global.c
fs/quota/dquot.c
fs/quota/quota_v1.c
fs/quota/quota_v2.c

index 4134d557a8e5ba6ba3ef349bddad863ec9478d3a..78f3a869748c5c24eab7a5ffc8bd729dceb81b23 100644 (file)
@@ -443,13 +443,17 @@ static int __ocfs2_global_write_info(struct super_block *sb, int type)
 int ocfs2_global_write_info(struct super_block *sb, int type)
 {
        int err;
-       struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv;
+       struct quota_info *dqopt = sb_dqopt(sb);
+       struct ocfs2_mem_dqinfo *info = dqopt->info[type].dqi_priv;
 
+       down_write(&dqopt->dqio_sem);
        err = ocfs2_qinfo_lock(info, 1);
        if (err < 0)
-               return err;
+               goto out_sem;
        err = __ocfs2_global_write_info(sb, type);
        ocfs2_qinfo_unlock(info, 1);
+out_sem:
+       up_write(&dqopt->dqio_sem);
        return err;
 }
 
index 332f7026edad82e97239be24cc8360b6ab40d020..1e1ff97098ec3c85a1b327a4f84952d86ffd3ee9 100644 (file)
@@ -415,10 +415,8 @@ int dquot_acquire(struct dquot *dquot)
                ret = dqopt->ops[dquot->dq_id.type]->commit_dqblk(dquot);
                /* Write the info if needed */
                if (info_dirty(&dqopt->info[dquot->dq_id.type])) {
-                       down_write(&dqopt->dqio_sem);
                        ret2 = dqopt->ops[dquot->dq_id.type]->write_file_info(
                                        dquot->dq_sb, dquot->dq_id.type);
-                       up_write(&dqopt->dqio_sem);
                }
                if (ret < 0)
                        goto out_iolock;
@@ -482,10 +480,8 @@ int dquot_release(struct dquot *dquot)
                ret = dqopt->ops[dquot->dq_id.type]->release_dqblk(dquot);
                /* Write the info */
                if (info_dirty(&dqopt->info[dquot->dq_id.type])) {
-                       down_write(&dqopt->dqio_sem);
                        ret2 = dqopt->ops[dquot->dq_id.type]->write_file_info(
                                                dquot->dq_sb, dquot->dq_id.type);
-                       up_write(&dqopt->dqio_sem);
                }
                if (ret >= 0)
                        ret = ret2;
@@ -2054,13 +2050,9 @@ EXPORT_SYMBOL(dquot_transfer);
  */
 int dquot_commit_info(struct super_block *sb, int type)
 {
-       int ret;
        struct quota_info *dqopt = sb_dqopt(sb);
 
-       down_write(&dqopt->dqio_sem);
-       ret = dqopt->ops[type]->write_file_info(sb, type);
-       up_write(&dqopt->dqio_sem);
-       return ret;
+       return dqopt->ops[type]->write_file_info(sb, type);
 }
 EXPORT_SYMBOL(dquot_commit_info);
 
index 12d69cda57cca9f25a998e88b9be38e534aa0e11..fe68bf544b29881530dc1f953c242a50487f5b28 100644 (file)
@@ -186,6 +186,7 @@ static int v1_write_file_info(struct super_block *sb, int type)
        struct v1_disk_dqblk dqblk;
        int ret;
 
+       down_write(&dqopt->dqio_sem);
        dqopt->info[type].dqi_flags &= ~DQF_INFO_DIRTY;
        ret = sb->s_op->quota_read(sb, type, (char *)&dqblk,
                                sizeof(struct v1_disk_dqblk), v1_dqoff(0));
@@ -203,6 +204,7 @@ static int v1_write_file_info(struct super_block *sb, int type)
        else if (ret > 0)
                ret = -EIO;
 out:
+       up_write(&dqopt->dqio_sem);
        return ret;
 }
 
index f82638e43c07d20074c13ab2a70b0da59ba6b410..5e47012d2f57b0c47e2ad0ffedeec3c0ab54b2fa 100644 (file)
@@ -154,10 +154,12 @@ static int v2_read_file_info(struct super_block *sb, int type)
 static int v2_write_file_info(struct super_block *sb, int type)
 {
        struct v2_disk_dqinfo dinfo;
-       struct mem_dqinfo *info = sb_dqinfo(sb, type);
+       struct quota_info *dqopt = sb_dqopt(sb);
+       struct mem_dqinfo *info = &dqopt->info[type];
        struct qtree_mem_dqinfo *qinfo = info->dqi_priv;
        ssize_t size;
 
+       down_write(&dqopt->dqio_sem);
        spin_lock(&dq_data_lock);
        info->dqi_flags &= ~DQF_INFO_DIRTY;
        dinfo.dqi_bgrace = cpu_to_le32(info->dqi_bgrace);
@@ -170,6 +172,7 @@ static int v2_write_file_info(struct super_block *sb, int type)
        dinfo.dqi_free_entry = cpu_to_le32(qinfo->dqi_free_entry);
        size = sb->s_op->quota_write(sb, type, (char *)&dinfo,
               sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF);
+       up_write(&dqopt->dqio_sem);
        if (size != sizeof(struct v2_disk_dqinfo)) {
                quota_error(sb, "Can't write info structure");
                return -1;