aboutsummaryrefslogtreecommitdiffstats
path: root/fs/quota
diff options
context:
space:
mode:
Diffstat (limited to 'fs/quota')
-rw-r--r--fs/quota/dquot.c275
-rw-r--r--fs/quota/quota.c95
-rw-r--r--fs/quota/quota_tree.c50
-rw-r--r--fs/quota/quota_tree.h6
-rw-r--r--fs/quota/quota_v1.c4
-rw-r--r--fs/quota/quota_v2.c6
6 files changed, 265 insertions, 171 deletions
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index df6832ec17c3..1ad8bf076cfc 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -82,7 +82,7 @@
82 82
83/* 83/*
84 * There are three quota SMP locks. dq_list_lock protects all lists with quotas 84 * There are three quota SMP locks. dq_list_lock protects all lists with quotas
85 * and quota formats, dqstats structure containing statistics about the lists 85 * and quota formats.
86 * dq_data_lock protects data from dq_dqb and also mem_dqinfo structures and 86 * dq_data_lock protects data from dq_dqb and also mem_dqinfo structures and
87 * also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes. 87 * also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes.
88 * i_blocks and i_bytes updates itself are guarded by i_lock acquired directly 88 * i_blocks and i_bytes updates itself are guarded by i_lock acquired directly
@@ -132,7 +132,9 @@ static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_state_lock);
132__cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_data_lock); 132__cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_data_lock);
133EXPORT_SYMBOL(dq_data_lock); 133EXPORT_SYMBOL(dq_data_lock);
134 134
135#if defined(CONFIG_QUOTA_DEBUG) || defined(CONFIG_PRINT_QUOTA_WARNING)
135static char *quotatypes[] = INITQFNAMES; 136static char *quotatypes[] = INITQFNAMES;
137#endif
136static struct quota_format_type *quota_formats; /* List of registered formats */ 138static struct quota_format_type *quota_formats; /* List of registered formats */
137static struct quota_module_name module_names[] = INIT_QUOTA_MODULE_NAMES; 139static struct quota_module_name module_names[] = INIT_QUOTA_MODULE_NAMES;
138 140
@@ -226,6 +228,10 @@ static struct hlist_head *dquot_hash;
226 228
227struct dqstats dqstats; 229struct dqstats dqstats;
228EXPORT_SYMBOL(dqstats); 230EXPORT_SYMBOL(dqstats);
231#ifdef CONFIG_SMP
232struct dqstats *dqstats_pcpu;
233EXPORT_SYMBOL(dqstats_pcpu);
234#endif
229 235
230static qsize_t inode_get_rsv_space(struct inode *inode); 236static qsize_t inode_get_rsv_space(struct inode *inode);
231static void __dquot_initialize(struct inode *inode, int type); 237static void __dquot_initialize(struct inode *inode, int type);
@@ -273,7 +279,7 @@ static struct dquot *find_dquot(unsigned int hashent, struct super_block *sb,
273static inline void put_dquot_last(struct dquot *dquot) 279static inline void put_dquot_last(struct dquot *dquot)
274{ 280{
275 list_add_tail(&dquot->dq_free, &free_dquots); 281 list_add_tail(&dquot->dq_free, &free_dquots);
276 dqstats.free_dquots++; 282 dqstats_inc(DQST_FREE_DQUOTS);
277} 283}
278 284
279static inline void remove_free_dquot(struct dquot *dquot) 285static inline void remove_free_dquot(struct dquot *dquot)
@@ -281,7 +287,7 @@ static inline void remove_free_dquot(struct dquot *dquot)
281 if (list_empty(&dquot->dq_free)) 287 if (list_empty(&dquot->dq_free))
282 return; 288 return;
283 list_del_init(&dquot->dq_free); 289 list_del_init(&dquot->dq_free);
284 dqstats.free_dquots--; 290 dqstats_dec(DQST_FREE_DQUOTS);
285} 291}
286 292
287static inline void put_inuse(struct dquot *dquot) 293static inline void put_inuse(struct dquot *dquot)
@@ -289,12 +295,12 @@ static inline void put_inuse(struct dquot *dquot)
289 /* We add to the back of inuse list so we don't have to restart 295 /* We add to the back of inuse list so we don't have to restart
290 * when traversing this list and we block */ 296 * when traversing this list and we block */
291 list_add_tail(&dquot->dq_inuse, &inuse_list); 297 list_add_tail(&dquot->dq_inuse, &inuse_list);
292 dqstats.allocated_dquots++; 298 dqstats_inc(DQST_ALLOC_DQUOTS);
293} 299}
294 300
295static inline void remove_inuse(struct dquot *dquot) 301static inline void remove_inuse(struct dquot *dquot)
296{ 302{
297 dqstats.allocated_dquots--; 303 dqstats_dec(DQST_ALLOC_DQUOTS);
298 list_del(&dquot->dq_inuse); 304 list_del(&dquot->dq_inuse);
299} 305}
300/* 306/*
@@ -317,14 +323,23 @@ static inline int mark_dquot_dirty(struct dquot *dquot)
317 return dquot->dq_sb->dq_op->mark_dirty(dquot); 323 return dquot->dq_sb->dq_op->mark_dirty(dquot);
318} 324}
319 325
326/* Mark dquot dirty in atomic manner, and return it's old dirty flag state */
320int dquot_mark_dquot_dirty(struct dquot *dquot) 327int dquot_mark_dquot_dirty(struct dquot *dquot)
321{ 328{
329 int ret = 1;
330
331 /* If quota is dirty already, we don't have to acquire dq_list_lock */
332 if (test_bit(DQ_MOD_B, &dquot->dq_flags))
333 return 1;
334
322 spin_lock(&dq_list_lock); 335 spin_lock(&dq_list_lock);
323 if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags)) 336 if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags)) {
324 list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)-> 337 list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)->
325 info[dquot->dq_type].dqi_dirty_list); 338 info[dquot->dq_type].dqi_dirty_list);
339 ret = 0;
340 }
326 spin_unlock(&dq_list_lock); 341 spin_unlock(&dq_list_lock);
327 return 0; 342 return ret;
328} 343}
329EXPORT_SYMBOL(dquot_mark_dquot_dirty); 344EXPORT_SYMBOL(dquot_mark_dquot_dirty);
330 345
@@ -550,8 +565,8 @@ int dquot_scan_active(struct super_block *sb,
550 continue; 565 continue;
551 /* Now we have active dquot so we can just increase use count */ 566 /* Now we have active dquot so we can just increase use count */
552 atomic_inc(&dquot->dq_count); 567 atomic_inc(&dquot->dq_count);
553 dqstats.lookups++;
554 spin_unlock(&dq_list_lock); 568 spin_unlock(&dq_list_lock);
569 dqstats_inc(DQST_LOOKUPS);
555 dqput(old_dquot); 570 dqput(old_dquot);
556 old_dquot = dquot; 571 old_dquot = dquot;
557 ret = fn(dquot, priv); 572 ret = fn(dquot, priv);
@@ -596,8 +611,8 @@ int vfs_quota_sync(struct super_block *sb, int type, int wait)
596 * holding reference so we can safely just increase 611 * holding reference so we can safely just increase
597 * use count */ 612 * use count */
598 atomic_inc(&dquot->dq_count); 613 atomic_inc(&dquot->dq_count);
599 dqstats.lookups++;
600 spin_unlock(&dq_list_lock); 614 spin_unlock(&dq_list_lock);
615 dqstats_inc(DQST_LOOKUPS);
601 sb->dq_op->write_dquot(dquot); 616 sb->dq_op->write_dquot(dquot);
602 dqput(dquot); 617 dqput(dquot);
603 spin_lock(&dq_list_lock); 618 spin_lock(&dq_list_lock);
@@ -609,9 +624,7 @@ int vfs_quota_sync(struct super_block *sb, int type, int wait)
609 if ((cnt == type || type == -1) && sb_has_quota_active(sb, cnt) 624 if ((cnt == type || type == -1) && sb_has_quota_active(sb, cnt)
610 && info_dirty(&dqopt->info[cnt])) 625 && info_dirty(&dqopt->info[cnt]))
611 sb->dq_op->write_info(sb, cnt); 626 sb->dq_op->write_info(sb, cnt);
612 spin_lock(&dq_list_lock); 627 dqstats_inc(DQST_SYNCS);
613 dqstats.syncs++;
614 spin_unlock(&dq_list_lock);
615 mutex_unlock(&dqopt->dqonoff_mutex); 628 mutex_unlock(&dqopt->dqonoff_mutex);
616 629
617 if (!wait || (sb_dqopt(sb)->flags & DQUOT_QUOTA_SYS_FILE)) 630 if (!wait || (sb_dqopt(sb)->flags & DQUOT_QUOTA_SYS_FILE))
@@ -663,6 +676,22 @@ static void prune_dqcache(int count)
663 } 676 }
664} 677}
665 678
679static int dqstats_read(unsigned int type)
680{
681 int count = 0;
682#ifdef CONFIG_SMP
683 int cpu;
684 for_each_possible_cpu(cpu)
685 count += per_cpu_ptr(dqstats_pcpu, cpu)->stat[type];
686 /* Statistics reading is racy, but absolute accuracy isn't required */
687 if (count < 0)
688 count = 0;
689#else
690 count = dqstats.stat[type];
691#endif
692 return count;
693}
694
666/* 695/*
667 * This is called from kswapd when we think we need some 696 * This is called from kswapd when we think we need some
668 * more memory 697 * more memory
@@ -675,7 +704,7 @@ static int shrink_dqcache_memory(int nr, gfp_t gfp_mask)
675 prune_dqcache(nr); 704 prune_dqcache(nr);
676 spin_unlock(&dq_list_lock); 705 spin_unlock(&dq_list_lock);
677 } 706 }
678 return (dqstats.free_dquots / 100) * sysctl_vfs_cache_pressure; 707 return (dqstats_read(DQST_FREE_DQUOTS)/100) * sysctl_vfs_cache_pressure;
679} 708}
680 709
681static struct shrinker dqcache_shrinker = { 710static struct shrinker dqcache_shrinker = {
@@ -703,10 +732,7 @@ void dqput(struct dquot *dquot)
703 BUG(); 732 BUG();
704 } 733 }
705#endif 734#endif
706 735 dqstats_inc(DQST_DROPS);
707 spin_lock(&dq_list_lock);
708 dqstats.drops++;
709 spin_unlock(&dq_list_lock);
710we_slept: 736we_slept:
711 spin_lock(&dq_list_lock); 737 spin_lock(&dq_list_lock);
712 if (atomic_read(&dquot->dq_count) > 1) { 738 if (atomic_read(&dquot->dq_count) > 1) {
@@ -823,15 +849,15 @@ we_slept:
823 put_inuse(dquot); 849 put_inuse(dquot);
824 /* hash it first so it can be found */ 850 /* hash it first so it can be found */
825 insert_dquot_hash(dquot); 851 insert_dquot_hash(dquot);
826 dqstats.lookups++;
827 spin_unlock(&dq_list_lock); 852 spin_unlock(&dq_list_lock);
853 dqstats_inc(DQST_LOOKUPS);
828 } else { 854 } else {
829 if (!atomic_read(&dquot->dq_count)) 855 if (!atomic_read(&dquot->dq_count))
830 remove_free_dquot(dquot); 856 remove_free_dquot(dquot);
831 atomic_inc(&dquot->dq_count); 857 atomic_inc(&dquot->dq_count);
832 dqstats.cache_hits++;
833 dqstats.lookups++;
834 spin_unlock(&dq_list_lock); 858 spin_unlock(&dq_list_lock);
859 dqstats_inc(DQST_CACHE_HITS);
860 dqstats_inc(DQST_LOOKUPS);
835 } 861 }
836 /* Wait for dq_lock - after this we know that either dquot_release() is 862 /* Wait for dq_lock - after this we know that either dquot_release() is
837 * already finished or it will be canceled due to dq_count > 1 test */ 863 * already finished or it will be canceled due to dq_count > 1 test */
@@ -1680,16 +1706,19 @@ EXPORT_SYMBOL(dquot_free_inode);
1680 1706
1681/* 1707/*
1682 * Transfer the number of inode and blocks from one diskquota to an other. 1708 * Transfer the number of inode and blocks from one diskquota to an other.
1709 * On success, dquot references in transfer_to are consumed and references
1710 * to original dquots that need to be released are placed there. On failure,
1711 * references are kept untouched.
1683 * 1712 *
1684 * This operation can block, but only after everything is updated 1713 * This operation can block, but only after everything is updated
1685 * A transaction must be started when entering this function. 1714 * A transaction must be started when entering this function.
1715 *
1686 */ 1716 */
1687static int __dquot_transfer(struct inode *inode, qid_t *chid, unsigned long mask) 1717int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)
1688{ 1718{
1689 qsize_t space, cur_space; 1719 qsize_t space, cur_space;
1690 qsize_t rsv_space = 0; 1720 qsize_t rsv_space = 0;
1691 struct dquot *transfer_from[MAXQUOTAS]; 1721 struct dquot *transfer_from[MAXQUOTAS] = {};
1692 struct dquot *transfer_to[MAXQUOTAS];
1693 int cnt, ret = 0; 1722 int cnt, ret = 0;
1694 char warntype_to[MAXQUOTAS]; 1723 char warntype_to[MAXQUOTAS];
1695 char warntype_from_inodes[MAXQUOTAS], warntype_from_space[MAXQUOTAS]; 1724 char warntype_from_inodes[MAXQUOTAS], warntype_from_space[MAXQUOTAS];
@@ -1699,19 +1728,12 @@ static int __dquot_transfer(struct inode *inode, qid_t *chid, unsigned long mask
1699 if (IS_NOQUOTA(inode)) 1728 if (IS_NOQUOTA(inode))
1700 return 0; 1729 return 0;
1701 /* Initialize the arrays */ 1730 /* Initialize the arrays */
1702 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1731 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1703 transfer_from[cnt] = NULL;
1704 transfer_to[cnt] = NULL;
1705 warntype_to[cnt] = QUOTA_NL_NOWARN; 1732 warntype_to[cnt] = QUOTA_NL_NOWARN;
1706 }
1707 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1708 if (mask & (1 << cnt))
1709 transfer_to[cnt] = dqget(inode->i_sb, chid[cnt], cnt);
1710 }
1711 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1733 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1712 if (IS_NOQUOTA(inode)) { /* File without quota accounting? */ 1734 if (IS_NOQUOTA(inode)) { /* File without quota accounting? */
1713 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1735 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1714 goto put_all; 1736 return 0;
1715 } 1737 }
1716 spin_lock(&dq_data_lock); 1738 spin_lock(&dq_data_lock);
1717 cur_space = inode_get_bytes(inode); 1739 cur_space = inode_get_bytes(inode);
@@ -1763,47 +1785,41 @@ static int __dquot_transfer(struct inode *inode, qid_t *chid, unsigned long mask
1763 1785
1764 mark_all_dquot_dirty(transfer_from); 1786 mark_all_dquot_dirty(transfer_from);
1765 mark_all_dquot_dirty(transfer_to); 1787 mark_all_dquot_dirty(transfer_to);
1766 /* The reference we got is transferred to the inode */ 1788 /* Pass back references to put */
1767 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1789 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1768 transfer_to[cnt] = NULL; 1790 transfer_to[cnt] = transfer_from[cnt];
1769warn_put_all: 1791warn:
1770 flush_warnings(transfer_to, warntype_to); 1792 flush_warnings(transfer_to, warntype_to);
1771 flush_warnings(transfer_from, warntype_from_inodes); 1793 flush_warnings(transfer_from, warntype_from_inodes);
1772 flush_warnings(transfer_from, warntype_from_space); 1794 flush_warnings(transfer_from, warntype_from_space);
1773put_all:
1774 dqput_all(transfer_from);
1775 dqput_all(transfer_to);
1776 return ret; 1795 return ret;
1777over_quota: 1796over_quota:
1778 spin_unlock(&dq_data_lock); 1797 spin_unlock(&dq_data_lock);
1779 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1798 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1780 /* Clear dquot pointers we don't want to dqput() */ 1799 goto warn;
1781 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1782 transfer_from[cnt] = NULL;
1783 goto warn_put_all;
1784} 1800}
1801EXPORT_SYMBOL(__dquot_transfer);
1785 1802
1786/* Wrapper for transferring ownership of an inode for uid/gid only 1803/* Wrapper for transferring ownership of an inode for uid/gid only
1787 * Called from FSXXX_setattr() 1804 * Called from FSXXX_setattr()
1788 */ 1805 */
1789int dquot_transfer(struct inode *inode, struct iattr *iattr) 1806int dquot_transfer(struct inode *inode, struct iattr *iattr)
1790{ 1807{
1791 qid_t chid[MAXQUOTAS]; 1808 struct dquot *transfer_to[MAXQUOTAS] = {};
1792 unsigned long mask = 0; 1809 struct super_block *sb = inode->i_sb;
1810 int ret;
1793 1811
1794 if (iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) { 1812 if (!sb_any_quota_active(sb) || IS_NOQUOTA(inode))
1795 mask |= 1 << USRQUOTA; 1813 return 0;
1796 chid[USRQUOTA] = iattr->ia_uid; 1814
1797 } 1815 if (iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid)
1798 if (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) { 1816 transfer_to[USRQUOTA] = dqget(sb, iattr->ia_uid, USRQUOTA);
1799 mask |= 1 << GRPQUOTA; 1817 if (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)
1800 chid[GRPQUOTA] = iattr->ia_gid; 1818 transfer_to[GRPQUOTA] = dqget(sb, iattr->ia_uid, GRPQUOTA);
1801 } 1819
1802 if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) { 1820 ret = __dquot_transfer(inode, transfer_to);
1803 dquot_initialize(inode); 1821 dqput_all(transfer_to);
1804 return __dquot_transfer(inode, chid, mask); 1822 return ret;
1805 }
1806 return 0;
1807} 1823}
1808EXPORT_SYMBOL(dquot_transfer); 1824EXPORT_SYMBOL(dquot_transfer);
1809 1825
@@ -2278,25 +2294,30 @@ static inline qsize_t stoqb(qsize_t space)
2278} 2294}
2279 2295
2280/* Generic routine for getting common part of quota structure */ 2296/* Generic routine for getting common part of quota structure */
2281static void do_get_dqblk(struct dquot *dquot, struct if_dqblk *di) 2297static void do_get_dqblk(struct dquot *dquot, struct fs_disk_quota *di)
2282{ 2298{
2283 struct mem_dqblk *dm = &dquot->dq_dqb; 2299 struct mem_dqblk *dm = &dquot->dq_dqb;
2284 2300
2301 memset(di, 0, sizeof(*di));
2302 di->d_version = FS_DQUOT_VERSION;
2303 di->d_flags = dquot->dq_type == USRQUOTA ?
2304 XFS_USER_QUOTA : XFS_GROUP_QUOTA;
2305 di->d_id = dquot->dq_id;
2306
2285 spin_lock(&dq_data_lock); 2307 spin_lock(&dq_data_lock);
2286 di->dqb_bhardlimit = stoqb(dm->dqb_bhardlimit); 2308 di->d_blk_hardlimit = stoqb(dm->dqb_bhardlimit);
2287 di->dqb_bsoftlimit = stoqb(dm->dqb_bsoftlimit); 2309 di->d_blk_softlimit = stoqb(dm->dqb_bsoftlimit);
2288 di->dqb_curspace = dm->dqb_curspace + dm->dqb_rsvspace; 2310 di->d_ino_hardlimit = dm->dqb_ihardlimit;
2289 di->dqb_ihardlimit = dm->dqb_ihardlimit; 2311 di->d_ino_softlimit = dm->dqb_isoftlimit;
2290 di->dqb_isoftlimit = dm->dqb_isoftlimit; 2312 di->d_bcount = dm->dqb_curspace + dm->dqb_rsvspace;
2291 di->dqb_curinodes = dm->dqb_curinodes; 2313 di->d_icount = dm->dqb_curinodes;
2292 di->dqb_btime = dm->dqb_btime; 2314 di->d_btimer = dm->dqb_btime;
2293 di->dqb_itime = dm->dqb_itime; 2315 di->d_itimer = dm->dqb_itime;
2294 di->dqb_valid = QIF_ALL;
2295 spin_unlock(&dq_data_lock); 2316 spin_unlock(&dq_data_lock);
2296} 2317}
2297 2318
2298int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, 2319int vfs_get_dqblk(struct super_block *sb, int type, qid_t id,
2299 struct if_dqblk *di) 2320 struct fs_disk_quota *di)
2300{ 2321{
2301 struct dquot *dquot; 2322 struct dquot *dquot;
2302 2323
@@ -2310,51 +2331,70 @@ int vfs_get_dqblk(struct super_block *sb, int type, qid_t id,
2310} 2331}
2311EXPORT_SYMBOL(vfs_get_dqblk); 2332EXPORT_SYMBOL(vfs_get_dqblk);
2312 2333
2334#define VFS_FS_DQ_MASK \
2335 (FS_DQ_BCOUNT | FS_DQ_BSOFT | FS_DQ_BHARD | \
2336 FS_DQ_ICOUNT | FS_DQ_ISOFT | FS_DQ_IHARD | \
2337 FS_DQ_BTIMER | FS_DQ_ITIMER)
2338
2313/* Generic routine for setting common part of quota structure */ 2339/* Generic routine for setting common part of quota structure */
2314static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di) 2340static int do_set_dqblk(struct dquot *dquot, struct fs_disk_quota *di)
2315{ 2341{
2316 struct mem_dqblk *dm = &dquot->dq_dqb; 2342 struct mem_dqblk *dm = &dquot->dq_dqb;
2317 int check_blim = 0, check_ilim = 0; 2343 int check_blim = 0, check_ilim = 0;
2318 struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type]; 2344 struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
2319 2345
2320 if ((di->dqb_valid & QIF_BLIMITS && 2346 if (di->d_fieldmask & ~VFS_FS_DQ_MASK)
2321 (di->dqb_bhardlimit > dqi->dqi_maxblimit || 2347 return -EINVAL;
2322 di->dqb_bsoftlimit > dqi->dqi_maxblimit)) || 2348
2323 (di->dqb_valid & QIF_ILIMITS && 2349 if (((di->d_fieldmask & FS_DQ_BSOFT) &&
2324 (di->dqb_ihardlimit > dqi->dqi_maxilimit || 2350 (di->d_blk_softlimit > dqi->dqi_maxblimit)) ||
2325 di->dqb_isoftlimit > dqi->dqi_maxilimit))) 2351 ((di->d_fieldmask & FS_DQ_BHARD) &&
2352 (di->d_blk_hardlimit > dqi->dqi_maxblimit)) ||
2353 ((di->d_fieldmask & FS_DQ_ISOFT) &&
2354 (di->d_ino_softlimit > dqi->dqi_maxilimit)) ||
2355 ((di->d_fieldmask & FS_DQ_IHARD) &&
2356 (di->d_ino_hardlimit > dqi->dqi_maxilimit)))
2326 return -ERANGE; 2357 return -ERANGE;
2327 2358
2328 spin_lock(&dq_data_lock); 2359 spin_lock(&dq_data_lock);
2329 if (di->dqb_valid & QIF_SPACE) { 2360 if (di->d_fieldmask & FS_DQ_BCOUNT) {
2330 dm->dqb_curspace = di->dqb_curspace - dm->dqb_rsvspace; 2361 dm->dqb_curspace = di->d_bcount - dm->dqb_rsvspace;
2331 check_blim = 1; 2362 check_blim = 1;
2332 set_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags); 2363 set_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags);
2333 } 2364 }
2334 if (di->dqb_valid & QIF_BLIMITS) { 2365
2335 dm->dqb_bsoftlimit = qbtos(di->dqb_bsoftlimit); 2366 if (di->d_fieldmask & FS_DQ_BSOFT)
2336 dm->dqb_bhardlimit = qbtos(di->dqb_bhardlimit); 2367 dm->dqb_bsoftlimit = qbtos(di->d_blk_softlimit);
2368 if (di->d_fieldmask & FS_DQ_BHARD)
2369 dm->dqb_bhardlimit = qbtos(di->d_blk_hardlimit);
2370 if (di->d_fieldmask & (FS_DQ_BSOFT | FS_DQ_BHARD)) {
2337 check_blim = 1; 2371 check_blim = 1;
2338 set_bit(DQ_LASTSET_B + QIF_BLIMITS_B, &dquot->dq_flags); 2372 set_bit(DQ_LASTSET_B + QIF_BLIMITS_B, &dquot->dq_flags);
2339 } 2373 }
2340 if (di->dqb_valid & QIF_INODES) { 2374
2341 dm->dqb_curinodes = di->dqb_curinodes; 2375 if (di->d_fieldmask & FS_DQ_ICOUNT) {
2376 dm->dqb_curinodes = di->d_icount;
2342 check_ilim = 1; 2377 check_ilim = 1;
2343 set_bit(DQ_LASTSET_B + QIF_INODES_B, &dquot->dq_flags); 2378 set_bit(DQ_LASTSET_B + QIF_INODES_B, &dquot->dq_flags);
2344 } 2379 }
2345 if (di->dqb_valid & QIF_ILIMITS) { 2380
2346 dm->dqb_isoftlimit = di->dqb_isoftlimit; 2381 if (di->d_fieldmask & FS_DQ_ISOFT)
2347 dm->dqb_ihardlimit = di->dqb_ihardlimit; 2382 dm->dqb_isoftlimit = di->d_ino_softlimit;
2383 if (di->d_fieldmask & FS_DQ_IHARD)
2384 dm->dqb_ihardlimit = di->d_ino_hardlimit;
2385 if (di->d_fieldmask & (FS_DQ_ISOFT | FS_DQ_IHARD)) {
2348 check_ilim = 1; 2386 check_ilim = 1;
2349 set_bit(DQ_LASTSET_B + QIF_ILIMITS_B, &dquot->dq_flags); 2387 set_bit(DQ_LASTSET_B + QIF_ILIMITS_B, &dquot->dq_flags);
2350 } 2388 }
2351 if (di->dqb_valid & QIF_BTIME) { 2389
2352 dm->dqb_btime = di->dqb_btime; 2390 if (di->d_fieldmask & FS_DQ_BTIMER) {
2391 dm->dqb_btime = di->d_btimer;
2353 check_blim = 1; 2392 check_blim = 1;
2354 set_bit(DQ_LASTSET_B + QIF_BTIME_B, &dquot->dq_flags); 2393 set_bit(DQ_LASTSET_B + QIF_BTIME_B, &dquot->dq_flags);
2355 } 2394 }
2356 if (di->dqb_valid & QIF_ITIME) { 2395
2357 dm->dqb_itime = di->dqb_itime; 2396 if (di->d_fieldmask & FS_DQ_ITIMER) {
2397 dm->dqb_itime = di->d_itimer;
2358 check_ilim = 1; 2398 check_ilim = 1;
2359 set_bit(DQ_LASTSET_B + QIF_ITIME_B, &dquot->dq_flags); 2399 set_bit(DQ_LASTSET_B + QIF_ITIME_B, &dquot->dq_flags);
2360 } 2400 }
@@ -2364,7 +2404,7 @@ static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
2364 dm->dqb_curspace < dm->dqb_bsoftlimit) { 2404 dm->dqb_curspace < dm->dqb_bsoftlimit) {
2365 dm->dqb_btime = 0; 2405 dm->dqb_btime = 0;
2366 clear_bit(DQ_BLKS_B, &dquot->dq_flags); 2406 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
2367 } else if (!(di->dqb_valid & QIF_BTIME)) 2407 } else if (!(di->d_fieldmask & FS_DQ_BTIMER))
2368 /* Set grace only if user hasn't provided his own... */ 2408 /* Set grace only if user hasn't provided his own... */
2369 dm->dqb_btime = get_seconds() + dqi->dqi_bgrace; 2409 dm->dqb_btime = get_seconds() + dqi->dqi_bgrace;
2370 } 2410 }
@@ -2373,7 +2413,7 @@ static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
2373 dm->dqb_curinodes < dm->dqb_isoftlimit) { 2413 dm->dqb_curinodes < dm->dqb_isoftlimit) {
2374 dm->dqb_itime = 0; 2414 dm->dqb_itime = 0;
2375 clear_bit(DQ_INODES_B, &dquot->dq_flags); 2415 clear_bit(DQ_INODES_B, &dquot->dq_flags);
2376 } else if (!(di->dqb_valid & QIF_ITIME)) 2416 } else if (!(di->d_fieldmask & FS_DQ_ITIMER))
2377 /* Set grace only if user hasn't provided his own... */ 2417 /* Set grace only if user hasn't provided his own... */
2378 dm->dqb_itime = get_seconds() + dqi->dqi_igrace; 2418 dm->dqb_itime = get_seconds() + dqi->dqi_igrace;
2379 } 2419 }
@@ -2389,7 +2429,7 @@ static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
2389} 2429}
2390 2430
2391int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, 2431int vfs_set_dqblk(struct super_block *sb, int type, qid_t id,
2392 struct if_dqblk *di) 2432 struct fs_disk_quota *di)
2393{ 2433{
2394 struct dquot *dquot; 2434 struct dquot *dquot;
2395 int rc; 2435 int rc;
@@ -2468,62 +2508,74 @@ const struct quotactl_ops vfs_quotactl_ops = {
2468 .set_dqblk = vfs_set_dqblk 2508 .set_dqblk = vfs_set_dqblk
2469}; 2509};
2470 2510
2511
2512static int do_proc_dqstats(struct ctl_table *table, int write,
2513 void __user *buffer, size_t *lenp, loff_t *ppos)
2514{
2515#ifdef CONFIG_SMP
2516 /* Update global table */
2517 unsigned int type = (int *)table->data - dqstats.stat;
2518 dqstats.stat[type] = dqstats_read(type);
2519#endif
2520 return proc_dointvec(table, write, buffer, lenp, ppos);
2521}
2522
2471static ctl_table fs_dqstats_table[] = { 2523static ctl_table fs_dqstats_table[] = {
2472 { 2524 {
2473 .procname = "lookups", 2525 .procname = "lookups",
2474 .data = &dqstats.lookups, 2526 .data = &dqstats.stat[DQST_LOOKUPS],
2475 .maxlen = sizeof(int), 2527 .maxlen = sizeof(int),
2476 .mode = 0444, 2528 .mode = 0444,
2477 .proc_handler = proc_dointvec, 2529 .proc_handler = do_proc_dqstats,
2478 }, 2530 },
2479 { 2531 {
2480 .procname = "drops", 2532 .procname = "drops",
2481 .data = &dqstats.drops, 2533 .data = &dqstats.stat[DQST_DROPS],
2482 .maxlen = sizeof(int), 2534 .maxlen = sizeof(int),
2483 .mode = 0444, 2535 .mode = 0444,
2484 .proc_handler = proc_dointvec, 2536 .proc_handler = do_proc_dqstats,
2485 }, 2537 },
2486 { 2538 {
2487 .procname = "reads", 2539 .procname = "reads",
2488 .data = &dqstats.reads, 2540 .data = &dqstats.stat[DQST_READS],
2489 .maxlen = sizeof(int), 2541 .maxlen = sizeof(int),
2490 .mode = 0444, 2542 .mode = 0444,
2491 .proc_handler = proc_dointvec, 2543 .proc_handler = do_proc_dqstats,
2492 }, 2544 },
2493 { 2545 {
2494 .procname = "writes", 2546 .procname = "writes",
2495 .data = &dqstats.writes, 2547 .data = &dqstats.stat[DQST_WRITES],
2496 .maxlen = sizeof(int), 2548 .maxlen = sizeof(int),
2497 .mode = 0444, 2549 .mode = 0444,
2498 .proc_handler = proc_dointvec, 2550 .proc_handler = do_proc_dqstats,
2499 }, 2551 },
2500 { 2552 {
2501 .procname = "cache_hits", 2553 .procname = "cache_hits",
2502 .data = &dqstats.cache_hits, 2554 .data = &dqstats.stat[DQST_CACHE_HITS],
2503 .maxlen = sizeof(int), 2555 .maxlen = sizeof(int),
2504 .mode = 0444, 2556 .mode = 0444,
2505 .proc_handler = proc_dointvec, 2557 .proc_handler = do_proc_dqstats,
2506 }, 2558 },
2507 { 2559 {
2508 .procname = "allocated_dquots", 2560 .procname = "allocated_dquots",
2509 .data = &dqstats.allocated_dquots, 2561 .data = &dqstats.stat[DQST_ALLOC_DQUOTS],
2510 .maxlen = sizeof(int), 2562 .maxlen = sizeof(int),
2511 .mode = 0444, 2563 .mode = 0444,
2512 .proc_handler = proc_dointvec, 2564 .proc_handler = do_proc_dqstats,
2513 }, 2565 },
2514 { 2566 {
2515 .procname = "free_dquots", 2567 .procname = "free_dquots",
2516 .data = &dqstats.free_dquots, 2568 .data = &dqstats.stat[DQST_FREE_DQUOTS],
2517 .maxlen = sizeof(int), 2569 .maxlen = sizeof(int),
2518 .mode = 0444, 2570 .mode = 0444,
2519 .proc_handler = proc_dointvec, 2571 .proc_handler = do_proc_dqstats,
2520 }, 2572 },
2521 { 2573 {
2522 .procname = "syncs", 2574 .procname = "syncs",
2523 .data = &dqstats.syncs, 2575 .data = &dqstats.stat[DQST_SYNCS],
2524 .maxlen = sizeof(int), 2576 .maxlen = sizeof(int),
2525 .mode = 0444, 2577 .mode = 0444,
2526 .proc_handler = proc_dointvec, 2578 .proc_handler = do_proc_dqstats,
2527 }, 2579 },
2528#ifdef CONFIG_PRINT_QUOTA_WARNING 2580#ifdef CONFIG_PRINT_QUOTA_WARNING
2529 { 2581 {
@@ -2575,6 +2627,13 @@ static int __init dquot_init(void)
2575 if (!dquot_hash) 2627 if (!dquot_hash)
2576 panic("Cannot create dquot hash table"); 2628 panic("Cannot create dquot hash table");
2577 2629
2630#ifdef CONFIG_SMP
2631 dqstats_pcpu = alloc_percpu(struct dqstats);
2632 if (!dqstats_pcpu)
2633 panic("Cannot create dquot stats table");
2634#endif
2635 memset(&dqstats, 0, sizeof(struct dqstats));
2636
2578 /* Find power-of-two hlist_heads which can fit into allocation */ 2637 /* Find power-of-two hlist_heads which can fit into allocation */
2579 nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head); 2638 nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head);
2580 dq_hash_bits = 0; 2639 dq_hash_bits = 0;
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 95388f9b7356..ce3dfd066f59 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -45,36 +45,22 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
45 return security_quotactl(cmd, type, id, sb); 45 return security_quotactl(cmd, type, id, sb);
46} 46}
47 47
48static void quota_sync_one(struct super_block *sb, void *arg)
49{
50 if (sb->s_qcop && sb->s_qcop->quota_sync)
51 sb->s_qcop->quota_sync(sb, *(int *)arg, 1);
52}
53
48static int quota_sync_all(int type) 54static int quota_sync_all(int type)
49{ 55{
50 struct super_block *sb;
51 int ret; 56 int ret;
52 57
53 if (type >= MAXQUOTAS) 58 if (type >= MAXQUOTAS)
54 return -EINVAL; 59 return -EINVAL;
55 ret = security_quotactl(Q_SYNC, type, 0, NULL); 60 ret = security_quotactl(Q_SYNC, type, 0, NULL);
56 if (ret) 61 if (!ret)
57 return ret; 62 iterate_supers(quota_sync_one, &type);
58 63 return ret;
59 spin_lock(&sb_lock);
60restart:
61 list_for_each_entry(sb, &super_blocks, s_list) {
62 if (!sb->s_qcop || !sb->s_qcop->quota_sync)
63 continue;
64
65 sb->s_count++;
66 spin_unlock(&sb_lock);
67 down_read(&sb->s_umount);
68 if (sb->s_root)
69 sb->s_qcop->quota_sync(sb, type, 1);
70 up_read(&sb->s_umount);
71 spin_lock(&sb_lock);
72 if (__put_super_and_need_restart(sb))
73 goto restart;
74 }
75 spin_unlock(&sb_lock);
76
77 return 0;
78} 64}
79 65
80static int quota_quotaon(struct super_block *sb, int type, int cmd, qid_t id, 66static int quota_quotaon(struct super_block *sb, int type, int cmd, qid_t id,
@@ -113,8 +99,6 @@ static int quota_getinfo(struct super_block *sb, int type, void __user *addr)
113 struct if_dqinfo info; 99 struct if_dqinfo info;
114 int ret; 100 int ret;
115 101
116 if (!sb_has_quota_active(sb, type))
117 return -ESRCH;
118 if (!sb->s_qcop->get_info) 102 if (!sb->s_qcop->get_info)
119 return -ENOSYS; 103 return -ENOSYS;
120 ret = sb->s_qcop->get_info(sb, type, &info); 104 ret = sb->s_qcop->get_info(sb, type, &info);
@@ -129,43 +113,80 @@ static int quota_setinfo(struct super_block *sb, int type, void __user *addr)
129 113
130 if (copy_from_user(&info, addr, sizeof(info))) 114 if (copy_from_user(&info, addr, sizeof(info)))
131 return -EFAULT; 115 return -EFAULT;
132 if (!sb_has_quota_active(sb, type))
133 return -ESRCH;
134 if (!sb->s_qcop->set_info) 116 if (!sb->s_qcop->set_info)
135 return -ENOSYS; 117 return -ENOSYS;
136 return sb->s_qcop->set_info(sb, type, &info); 118 return sb->s_qcop->set_info(sb, type, &info);
137} 119}
138 120
121static void copy_to_if_dqblk(struct if_dqblk *dst, struct fs_disk_quota *src)
122{
123 dst->dqb_bhardlimit = src->d_blk_hardlimit;
124 dst->dqb_bsoftlimit = src->d_blk_softlimit;
125 dst->dqb_curspace = src->d_bcount;
126 dst->dqb_ihardlimit = src->d_ino_hardlimit;
127 dst->dqb_isoftlimit = src->d_ino_softlimit;
128 dst->dqb_curinodes = src->d_icount;
129 dst->dqb_btime = src->d_btimer;
130 dst->dqb_itime = src->d_itimer;
131 dst->dqb_valid = QIF_ALL;
132}
133
139static int quota_getquota(struct super_block *sb, int type, qid_t id, 134static int quota_getquota(struct super_block *sb, int type, qid_t id,
140 void __user *addr) 135 void __user *addr)
141{ 136{
137 struct fs_disk_quota fdq;
142 struct if_dqblk idq; 138 struct if_dqblk idq;
143 int ret; 139 int ret;
144 140
145 if (!sb_has_quota_active(sb, type))
146 return -ESRCH;
147 if (!sb->s_qcop->get_dqblk) 141 if (!sb->s_qcop->get_dqblk)
148 return -ENOSYS; 142 return -ENOSYS;
149 ret = sb->s_qcop->get_dqblk(sb, type, id, &idq); 143 ret = sb->s_qcop->get_dqblk(sb, type, id, &fdq);
150 if (ret) 144 if (ret)
151 return ret; 145 return ret;
146 copy_to_if_dqblk(&idq, &fdq);
152 if (copy_to_user(addr, &idq, sizeof(idq))) 147 if (copy_to_user(addr, &idq, sizeof(idq)))
153 return -EFAULT; 148 return -EFAULT;
154 return 0; 149 return 0;
155} 150}
156 151
152static void copy_from_if_dqblk(struct fs_disk_quota *dst, struct if_dqblk *src)
153{
154 dst->d_blk_hardlimit = src->dqb_bhardlimit;
155 dst->d_blk_softlimit = src->dqb_bsoftlimit;
156 dst->d_bcount = src->dqb_curspace;
157 dst->d_ino_hardlimit = src->dqb_ihardlimit;
158 dst->d_ino_softlimit = src->dqb_isoftlimit;
159 dst->d_icount = src->dqb_curinodes;
160 dst->d_btimer = src->dqb_btime;
161 dst->d_itimer = src->dqb_itime;
162
163 dst->d_fieldmask = 0;
164 if (src->dqb_valid & QIF_BLIMITS)
165 dst->d_fieldmask |= FS_DQ_BSOFT | FS_DQ_BHARD;
166 if (src->dqb_valid & QIF_SPACE)
167 dst->d_fieldmask |= FS_DQ_BCOUNT;
168 if (src->dqb_valid & QIF_ILIMITS)
169 dst->d_fieldmask |= FS_DQ_ISOFT | FS_DQ_IHARD;
170 if (src->dqb_valid & QIF_INODES)
171 dst->d_fieldmask |= FS_DQ_ICOUNT;
172 if (src->dqb_valid & QIF_BTIME)
173 dst->d_fieldmask |= FS_DQ_BTIMER;
174 if (src->dqb_valid & QIF_ITIME)
175 dst->d_fieldmask |= FS_DQ_ITIMER;
176}
177
157static int quota_setquota(struct super_block *sb, int type, qid_t id, 178static int quota_setquota(struct super_block *sb, int type, qid_t id,
158 void __user *addr) 179 void __user *addr)
159{ 180{
181 struct fs_disk_quota fdq;
160 struct if_dqblk idq; 182 struct if_dqblk idq;
161 183
162 if (copy_from_user(&idq, addr, sizeof(idq))) 184 if (copy_from_user(&idq, addr, sizeof(idq)))
163 return -EFAULT; 185 return -EFAULT;
164 if (!sb_has_quota_active(sb, type))
165 return -ESRCH;
166 if (!sb->s_qcop->set_dqblk) 186 if (!sb->s_qcop->set_dqblk)
167 return -ENOSYS; 187 return -ENOSYS;
168 return sb->s_qcop->set_dqblk(sb, type, id, &idq); 188 copy_from_if_dqblk(&fdq, &idq);
189 return sb->s_qcop->set_dqblk(sb, type, id, &fdq);
169} 190}
170 191
171static int quota_setxstate(struct super_block *sb, int cmd, void __user *addr) 192static int quota_setxstate(struct super_block *sb, int cmd, void __user *addr)
@@ -199,9 +220,9 @@ static int quota_setxquota(struct super_block *sb, int type, qid_t id,
199 220
200 if (copy_from_user(&fdq, addr, sizeof(fdq))) 221 if (copy_from_user(&fdq, addr, sizeof(fdq)))
201 return -EFAULT; 222 return -EFAULT;
202 if (!sb->s_qcop->set_xquota) 223 if (!sb->s_qcop->set_dqblk)
203 return -ENOSYS; 224 return -ENOSYS;
204 return sb->s_qcop->set_xquota(sb, type, id, &fdq); 225 return sb->s_qcop->set_dqblk(sb, type, id, &fdq);
205} 226}
206 227
207static int quota_getxquota(struct super_block *sb, int type, qid_t id, 228static int quota_getxquota(struct super_block *sb, int type, qid_t id,
@@ -210,9 +231,9 @@ static int quota_getxquota(struct super_block *sb, int type, qid_t id,
210 struct fs_disk_quota fdq; 231 struct fs_disk_quota fdq;
211 int ret; 232 int ret;
212 233
213 if (!sb->s_qcop->get_xquota) 234 if (!sb->s_qcop->get_dqblk)
214 return -ENOSYS; 235 return -ENOSYS;
215 ret = sb->s_qcop->get_xquota(sb, type, id, &fdq); 236 ret = sb->s_qcop->get_dqblk(sb, type, id, &fdq);
216 if (!ret && copy_to_user(addr, &fdq, sizeof(fdq))) 237 if (!ret && copy_to_user(addr, &fdq, sizeof(fdq)))
217 return -EFAULT; 238 return -EFAULT;
218 return ret; 239 return ret;
diff --git a/fs/quota/quota_tree.c b/fs/quota/quota_tree.c
index f81f4bcfb178..24f03407eeb5 100644
--- a/fs/quota/quota_tree.c
+++ b/fs/quota/quota_tree.c
@@ -60,9 +60,17 @@ static ssize_t read_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf)
60static ssize_t write_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf) 60static ssize_t write_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf)
61{ 61{
62 struct super_block *sb = info->dqi_sb; 62 struct super_block *sb = info->dqi_sb;
63 ssize_t ret;
63 64
64 return sb->s_op->quota_write(sb, info->dqi_type, buf, 65 ret = sb->s_op->quota_write(sb, info->dqi_type, buf,
65 info->dqi_usable_bs, blk << info->dqi_blocksize_bits); 66 info->dqi_usable_bs, blk << info->dqi_blocksize_bits);
67 if (ret != info->dqi_usable_bs) {
68 q_warn(KERN_WARNING "VFS: dquota write failed on "
69 "dev %s\n", sb->s_id);
70 if (ret >= 0)
71 ret = -EIO;
72 }
73 return ret;
66} 74}
67 75
68/* Remove empty block from list and return it */ 76/* Remove empty block from list and return it */
@@ -152,7 +160,7 @@ static int remove_free_dqentry(struct qtree_mem_dqinfo *info, char *buf,
152 dh->dqdh_next_free = dh->dqdh_prev_free = cpu_to_le32(0); 160 dh->dqdh_next_free = dh->dqdh_prev_free = cpu_to_le32(0);
153 /* No matter whether write succeeds block is out of list */ 161 /* No matter whether write succeeds block is out of list */
154 if (write_blk(info, blk, buf) < 0) 162 if (write_blk(info, blk, buf) < 0)
155 printk(KERN_ERR 163 q_warn(KERN_ERR
156 "VFS: Can't write block (%u) with free entries.\n", 164 "VFS: Can't write block (%u) with free entries.\n",
157 blk); 165 blk);
158 return 0; 166 return 0;
@@ -244,7 +252,7 @@ static uint find_free_dqentry(struct qtree_mem_dqinfo *info,
244 if (le16_to_cpu(dh->dqdh_entries) + 1 >= qtree_dqstr_in_blk(info)) { 252 if (le16_to_cpu(dh->dqdh_entries) + 1 >= qtree_dqstr_in_blk(info)) {
245 *err = remove_free_dqentry(info, buf, blk); 253 *err = remove_free_dqentry(info, buf, blk);
246 if (*err < 0) { 254 if (*err < 0) {
247 printk(KERN_ERR "VFS: find_free_dqentry(): Can't " 255 q_warn(KERN_ERR "VFS: find_free_dqentry(): Can't "
248 "remove block (%u) from entry free list.\n", 256 "remove block (%u) from entry free list.\n",
249 blk); 257 blk);
250 goto out_buf; 258 goto out_buf;
@@ -268,7 +276,7 @@ static uint find_free_dqentry(struct qtree_mem_dqinfo *info,
268#endif 276#endif
269 *err = write_blk(info, blk, buf); 277 *err = write_blk(info, blk, buf);
270 if (*err < 0) { 278 if (*err < 0) {
271 printk(KERN_ERR "VFS: find_free_dqentry(): Can't write quota " 279 q_warn(KERN_ERR "VFS: find_free_dqentry(): Can't write quota "
272 "data block %u.\n", blk); 280 "data block %u.\n", blk);
273 goto out_buf; 281 goto out_buf;
274 } 282 }
@@ -303,7 +311,7 @@ static int do_insert_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
303 } else { 311 } else {
304 ret = read_blk(info, *treeblk, buf); 312 ret = read_blk(info, *treeblk, buf);
305 if (ret < 0) { 313 if (ret < 0) {
306 printk(KERN_ERR "VFS: Can't read tree quota block " 314 q_warn(KERN_ERR "VFS: Can't read tree quota block "
307 "%u.\n", *treeblk); 315 "%u.\n", *treeblk);
308 goto out_buf; 316 goto out_buf;
309 } 317 }
@@ -365,7 +373,7 @@ int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
365 if (!dquot->dq_off) { 373 if (!dquot->dq_off) {
366 ret = dq_insert_tree(info, dquot); 374 ret = dq_insert_tree(info, dquot);
367 if (ret < 0) { 375 if (ret < 0) {
368 printk(KERN_ERR "VFS: Error %zd occurred while " 376 q_warn(KERN_ERR "VFS: Error %zd occurred while "
369 "creating quota.\n", ret); 377 "creating quota.\n", ret);
370 kfree(ddquot); 378 kfree(ddquot);
371 return ret; 379 return ret;
@@ -377,14 +385,14 @@ int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
377 ret = sb->s_op->quota_write(sb, type, ddquot, info->dqi_entry_size, 385 ret = sb->s_op->quota_write(sb, type, ddquot, info->dqi_entry_size,
378 dquot->dq_off); 386 dquot->dq_off);
379 if (ret != info->dqi_entry_size) { 387 if (ret != info->dqi_entry_size) {
380 printk(KERN_WARNING "VFS: dquota write failed on dev %s\n", 388 q_warn(KERN_WARNING "VFS: dquota write failed on dev %s\n",
381 sb->s_id); 389 sb->s_id);
382 if (ret >= 0) 390 if (ret >= 0)
383 ret = -ENOSPC; 391 ret = -ENOSPC;
384 } else { 392 } else {
385 ret = 0; 393 ret = 0;
386 } 394 }
387 dqstats.writes++; 395 dqstats_inc(DQST_WRITES);
388 kfree(ddquot); 396 kfree(ddquot);
389 397
390 return ret; 398 return ret;
@@ -402,14 +410,14 @@ static int free_dqentry(struct qtree_mem_dqinfo *info, struct dquot *dquot,
402 if (!buf) 410 if (!buf)
403 return -ENOMEM; 411 return -ENOMEM;
404 if (dquot->dq_off >> info->dqi_blocksize_bits != blk) { 412 if (dquot->dq_off >> info->dqi_blocksize_bits != blk) {
405 printk(KERN_ERR "VFS: Quota structure has offset to other " 413 q_warn(KERN_ERR "VFS: Quota structure has offset to other "
406 "block (%u) than it should (%u).\n", blk, 414 "block (%u) than it should (%u).\n", blk,
407 (uint)(dquot->dq_off >> info->dqi_blocksize_bits)); 415 (uint)(dquot->dq_off >> info->dqi_blocksize_bits));
408 goto out_buf; 416 goto out_buf;
409 } 417 }
410 ret = read_blk(info, blk, buf); 418 ret = read_blk(info, blk, buf);
411 if (ret < 0) { 419 if (ret < 0) {
412 printk(KERN_ERR "VFS: Can't read quota data block %u\n", blk); 420 q_warn(KERN_ERR "VFS: Can't read quota data block %u\n", blk);
413 goto out_buf; 421 goto out_buf;
414 } 422 }
415 dh = (struct qt_disk_dqdbheader *)buf; 423 dh = (struct qt_disk_dqdbheader *)buf;
@@ -419,7 +427,7 @@ static int free_dqentry(struct qtree_mem_dqinfo *info, struct dquot *dquot,
419 if (ret >= 0) 427 if (ret >= 0)
420 ret = put_free_dqblk(info, buf, blk); 428 ret = put_free_dqblk(info, buf, blk);
421 if (ret < 0) { 429 if (ret < 0) {
422 printk(KERN_ERR "VFS: Can't move quota data block (%u) " 430 q_warn(KERN_ERR "VFS: Can't move quota data block (%u) "
423 "to free list.\n", blk); 431 "to free list.\n", blk);
424 goto out_buf; 432 goto out_buf;
425 } 433 }
@@ -432,14 +440,14 @@ static int free_dqentry(struct qtree_mem_dqinfo *info, struct dquot *dquot,
432 /* Insert will write block itself */ 440 /* Insert will write block itself */
433 ret = insert_free_dqentry(info, buf, blk); 441 ret = insert_free_dqentry(info, buf, blk);
434 if (ret < 0) { 442 if (ret < 0) {
435 printk(KERN_ERR "VFS: Can't insert quota data " 443 q_warn(KERN_ERR "VFS: Can't insert quota data "
436 "block (%u) to free entry list.\n", blk); 444 "block (%u) to free entry list.\n", blk);
437 goto out_buf; 445 goto out_buf;
438 } 446 }
439 } else { 447 } else {
440 ret = write_blk(info, blk, buf); 448 ret = write_blk(info, blk, buf);
441 if (ret < 0) { 449 if (ret < 0) {
442 printk(KERN_ERR "VFS: Can't write quota data " 450 q_warn(KERN_ERR "VFS: Can't write quota data "
443 "block %u\n", blk); 451 "block %u\n", blk);
444 goto out_buf; 452 goto out_buf;
445 } 453 }
@@ -464,7 +472,7 @@ static int remove_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
464 return -ENOMEM; 472 return -ENOMEM;
465 ret = read_blk(info, *blk, buf); 473 ret = read_blk(info, *blk, buf);
466 if (ret < 0) { 474 if (ret < 0) {
467 printk(KERN_ERR "VFS: Can't read quota data block %u\n", *blk); 475 q_warn(KERN_ERR "VFS: Can't read quota data block %u\n", *blk);
468 goto out_buf; 476 goto out_buf;
469 } 477 }
470 newblk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]); 478 newblk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]);
@@ -488,7 +496,7 @@ static int remove_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
488 } else { 496 } else {
489 ret = write_blk(info, *blk, buf); 497 ret = write_blk(info, *blk, buf);
490 if (ret < 0) 498 if (ret < 0)
491 printk(KERN_ERR "VFS: Can't write quota tree " 499 q_warn(KERN_ERR "VFS: Can't write quota tree "
492 "block %u.\n", *blk); 500 "block %u.\n", *blk);
493 } 501 }
494 } 502 }
@@ -521,7 +529,7 @@ static loff_t find_block_dqentry(struct qtree_mem_dqinfo *info,
521 return -ENOMEM; 529 return -ENOMEM;
522 ret = read_blk(info, blk, buf); 530 ret = read_blk(info, blk, buf);
523 if (ret < 0) { 531 if (ret < 0) {
524 printk(KERN_ERR "VFS: Can't read quota tree block %u.\n", blk); 532 q_warn(KERN_ERR "VFS: Can't read quota tree block %u.\n", blk);
525 goto out_buf; 533 goto out_buf;
526 } 534 }
527 ddquot = buf + sizeof(struct qt_disk_dqdbheader); 535 ddquot = buf + sizeof(struct qt_disk_dqdbheader);
@@ -531,7 +539,7 @@ static loff_t find_block_dqentry(struct qtree_mem_dqinfo *info,
531 ddquot += info->dqi_entry_size; 539 ddquot += info->dqi_entry_size;
532 } 540 }
533 if (i == qtree_dqstr_in_blk(info)) { 541 if (i == qtree_dqstr_in_blk(info)) {
534 printk(KERN_ERR "VFS: Quota for id %u referenced " 542 q_warn(KERN_ERR "VFS: Quota for id %u referenced "
535 "but not present.\n", dquot->dq_id); 543 "but not present.\n", dquot->dq_id);
536 ret = -EIO; 544 ret = -EIO;
537 goto out_buf; 545 goto out_buf;
@@ -556,7 +564,7 @@ static loff_t find_tree_dqentry(struct qtree_mem_dqinfo *info,
556 return -ENOMEM; 564 return -ENOMEM;
557 ret = read_blk(info, blk, buf); 565 ret = read_blk(info, blk, buf);
558 if (ret < 0) { 566 if (ret < 0) {
559 printk(KERN_ERR "VFS: Can't read quota tree block %u.\n", blk); 567 q_warn(KERN_ERR "VFS: Can't read quota tree block %u.\n", blk);
560 goto out_buf; 568 goto out_buf;
561 } 569 }
562 ret = 0; 570 ret = 0;
@@ -599,7 +607,7 @@ int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
599 offset = find_dqentry(info, dquot); 607 offset = find_dqentry(info, dquot);
600 if (offset <= 0) { /* Entry not present? */ 608 if (offset <= 0) { /* Entry not present? */
601 if (offset < 0) 609 if (offset < 0)
602 printk(KERN_ERR "VFS: Can't read quota " 610 q_warn(KERN_ERR "VFS: Can't read quota "
603 "structure for id %u.\n", dquot->dq_id); 611 "structure for id %u.\n", dquot->dq_id);
604 dquot->dq_off = 0; 612 dquot->dq_off = 0;
605 set_bit(DQ_FAKE_B, &dquot->dq_flags); 613 set_bit(DQ_FAKE_B, &dquot->dq_flags);
@@ -617,7 +625,7 @@ int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
617 if (ret != info->dqi_entry_size) { 625 if (ret != info->dqi_entry_size) {
618 if (ret >= 0) 626 if (ret >= 0)
619 ret = -EIO; 627 ret = -EIO;
620 printk(KERN_ERR "VFS: Error while reading quota " 628 q_warn(KERN_ERR "VFS: Error while reading quota "
621 "structure for id %u.\n", dquot->dq_id); 629 "structure for id %u.\n", dquot->dq_id);
622 set_bit(DQ_FAKE_B, &dquot->dq_flags); 630 set_bit(DQ_FAKE_B, &dquot->dq_flags);
623 memset(&dquot->dq_dqb, 0, sizeof(struct mem_dqblk)); 631 memset(&dquot->dq_dqb, 0, sizeof(struct mem_dqblk));
@@ -634,7 +642,7 @@ int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
634 spin_unlock(&dq_data_lock); 642 spin_unlock(&dq_data_lock);
635 kfree(ddquot); 643 kfree(ddquot);
636out: 644out:
637 dqstats.reads++; 645 dqstats_inc(DQST_READS);
638 return ret; 646 return ret;
639} 647}
640EXPORT_SYMBOL(qtree_read_dquot); 648EXPORT_SYMBOL(qtree_read_dquot);
diff --git a/fs/quota/quota_tree.h b/fs/quota/quota_tree.h
index a1ab8db81a51..ccc3e71fb1d8 100644
--- a/fs/quota/quota_tree.h
+++ b/fs/quota/quota_tree.h
@@ -22,4 +22,10 @@ struct qt_disk_dqdbheader {
22 22
23#define QT_TREEOFF 1 /* Offset of tree in file in blocks */ 23#define QT_TREEOFF 1 /* Offset of tree in file in blocks */
24 24
25#define q_warn(fmt, args...) \
26do { \
27 if (printk_ratelimit()) \
28 printk(fmt, ## args); \
29} while(0)
30
25#endif /* _LINUX_QUOTAIO_TREE_H */ 31#endif /* _LINUX_QUOTAIO_TREE_H */
diff --git a/fs/quota/quota_v1.c b/fs/quota/quota_v1.c
index 2ae757e9c008..4af344c5852a 100644
--- a/fs/quota/quota_v1.c
+++ b/fs/quota/quota_v1.c
@@ -71,7 +71,7 @@ static int v1_read_dqblk(struct dquot *dquot)
71 dquot->dq_dqb.dqb_ihardlimit == 0 && 71 dquot->dq_dqb.dqb_ihardlimit == 0 &&
72 dquot->dq_dqb.dqb_isoftlimit == 0) 72 dquot->dq_dqb.dqb_isoftlimit == 0)
73 set_bit(DQ_FAKE_B, &dquot->dq_flags); 73 set_bit(DQ_FAKE_B, &dquot->dq_flags);
74 dqstats.reads++; 74 dqstats_inc(DQST_READS);
75 75
76 return 0; 76 return 0;
77} 77}
@@ -104,7 +104,7 @@ static int v1_commit_dqblk(struct dquot *dquot)
104 ret = 0; 104 ret = 0;
105 105
106out: 106out:
107 dqstats.writes++; 107 dqstats_inc(DQST_WRITES);
108 108
109 return ret; 109 return ret;
110} 110}
diff --git a/fs/quota/quota_v2.c b/fs/quota/quota_v2.c
index e3da02f4986f..135206af1458 100644
--- a/fs/quota/quota_v2.c
+++ b/fs/quota/quota_v2.c
@@ -63,7 +63,7 @@ static int v2_read_header(struct super_block *sb, int type,
63 size = sb->s_op->quota_read(sb, type, (char *)dqhead, 63 size = sb->s_op->quota_read(sb, type, (char *)dqhead,
64 sizeof(struct v2_disk_dqheader), 0); 64 sizeof(struct v2_disk_dqheader), 0);
65 if (size != sizeof(struct v2_disk_dqheader)) { 65 if (size != sizeof(struct v2_disk_dqheader)) {
66 printk(KERN_WARNING "quota_v2: Failed header read:" 66 q_warn(KERN_WARNING "quota_v2: Failed header read:"
67 " expected=%zd got=%zd\n", 67 " expected=%zd got=%zd\n",
68 sizeof(struct v2_disk_dqheader), size); 68 sizeof(struct v2_disk_dqheader), size);
69 return 0; 69 return 0;
@@ -106,7 +106,7 @@ static int v2_read_file_info(struct super_block *sb, int type)
106 size = sb->s_op->quota_read(sb, type, (char *)&dinfo, 106 size = sb->s_op->quota_read(sb, type, (char *)&dinfo,
107 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF); 107 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF);
108 if (size != sizeof(struct v2_disk_dqinfo)) { 108 if (size != sizeof(struct v2_disk_dqinfo)) {
109 printk(KERN_WARNING "quota_v2: Can't read info structure on device %s.\n", 109 q_warn(KERN_WARNING "quota_v2: Can't read info structure on device %s.\n",
110 sb->s_id); 110 sb->s_id);
111 return -1; 111 return -1;
112 } 112 }
@@ -167,7 +167,7 @@ static int v2_write_file_info(struct super_block *sb, int type)
167 size = sb->s_op->quota_write(sb, type, (char *)&dinfo, 167 size = sb->s_op->quota_write(sb, type, (char *)&dinfo,
168 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF); 168 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF);
169 if (size != sizeof(struct v2_disk_dqinfo)) { 169 if (size != sizeof(struct v2_disk_dqinfo)) {
170 printk(KERN_WARNING "Can't write info structure on device %s.\n", 170 q_warn(KERN_WARNING "Can't write info structure on device %s.\n",
171 sb->s_id); 171 sb->s_id);
172 return -1; 172 return -1;
173 } 173 }