/* Read global header */
oinfo->dqi_gqinode = ocfs2_get_system_file_inode(OCFS2_SB(sb), ino[type],
OCFS2_INVALID_SLOT); if (!oinfo->dqi_gqinode) {
mlog(ML_ERROR, "failed to get global quota inode (type=%d)\n",
type);
status = -EINVAL; goto out_err;
}
status = ocfs2_lock_global_qf(oinfo, 0); if (status < 0) {
mlog_errno(status); goto out_err;
}
status = ocfs2_extent_map_get_blocks(oinfo->dqi_gqinode, 0, &oinfo->dqi_giblk,
&pcount, NULL); if (status < 0) {
mlog_errno(status); goto out_unlock;
}
staticint ocfs2_calc_global_qinit_credits(struct super_block *sb, int type)
{ /* We modify all the allocated blocks, tree root, info block and
* the inode */ return (ocfs2_global_qinit_alloc(sb, type) + 2) *
OCFS2_QUOTA_BLOCK_UPDATE_CREDITS + 1;
}
/* Sync local information about quota modifications with global quota file. *Callermusthavestartedthetransactionandobtainedexclusivelockfor
* global quota file inode */ int __ocfs2_sync_dquot(struct dquot *dquot, int freeing)
{ int err, err2; struct super_block *sb = dquot->dq_sb; int type = dquot->dq_id.type; struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv; struct ocfs2_global_disk_dqblk dqblk;
s64 spacechange, inodechange;
time64_t olditime, oldbtime;
err = sb->s_op->quota_read(sb, type, (char *)&dqblk, sizeof(struct ocfs2_global_disk_dqblk),
dquot->dq_off); if (err != sizeof(struct ocfs2_global_disk_dqblk)) { if (err >= 0) {
mlog(ML_ERROR, "Short read from global quota file " "(%u read)\n", err);
err = -EIO;
} goto out;
}
/* Update space and inode usage. Get also other information from *globalquotafilesothatwedon'toverwriteanychangesthere.
* We are */
spin_lock(&dquot->dq_dqb_lock);
spacechange = dquot->dq_dqb.dqb_curspace -
OCFS2_DQUOT(dquot)->dq_origspace;
inodechange = dquot->dq_dqb.dqb_curinodes -
OCFS2_DQUOT(dquot)->dq_originodes;
olditime = dquot->dq_dqb.dqb_itime;
oldbtime = dquot->dq_dqb.dqb_btime;
ocfs2_global_disk2memdqb(dquot, &dqblk);
trace_ocfs2_sync_dquot(from_kqid(&init_user_ns, dquot->dq_id),
dquot->dq_dqb.dqb_curspace,
(longlong)spacechange,
dquot->dq_dqb.dqb_curinodes,
(longlong)inodechange); if (!test_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags))
dquot->dq_dqb.dqb_curspace += spacechange; if (!test_bit(DQ_LASTSET_B + QIF_INODES_B, &dquot->dq_flags))
dquot->dq_dqb.dqb_curinodes += inodechange; /* Set properly space grace time... */ if (dquot->dq_dqb.dqb_bsoftlimit &&
dquot->dq_dqb.dqb_curspace > dquot->dq_dqb.dqb_bsoftlimit) { if (!test_bit(DQ_LASTSET_B + QIF_BTIME_B, &dquot->dq_flags) &&
oldbtime > 0) { if (dquot->dq_dqb.dqb_btime > 0)
dquot->dq_dqb.dqb_btime =
min(dquot->dq_dqb.dqb_btime, oldbtime); else
dquot->dq_dqb.dqb_btime = oldbtime;
}
} else {
dquot->dq_dqb.dqb_btime = 0;
clear_bit(DQ_BLKS_B, &dquot->dq_flags);
} /* Set properly inode grace time... */ if (dquot->dq_dqb.dqb_isoftlimit &&
dquot->dq_dqb.dqb_curinodes > dquot->dq_dqb.dqb_isoftlimit) { if (!test_bit(DQ_LASTSET_B + QIF_ITIME_B, &dquot->dq_flags) &&
olditime > 0) { if (dquot->dq_dqb.dqb_itime > 0)
dquot->dq_dqb.dqb_itime =
min(dquot->dq_dqb.dqb_itime, olditime); else
dquot->dq_dqb.dqb_itime = olditime;
}
} else {
dquot->dq_dqb.dqb_itime = 0;
clear_bit(DQ_INODES_B, &dquot->dq_flags);
} /* All information is properly updated, clear the flags */
__clear_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags);
__clear_bit(DQ_LASTSET_B + QIF_INODES_B, &dquot->dq_flags);
__clear_bit(DQ_LASTSET_B + QIF_BLIMITS_B, &dquot->dq_flags);
__clear_bit(DQ_LASTSET_B + QIF_ILIMITS_B, &dquot->dq_flags);
__clear_bit(DQ_LASTSET_B + QIF_BTIME_B, &dquot->dq_flags);
__clear_bit(DQ_LASTSET_B + QIF_ITIME_B, &dquot->dq_flags);
OCFS2_DQUOT(dquot)->dq_origspace = dquot->dq_dqb.dqb_curspace;
OCFS2_DQUOT(dquot)->dq_originodes = dquot->dq_dqb.dqb_curinodes;
spin_unlock(&dquot->dq_dqb_lock);
err = ocfs2_qinfo_lock(info, freeing); if (err < 0) {
mlog(ML_ERROR, "Failed to lock quota info, losing quota write" " (type=%d, id=%u)\n", dquot->dq_id.type,
(unsigned)from_kqid(&init_user_ns, dquot->dq_id)); goto out;
} if (freeing)
OCFS2_DQUOT(dquot)->dq_use_count--;
err = qtree_write_dquot(&info->dqi_gi, dquot); if (err < 0) goto out_qlock; if (freeing && !OCFS2_DQUOT(dquot)->dq_use_count) {
err = qtree_release_dquot(&info->dqi_gi, dquot); if (info_dirty(sb_dqinfo(sb, type))) {
err2 = __ocfs2_global_write_info(sb, type); if (!err)
err = err2;
}
}
out_qlock:
ocfs2_qinfo_unlock(info, freeing);
out: if (err < 0)
mlog_errno(err); return err;
}
trace_ocfs2_sync_dquot_helper(from_kqid(&init_user_ns, dquot->dq_id),
dquot->dq_id.type,
type, sb->s_id); if (type != dquot->dq_id.type) goto out;
status = ocfs2_lock_global_qf(oinfo, 1); if (status < 0) goto out;
handle = ocfs2_start_trans(osb, OCFS2_QSYNC_CREDITS); if (IS_ERR(handle)) {
status = PTR_ERR(handle);
mlog_errno(status); goto out_ilock;
}
down_write(&sb_dqopt(sb)->dqio_sem);
memalloc = memalloc_nofs_save();
status = ocfs2_sync_dquot(dquot); if (status < 0)
mlog_errno(status); /* We have to write local structure as well... */
status = ocfs2_local_write_dquot(dquot); if (status < 0)
mlog_errno(status);
memalloc_nofs_restore(memalloc);
up_write(&sb_dqopt(sb)->dqio_sem);
ocfs2_commit_trans(osb, handle);
out_ilock:
ocfs2_unlock_global_qf(oinfo, 1);
out: return status;
}
list = llist_del_all(&osb->dquot_drop_list);
llist_for_each_entry_safe(odquot, next_odquot, list, list) { /* Drop the reference we acquired in ocfs2_dquot_release() */
dqput(&odquot->dq_dquot);
}
}
mutex_lock(&dquot->dq_lock); /* Check whether we are not racing with some other dqget() */ if (dquot_is_busy(dquot)) goto out; /* Running from downconvert thread? Postpone quota processing to wq */ if (current == osb->dc_task) { /* *Grabourownreferencetodquotandqueueitfordelayed *dropping.Quotacoderechecksaftercalling *->release_dquot()andwon'tfreedquotstructure.
*/
dqgrab(dquot); /* First entry on list -> queue work */ if (llist_add(&OCFS2_DQUOT(dquot)->list, &osb->dquot_drop_list))
queue_work(osb->ocfs2_wq, &osb->dquot_drop_work); goto out;
}
status = ocfs2_lock_global_qf(oinfo, 1); if (status < 0) goto out;
handle = ocfs2_start_trans(osb,
ocfs2_calc_qdel_credits(dquot->dq_sb, dquot->dq_id.type)); if (IS_ERR(handle)) { /* *Markdquotasinactivetoavoidendlesscyclein *quota_release_workfn().
*/
clear_bit(DQ_ACTIVE_B, &dquot->dq_flags);
status = PTR_ERR(handle);
mlog_errno(status); goto out_ilock;
}
status = ocfs2_global_release_dquot(dquot); if (status < 0) {
mlog_errno(status); goto out_trans;
}
status = ocfs2_local_release_dquot(handle, dquot); /* *Ifwefailhere,wecannotdomuchasglobalstructureis *alreadyreleased.Sojustcomplain...
*/ if (status < 0)
mlog_errno(status); /* *Cleardq_offsothatwesearchforthestructureinquotafilenext *timeweacquireit.Thestructuremightbedeletedandreallocated *elsewherebyanothernodewhileourdquotstructureisonfreelist.
*/
dquot->dq_off = 0;
clear_bit(DQ_ACTIVE_B, &dquot->dq_flags);
out_trans:
ocfs2_commit_trans(osb, handle);
out_ilock:
ocfs2_unlock_global_qf(oinfo, 1);
out:
mutex_unlock(&dquot->dq_lock); if (status)
mlog_errno(status); return status;
}
/* *Readglobaldquotstructurefromdiskorcreateitifitdoes *notexist.Alsoupdateusecountoftheglobalstructureand *createstructureinnode-localquotafile.
*/ staticint ocfs2_acquire_dquot(struct dquot *dquot)
{ int status = 0, err; int ex = 0; struct super_block *sb = dquot->dq_sb; struct ocfs2_super *osb = OCFS2_SB(sb); int type = dquot->dq_id.type; struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv; struct inode *gqinode = info->dqi_gqinode; int need_alloc = ocfs2_global_qinit_alloc(sb, type);
handle_t *handle;
trace_ocfs2_acquire_dquot(from_kqid(&init_user_ns, dquot->dq_id),
type);
mutex_lock(&dquot->dq_lock); /* *Weneedanexclusivelock,becausewe'regoingtoupdateusecount *andinstantiatepossiblynewdquotstructure
*/
status = ocfs2_lock_global_qf(info, 1); if (status < 0) goto out;
status = ocfs2_qinfo_lock(info, 0); if (status < 0) goto out_dq; /* *Wealwayswanttoreaddquotstructurefromdiskbecausewedon't *knowwhathappenedwithitwhileitwasonfreelist.
*/
status = qtree_read_dquot(&info->dqi_gi, dquot);
ocfs2_qinfo_unlock(info, 0); if (status < 0) goto out_dq;
OCFS2_DQUOT(dquot)->dq_use_count++;
OCFS2_DQUOT(dquot)->dq_origspace = dquot->dq_dqb.dqb_curspace;
OCFS2_DQUOT(dquot)->dq_originodes = dquot->dq_dqb.dqb_curinodes; if (!dquot->dq_off) { /* No real quota entry? */
ex = 1; /* *Addblockstoquotafilebeforewestartatransactionsince *lockingallocatorsranksaboveatransactionstart
*/
WARN_ON(journal_current_handle());
status = ocfs2_extend_no_holes(gqinode, NULL,
i_size_read(gqinode) + (need_alloc << sb->s_blocksize_bits),
i_size_read(gqinode)); if (status < 0) goto out_dq;
}
handle = ocfs2_start_trans(osb,
ocfs2_calc_global_qinit_credits(sb, type)); if (IS_ERR(handle)) {
status = PTR_ERR(handle); goto out_dq;
}
status = ocfs2_qinfo_lock(info, ex); if (status < 0) goto out_trans;
status = qtree_write_dquot(&info->dqi_gi, dquot); if (ex && info_dirty(sb_dqinfo(sb, type))) {
err = __ocfs2_global_write_info(sb, type); if (!status)
status = err;
}
ocfs2_qinfo_unlock(info, ex);
out_trans:
ocfs2_commit_trans(osb, handle);
out_dq:
ocfs2_unlock_global_qf(info, 1); if (status < 0) goto out;
status = ocfs2_create_local_dquot(dquot); if (status < 0) goto out;
set_bit(DQ_ACTIVE_B, &dquot->dq_flags);
out:
mutex_unlock(&dquot->dq_lock); if (status)
mlog_errno(status); return status;
}
staticint ocfs2_get_next_id(struct super_block *sb, struct kqid *qid)
{ int type = qid->type; struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv; int status = 0;
trace_ocfs2_get_next_id(from_kqid(&init_user_ns, *qid), type); if (!sb_has_quota_active(sb, type)) {
status = -ESRCH; goto out;
}
status = ocfs2_lock_global_qf(info, 0); if (status < 0) goto out;
status = ocfs2_qinfo_lock(info, 0); if (status < 0) goto out_global;
status = qtree_get_next_id(&info->dqi_gi, qid);
ocfs2_qinfo_unlock(info, 0);
out_global:
ocfs2_unlock_global_qf(info, 0);
out: /* *AvoidloggingENOENTsinceitjustmeansthereisn'tnextIDand *ESRCHwhichmeansquotaisn'tenabledforthefilesystem.
*/ if (status && status != -ENOENT && status != -ESRCH)
mlog_errno(status); return status;
}
/* In case user set some limits, sync dquot immediately to global
* quota file so that information propagates quicker */
spin_lock(&dquot->dq_dqb_lock); if (dquot->dq_flags & mask)
sync = 1;
spin_unlock(&dquot->dq_dqb_lock); /* This is a slight hack but we can't afford getting global quota
* lock if we already have a transaction started. */ if (!sync || journal_current_handle()) {
status = ocfs2_write_dquot(dquot); goto out;
}
status = ocfs2_lock_global_qf(oinfo, 1); if (status < 0) goto out;
handle = ocfs2_start_trans(osb, OCFS2_QSYNC_CREDITS); if (IS_ERR(handle)) {
status = PTR_ERR(handle);
mlog_errno(status); goto out_ilock;
}
down_write(&sb_dqopt(sb)->dqio_sem);
memalloc = memalloc_nofs_save();
status = ocfs2_sync_dquot(dquot); if (status < 0) {
mlog_errno(status); goto out_dlock;
} /* Now write updated local dquot structure */
status = ocfs2_local_write_dquot(dquot);
out_dlock:
memalloc_nofs_restore(memalloc);
up_write(&sb_dqopt(sb)->dqio_sem);
ocfs2_commit_trans(osb, handle);
out_ilock:
ocfs2_unlock_global_qf(oinfo, 1);
out: if (status)
mlog_errno(status); return status;
}
/* This should happen only after set_dqinfo(). */ staticint ocfs2_write_info(struct super_block *sb, int type)
{
handle_t *handle; int status = 0; struct ocfs2_mem_dqinfo *oinfo = sb_dqinfo(sb, type)->dqi_priv;
status = ocfs2_lock_global_qf(oinfo, 1); if (status < 0) goto out;
handle = ocfs2_start_trans(OCFS2_SB(sb), OCFS2_QINFO_WRITE_CREDITS); if (IS_ERR(handle)) {
status = PTR_ERR(handle);
mlog_errno(status); goto out_ilock;
}
status = dquot_commit_info(sb, type);
ocfs2_commit_trans(OCFS2_SB(sb), handle);
out_ilock:
ocfs2_unlock_global_qf(oinfo, 1);
out: if (status)
mlog_errno(status); return status;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.