Commit dc52dd3a authored by Dmitry Monakhov's avatar Dmitry Monakhov Committed by Jan Kara

quota: Move duplicated code to separate functions

- for(..) { mark_dquot_dirty(); } -> mark_all_dquot_dirty()
- for(..) { dput(); }             -> dqput_all()
Signed-off-by: default avatarDmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent a9e7f447
...@@ -323,6 +323,30 @@ int dquot_mark_dquot_dirty(struct dquot *dquot) ...@@ -323,6 +323,30 @@ int dquot_mark_dquot_dirty(struct dquot *dquot)
} }
EXPORT_SYMBOL(dquot_mark_dquot_dirty); EXPORT_SYMBOL(dquot_mark_dquot_dirty);
/* Dirtify all the dquots - this can block when journalling */
static inline int mark_all_dquot_dirty(struct dquot * const *dquot)
{
int ret, err, cnt;
ret = err = 0;
for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
if (dquot[cnt])
/* Even in case of error we have to continue */
ret = mark_dquot_dirty(dquot[cnt]);
if (!err)
err = ret;
}
return err;
}
static inline void dqput_all(struct dquot **dquot)
{
unsigned int cnt;
for (cnt = 0; cnt < MAXQUOTAS; cnt++)
dqput(dquot[cnt]);
}
/* This function needs dq_list_lock */ /* This function needs dq_list_lock */
static inline int clear_dquot_dirty(struct dquot *dquot) static inline int clear_dquot_dirty(struct dquot *dquot)
{ {
...@@ -1268,8 +1292,7 @@ int dquot_initialize(struct inode *inode, int type) ...@@ -1268,8 +1292,7 @@ int dquot_initialize(struct inode *inode, int type)
out_err: out_err:
up_write(&sb_dqopt(sb)->dqptr_sem); up_write(&sb_dqopt(sb)->dqptr_sem);
/* Drop unused references */ /* Drop unused references */
for (cnt = 0; cnt < MAXQUOTAS; cnt++) dqput_all(got);
dqput(got[cnt]);
return ret; return ret;
} }
EXPORT_SYMBOL(dquot_initialize); EXPORT_SYMBOL(dquot_initialize);
...@@ -1288,9 +1311,7 @@ int dquot_drop(struct inode *inode) ...@@ -1288,9 +1311,7 @@ int dquot_drop(struct inode *inode)
inode->i_dquot[cnt] = NULL; inode->i_dquot[cnt] = NULL;
} }
up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
dqput_all(put);
for (cnt = 0; cnt < MAXQUOTAS; cnt++)
dqput(put[cnt]);
return 0; return 0;
} }
EXPORT_SYMBOL(dquot_drop); EXPORT_SYMBOL(dquot_drop);
...@@ -1439,10 +1460,7 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, ...@@ -1439,10 +1460,7 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number,
if (reserve) if (reserve)
goto out_flush_warn; goto out_flush_warn;
/* Dirtify all the dquots - this can block when journalling */ mark_all_dquot_dirty(inode->i_dquot);
for (cnt = 0; cnt < MAXQUOTAS; cnt++)
if (inode->i_dquot[cnt])
mark_dquot_dirty(inode->i_dquot[cnt]);
out_flush_warn: out_flush_warn:
flush_warnings(inode->i_dquot, warntype); flush_warnings(inode->i_dquot, warntype);
out_unlock: out_unlock:
...@@ -1500,10 +1518,7 @@ int dquot_alloc_inode(const struct inode *inode, qsize_t number) ...@@ -1500,10 +1518,7 @@ int dquot_alloc_inode(const struct inode *inode, qsize_t number)
warn_put_all: warn_put_all:
spin_unlock(&dq_data_lock); spin_unlock(&dq_data_lock);
if (ret == QUOTA_OK) if (ret == QUOTA_OK)
/* Dirtify all the dquots - this can block when journalling */ mark_all_dquot_dirty(inode->i_dquot);
for (cnt = 0; cnt < MAXQUOTAS; cnt++)
if (inode->i_dquot[cnt])
mark_dquot_dirty(inode->i_dquot[cnt]);
flush_warnings(inode->i_dquot, warntype); flush_warnings(inode->i_dquot, warntype);
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
return ret; return ret;
...@@ -1537,10 +1552,7 @@ int dquot_claim_space(struct inode *inode, qsize_t number) ...@@ -1537,10 +1552,7 @@ int dquot_claim_space(struct inode *inode, qsize_t number)
/* Update inode bytes */ /* Update inode bytes */
inode_claim_rsv_space(inode, number); inode_claim_rsv_space(inode, number);
spin_unlock(&dq_data_lock); spin_unlock(&dq_data_lock);
/* Dirtify all the dquots - this can block when journalling */ mark_all_dquot_dirty(inode->i_dquot);
for (cnt = 0; cnt < MAXQUOTAS; cnt++)
if (inode->i_dquot[cnt])
mark_dquot_dirty(inode->i_dquot[cnt]);
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
out: out:
return ret; return ret;
...@@ -1584,10 +1596,7 @@ out_sub: ...@@ -1584,10 +1596,7 @@ out_sub:
if (reserve) if (reserve)
goto out_unlock; goto out_unlock;
/* Dirtify all the dquots - this can block when journalling */ mark_all_dquot_dirty(inode->i_dquot);
for (cnt = 0; cnt < MAXQUOTAS; cnt++)
if (inode->i_dquot[cnt])
mark_dquot_dirty(inode->i_dquot[cnt]);
out_unlock: out_unlock:
flush_warnings(inode->i_dquot, warntype); flush_warnings(inode->i_dquot, warntype);
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
...@@ -1637,10 +1646,7 @@ int dquot_free_inode(const struct inode *inode, qsize_t number) ...@@ -1637,10 +1646,7 @@ int dquot_free_inode(const struct inode *inode, qsize_t number)
dquot_decr_inodes(inode->i_dquot[cnt], number); dquot_decr_inodes(inode->i_dquot[cnt], number);
} }
spin_unlock(&dq_data_lock); spin_unlock(&dq_data_lock);
/* Dirtify all the dquots - this can block when journalling */ mark_all_dquot_dirty(inode->i_dquot);
for (cnt = 0; cnt < MAXQUOTAS; cnt++)
if (inode->i_dquot[cnt])
mark_dquot_dirty(inode->i_dquot[cnt]);
flush_warnings(inode->i_dquot, warntype); flush_warnings(inode->i_dquot, warntype);
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
return QUOTA_OK; return QUOTA_OK;
...@@ -1734,25 +1740,18 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr) ...@@ -1734,25 +1740,18 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
spin_unlock(&dq_data_lock); spin_unlock(&dq_data_lock);
up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
/* Dirtify all the dquots - this can block when journalling */ mark_all_dquot_dirty(transfer_from);
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { mark_all_dquot_dirty(transfer_to);
if (transfer_from[cnt])
mark_dquot_dirty(transfer_from[cnt]);
if (transfer_to[cnt]) {
mark_dquot_dirty(transfer_to[cnt]);
/* The reference we got is transferred to the inode */ /* The reference we got is transferred to the inode */
for (cnt = 0; cnt < MAXQUOTAS; cnt++)
transfer_to[cnt] = NULL; transfer_to[cnt] = NULL;
}
}
warn_put_all: warn_put_all:
flush_warnings(transfer_to, warntype_to); flush_warnings(transfer_to, warntype_to);
flush_warnings(transfer_from, warntype_from_inodes); flush_warnings(transfer_from, warntype_from_inodes);
flush_warnings(transfer_from, warntype_from_space); flush_warnings(transfer_from, warntype_from_space);
put_all: put_all:
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { dqput_all(transfer_from);
dqput(transfer_from[cnt]); dqput_all(transfer_to);
dqput(transfer_to[cnt]);
}
return ret; return ret;
over_quota: over_quota:
spin_unlock(&dq_data_lock); spin_unlock(&dq_data_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment