• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/fs/quota/

Lines Matching refs:dquot

37  *		Write updated not to require dquot lock
87 * also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes.
97 * the life of the dquot structure and so needn't to be protected by a lock
109 * Each dquot has its dq_lock mutex. Locked dquots might not be referenced
111 * Currently dquot is locked only when it is being read to memory (or space for
119 * i_mutex > dqonoff_sem > journal_lock > dqptr_sem > dquot->dq_lock >
125 * filesystems usually want to do some IO on dquot from ->mark_dirty which is
157 /* SLAB cache for dquot structures */
222 * The quota code uses three lists for dquot management: the inuse_list,
223 * free_dquots, and dquot_hash[] array. A single dquot structure may be
227 * list is used for invalidate operation, which must look at every dquot.
230 * and this list is searched whenever we need an available dquot. Dquots are
233 * dquot is invalidated it's completely released from memory.
237 * mechanism to locate a specific dquot.
263 static inline void insert_dquot_hash(struct dquot *dquot)
266 head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type);
267 hlist_add_head(&dquot->dq_hash, head);
270 static inline void remove_dquot_hash(struct dquot *dquot)
272 hlist_del_init(&dquot->dq_hash);
275 static struct dquot *find_dquot(unsigned int hashent, struct super_block *sb,
279 struct dquot *dquot;
282 dquot = hlist_entry(node, struct dquot, dq_hash);
283 if (dquot->dq_sb == sb && dquot->dq_id == id &&
284 dquot->dq_type == type)
285 return dquot;
290 /* Add a dquot to the tail of the free list */
291 static inline void put_dquot_last(struct dquot *dquot)
293 list_add_tail(&dquot->dq_free, &free_dquots);
297 static inline void remove_free_dquot(struct dquot *dquot)
299 if (list_empty(&dquot->dq_free))
301 list_del_init(&dquot->dq_free);
305 static inline void put_inuse(struct dquot *dquot)
309 list_add_tail(&dquot->dq_inuse, &inuse_list);
313 static inline void remove_inuse(struct dquot *dquot)
316 list_del(&dquot->dq_inuse);
322 static void wait_on_dquot(struct dquot *dquot)
324 mutex_lock(&dquot->dq_lock);
325 mutex_unlock(&dquot->dq_lock);
328 static inline int dquot_dirty(struct dquot *dquot)
330 return test_bit(DQ_MOD_B, &dquot->dq_flags);
333 static inline int mark_dquot_dirty(struct dquot *dquot)
335 return dquot->dq_sb->dq_op->mark_dirty(dquot);
338 /* Mark dquot dirty in atomic manner, and return it's old dirty flag state */
339 int dquot_mark_dquot_dirty(struct dquot *dquot)
344 if (test_bit(DQ_MOD_B, &dquot->dq_flags))
348 if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags)) {
349 list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)->
350 info[dquot->dq_type].dqi_dirty_list);
359 static inline int mark_all_dquot_dirty(struct dquot * const *dquot)
365 if (dquot[cnt])
367 ret = mark_dquot_dirty(dquot[cnt]);
374 static inline void dqput_all(struct dquot **dquot)
379 dqput(dquot[cnt]);
383 static inline int clear_dquot_dirty(struct dquot *dquot)
385 if (!test_and_clear_bit(DQ_MOD_B, &dquot->dq_flags))
387 list_del_init(&dquot->dq_dirty);
398 * Read dquot from disk and alloc space for it
401 int dquot_acquire(struct dquot *dquot)
404 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
406 mutex_lock(&dquot->dq_lock);
408 if (!test_bit(DQ_READ_B, &dquot->dq_flags))
409 ret = dqopt->ops[dquot->dq_type]->read_dqblk(dquot);
412 set_bit(DQ_READ_B, &dquot->dq_flags);
413 /* Instantiate dquot if needed */
414 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) {
415 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
417 if (info_dirty(&dqopt->info[dquot->dq_type])) {
418 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(
419 dquot->dq_sb, dquot->dq_type);
428 set_bit(DQ_ACTIVE_B, &dquot->dq_flags);
431 mutex_unlock(&dquot->dq_lock);
437 * Write dquot to disk
439 int dquot_commit(struct dquot *dquot)
442 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
446 if (!clear_dquot_dirty(dquot)) {
451 /* Inactive dquot can be only if there was error during read/init
453 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
454 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
455 if (info_dirty(&dqopt->info[dquot->dq_type])) {
456 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(
457 dquot->dq_sb, dquot->dq_type);
469 * Release dquot
471 int dquot_release(struct dquot *dquot)
474 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
476 mutex_lock(&dquot->dq_lock);
478 if (atomic_read(&dquot->dq_count) > 1)
481 if (dqopt->ops[dquot->dq_type]->release_dqblk) {
482 ret = dqopt->ops[dquot->dq_type]->release_dqblk(dquot);
484 if (info_dirty(&dqopt->info[dquot->dq_type])) {
485 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(
486 dquot->dq_sb, dquot->dq_type);
491 clear_bit(DQ_ACTIVE_B, &dquot->dq_flags);
494 mutex_unlock(&dquot->dq_lock);
499 void dquot_destroy(struct dquot *dquot)
501 kmem_cache_free(dquot_cachep, dquot);
505 static inline void do_destroy_dquot(struct dquot *dquot)
507 dquot->dq_sb->dq_op->destroy_dquot(dquot);
518 struct dquot *dquot, *tmp;
522 list_for_each_entry_safe(dquot, tmp, &inuse_list, dq_inuse) {
523 if (dquot->dq_sb != sb)
525 if (dquot->dq_type != type)
527 /* Wait for dquot users */
528 if (atomic_read(&dquot->dq_count)) {
531 atomic_inc(&dquot->dq_count);
532 prepare_to_wait(&dquot->dq_wait_unused, &wait,
536 * the dquot.
538 * at most one process waiting for dquot to free.
542 if (atomic_read(&dquot->dq_count) > 1)
544 finish_wait(&dquot->dq_wait_unused, &wait);
545 dqput(dquot);
546 /* At this moment dquot() need not exist (it could be
555 remove_dquot_hash(dquot);
556 remove_free_dquot(dquot);
557 remove_inuse(dquot);
558 do_destroy_dquot(dquot);
563 /* Call callback for every active dquot on given filesystem */
565 int (*fn)(struct dquot *dquot, unsigned long priv),
568 struct dquot *dquot, *old_dquot = NULL;
573 list_for_each_entry(dquot, &inuse_list, dq_inuse) {
574 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags))
576 if (dquot->dq_sb != sb)
578 /* Now we have active dquot so we can just increase use count */
579 atomic_inc(&dquot->dq_count);
583 old_dquot = dquot;
584 ret = fn(dquot, priv);
588 /* We are safe to continue now because our dquot could not
602 struct dquot *dquot;
615 dquot = list_first_entry(dirty, struct dquot,
617 /* Dirty and inactive can be only bad dquot... */
618 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
619 clear_dquot_dirty(dquot);
622 /* Now we have active dquot from which someone is
625 atomic_inc(&dquot->dq_count);
628 sb->dq_op->write_dquot(dquot);
629 dqput(dquot);
677 struct dquot *dquot;
681 dquot = list_entry(head, struct dquot, dq_free);
682 remove_dquot_hash(dquot);
683 remove_free_dquot(dquot);
684 remove_inuse(dquot);
685 do_destroy_dquot(dquot);
713 * Put reference to dquot
716 void dqput(struct dquot *dquot)
720 if (!dquot)
723 if (!atomic_read(&dquot->dq_count)) {
724 quota_error(dquot->dq_sb, "trying to free free dquot of %s %d",
725 quotatypes[dquot->dq_type], dquot->dq_id);
732 if (atomic_read(&dquot->dq_count) > 1) {
734 atomic_dec(&dquot->dq_count);
735 /* Releasing dquot during quotaoff phase? */
736 if (!sb_has_quota_active(dquot->dq_sb, dquot->dq_type) &&
737 atomic_read(&dquot->dq_count) == 1)
738 wake_up(&dquot->dq_wait_unused);
742 /* Need to release dquot? */
743 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && dquot_dirty(dquot)) {
745 /* Commit dquot before releasing */
746 ret = dquot->dq_sb->dq_op->write_dquot(dquot);
748 quota_error(dquot->dq_sb, "Can't write quota structure"
756 clear_dquot_dirty(dquot);
761 /* Clear flag in case dquot was inactive (something bad happened) */
762 clear_dquot_dirty(dquot);
763 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
765 dquot->dq_sb->dq_op->release_dquot(dquot);
768 atomic_dec(&dquot->dq_count);
771 BUG_ON(!list_empty(&dquot->dq_free));
773 put_dquot_last(dquot);
778 struct dquot *dquot_alloc(struct super_block *sb, int type)
784 static struct dquot *get_empty_dquot(struct super_block *sb, int type)
786 struct dquot *dquot;
788 dquot = sb->dq_op->alloc_dquot(sb, type);
789 if(!dquot)
792 mutex_init(&dquot->dq_lock);
793 INIT_LIST_HEAD(&dquot->dq_free);
794 INIT_LIST_HEAD(&dquot->dq_inuse);
795 INIT_HLIST_NODE(&dquot->dq_hash);
796 INIT_LIST_HEAD(&dquot->dq_dirty);
797 init_waitqueue_head(&dquot->dq_wait_unused);
798 dquot->dq_sb = sb;
799 dquot->dq_type = type;
800 atomic_set(&dquot->dq_count, 1);
802 return dquot;
806 * Get reference to dquot
809 * destroying our dquot by:
811 * b) getting a reference to dquot before we release dq_list_lock
813 struct dquot *dqget(struct super_block *sb, unsigned int id, int type)
816 struct dquot *dquot = NULL, *empty = NULL;
830 dquot = find_dquot(hashent, sb, id, type);
831 if (!dquot) {
839 dquot = empty;
841 dquot->dq_id = id;
843 put_inuse(dquot);
845 insert_dquot_hash(dquot);
849 if (!atomic_read(&dquot->dq_count))
850 remove_free_dquot(dquot);
851 atomic_inc(&dquot->dq_count);
858 wait_on_dquot(dquot);
859 /* Read the dquot / allocate space in quota file */
860 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) &&
861 sb->dq_op->acquire_dquot(dquot) < 0) {
862 dqput(dquot);
863 dquot = NULL;
867 BUG_ON(!dquot->dq_sb); /* Has somebody invalidated entry under us? */
873 return dquot;
941 static inline int dqput_blocks(struct dquot *dquot)
943 if (atomic_read(&dquot->dq_count) <= 1)
949 * Remove references to dquots from inode and add dquot to list for freeing
950 * if we have the last referece to dquot
956 struct dquot *dquot = inode->i_dquot[type];
959 if (dquot) {
960 if (dqput_blocks(dquot)) {
962 if (atomic_read(&dquot->dq_count) != 1)
963 quota_error(inode->i_sb, "Adding dquot with "
965 atomic_read(&dquot->dq_count));
968 /* As dquot must have currently users it can't be on
970 list_add(&dquot->dq_free, tofree_head);
975 dqput(dquot); /* We have guaranteed we won't block */
988 struct dquot *dquot;
992 dquot = list_entry(act_head, struct dquot, dq_free);
994 /* Remove dquot from the list so we won't have problems... */
995 list_del_init(&dquot->dq_free);
996 dqput(dquot);
1043 static inline void dquot_incr_inodes(struct dquot *dquot, qsize_t number)
1045 dquot->dq_dqb.dqb_curinodes += number;
1048 static inline void dquot_incr_space(struct dquot *dquot, qsize_t number)
1050 dquot->dq_dqb.dqb_curspace += number;
1053 static inline void dquot_resv_space(struct dquot *dquot, qsize_t number)
1055 dquot->dq_dqb.dqb_rsvspace += number;
1061 static void dquot_claim_reserved_space(struct dquot *dquot, qsize_t number)
1063 if (dquot->dq_dqb.dqb_rsvspace < number) {
1065 number = dquot->dq_dqb.dqb_rsvspace;
1067 dquot->dq_dqb.dqb_curspace += number;
1068 dquot->dq_dqb.dqb_rsvspace -= number;
1072 void dquot_free_reserved_space(struct dquot *dquot, qsize_t number)
1074 if (dquot->dq_dqb.dqb_rsvspace >= number)
1075 dquot->dq_dqb.dqb_rsvspace -= number;
1078 dquot->dq_dqb.dqb_rsvspace = 0;
1082 static void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
1084 if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE ||
1085 dquot->dq_dqb.dqb_curinodes >= number)
1086 dquot->dq_dqb.dqb_curinodes -= number;
1088 dquot->dq_dqb.dqb_curinodes = 0;
1089 if (dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit)
1090 dquot->dq_dqb.dqb_itime = (time_t) 0;
1091 clear_bit(DQ_INODES_B, &dquot->dq_flags);
1094 static void dquot_decr_space(struct dquot *dquot, qsize_t number)
1096 if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE ||
1097 dquot->dq_dqb.dqb_curspace >= number)
1098 dquot->dq_dqb.dqb_curspace -= number;
1100 dquot->dq_dqb.dqb_curspace = 0;
1101 if (dquot->dq_dqb.dqb_curspace <= dquot->dq_dqb.dqb_bsoftlimit)
1102 dquot->dq_dqb.dqb_btime = (time_t) 0;
1103 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
1106 static int warning_issued(struct dquot *dquot, const int warntype)
1115 return test_and_set_bit(flag, &dquot->dq_flags);
1121 static int need_print_warning(struct dquot *dquot)
1126 switch (dquot->dq_type) {
1128 return current_fsuid() == dquot->dq_id;
1130 return in_group_p(dquot->dq_id);
1136 static void print_warning(struct dquot *dquot, const int warntype)
1144 warntype == QUOTA_NL_BSOFTBELOW || !need_print_warning(dquot))
1150 tty_write_message(tty, dquot->dq_sb->s_id);
1155 tty_write_message(tty, quotatypes[dquot->dq_type]);
1186 static void flush_warnings(struct dquot *const *dquots, char *warntype)
1188 struct dquot *dq;
1204 static int ignore_hardlimit(struct dquot *dquot)
1206 struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
1214 static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
1216 qsize_t newinodes = dquot->dq_dqb.dqb_curinodes + inodes;
1219 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) ||
1220 test_bit(DQ_FAKE_B, &dquot->dq_flags))
1223 if (dquot->dq_dqb.dqb_ihardlimit &&
1224 newinodes > dquot->dq_dqb.dqb_ihardlimit &&
1225 !ignore_hardlimit(dquot)) {
1230 if (dquot->dq_dqb.dqb_isoftlimit &&
1231 newinodes > dquot->dq_dqb.dqb_isoftlimit &&
1232 dquot->dq_dqb.dqb_itime &&
1233 get_seconds() >= dquot->dq_dqb.dqb_itime &&
1234 !ignore_hardlimit(dquot)) {
1239 if (dquot->dq_dqb.dqb_isoftlimit &&
1240 newinodes > dquot->dq_dqb.dqb_isoftlimit &&
1241 dquot->dq_dqb.dqb_itime == 0) {
1243 dquot->dq_dqb.dqb_itime = get_seconds() +
1244 sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
1251 static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype)
1254 struct super_block *sb = dquot->dq_sb;
1257 if (!sb_has_quota_limits_enabled(sb, dquot->dq_type) ||
1258 test_bit(DQ_FAKE_B, &dquot->dq_flags))
1261 tspace = dquot->dq_dqb.dqb_curspace + dquot->dq_dqb.dqb_rsvspace
1264 if (dquot->dq_dqb.dqb_bhardlimit &&
1265 tspace > dquot->dq_dqb.dqb_bhardlimit &&
1266 !ignore_hardlimit(dquot)) {
1272 if (dquot->dq_dqb.dqb_bsoftlimit &&
1273 tspace > dquot->dq_dqb.dqb_bsoftlimit &&
1274 dquot->dq_dqb.dqb_btime &&
1275 get_seconds() >= dquot->dq_dqb.dqb_btime &&
1276 !ignore_hardlimit(dquot)) {
1282 if (dquot->dq_dqb.dqb_bsoftlimit &&
1283 tspace > dquot->dq_dqb.dqb_bsoftlimit &&
1284 dquot->dq_dqb.dqb_btime == 0) {
1287 dquot->dq_dqb.dqb_btime = get_seconds() +
1288 sb_dqopt(sb)->info[dquot->dq_type].dqi_bgrace;
1301 static int info_idq_free(struct dquot *dquot, qsize_t inodes)
1305 if (test_bit(DQ_FAKE_B, &dquot->dq_flags) ||
1306 dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit ||
1307 !sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type))
1310 newinodes = dquot->dq_dqb.dqb_curinodes - inodes;
1311 if (newinodes <= dquot->dq_dqb.dqb_isoftlimit)
1313 if (dquot->dq_dqb.dqb_curinodes >= dquot->dq_dqb.dqb_ihardlimit &&
1314 newinodes < dquot->dq_dqb.dqb_ihardlimit)
1319 static int info_bdq_free(struct dquot *dquot, qsize_t space)
1321 if (test_bit(DQ_FAKE_B, &dquot->dq_flags) ||
1322 dquot->dq_dqb.dqb_curspace <= dquot->dq_dqb.dqb_bsoftlimit)
1325 if (dquot->dq_dqb.dqb_curspace - space <= dquot->dq_dqb.dqb_bsoftlimit)
1327 if (dquot->dq_dqb.dqb_curspace >= dquot->dq_dqb.dqb_bhardlimit &&
1328 dquot->dq_dqb.dqb_curspace - space < dquot->dq_dqb.dqb_bhardlimit)
1349 * might need a lot of space in journal for dquot structure allocation.
1355 struct dquot *got[MAXQUOTAS];
1419 struct dquot *put[MAXQUOTAS];
1526 * the current transaction so that dquot write and inode write go into the
1725 * On success, dquot references in transfer_to are consumed and references
1733 int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)
1737 struct dquot *transfer_from[MAXQUOTAS] = {};
1824 struct dquot *transfer_to[MAXQUOTAS] = {};
2090 * When S_NOQUOTA is set, remove dquot references as no more
2301 static void do_get_dqblk(struct dquot *dquot, struct fs_disk_quota *di)
2303 struct mem_dqblk *dm = &dquot->dq_dqb;
2307 di->d_flags = dquot->dq_type == USRQUOTA ?
2309 di->d_id = dquot->dq_id;
2326 struct dquot *dquot;
2328 dquot = dqget(sb, id, type);
2329 if (!dquot)
2331 do_get_dqblk(dquot, di);
2332 dqput(dquot);
2344 static int do_set_dqblk(struct dquot *dquot, struct fs_disk_quota *di)
2346 struct mem_dqblk *dm = &dquot->dq_dqb;
2348 struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
2367 set_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags);
2376 set_bit(DQ_LASTSET_B + QIF_BLIMITS_B, &dquot->dq_flags);
2382 set_bit(DQ_LASTSET_B + QIF_INODES_B, &dquot->dq_flags);
2391 set_bit(DQ_LASTSET_B + QIF_ILIMITS_B, &dquot->dq_flags);
2397 set_bit(DQ_LASTSET_B + QIF_BTIME_B, &dquot->dq_flags);
2403 set_bit(DQ_LASTSET_B + QIF_ITIME_B, &dquot->dq_flags);
2410 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
2419 clear_bit(DQ_INODES_B, &dquot->dq_flags);
2426 clear_bit(DQ_FAKE_B, &dquot->dq_flags);
2428 set_bit(DQ_FAKE_B, &dquot->dq_flags);
2430 mark_dquot_dirty(dquot);
2438 struct dquot *dquot;
2441 dquot = dqget(sb, id, type);
2442 if (!dquot) {
2446 rc = do_set_dqblk(dquot, di);
2447 dqput(dquot);
2623 dquot_cachep = kmem_cache_create("dquot",
2624 sizeof(struct dquot), sizeof(unsigned long) * 4,
2632 panic("Cannot create dquot hash table");
2637 panic("Cannot create dquot stat counters");