56 #include <linux/errno.h>
57 #include <linux/kernel.h>
61 #include <linux/time.h>
62 #include <linux/types.h>
63 #include <linux/string.h>
64 #include <linux/fcntl.h>
65 #include <linux/stat.h>
66 #include <linux/tty.h>
68 #include <linux/slab.h>
69 #include <linux/sysctl.h>
71 #include <linux/module.h>
74 #include <linux/sched.h>
77 #include <linux/capability.h>
79 #include "../internal.h"
136 const char *
fmt, ...)
138 if (printk_ratelimit()) {
148 sb->
s_id, func, &vaf);
155 #if defined(CONFIG_QUOTA_DEBUG) || defined(CONFIG_PRINT_QUOTA_WARNING)
166 spin_lock(&dq_list_lock);
169 spin_unlock(&dq_list_lock);
178 spin_lock(&dq_list_lock);
179 for (actqf = "a_formats; *actqf && *actqf !=
fmt;
184 spin_unlock(&dq_list_lock);
192 spin_lock(&dq_list_lock);
193 for (actqf = quota_formats; actqf && actqf->
qf_fmt_id !=
id;
196 if (!actqf || !try_module_get(actqf->
qf_owner)) {
199 spin_unlock(&dq_list_lock);
201 for (qm = 0; module_names[qm].
qm_fmt_id &&
204 if (!module_names[qm].qm_fmt_id ||
205 request_module(module_names[qm].qm_mod_name))
208 spin_lock(&dq_list_lock);
209 for (actqf = quota_formats; actqf && actqf->
qf_fmt_id !=
id;
212 if (actqf && !try_module_get(actqf->
qf_owner))
215 spin_unlock(&dq_list_lock);
246 static unsigned int dq_hash_bits, dq_hash_mask;
255 static inline unsigned int
263 return (tmp + (tmp >> dq_hash_bits)) & dq_hash_mask;
269 static inline void insert_dquot_hash(
struct dquot *
dquot)
272 head = dquot_hash + hashfn(dquot->
dq_sb, dquot->
dq_id);
273 hlist_add_head(&dquot->
dq_hash, head);
276 static inline void remove_dquot_hash(
struct dquot *
dquot)
278 hlist_del_init(&dquot->
dq_hash);
281 static struct dquot *find_dquot(
unsigned int hashent,
struct super_block *sb,
296 static inline void put_dquot_last(
struct dquot *dquot)
302 static inline void remove_free_dquot(
struct dquot *dquot)
304 if (list_empty(&dquot->
dq_free))
306 list_del_init(&dquot->
dq_free);
310 static inline void put_inuse(
struct dquot *dquot)
318 static inline void remove_inuse(
struct dquot *dquot)
327 static void wait_on_dquot(
struct dquot *dquot)
333 static inline int dquot_dirty(
struct dquot *dquot)
338 static inline int mark_dquot_dirty(
struct dquot *dquot)
340 return dquot->
dq_sb->dq_op->mark_dirty(dquot);
352 spin_lock(&dq_list_lock);
358 spin_unlock(&dq_list_lock);
364 static inline int mark_all_dquot_dirty(
struct dquot *
const *dquot)
372 ret = mark_dquot_dirty(dquot[cnt]);
379 static inline void dqput_all(
struct dquot **dquot)
388 static inline int clear_dquot_dirty(
struct dquot *dquot)
408 int ret = 0, ret2 = 0;
414 ret = dqopt->
ops[dquot->
dq_id.type]->read_dqblk(dquot);
420 ret = dqopt->
ops[dquot->
dq_id.type]->commit_dqblk(dquot);
422 if (info_dirty(&dqopt->
info[dquot->
dq_id.type])) {
423 ret2 = dqopt->
ops[dquot->
dq_id.type]->write_file_info(
450 spin_lock(&dq_list_lock);
451 if (!clear_dquot_dirty(dquot)) {
452 spin_unlock(&dq_list_lock);
455 spin_unlock(&dq_list_lock);
459 ret = dqopt->
ops[dquot->
dq_id.type]->commit_dqblk(dquot);
473 int ret = 0, ret2 = 0;
481 if (dqopt->
ops[dquot->
dq_id.type]->release_dqblk) {
482 ret = dqopt->
ops[dquot->
dq_id.type]->release_dqblk(dquot);
484 if (info_dirty(&dqopt->
info[dquot->
dq_id.type])) {
485 ret2 = dqopt->
ops[dquot->
dq_id.type]->write_file_info(
505 static inline void do_destroy_dquot(
struct dquot *dquot)
507 dquot->
dq_sb->dq_op->destroy_dquot(dquot);
516 static void invalidate_dquots(
struct super_block *sb,
int type)
518 struct dquot *dquot, *
tmp;
521 spin_lock(&dq_list_lock);
523 if (dquot->
dq_sb != sb)
525 if (dquot->
dq_id.type != type)
534 spin_unlock(&dq_list_lock);
555 remove_dquot_hash(dquot);
556 remove_free_dquot(dquot);
558 do_destroy_dquot(dquot);
560 spin_unlock(&dq_list_lock);
565 int (*
fn)(
struct dquot *dquot,
unsigned long priv),
568 struct dquot *dquot, *old_dquot =
NULL;
572 spin_lock(&dq_list_lock);
576 if (dquot->
dq_sb != sb)
580 spin_unlock(&dq_list_lock);
584 ret =
fn(dquot, priv);
587 spin_lock(&dq_list_lock);
591 spin_unlock(&dq_list_lock);
610 if (type != -1 && cnt != type)
612 if (!sb_has_quota_active(sb, cnt))
614 spin_lock(&dq_list_lock);
615 dirty = &dqopt->
info[
cnt].dqi_dirty_list;
616 while (!list_empty(dirty)) {
621 clear_dquot_dirty(dquot);
628 spin_unlock(&dq_list_lock);
630 err = sb->
dq_op->write_dquot(dquot);
634 spin_lock(&dq_list_lock);
636 spin_unlock(&dq_list_lock);
640 if ((cnt == type || type == -1) && sb_has_quota_active(sb, cnt)
641 && info_dirty(&dqopt->
info[cnt]))
642 sb->
dq_op->write_info(sb, cnt);
666 if (sb->
s_op->sync_fs)
667 sb->
s_op->sync_fs(sb, 1);
676 if (type != -1 && cnt != type)
678 if (!sb_has_quota_active(sb, cnt))
691 static void prune_dqcache(
int count)
696 head = free_dquots.
prev;
697 while (head != &free_dquots && count) {
699 remove_dquot_hash(dquot);
700 remove_free_dquot(dquot);
702 do_destroy_dquot(dquot);
704 head = free_dquots.
prev;
718 spin_lock(&dq_list_lock);
720 spin_unlock(&dq_list_lock);
727 static struct shrinker dqcache_shrinker = {
728 .shrink = shrink_dqcache_memory,
742 #ifdef CONFIG_QUOTA_DEBUG
744 quota_error(dquot->
dq_sb,
"trying to free free dquot of %s %d",
745 quotatypes[dquot->
dq_id.type],
752 spin_lock(&dq_list_lock);
757 if (!sb_has_quota_active(dquot->
dq_sb, dquot->
dq_id.type) &&
760 spin_unlock(&dq_list_lock);
765 spin_unlock(&dq_list_lock);
767 ret = dquot->
dq_sb->dq_op->write_dquot(dquot);
769 quota_error(dquot->
dq_sb,
"Can't write quota structure"
770 " (error %d). Quota may get out of sync!",
776 spin_lock(&dq_list_lock);
777 clear_dquot_dirty(dquot);
778 spin_unlock(&dq_list_lock);
783 clear_dquot_dirty(dquot);
785 spin_unlock(&dq_list_lock);
786 dquot->
dq_sb->dq_op->release_dquot(dquot);
790 #ifdef CONFIG_QUOTA_DEBUG
794 put_dquot_last(dquot);
795 spin_unlock(&dq_list_lock);
801 return kmem_cache_zalloc(dquot_cachep,
GFP_NOFS);
805 static struct dquot *get_empty_dquot(
struct super_block *sb,
int type)
809 dquot = sb->
dq_op->alloc_dquot(sb, type);
814 INIT_LIST_HEAD(&dquot->
dq_free);
816 INIT_HLIST_NODE(&dquot->
dq_hash);
820 dquot->
dq_id = make_kqid_invalid(type);
836 unsigned int hashent = hashfn(sb, qid);
839 if (!sb_has_quota_active(sb, qid.
type))
842 spin_lock(&dq_list_lock);
843 spin_lock(&dq_state_lock);
844 if (!sb_has_quota_active(sb, qid.
type)) {
845 spin_unlock(&dq_state_lock);
846 spin_unlock(&dq_list_lock);
849 spin_unlock(&dq_state_lock);
851 dquot = find_dquot(hashent, sb, qid);
854 spin_unlock(&dq_list_lock);
855 empty = get_empty_dquot(sb, qid.
type);
866 insert_dquot_hash(dquot);
867 spin_unlock(&dq_list_lock);
871 remove_free_dquot(dquot);
873 spin_unlock(&dq_list_lock);
879 wait_on_dquot(dquot);
882 sb->
dq_op->acquire_dquot(dquot) < 0) {
887 #ifdef CONFIG_QUOTA_DEBUG
892 do_destroy_dquot(empty);
898 static int dqinit_needed(
struct inode *
inode,
int type)
905 return !inode->i_dquot[
type];
907 if (!inode->i_dquot[cnt])
913 static void add_dquot_ref(
struct super_block *sb,
int type)
916 #ifdef CONFIG_QUOTA_DEBUG
920 spin_lock(&inode_sb_list_lock);
922 spin_lock(&inode->
i_lock);
925 !dqinit_needed(inode, type)) {
926 spin_unlock(&inode->
i_lock);
930 spin_unlock(&inode->
i_lock);
931 spin_unlock(&inode_sb_list_lock);
933 #ifdef CONFIG_QUOTA_DEBUG
934 if (
unlikely(inode_get_rsv_space(inode) > 0))
938 __dquot_initialize(inode, type);
949 spin_lock(&inode_sb_list_lock);
951 spin_unlock(&inode_sb_list_lock);
954 #ifdef CONFIG_QUOTA_DEBUG
956 quota_error(sb,
"Writes happened before quota was turned on "
957 "thus quota information is probably inconsistent. "
958 "Please run quotacheck(8)");
967 static inline int dqput_blocks(
struct dquot *dquot)
979 static int remove_inode_dquot_ref(
struct inode *inode,
int type,
982 struct dquot *dquot = inode->i_dquot[
type];
986 if (dqput_blocks(dquot)) {
987 #ifdef CONFIG_QUOTA_DEBUG
989 quota_error(inode->
i_sb,
"Adding dquot with "
990 "dq_count %d to dispose list",
993 spin_lock(&dq_list_lock);
996 list_add(&dquot->
dq_free, tofree_head);
997 spin_unlock(&dq_list_lock);
1011 static void put_dquot_list(
struct list_head *tofree_head)
1014 struct dquot *dquot;
1016 act_head = tofree_head->
next;
1017 while (act_head != tofree_head) {
1019 act_head = act_head->
next;
1021 list_del_init(&dquot->
dq_free);
1026 static void remove_dquot_ref(
struct super_block *sb,
int type,
1029 struct inode *
inode;
1032 spin_lock(&inode_sb_list_lock);
1041 if (
unlikely(inode_get_rsv_space(inode) > 0))
1043 remove_inode_dquot_ref(inode, type, tofree_head);
1046 spin_unlock(&inode_sb_list_lock);
1047 #ifdef CONFIG_QUOTA_DEBUG
1050 " was disabled thus quota information is probably "
1051 "inconsistent. Please run quotacheck(8).\n", sb->
s_id);
1057 static void drop_dquot_ref(
struct super_block *sb,
int type)
1063 remove_dquot_ref(sb, type, &tofree_head);
1064 up_write(&sb_dqopt(sb)->dqptr_sem);
1065 put_dquot_list(&tofree_head);
1069 static inline void dquot_incr_inodes(
struct dquot *dquot,
qsize_t number)
1071 dquot->
dq_dqb.dqb_curinodes += number;
1074 static inline void dquot_incr_space(
struct dquot *dquot,
qsize_t number)
1076 dquot->
dq_dqb.dqb_curspace += number;
1079 static inline void dquot_resv_space(
struct dquot *dquot,
qsize_t number)
1081 dquot->
dq_dqb.dqb_rsvspace += number;
1087 static void dquot_claim_reserved_space(
struct dquot *dquot,
qsize_t number)
1089 if (dquot->
dq_dqb.dqb_rsvspace < number) {
1091 number = dquot->
dq_dqb.dqb_rsvspace;
1093 dquot->
dq_dqb.dqb_curspace += number;
1094 dquot->
dq_dqb.dqb_rsvspace -= number;
1098 void dquot_free_reserved_space(
struct dquot *dquot,
qsize_t number)
1100 if (dquot->
dq_dqb.dqb_rsvspace >= number)
1101 dquot->
dq_dqb.dqb_rsvspace -= number;
1104 dquot->
dq_dqb.dqb_rsvspace = 0;
1108 static void dquot_decr_inodes(
struct dquot *dquot,
qsize_t number)
1111 dquot->
dq_dqb.dqb_curinodes >= number)
1112 dquot->
dq_dqb.dqb_curinodes -= number;
1114 dquot->
dq_dqb.dqb_curinodes = 0;
1115 if (dquot->
dq_dqb.dqb_curinodes <= dquot->
dq_dqb.dqb_isoftlimit)
1120 static void dquot_decr_space(
struct dquot *dquot,
qsize_t number)
1123 dquot->
dq_dqb.dqb_curspace >= number)
1124 dquot->
dq_dqb.dqb_curspace -= number;
1126 dquot->
dq_dqb.dqb_curspace = 0;
1127 if (dquot->
dq_dqb.dqb_curspace <= dquot->
dq_dqb.dqb_bsoftlimit)
1138 static int warning_issued(
struct dquot *dquot,
const int warntype)
1150 #ifdef CONFIG_PRINT_QUOTA_WARNING
1151 static int flag_print_warnings = 1;
1155 if (!flag_print_warnings)
1170 static void print_warning(
struct dquot_warn *warn)
1174 int warntype = warn->
w_type;
1193 msg =
" file limit reached.\r\n";
1196 msg =
" file quota exceeded too long.\r\n";
1199 msg =
" file quota exceeded.\r\n";
1202 msg =
" block limit reached.\r\n";
1205 msg =
" block quota exceeded too long.\r\n";
1208 msg =
" block quota exceeded.\r\n";
1216 static void prepare_warning(
struct dquot_warn *warn,
struct dquot *dquot,
1219 if (warning_issued(dquot, warntype))
1231 static void flush_warnings(
struct dquot_warn *warn)
1238 #ifdef CONFIG_PRINT_QUOTA_WARNING
1239 print_warning(&warn[i]);
1242 warn[i].w_sb->s_dev, warn[i].
w_type);
1246 static int ignore_hardlimit(
struct dquot *dquot)
1256 static int check_idq(
struct dquot *dquot,
qsize_t inodes,
1261 if (!sb_has_quota_limits_enabled(dquot->
dq_sb, dquot->
dq_id.type) ||
1265 if (dquot->
dq_dqb.dqb_ihardlimit &&
1266 newinodes > dquot->
dq_dqb.dqb_ihardlimit &&
1267 !ignore_hardlimit(dquot)) {
1272 if (dquot->
dq_dqb.dqb_isoftlimit &&
1273 newinodes > dquot->
dq_dqb.dqb_isoftlimit &&
1274 dquot->
dq_dqb.dqb_itime &&
1276 !ignore_hardlimit(dquot)) {
1281 if (dquot->
dq_dqb.dqb_isoftlimit &&
1282 newinodes > dquot->
dq_dqb.dqb_isoftlimit &&
1283 dquot->
dq_dqb.dqb_itime == 0) {
1286 sb_dqopt(dquot->
dq_sb)->info[dquot->
dq_id.type].dqi_igrace;
1293 static int check_bdq(
struct dquot *dquot,
qsize_t space,
int prealloc,
1299 if (!sb_has_quota_limits_enabled(sb, dquot->
dq_id.type) ||
1303 tspace = dquot->
dq_dqb.dqb_curspace + dquot->
dq_dqb.dqb_rsvspace
1306 if (dquot->
dq_dqb.dqb_bhardlimit &&
1307 tspace > dquot->
dq_dqb.dqb_bhardlimit &&
1308 !ignore_hardlimit(dquot)) {
1314 if (dquot->
dq_dqb.dqb_bsoftlimit &&
1315 tspace > dquot->
dq_dqb.dqb_bsoftlimit &&
1316 dquot->
dq_dqb.dqb_btime &&
1318 !ignore_hardlimit(dquot)) {
1324 if (dquot->
dq_dqb.dqb_bsoftlimit &&
1325 tspace > dquot->
dq_dqb.dqb_bsoftlimit &&
1326 dquot->
dq_dqb.dqb_btime == 0) {
1330 sb_dqopt(sb)->info[dquot->
dq_id.type].dqi_bgrace;
1343 static int info_idq_free(
struct dquot *dquot,
qsize_t inodes)
1348 dquot->
dq_dqb.dqb_curinodes <= dquot->
dq_dqb.dqb_isoftlimit ||
1349 !sb_has_quota_limits_enabled(dquot->
dq_sb, dquot->
dq_id.type))
1352 newinodes = dquot->
dq_dqb.dqb_curinodes - inodes;
1353 if (newinodes <= dquot->dq_dqb.dqb_isoftlimit)
1355 if (dquot->
dq_dqb.dqb_curinodes >= dquot->
dq_dqb.dqb_ihardlimit &&
1356 newinodes < dquot->dq_dqb.dqb_ihardlimit)
1361 static int info_bdq_free(
struct dquot *dquot,
qsize_t space)
1364 dquot->
dq_dqb.dqb_curspace <= dquot->
dq_dqb.dqb_bsoftlimit)
1367 if (dquot->
dq_dqb.dqb_curspace - space <= dquot->dq_dqb.dqb_bsoftlimit)
1369 if (dquot->
dq_dqb.dqb_curspace >= dquot->
dq_dqb.dqb_bhardlimit &&
1370 dquot->
dq_dqb.dqb_curspace - space < dquot->dq_dqb.dqb_bhardlimit)
1375 static int dquot_active(
const struct inode *inode)
1381 return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb);
1393 static void __dquot_initialize(
struct inode *inode,
int type)
1402 if (!dquot_active(inode))
1409 if (type != -1 && cnt != type)
1413 qid = make_kqid_uid(inode->
i_uid);
1416 qid = make_kqid_gid(inode->
i_gid);
1426 if (type != -1 && cnt != type)
1429 if (!sb_has_quota_active(sb, cnt))
1434 if (!inode->i_dquot[cnt]) {
1435 inode->i_dquot[
cnt] = got[
cnt];
1441 rsv = inode_get_rsv_space(inode);
1443 dquot_resv_space(inode->i_dquot[cnt], rsv);
1447 up_write(&sb_dqopt(sb)->dqptr_sem);
1454 __dquot_initialize(inode, -1);
1461 static void __dquot_drop(
struct inode *inode)
1468 put[
cnt] = inode->i_dquot[
cnt];
1490 if (inode->i_dquot[cnt])
1494 if (cnt < MAXQUOTAS)
1495 __dquot_drop(inode);
1503 static qsize_t *inode_reserved_space(
struct inode * inode)
1507 BUG_ON(!inode->
i_sb->dq_op->get_reserved_space);
1508 return inode->
i_sb->dq_op->get_reserved_space(inode);
1513 spin_lock(&inode->
i_lock);
1514 *inode_reserved_space(inode) += number;
1515 spin_unlock(&inode->
i_lock);
1521 spin_lock(&inode->
i_lock);
1522 *inode_reserved_space(inode) -= number;
1524 spin_unlock(&inode->
i_lock);
1530 spin_lock(&inode->
i_lock);
1531 *inode_reserved_space(inode) -= number;
1532 spin_unlock(&inode->
i_lock);
1536 static qsize_t inode_get_rsv_space(
struct inode *inode)
1540 if (!inode->
i_sb->dq_op->get_reserved_space)
1542 spin_lock(&inode->
i_lock);
1543 ret = *inode_reserved_space(inode);
1544 spin_unlock(&inode->
i_lock);
1548 static void inode_incr_space(
struct inode *inode,
qsize_t number,
1557 static void inode_decr_space(
struct inode *inode,
qsize_t number,
int reserve)
1582 struct dquot **dquots = inode->i_dquot;
1589 if (!dquot_active(inode)) {
1590 inode_incr_space(inode, number, reserve);
1602 ret = check_bdq(dquots[cnt], number,
1606 goto out_flush_warn;
1613 dquot_resv_space(dquots[cnt], number);
1615 dquot_incr_space(dquots[cnt], number);
1617 inode_incr_space(inode, number, reserve);
1621 goto out_flush_warn;
1622 mark_all_dquot_dirty(dquots);
1625 flush_warnings(warn);
1638 struct dquot *
const *dquots = inode->i_dquot;
1642 if (!dquot_active(inode))
1651 ret = check_idq(dquots[cnt], 1, &warn[cnt]);
1659 dquot_incr_inodes(dquots[cnt], 1);
1665 mark_all_dquot_dirty(dquots);
1667 flush_warnings(warn);
1679 if (!dquot_active(inode)) {
1688 if (inode->i_dquot[cnt])
1689 dquot_claim_reserved_space(inode->i_dquot[cnt],
1695 mark_all_dquot_dirty(inode->i_dquot);
1708 struct dquot **dquots = inode->i_dquot;
1713 if (!dquot_active(inode)) {
1714 inode_decr_space(inode, number, reserve);
1726 wtype = info_bdq_free(dquots[cnt], number);
1728 prepare_warning(&warn[cnt], dquots[cnt], wtype);
1730 dquot_free_reserved_space(dquots[cnt], number);
1732 dquot_decr_space(dquots[cnt], number);
1734 inode_decr_space(inode, number, reserve);
1739 mark_all_dquot_dirty(dquots);
1742 flush_warnings(warn);
1753 struct dquot *
const *dquots = inode->i_dquot;
1757 if (!dquot_active(inode))
1768 wtype = info_idq_free(dquots[cnt], 1);
1770 prepare_warning(&warn[cnt], dquots[cnt], wtype);
1771 dquot_decr_inodes(dquots[cnt], 1);
1774 mark_all_dquot_dirty(dquots);
1776 flush_warnings(warn);
1794 struct dquot *transfer_from[
MAXQUOTAS] = {};
1798 struct dquot_warn warn_from_inodes[MAXQUOTAS];
1799 struct dquot_warn warn_from_space[MAXQUOTAS];
1818 rsv_space = inode_get_rsv_space(inode);
1819 space = cur_space + rsv_space;
1825 if (!transfer_to[cnt])
1828 if (!sb_has_quota_active(inode->
i_sb, cnt))
1831 transfer_from[
cnt] = inode->i_dquot[
cnt];
1832 ret = check_idq(transfer_to[cnt], 1, &warn_to[cnt]);
1835 ret = check_bdq(transfer_to[cnt], space, 0, &warn_to[cnt]);
1847 if (transfer_from[cnt]) {
1849 wtype = info_idq_free(transfer_from[cnt], 1);
1851 prepare_warning(&warn_from_inodes[cnt],
1852 transfer_from[cnt], wtype);
1853 wtype = info_bdq_free(transfer_from[cnt], space);
1855 prepare_warning(&warn_from_space[cnt],
1856 transfer_from[cnt], wtype);
1857 dquot_decr_inodes(transfer_from[cnt], 1);
1858 dquot_decr_space(transfer_from[cnt], cur_space);
1859 dquot_free_reserved_space(transfer_from[cnt],
1863 dquot_incr_inodes(transfer_to[cnt], 1);
1864 dquot_incr_space(transfer_to[cnt], cur_space);
1865 dquot_resv_space(transfer_to[cnt], rsv_space);
1867 inode->i_dquot[
cnt] = transfer_to[
cnt];
1872 mark_all_dquot_dirty(transfer_from);
1873 mark_all_dquot_dirty(transfer_to);
1874 flush_warnings(warn_to);
1875 flush_warnings(warn_from_inodes);
1876 flush_warnings(warn_from_space);
1880 transfer_to[
cnt] = transfer_from[
cnt];
1885 flush_warnings(warn_to);
1895 struct dquot *transfer_to[
MAXQUOTAS] = {};
1899 if (!dquot_active(inode))
1908 dqput_all(transfer_to);
1922 ret = dqopt->
ops[
type]->write_file_info(sb, type);
1980 if (!sb_any_quota_loaded(sb)) {
1986 if (type != -1 && cnt != type)
1988 if (!sb_has_quota_loaded(sb, cnt))
1992 spin_lock(&dq_state_lock);
1994 dquot_state_flag(DQUOT_SUSPENDED, cnt);
1995 spin_unlock(&dq_state_lock);
1997 spin_lock(&dq_state_lock);
1998 dqopt->
flags &= ~dquot_state_flag(flags, cnt);
2000 if (!sb_has_quota_loaded(sb, cnt) &&
2001 sb_has_quota_suspended(sb, cnt)) {
2002 dqopt->
flags &= ~dquot_state_flag(
2003 DQUOT_SUSPENDED, cnt);
2004 spin_unlock(&dq_state_lock);
2009 spin_unlock(&dq_state_lock);
2013 if (sb_has_quota_loaded(sb, cnt) && !(flags & DQUOT_SUSPENDED))
2017 drop_dquot_ref(sb, cnt);
2018 invalidate_dquots(sb, cnt);
2023 if (info_dirty(&dqopt->
info[cnt]))
2024 sb->
dq_op->write_info(sb, cnt);
2025 if (dqopt->
ops[cnt]->free_file_info)
2026 dqopt->
ops[
cnt]->free_file_info(sb, cnt);
2027 put_quota_format(dqopt->
info[cnt].dqi_format);
2030 if (!sb_has_quota_loaded(sb, cnt))
2032 dqopt->
info[
cnt].dqi_flags = 0;
2033 dqopt->
info[
cnt].dqi_igrace = 0;
2034 dqopt->
info[
cnt].dqi_bgrace = 0;
2045 if (sb->
s_op->sync_fs)
2046 sb->
s_op->sync_fs(sb, 1);
2054 if (toputinode[cnt]) {
2058 if (!sb_has_quota_loaded(sb, cnt)) {
2065 mark_inode_dirty_sync(toputinode[cnt]);
2073 if (toputinode[cnt]) {
2082 iput(toputinode[cnt]);
2083 else if (!toputinode[cnt]->
i_nlink)
2105 static int vfs_load_quota_inode(
struct inode *inode,
int type,
int format_id,
2124 if (!sb->
s_op->quota_write || !sb->
s_op->quota_read) {
2145 if (sb_has_quota_loaded(sb, type)) {
2163 __dquot_drop(inode);
2168 if (!dqopt->
files[type])
2171 if (!fmt->
qf_ops->check_quota_file(sb, type))
2177 INIT_LIST_HEAD(&dqopt->
info[type].dqi_dirty_list);
2179 error = dqopt->
ops[
type]->read_file_info(sb, type);
2187 spin_lock(&dq_state_lock);
2188 dqopt->
flags |= dquot_state_flag(flags, type);
2189 spin_unlock(&dq_state_lock);
2191 add_dquot_ref(sb, type);
2200 if (oldflags != -1) {
2210 put_quota_format(fmt);
2219 struct inode *
inode;
2224 if (type != -1 && cnt != type)
2228 if (!sb_has_quota_suspended(sb, cnt)) {
2234 spin_lock(&dq_state_lock);
2235 flags = dqopt->
flags & dquot_state_flag(DQUOT_USAGE_ENABLED |
2239 spin_unlock(&dq_state_lock);
2242 flags = dquot_generic_flag(flags, cnt);
2243 ret = vfs_load_quota_inode(inode, cnt,
2244 dqopt->
info[cnt].dqi_fmt_id, flags);
2259 if (path->
dentry->d_sb != sb)
2262 error = vfs_load_quota_inode(path->
dentry->d_inode, type,
2263 format_id, DQUOT_USAGE_ENABLED |
2286 if (sb_has_quota_loaded(sb, type)) {
2289 if (!sb_has_quota_loaded(sb, type)) {
2293 if (flags & DQUOT_USAGE_ENABLED &&
2294 sb_has_quota_usage_enabled(sb, type)) {
2299 sb_has_quota_limits_enabled(sb, type)) {
2303 spin_lock(&dq_state_lock);
2304 sb_dqopt(sb)->flags |= dquot_state_flag(flags, type);
2305 spin_unlock(&dq_state_lock);
2312 return vfs_load_quota_inode(inode, type, format_id, flags);
2321 int format_id,
int type)
2330 return PTR_ERR(dentry);
2339 error = vfs_load_quota_inode(dentry->
d_inode, type, format_id,
2359 static void do_get_dqblk(
struct dquot *dquot,
struct fs_disk_quota *di)
2363 memset(di, 0,
sizeof(*di));
2369 spin_lock(&dq_data_lock);
2378 spin_unlock(&dq_data_lock);
2384 struct dquot *dquot;
2386 dquot =
dqget(sb, qid);
2389 do_get_dqblk(dquot, di);
2396 #define VFS_FS_DQ_MASK \
2397 (FS_DQ_BCOUNT | FS_DQ_BSOFT | FS_DQ_BHARD | \
2398 FS_DQ_ICOUNT | FS_DQ_ISOFT | FS_DQ_IHARD | \
2399 FS_DQ_BTIMER | FS_DQ_ITIMER)
2402 static int do_set_dqblk(
struct dquot *dquot,
struct fs_disk_quota *di)
2405 int check_blim = 0, check_ilim = 0;
2488 mark_dquot_dirty(dquot);
2496 struct dquot *dquot;
2499 dquot =
dqget(sb, qid);
2504 rc = do_set_dqblk(dquot, di);
2517 if (!sb_has_quota_active(sb, type)) {
2521 mi = sb_dqopt(sb)->info +
type;
2540 if (!sb_has_quota_active(sb, type)) {
2544 mi = sb_dqopt(sb)->info +
type;
2556 sb->
dq_op->write_info(sb, type);
2575 void __user *
buffer,
size_t *lenp, loff_t *ppos)
2589 .maxlen =
sizeof(
int),
2594 .procname =
"drops",
2596 .maxlen =
sizeof(
int),
2601 .procname =
"reads",
2603 .maxlen =
sizeof(
int),
2608 .procname =
"writes",
2610 .maxlen =
sizeof(
int),
2615 .procname =
"cache_hits",
2617 .maxlen =
sizeof(
int),
2622 .procname =
"allocated_dquots",
2624 .maxlen =
sizeof(
int),
2629 .procname =
"free_dquots",
2631 .maxlen =
sizeof(
int),
2636 .procname =
"syncs",
2638 .maxlen =
sizeof(
int),
2642 #ifdef CONFIG_PRINT_QUOTA_WARNING
2644 .procname =
"warnings",
2645 .data = &flag_print_warnings,
2646 .maxlen =
sizeof(
int),
2658 .child = fs_dqstats_table,
2672 static int __init dquot_init(
void)
2675 unsigned long nr_hash,
order;
2682 sizeof(
struct dquot),
sizeof(
unsigned long) * 4,
2690 panic(
"Cannot create dquot hash table");
2695 panic(
"Cannot create dquot stat counters");
2703 }
while (nr_hash >> dq_hash_bits);
2706 nr_hash = 1
UL << dq_hash_bits;
2707 dq_hash_mask = nr_hash - 1;
2708 for (i = 0; i < nr_hash; i++)
2711 printk(
"Dquot-cache hash table entries: %ld (order %ld, %ld bytes)\n",