aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/attr.c11
-rw-r--r--fs/ext2/balloc.c12
-rw-r--r--fs/ext2/file.c5
-rw-r--r--fs/ext2/ialloc.c14
-rw-r--r--fs/ext2/inode.c7
-rw-r--r--fs/ext2/namei.c51
-rw-r--r--fs/ext2/super.c2
-rw-r--r--fs/ext2/xattr.c10
-rw-r--r--fs/ext3/balloc.c11
-rw-r--r--fs/ext3/file.c7
-rw-r--r--fs/ext3/ialloc.c16
-rw-r--r--fs/ext3/inode.c41
-rw-r--r--fs/ext3/namei.c24
-rw-r--r--fs/ext3/super.c246
-rw-r--r--fs/ext3/xattr.c22
-rw-r--r--fs/ext4/file.c3
-rw-r--r--fs/ext4/ialloc.c16
-rw-r--r--fs/ext4/inode.c27
-rw-r--r--fs/ext4/mballoc.c6
-rw-r--r--fs/ext4/namei.c23
-rw-r--r--fs/ext4/super.c15
-rw-r--r--fs/ext4/xattr.c8
-rw-r--r--fs/gfs2/quota.c9
-rw-r--r--fs/gfs2/quota.h2
-rw-r--r--fs/gfs2/super.c2
-rw-r--r--fs/gfs2/sys.c2
-rw-r--r--fs/inode.c4
-rw-r--r--fs/jbd/commit.c10
-rw-r--r--fs/jbd/transaction.c43
-rw-r--r--fs/jfs/acl.c26
-rw-r--r--fs/jfs/file.c31
-rw-r--r--fs/jfs/inode.c9
-rw-r--r--fs/jfs/jfs_acl.h7
-rw-r--r--fs/jfs/jfs_dtree.c28
-rw-r--r--fs/jfs/jfs_extent.c16
-rw-r--r--fs/jfs/jfs_inode.c8
-rw-r--r--fs/jfs/jfs_inode.h1
-rw-r--r--fs/jfs/jfs_xtree.c21
-rw-r--r--fs/jfs/namei.c23
-rw-r--r--fs/jfs/super.c6
-rw-r--r--fs/jfs/xattr.c17
-rw-r--r--fs/namei.c16
-rw-r--r--fs/nfsd/vfs.c4
-rw-r--r--fs/ocfs2/alloc.c13
-rw-r--r--fs/ocfs2/aops.c11
-rw-r--r--fs/ocfs2/dir.c37
-rw-r--r--fs/ocfs2/file.c20
-rw-r--r--fs/ocfs2/inode.c6
-rw-r--r--fs/ocfs2/namei.c52
-rw-r--r--fs/ocfs2/quota_global.c7
-rw-r--r--fs/ocfs2/refcounttree.c2
-rw-r--r--fs/open.c5
-rw-r--r--fs/quota/Kconfig5
-rw-r--r--fs/quota/Makefile2
-rw-r--r--fs/quota/compat.c118
-rw-r--r--fs/quota/dquot.c412
-rw-r--r--fs/quota/netlink.c95
-rw-r--r--fs/quota/quota.c735
-rw-r--r--fs/reiserfs/bitmap.c10
-rw-r--r--fs/reiserfs/file.c2
-rw-r--r--fs/reiserfs/inode.c20
-rw-r--r--fs/reiserfs/namei.c23
-rw-r--r--fs/reiserfs/stree.c20
-rw-r--r--fs/reiserfs/super.c15
-rw-r--r--fs/reiserfs/xattr.c4
-rw-r--r--fs/sync.c14
-rw-r--r--fs/udf/balloc.c35
-rw-r--r--fs/udf/file.c28
-rw-r--r--fs/udf/ialloc.c14
-rw-r--r--fs/udf/inode.c6
-rw-r--r--fs/udf/namei.c17
-rw-r--r--fs/ufs/balloc.c24
-rw-r--r--fs/ufs/file.c3
-rw-r--r--fs/ufs/ialloc.c11
-rw-r--r--fs/ufs/inode.c4
-rw-r--r--fs/ufs/namei.c18
-rw-r--r--fs/ufs/super.c6
-rw-r--r--fs/ufs/truncate.c10
-rw-r--r--fs/xfs/linux-2.6/xfs_quotaops.c19
79 files changed, 1427 insertions, 1258 deletions
diff --git a/fs/attr.c b/fs/attr.c
index 96d394bdaddf..0a6ea54cde7d 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -12,7 +12,6 @@
12#include <linux/capability.h> 12#include <linux/capability.h>
13#include <linux/fsnotify.h> 13#include <linux/fsnotify.h>
14#include <linux/fcntl.h> 14#include <linux/fcntl.h>
15#include <linux/quotaops.h>
16#include <linux/security.h> 15#include <linux/security.h>
17 16
18/* Taken over from the old code... */ 17/* Taken over from the old code... */
@@ -212,14 +211,8 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
212 error = inode->i_op->setattr(dentry, attr); 211 error = inode->i_op->setattr(dentry, attr);
213 } else { 212 } else {
214 error = inode_change_ok(inode, attr); 213 error = inode_change_ok(inode, attr);
215 if (!error) { 214 if (!error)
216 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || 215 error = inode_setattr(inode, attr);
217 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
218 error = vfs_dq_transfer(inode, attr) ?
219 -EDQUOT : 0;
220 if (!error)
221 error = inode_setattr(inode, attr);
222 }
223 } 216 }
224 217
225 if (ia_valid & ATTR_SIZE) 218 if (ia_valid & ATTR_SIZE)
diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index 7f8d2e5a7ea6..1d081f0cfec2 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -570,7 +570,7 @@ do_more:
570error_return: 570error_return:
571 brelse(bitmap_bh); 571 brelse(bitmap_bh);
572 release_blocks(sb, freed); 572 release_blocks(sb, freed);
573 vfs_dq_free_block(inode, freed); 573 dquot_free_block(inode, freed);
574} 574}
575 575
576/** 576/**
@@ -1236,6 +1236,7 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
1236 unsigned short windowsz = 0; 1236 unsigned short windowsz = 0;
1237 unsigned long ngroups; 1237 unsigned long ngroups;
1238 unsigned long num = *count; 1238 unsigned long num = *count;
1239 int ret;
1239 1240
1240 *errp = -ENOSPC; 1241 *errp = -ENOSPC;
1241 sb = inode->i_sb; 1242 sb = inode->i_sb;
@@ -1247,8 +1248,9 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
1247 /* 1248 /*
1248 * Check quota for allocation of this block. 1249 * Check quota for allocation of this block.
1249 */ 1250 */
1250 if (vfs_dq_alloc_block(inode, num)) { 1251 ret = dquot_alloc_block(inode, num);
1251 *errp = -EDQUOT; 1252 if (ret) {
1253 *errp = ret;
1252 return 0; 1254 return 0;
1253 } 1255 }
1254 1256
@@ -1409,7 +1411,7 @@ allocated:
1409 1411
1410 *errp = 0; 1412 *errp = 0;
1411 brelse(bitmap_bh); 1413 brelse(bitmap_bh);
1412 vfs_dq_free_block(inode, *count-num); 1414 dquot_free_block(inode, *count-num);
1413 *count = num; 1415 *count = num;
1414 return ret_block; 1416 return ret_block;
1415 1417
@@ -1420,7 +1422,7 @@ out:
1420 * Undo the block allocation 1422 * Undo the block allocation
1421 */ 1423 */
1422 if (!performed_allocation) 1424 if (!performed_allocation)
1423 vfs_dq_free_block(inode, *count); 1425 dquot_free_block(inode, *count);
1424 brelse(bitmap_bh); 1426 brelse(bitmap_bh);
1425 return 0; 1427 return 0;
1426} 1428}
diff --git a/fs/ext2/file.c b/fs/ext2/file.c
index 586e3589d4c2..5d198d0697fb 100644
--- a/fs/ext2/file.c
+++ b/fs/ext2/file.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/time.h> 21#include <linux/time.h>
22#include <linux/pagemap.h> 22#include <linux/pagemap.h>
23#include <linux/quotaops.h>
23#include "ext2.h" 24#include "ext2.h"
24#include "xattr.h" 25#include "xattr.h"
25#include "acl.h" 26#include "acl.h"
@@ -70,7 +71,7 @@ const struct file_operations ext2_file_operations = {
70 .compat_ioctl = ext2_compat_ioctl, 71 .compat_ioctl = ext2_compat_ioctl,
71#endif 72#endif
72 .mmap = generic_file_mmap, 73 .mmap = generic_file_mmap,
73 .open = generic_file_open, 74 .open = dquot_file_open,
74 .release = ext2_release_file, 75 .release = ext2_release_file,
75 .fsync = ext2_fsync, 76 .fsync = ext2_fsync,
76 .splice_read = generic_file_splice_read, 77 .splice_read = generic_file_splice_read,
@@ -87,7 +88,7 @@ const struct file_operations ext2_xip_file_operations = {
87 .compat_ioctl = ext2_compat_ioctl, 88 .compat_ioctl = ext2_compat_ioctl,
88#endif 89#endif
89 .mmap = xip_file_mmap, 90 .mmap = xip_file_mmap,
90 .open = generic_file_open, 91 .open = dquot_file_open,
91 .release = ext2_release_file, 92 .release = ext2_release_file,
92 .fsync = ext2_fsync, 93 .fsync = ext2_fsync,
93}; 94};
diff --git a/fs/ext2/ialloc.c b/fs/ext2/ialloc.c
index 15387c9c17d8..ad7d572ee8dc 100644
--- a/fs/ext2/ialloc.c
+++ b/fs/ext2/ialloc.c
@@ -121,8 +121,8 @@ void ext2_free_inode (struct inode * inode)
121 if (!is_bad_inode(inode)) { 121 if (!is_bad_inode(inode)) {
122 /* Quota is already initialized in iput() */ 122 /* Quota is already initialized in iput() */
123 ext2_xattr_delete_inode(inode); 123 ext2_xattr_delete_inode(inode);
124 vfs_dq_free_inode(inode); 124 dquot_free_inode(inode);
125 vfs_dq_drop(inode); 125 dquot_drop(inode);
126 } 126 }
127 127
128 es = EXT2_SB(sb)->s_es; 128 es = EXT2_SB(sb)->s_es;
@@ -586,10 +586,10 @@ got:
586 goto fail_drop; 586 goto fail_drop;
587 } 587 }
588 588
589 if (vfs_dq_alloc_inode(inode)) { 589 dquot_initialize(inode);
590 err = -EDQUOT; 590 err = dquot_alloc_inode(inode);
591 if (err)
591 goto fail_drop; 592 goto fail_drop;
592 }
593 593
594 err = ext2_init_acl(inode, dir); 594 err = ext2_init_acl(inode, dir);
595 if (err) 595 if (err)
@@ -605,10 +605,10 @@ got:
605 return inode; 605 return inode;
606 606
607fail_free_drop: 607fail_free_drop:
608 vfs_dq_free_inode(inode); 608 dquot_free_inode(inode);
609 609
610fail_drop: 610fail_drop:
611 vfs_dq_drop(inode); 611 dquot_drop(inode);
612 inode->i_flags |= S_NOQUOTA; 612 inode->i_flags |= S_NOQUOTA;
613 inode->i_nlink = 0; 613 inode->i_nlink = 0;
614 unlock_new_inode(inode); 614 unlock_new_inode(inode);
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 36ae1cac767c..fc13cc119aad 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -60,6 +60,8 @@ static inline int ext2_inode_is_fast_symlink(struct inode *inode)
60 */ 60 */
61void ext2_delete_inode (struct inode * inode) 61void ext2_delete_inode (struct inode * inode)
62{ 62{
63 if (!is_bad_inode(inode))
64 dquot_initialize(inode);
63 truncate_inode_pages(&inode->i_data, 0); 65 truncate_inode_pages(&inode->i_data, 0);
64 66
65 if (is_bad_inode(inode)) 67 if (is_bad_inode(inode))
@@ -1464,9 +1466,12 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr)
1464 error = inode_change_ok(inode, iattr); 1466 error = inode_change_ok(inode, iattr);
1465 if (error) 1467 if (error)
1466 return error; 1468 return error;
1469
1470 if (iattr->ia_valid & ATTR_SIZE)
1471 dquot_initialize(inode);
1467 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) || 1472 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
1468 (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) { 1473 (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
1469 error = vfs_dq_transfer(inode, iattr) ? -EDQUOT : 0; 1474 error = dquot_transfer(inode, iattr);
1470 if (error) 1475 if (error)
1471 return error; 1476 return error;
1472 } 1477 }
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index dd7175ce5606..71efb0e9a3f2 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -31,6 +31,7 @@
31 */ 31 */
32 32
33#include <linux/pagemap.h> 33#include <linux/pagemap.h>
34#include <linux/quotaops.h>
34#include "ext2.h" 35#include "ext2.h"
35#include "xattr.h" 36#include "xattr.h"
36#include "acl.h" 37#include "acl.h"
@@ -99,24 +100,27 @@ struct dentry *ext2_get_parent(struct dentry *child)
99 */ 100 */
100static int ext2_create (struct inode * dir, struct dentry * dentry, int mode, struct nameidata *nd) 101static int ext2_create (struct inode * dir, struct dentry * dentry, int mode, struct nameidata *nd)
101{ 102{
102 struct inode * inode = ext2_new_inode (dir, mode); 103 struct inode *inode;
103 int err = PTR_ERR(inode); 104
104 if (!IS_ERR(inode)) { 105 dquot_initialize(dir);
105 inode->i_op = &ext2_file_inode_operations; 106
106 if (ext2_use_xip(inode->i_sb)) { 107 inode = ext2_new_inode(dir, mode);
107 inode->i_mapping->a_ops = &ext2_aops_xip; 108 if (IS_ERR(inode))
108 inode->i_fop = &ext2_xip_file_operations; 109 return PTR_ERR(inode);
109 } else if (test_opt(inode->i_sb, NOBH)) { 110
110 inode->i_mapping->a_ops = &ext2_nobh_aops; 111 inode->i_op = &ext2_file_inode_operations;
111 inode->i_fop = &ext2_file_operations; 112 if (ext2_use_xip(inode->i_sb)) {
112 } else { 113 inode->i_mapping->a_ops = &ext2_aops_xip;
113 inode->i_mapping->a_ops = &ext2_aops; 114 inode->i_fop = &ext2_xip_file_operations;
114 inode->i_fop = &ext2_file_operations; 115 } else if (test_opt(inode->i_sb, NOBH)) {
115 } 116 inode->i_mapping->a_ops = &ext2_nobh_aops;
116 mark_inode_dirty(inode); 117 inode->i_fop = &ext2_file_operations;
117 err = ext2_add_nondir(dentry, inode); 118 } else {
119 inode->i_mapping->a_ops = &ext2_aops;
120 inode->i_fop = &ext2_file_operations;
118 } 121 }
119 return err; 122 mark_inode_dirty(inode);
123 return ext2_add_nondir(dentry, inode);
120} 124}
121 125
122static int ext2_mknod (struct inode * dir, struct dentry *dentry, int mode, dev_t rdev) 126static int ext2_mknod (struct inode * dir, struct dentry *dentry, int mode, dev_t rdev)
@@ -127,6 +131,8 @@ static int ext2_mknod (struct inode * dir, struct dentry *dentry, int mode, dev_
127 if (!new_valid_dev(rdev)) 131 if (!new_valid_dev(rdev))
128 return -EINVAL; 132 return -EINVAL;
129 133
134 dquot_initialize(dir);
135
130 inode = ext2_new_inode (dir, mode); 136 inode = ext2_new_inode (dir, mode);
131 err = PTR_ERR(inode); 137 err = PTR_ERR(inode);
132 if (!IS_ERR(inode)) { 138 if (!IS_ERR(inode)) {
@@ -151,6 +157,8 @@ static int ext2_symlink (struct inode * dir, struct dentry * dentry,
151 if (l > sb->s_blocksize) 157 if (l > sb->s_blocksize)
152 goto out; 158 goto out;
153 159
160 dquot_initialize(dir);
161
154 inode = ext2_new_inode (dir, S_IFLNK | S_IRWXUGO); 162 inode = ext2_new_inode (dir, S_IFLNK | S_IRWXUGO);
155 err = PTR_ERR(inode); 163 err = PTR_ERR(inode);
156 if (IS_ERR(inode)) 164 if (IS_ERR(inode))
@@ -194,6 +202,8 @@ static int ext2_link (struct dentry * old_dentry, struct inode * dir,
194 if (inode->i_nlink >= EXT2_LINK_MAX) 202 if (inode->i_nlink >= EXT2_LINK_MAX)
195 return -EMLINK; 203 return -EMLINK;
196 204
205 dquot_initialize(dir);
206
197 inode->i_ctime = CURRENT_TIME_SEC; 207 inode->i_ctime = CURRENT_TIME_SEC;
198 inode_inc_link_count(inode); 208 inode_inc_link_count(inode);
199 atomic_inc(&inode->i_count); 209 atomic_inc(&inode->i_count);
@@ -216,6 +226,8 @@ static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode)
216 if (dir->i_nlink >= EXT2_LINK_MAX) 226 if (dir->i_nlink >= EXT2_LINK_MAX)
217 goto out; 227 goto out;
218 228
229 dquot_initialize(dir);
230
219 inode_inc_link_count(dir); 231 inode_inc_link_count(dir);
220 232
221 inode = ext2_new_inode (dir, S_IFDIR | mode); 233 inode = ext2_new_inode (dir, S_IFDIR | mode);
@@ -262,6 +274,8 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
262 struct page * page; 274 struct page * page;
263 int err = -ENOENT; 275 int err = -ENOENT;
264 276
277 dquot_initialize(dir);
278
265 de = ext2_find_entry (dir, &dentry->d_name, &page); 279 de = ext2_find_entry (dir, &dentry->d_name, &page);
266 if (!de) 280 if (!de)
267 goto out; 281 goto out;
@@ -304,6 +318,9 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
304 struct ext2_dir_entry_2 * old_de; 318 struct ext2_dir_entry_2 * old_de;
305 int err = -ENOENT; 319 int err = -ENOENT;
306 320
321 dquot_initialize(old_dir);
322 dquot_initialize(new_dir);
323
307 old_de = ext2_find_entry (old_dir, &old_dentry->d_name, &old_page); 324 old_de = ext2_find_entry (old_dir, &old_dentry->d_name, &old_page);
308 if (!old_de) 325 if (!old_de)
309 goto out; 326 goto out;
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index f9cb54a585ce..42e4a303b675 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -194,6 +194,8 @@ static void destroy_inodecache(void)
194static void ext2_clear_inode(struct inode *inode) 194static void ext2_clear_inode(struct inode *inode)
195{ 195{
196 struct ext2_block_alloc_info *rsv = EXT2_I(inode)->i_block_alloc_info; 196 struct ext2_block_alloc_info *rsv = EXT2_I(inode)->i_block_alloc_info;
197
198 dquot_drop(inode);
197 ext2_discard_reservation(inode); 199 ext2_discard_reservation(inode);
198 EXT2_I(inode)->i_block_alloc_info = NULL; 200 EXT2_I(inode)->i_block_alloc_info = NULL;
199 if (unlikely(rsv)) 201 if (unlikely(rsv))
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index 904f00642f84..e44dc92609be 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -644,8 +644,8 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
644 the inode. */ 644 the inode. */
645 ea_bdebug(new_bh, "reusing block"); 645 ea_bdebug(new_bh, "reusing block");
646 646
647 error = -EDQUOT; 647 error = dquot_alloc_block(inode, 1);
648 if (vfs_dq_alloc_block(inode, 1)) { 648 if (error) {
649 unlock_buffer(new_bh); 649 unlock_buffer(new_bh);
650 goto cleanup; 650 goto cleanup;
651 } 651 }
@@ -702,7 +702,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
702 * as if nothing happened and cleanup the unused block */ 702 * as if nothing happened and cleanup the unused block */
703 if (error && error != -ENOSPC) { 703 if (error && error != -ENOSPC) {
704 if (new_bh && new_bh != old_bh) 704 if (new_bh && new_bh != old_bh)
705 vfs_dq_free_block(inode, 1); 705 dquot_free_block(inode, 1);
706 goto cleanup; 706 goto cleanup;
707 } 707 }
708 } else 708 } else
@@ -734,7 +734,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
734 le32_add_cpu(&HDR(old_bh)->h_refcount, -1); 734 le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
735 if (ce) 735 if (ce)
736 mb_cache_entry_release(ce); 736 mb_cache_entry_release(ce);
737 vfs_dq_free_block(inode, 1); 737 dquot_free_block(inode, 1);
738 mark_buffer_dirty(old_bh); 738 mark_buffer_dirty(old_bh);
739 ea_bdebug(old_bh, "refcount now=%d", 739 ea_bdebug(old_bh, "refcount now=%d",
740 le32_to_cpu(HDR(old_bh)->h_refcount)); 740 le32_to_cpu(HDR(old_bh)->h_refcount));
@@ -797,7 +797,7 @@ ext2_xattr_delete_inode(struct inode *inode)
797 mark_buffer_dirty(bh); 797 mark_buffer_dirty(bh);
798 if (IS_SYNC(inode)) 798 if (IS_SYNC(inode))
799 sync_dirty_buffer(bh); 799 sync_dirty_buffer(bh);
800 vfs_dq_free_block(inode, 1); 800 dquot_free_block(inode, 1);
801 } 801 }
802 EXT2_I(inode)->i_file_acl = 0; 802 EXT2_I(inode)->i_file_acl = 0;
803 803
diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
index 27967f92e820..161da2d3f890 100644
--- a/fs/ext3/balloc.c
+++ b/fs/ext3/balloc.c
@@ -676,7 +676,7 @@ void ext3_free_blocks(handle_t *handle, struct inode *inode,
676 } 676 }
677 ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks); 677 ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
678 if (dquot_freed_blocks) 678 if (dquot_freed_blocks)
679 vfs_dq_free_block(inode, dquot_freed_blocks); 679 dquot_free_block(inode, dquot_freed_blocks);
680 return; 680 return;
681} 681}
682 682
@@ -1502,8 +1502,9 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
1502 /* 1502 /*
1503 * Check quota for allocation of this block. 1503 * Check quota for allocation of this block.
1504 */ 1504 */
1505 if (vfs_dq_alloc_block(inode, num)) { 1505 err = dquot_alloc_block(inode, num);
1506 *errp = -EDQUOT; 1506 if (err) {
1507 *errp = err;
1507 return 0; 1508 return 0;
1508 } 1509 }
1509 1510
@@ -1713,7 +1714,7 @@ allocated:
1713 1714
1714 *errp = 0; 1715 *errp = 0;
1715 brelse(bitmap_bh); 1716 brelse(bitmap_bh);
1716 vfs_dq_free_block(inode, *count-num); 1717 dquot_free_block(inode, *count-num);
1717 *count = num; 1718 *count = num;
1718 return ret_block; 1719 return ret_block;
1719 1720
@@ -1728,7 +1729,7 @@ out:
1728 * Undo the block allocation 1729 * Undo the block allocation
1729 */ 1730 */
1730 if (!performed_allocation) 1731 if (!performed_allocation)
1731 vfs_dq_free_block(inode, *count); 1732 dquot_free_block(inode, *count);
1732 brelse(bitmap_bh); 1733 brelse(bitmap_bh);
1733 return 0; 1734 return 0;
1734} 1735}
diff --git a/fs/ext3/file.c b/fs/ext3/file.c
index 388bbdfa0b4e..f55df0e61cbd 100644
--- a/fs/ext3/file.c
+++ b/fs/ext3/file.c
@@ -21,6 +21,7 @@
21#include <linux/time.h> 21#include <linux/time.h>
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/jbd.h> 23#include <linux/jbd.h>
24#include <linux/quotaops.h>
24#include <linux/ext3_fs.h> 25#include <linux/ext3_fs.h>
25#include <linux/ext3_jbd.h> 26#include <linux/ext3_jbd.h>
26#include "xattr.h" 27#include "xattr.h"
@@ -33,9 +34,9 @@
33 */ 34 */
34static int ext3_release_file (struct inode * inode, struct file * filp) 35static int ext3_release_file (struct inode * inode, struct file * filp)
35{ 36{
36 if (EXT3_I(inode)->i_state & EXT3_STATE_FLUSH_ON_CLOSE) { 37 if (ext3_test_inode_state(inode, EXT3_STATE_FLUSH_ON_CLOSE)) {
37 filemap_flush(inode->i_mapping); 38 filemap_flush(inode->i_mapping);
38 EXT3_I(inode)->i_state &= ~EXT3_STATE_FLUSH_ON_CLOSE; 39 ext3_clear_inode_state(inode, EXT3_STATE_FLUSH_ON_CLOSE);
39 } 40 }
40 /* if we are the last writer on the inode, drop the block reservation */ 41 /* if we are the last writer on the inode, drop the block reservation */
41 if ((filp->f_mode & FMODE_WRITE) && 42 if ((filp->f_mode & FMODE_WRITE) &&
@@ -62,7 +63,7 @@ const struct file_operations ext3_file_operations = {
62 .compat_ioctl = ext3_compat_ioctl, 63 .compat_ioctl = ext3_compat_ioctl,
63#endif 64#endif
64 .mmap = generic_file_mmap, 65 .mmap = generic_file_mmap,
65 .open = generic_file_open, 66 .open = dquot_file_open,
66 .release = ext3_release_file, 67 .release = ext3_release_file,
67 .fsync = ext3_sync_file, 68 .fsync = ext3_sync_file,
68 .splice_read = generic_file_splice_read, 69 .splice_read = generic_file_splice_read,
diff --git a/fs/ext3/ialloc.c b/fs/ext3/ialloc.c
index b39991285136..ef9008b885b5 100644
--- a/fs/ext3/ialloc.c
+++ b/fs/ext3/ialloc.c
@@ -123,10 +123,10 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
123 * Note: we must free any quota before locking the superblock, 123 * Note: we must free any quota before locking the superblock,
124 * as writing the quota to disk may need the lock as well. 124 * as writing the quota to disk may need the lock as well.
125 */ 125 */
126 vfs_dq_init(inode); 126 dquot_initialize(inode);
127 ext3_xattr_delete_inode(handle, inode); 127 ext3_xattr_delete_inode(handle, inode);
128 vfs_dq_free_inode(inode); 128 dquot_free_inode(inode);
129 vfs_dq_drop(inode); 129 dquot_drop(inode);
130 130
131 is_directory = S_ISDIR(inode->i_mode); 131 is_directory = S_ISDIR(inode->i_mode);
132 132
@@ -588,10 +588,10 @@ got:
588 sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0; 588 sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0;
589 589
590 ret = inode; 590 ret = inode;
591 if (vfs_dq_alloc_inode(inode)) { 591 dquot_initialize(inode);
592 err = -EDQUOT; 592 err = dquot_alloc_inode(inode);
593 if (err)
593 goto fail_drop; 594 goto fail_drop;
594 }
595 595
596 err = ext3_init_acl(handle, inode, dir); 596 err = ext3_init_acl(handle, inode, dir);
597 if (err) 597 if (err)
@@ -619,10 +619,10 @@ really_out:
619 return ret; 619 return ret;
620 620
621fail_free_drop: 621fail_free_drop:
622 vfs_dq_free_inode(inode); 622 dquot_free_inode(inode);
623 623
624fail_drop: 624fail_drop:
625 vfs_dq_drop(inode); 625 dquot_drop(inode);
626 inode->i_flags |= S_NOQUOTA; 626 inode->i_flags |= S_NOQUOTA;
627 inode->i_nlink = 0; 627 inode->i_nlink = 0;
628 unlock_new_inode(inode); 628 unlock_new_inode(inode);
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 7aca55fcc976..7f920b7263a4 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -196,6 +196,9 @@ void ext3_delete_inode (struct inode * inode)
196{ 196{
197 handle_t *handle; 197 handle_t *handle;
198 198
199 if (!is_bad_inode(inode))
200 dquot_initialize(inode);
201
199 truncate_inode_pages(&inode->i_data, 0); 202 truncate_inode_pages(&inode->i_data, 0);
200 203
201 if (is_bad_inode(inode)) 204 if (is_bad_inode(inode))
@@ -1378,7 +1381,7 @@ static int ext3_journalled_write_end(struct file *file,
1378 */ 1381 */
1379 if (pos + len > inode->i_size && ext3_can_truncate(inode)) 1382 if (pos + len > inode->i_size && ext3_can_truncate(inode))
1380 ext3_orphan_add(handle, inode); 1383 ext3_orphan_add(handle, inode);
1381 EXT3_I(inode)->i_state |= EXT3_STATE_JDATA; 1384 ext3_set_inode_state(inode, EXT3_STATE_JDATA);
1382 if (inode->i_size > EXT3_I(inode)->i_disksize) { 1385 if (inode->i_size > EXT3_I(inode)->i_disksize) {
1383 EXT3_I(inode)->i_disksize = inode->i_size; 1386 EXT3_I(inode)->i_disksize = inode->i_size;
1384 ret2 = ext3_mark_inode_dirty(handle, inode); 1387 ret2 = ext3_mark_inode_dirty(handle, inode);
@@ -1417,7 +1420,7 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block)
1417 journal_t *journal; 1420 journal_t *journal;
1418 int err; 1421 int err;
1419 1422
1420 if (EXT3_I(inode)->i_state & EXT3_STATE_JDATA) { 1423 if (ext3_test_inode_state(inode, EXT3_STATE_JDATA)) {
1421 /* 1424 /*
1422 * This is a REALLY heavyweight approach, but the use of 1425 * This is a REALLY heavyweight approach, but the use of
1423 * bmap on dirty files is expected to be extremely rare: 1426 * bmap on dirty files is expected to be extremely rare:
@@ -1436,7 +1439,7 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block)
1436 * everything they get. 1439 * everything they get.
1437 */ 1440 */
1438 1441
1439 EXT3_I(inode)->i_state &= ~EXT3_STATE_JDATA; 1442 ext3_clear_inode_state(inode, EXT3_STATE_JDATA);
1440 journal = EXT3_JOURNAL(inode); 1443 journal = EXT3_JOURNAL(inode);
1441 journal_lock_updates(journal); 1444 journal_lock_updates(journal);
1442 err = journal_flush(journal); 1445 err = journal_flush(journal);
@@ -1528,6 +1531,7 @@ static int ext3_ordered_writepage(struct page *page,
1528 int err; 1531 int err;
1529 1532
1530 J_ASSERT(PageLocked(page)); 1533 J_ASSERT(PageLocked(page));
1534 WARN_ON_ONCE(IS_RDONLY(inode));
1531 1535
1532 /* 1536 /*
1533 * We give up here if we're reentered, because it might be for a 1537 * We give up here if we're reentered, because it might be for a
@@ -1600,6 +1604,9 @@ static int ext3_writeback_writepage(struct page *page,
1600 int ret = 0; 1604 int ret = 0;
1601 int err; 1605 int err;
1602 1606
1607 J_ASSERT(PageLocked(page));
1608 WARN_ON_ONCE(IS_RDONLY(inode));
1609
1603 if (ext3_journal_current_handle()) 1610 if (ext3_journal_current_handle())
1604 goto out_fail; 1611 goto out_fail;
1605 1612
@@ -1642,6 +1649,9 @@ static int ext3_journalled_writepage(struct page *page,
1642 int ret = 0; 1649 int ret = 0;
1643 int err; 1650 int err;
1644 1651
1652 J_ASSERT(PageLocked(page));
1653 WARN_ON_ONCE(IS_RDONLY(inode));
1654
1645 if (ext3_journal_current_handle()) 1655 if (ext3_journal_current_handle())
1646 goto no_write; 1656 goto no_write;
1647 1657
@@ -1670,7 +1680,7 @@ static int ext3_journalled_writepage(struct page *page,
1670 PAGE_CACHE_SIZE, NULL, write_end_fn); 1680 PAGE_CACHE_SIZE, NULL, write_end_fn);
1671 if (ret == 0) 1681 if (ret == 0)
1672 ret = err; 1682 ret = err;
1673 EXT3_I(inode)->i_state |= EXT3_STATE_JDATA; 1683 ext3_set_inode_state(inode, EXT3_STATE_JDATA);
1674 unlock_page(page); 1684 unlock_page(page);
1675 } else { 1685 } else {
1676 /* 1686 /*
@@ -1785,8 +1795,9 @@ retry:
1785 handle = ext3_journal_start(inode, 2); 1795 handle = ext3_journal_start(inode, 2);
1786 if (IS_ERR(handle)) { 1796 if (IS_ERR(handle)) {
1787 /* This is really bad luck. We've written the data 1797 /* This is really bad luck. We've written the data
1788 * but cannot extend i_size. Bail out and pretend 1798 * but cannot extend i_size. Truncate allocated blocks
1789 * the write failed... */ 1799 * and pretend the write failed... */
1800 ext3_truncate(inode);
1790 ret = PTR_ERR(handle); 1801 ret = PTR_ERR(handle);
1791 goto out; 1802 goto out;
1792 } 1803 }
@@ -2402,7 +2413,7 @@ void ext3_truncate(struct inode *inode)
2402 goto out_notrans; 2413 goto out_notrans;
2403 2414
2404 if (inode->i_size == 0 && ext3_should_writeback_data(inode)) 2415 if (inode->i_size == 0 && ext3_should_writeback_data(inode))
2405 ei->i_state |= EXT3_STATE_FLUSH_ON_CLOSE; 2416 ext3_set_inode_state(inode, EXT3_STATE_FLUSH_ON_CLOSE);
2406 2417
2407 /* 2418 /*
2408 * We have to lock the EOF page here, because lock_page() nests 2419 * We have to lock the EOF page here, because lock_page() nests
@@ -2721,7 +2732,7 @@ int ext3_get_inode_loc(struct inode *inode, struct ext3_iloc *iloc)
2721{ 2732{
2722 /* We have all inode data except xattrs in memory here. */ 2733 /* We have all inode data except xattrs in memory here. */
2723 return __ext3_get_inode_loc(inode, iloc, 2734 return __ext3_get_inode_loc(inode, iloc,
2724 !(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)); 2735 !ext3_test_inode_state(inode, EXT3_STATE_XATTR));
2725} 2736}
2726 2737
2727void ext3_set_inode_flags(struct inode *inode) 2738void ext3_set_inode_flags(struct inode *inode)
@@ -2893,7 +2904,7 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2893 EXT3_GOOD_OLD_INODE_SIZE + 2904 EXT3_GOOD_OLD_INODE_SIZE +
2894 ei->i_extra_isize; 2905 ei->i_extra_isize;
2895 if (*magic == cpu_to_le32(EXT3_XATTR_MAGIC)) 2906 if (*magic == cpu_to_le32(EXT3_XATTR_MAGIC))
2896 ei->i_state |= EXT3_STATE_XATTR; 2907 ext3_set_inode_state(inode, EXT3_STATE_XATTR);
2897 } 2908 }
2898 } else 2909 } else
2899 ei->i_extra_isize = 0; 2910 ei->i_extra_isize = 0;
@@ -2955,7 +2966,7 @@ again:
2955 2966
2956 /* For fields not not tracking in the in-memory inode, 2967 /* For fields not not tracking in the in-memory inode,
2957 * initialise them to zero for new inodes. */ 2968 * initialise them to zero for new inodes. */
2958 if (ei->i_state & EXT3_STATE_NEW) 2969 if (ext3_test_inode_state(inode, EXT3_STATE_NEW))
2959 memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); 2970 memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size);
2960 2971
2961 ext3_get_inode_flags(ei); 2972 ext3_get_inode_flags(ei);
@@ -3052,7 +3063,7 @@ again:
3052 rc = ext3_journal_dirty_metadata(handle, bh); 3063 rc = ext3_journal_dirty_metadata(handle, bh);
3053 if (!err) 3064 if (!err)
3054 err = rc; 3065 err = rc;
3055 ei->i_state &= ~EXT3_STATE_NEW; 3066 ext3_clear_inode_state(inode, EXT3_STATE_NEW);
3056 3067
3057 atomic_set(&ei->i_sync_tid, handle->h_transaction->t_tid); 3068 atomic_set(&ei->i_sync_tid, handle->h_transaction->t_tid);
3058out_brelse: 3069out_brelse:
@@ -3140,6 +3151,8 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
3140 if (error) 3151 if (error)
3141 return error; 3152 return error;
3142 3153
3154 if (ia_valid & ATTR_SIZE)
3155 dquot_initialize(inode);
3143 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || 3156 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3144 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) { 3157 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3145 handle_t *handle; 3158 handle_t *handle;
@@ -3152,7 +3165,7 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
3152 error = PTR_ERR(handle); 3165 error = PTR_ERR(handle);
3153 goto err_out; 3166 goto err_out;
3154 } 3167 }
3155 error = vfs_dq_transfer(inode, attr) ? -EDQUOT : 0; 3168 error = dquot_transfer(inode, attr);
3156 if (error) { 3169 if (error) {
3157 ext3_journal_stop(handle); 3170 ext3_journal_stop(handle);
3158 return error; 3171 return error;
@@ -3237,7 +3250,7 @@ static int ext3_writepage_trans_blocks(struct inode *inode)
3237 ret = 2 * (bpp + indirects) + 2; 3250 ret = 2 * (bpp + indirects) + 2;
3238 3251
3239#ifdef CONFIG_QUOTA 3252#ifdef CONFIG_QUOTA
3240 /* We know that structure was already allocated during vfs_dq_init so 3253 /* We know that structure was already allocated during dquot_initialize so
3241 * we will be updating only the data blocks + inodes */ 3254 * we will be updating only the data blocks + inodes */
3242 ret += EXT3_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb); 3255 ret += EXT3_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb);
3243#endif 3256#endif
@@ -3328,7 +3341,7 @@ int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode)
3328 * i_size has been changed by generic_commit_write() and we thus need 3341 * i_size has been changed by generic_commit_write() and we thus need
3329 * to include the updated inode in the current transaction. 3342 * to include the updated inode in the current transaction.
3330 * 3343 *
3331 * Also, vfs_dq_alloc_space() will always dirty the inode when blocks 3344 * Also, dquot_alloc_space() will always dirty the inode when blocks
3332 * are allocated to the file. 3345 * are allocated to the file.
3333 * 3346 *
3334 * If the inode is marked synchronous, we don't honour that here - doing 3347 * If the inode is marked synchronous, we don't honour that here - doing
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index 7b0e44f7d66f..ee184084ca42 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -1696,6 +1696,8 @@ static int ext3_create (struct inode * dir, struct dentry * dentry, int mode,
1696 struct inode * inode; 1696 struct inode * inode;
1697 int err, retries = 0; 1697 int err, retries = 0;
1698 1698
1699 dquot_initialize(dir);
1700
1699retry: 1701retry:
1700 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 1702 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) +
1701 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1703 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 +
@@ -1730,6 +1732,8 @@ static int ext3_mknod (struct inode * dir, struct dentry *dentry,
1730 if (!new_valid_dev(rdev)) 1732 if (!new_valid_dev(rdev))
1731 return -EINVAL; 1733 return -EINVAL;
1732 1734
1735 dquot_initialize(dir);
1736
1733retry: 1737retry:
1734 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 1738 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) +
1735 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1739 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 +
@@ -1766,6 +1770,8 @@ static int ext3_mkdir(struct inode * dir, struct dentry * dentry, int mode)
1766 if (dir->i_nlink >= EXT3_LINK_MAX) 1770 if (dir->i_nlink >= EXT3_LINK_MAX)
1767 return -EMLINK; 1771 return -EMLINK;
1768 1772
1773 dquot_initialize(dir);
1774
1769retry: 1775retry:
1770 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 1776 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) +
1771 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1777 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 +
@@ -2060,7 +2066,9 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry)
2060 2066
2061 /* Initialize quotas before so that eventual writes go in 2067 /* Initialize quotas before so that eventual writes go in
2062 * separate transaction */ 2068 * separate transaction */
2063 vfs_dq_init(dentry->d_inode); 2069 dquot_initialize(dir);
2070 dquot_initialize(dentry->d_inode);
2071
2064 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb)); 2072 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb));
2065 if (IS_ERR(handle)) 2073 if (IS_ERR(handle))
2066 return PTR_ERR(handle); 2074 return PTR_ERR(handle);
@@ -2119,7 +2127,9 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry)
2119 2127
2120 /* Initialize quotas before so that eventual writes go 2128 /* Initialize quotas before so that eventual writes go
2121 * in separate transaction */ 2129 * in separate transaction */
2122 vfs_dq_init(dentry->d_inode); 2130 dquot_initialize(dir);
2131 dquot_initialize(dentry->d_inode);
2132
2123 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb)); 2133 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb));
2124 if (IS_ERR(handle)) 2134 if (IS_ERR(handle))
2125 return PTR_ERR(handle); 2135 return PTR_ERR(handle);
@@ -2174,6 +2184,8 @@ static int ext3_symlink (struct inode * dir,
2174 if (l > dir->i_sb->s_blocksize) 2184 if (l > dir->i_sb->s_blocksize)
2175 return -ENAMETOOLONG; 2185 return -ENAMETOOLONG;
2176 2186
2187 dquot_initialize(dir);
2188
2177retry: 2189retry:
2178 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 2190 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) +
2179 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 5 + 2191 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 5 +
@@ -2228,6 +2240,9 @@ static int ext3_link (struct dentry * old_dentry,
2228 2240
2229 if (inode->i_nlink >= EXT3_LINK_MAX) 2241 if (inode->i_nlink >= EXT3_LINK_MAX)
2230 return -EMLINK; 2242 return -EMLINK;
2243
2244 dquot_initialize(dir);
2245
2231 /* 2246 /*
2232 * Return -ENOENT if we've raced with unlink and i_nlink is 0. Doing 2247 * Return -ENOENT if we've raced with unlink and i_nlink is 0. Doing
2233 * otherwise has the potential to corrupt the orphan inode list. 2248 * otherwise has the potential to corrupt the orphan inode list.
@@ -2278,12 +2293,15 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2278 struct ext3_dir_entry_2 * old_de, * new_de; 2293 struct ext3_dir_entry_2 * old_de, * new_de;
2279 int retval, flush_file = 0; 2294 int retval, flush_file = 0;
2280 2295
2296 dquot_initialize(old_dir);
2297 dquot_initialize(new_dir);
2298
2281 old_bh = new_bh = dir_bh = NULL; 2299 old_bh = new_bh = dir_bh = NULL;
2282 2300
2283 /* Initialize quotas before so that eventual writes go 2301 /* Initialize quotas before so that eventual writes go
2284 * in separate transaction */ 2302 * in separate transaction */
2285 if (new_dentry->d_inode) 2303 if (new_dentry->d_inode)
2286 vfs_dq_init(new_dentry->d_inode); 2304 dquot_initialize(new_dentry->d_inode);
2287 handle = ext3_journal_start(old_dir, 2 * 2305 handle = ext3_journal_start(old_dir, 2 *
2288 EXT3_DATA_TRANS_BLOCKS(old_dir->i_sb) + 2306 EXT3_DATA_TRANS_BLOCKS(old_dir->i_sb) +
2289 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 2); 2307 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 2);
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index afa2b569da10..e844accbf55d 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -181,7 +181,7 @@ static void ext3_handle_error(struct super_block *sb)
181 if (!test_opt (sb, ERRORS_CONT)) { 181 if (!test_opt (sb, ERRORS_CONT)) {
182 journal_t *journal = EXT3_SB(sb)->s_journal; 182 journal_t *journal = EXT3_SB(sb)->s_journal;
183 183
184 EXT3_SB(sb)->s_mount_opt |= EXT3_MOUNT_ABORT; 184 set_opt(EXT3_SB(sb)->s_mount_opt, ABORT);
185 if (journal) 185 if (journal)
186 journal_abort(journal, -EIO); 186 journal_abort(journal, -EIO);
187 } 187 }
@@ -296,7 +296,7 @@ void ext3_abort (struct super_block * sb, const char * function,
296 "error: remounting filesystem read-only"); 296 "error: remounting filesystem read-only");
297 EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; 297 EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS;
298 sb->s_flags |= MS_RDONLY; 298 sb->s_flags |= MS_RDONLY;
299 EXT3_SB(sb)->s_mount_opt |= EXT3_MOUNT_ABORT; 299 set_opt(EXT3_SB(sb)->s_mount_opt, ABORT);
300 if (EXT3_SB(sb)->s_journal) 300 if (EXT3_SB(sb)->s_journal)
301 journal_abort(EXT3_SB(sb)->s_journal, -EIO); 301 journal_abort(EXT3_SB(sb)->s_journal, -EIO);
302} 302}
@@ -528,6 +528,8 @@ static void destroy_inodecache(void)
528static void ext3_clear_inode(struct inode *inode) 528static void ext3_clear_inode(struct inode *inode)
529{ 529{
530 struct ext3_block_alloc_info *rsv = EXT3_I(inode)->i_block_alloc_info; 530 struct ext3_block_alloc_info *rsv = EXT3_I(inode)->i_block_alloc_info;
531
532 dquot_drop(inode);
531 ext3_discard_reservation(inode); 533 ext3_discard_reservation(inode);
532 EXT3_I(inode)->i_block_alloc_info = NULL; 534 EXT3_I(inode)->i_block_alloc_info = NULL;
533 if (unlikely(rsv)) 535 if (unlikely(rsv))
@@ -562,10 +564,10 @@ static inline void ext3_show_quota_options(struct seq_file *seq, struct super_bl
562 if (sbi->s_qf_names[GRPQUOTA]) 564 if (sbi->s_qf_names[GRPQUOTA])
563 seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]); 565 seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]);
564 566
565 if (sbi->s_mount_opt & EXT3_MOUNT_USRQUOTA) 567 if (test_opt(sb, USRQUOTA))
566 seq_puts(seq, ",usrquota"); 568 seq_puts(seq, ",usrquota");
567 569
568 if (sbi->s_mount_opt & EXT3_MOUNT_GRPQUOTA) 570 if (test_opt(sb, GRPQUOTA))
569 seq_puts(seq, ",grpquota"); 571 seq_puts(seq, ",grpquota");
570#endif 572#endif
571} 573}
@@ -656,8 +658,7 @@ static int ext3_show_options(struct seq_file *seq, struct vfsmount *vfs)
656 if (test_opt(sb, NOBH)) 658 if (test_opt(sb, NOBH))
657 seq_puts(seq, ",nobh"); 659 seq_puts(seq, ",nobh");
658 660
659 seq_printf(seq, ",data=%s", data_mode_string(sbi->s_mount_opt & 661 seq_printf(seq, ",data=%s", data_mode_string(test_opt(sb, DATA_FLAGS)));
660 EXT3_MOUNT_DATA_FLAGS));
661 if (test_opt(sb, DATA_ERR_ABORT)) 662 if (test_opt(sb, DATA_ERR_ABORT))
662 seq_puts(seq, ",data_err=abort"); 663 seq_puts(seq, ",data_err=abort");
663 664
@@ -751,13 +752,6 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
751 const char *data, size_t len, loff_t off); 752 const char *data, size_t len, loff_t off);
752 753
753static const struct dquot_operations ext3_quota_operations = { 754static const struct dquot_operations ext3_quota_operations = {
754 .initialize = dquot_initialize,
755 .drop = dquot_drop,
756 .alloc_space = dquot_alloc_space,
757 .alloc_inode = dquot_alloc_inode,
758 .free_space = dquot_free_space,
759 .free_inode = dquot_free_inode,
760 .transfer = dquot_transfer,
761 .write_dquot = ext3_write_dquot, 755 .write_dquot = ext3_write_dquot,
762 .acquire_dquot = ext3_acquire_dquot, 756 .acquire_dquot = ext3_acquire_dquot,
763 .release_dquot = ext3_release_dquot, 757 .release_dquot = ext3_release_dquot,
@@ -896,6 +890,63 @@ static ext3_fsblk_t get_sb_block(void **data, struct super_block *sb)
896 return sb_block; 890 return sb_block;
897} 891}
898 892
893#ifdef CONFIG_QUOTA
894static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
895{
896 struct ext3_sb_info *sbi = EXT3_SB(sb);
897 char *qname;
898
899 if (sb_any_quota_loaded(sb) &&
900 !sbi->s_qf_names[qtype]) {
901 ext3_msg(sb, KERN_ERR,
902 "Cannot change journaled "
903 "quota options when quota turned on");
904 return 0;
905 }
906 qname = match_strdup(args);
907 if (!qname) {
908 ext3_msg(sb, KERN_ERR,
909 "Not enough memory for storing quotafile name");
910 return 0;
911 }
912 if (sbi->s_qf_names[qtype] &&
913 strcmp(sbi->s_qf_names[qtype], qname)) {
914 ext3_msg(sb, KERN_ERR,
915 "%s quota file already specified", QTYPE2NAME(qtype));
916 kfree(qname);
917 return 0;
918 }
919 sbi->s_qf_names[qtype] = qname;
920 if (strchr(sbi->s_qf_names[qtype], '/')) {
921 ext3_msg(sb, KERN_ERR,
922 "quotafile must be on filesystem root");
923 kfree(sbi->s_qf_names[qtype]);
924 sbi->s_qf_names[qtype] = NULL;
925 return 0;
926 }
927 set_opt(sbi->s_mount_opt, QUOTA);
928 return 1;
929}
930
931static int clear_qf_name(struct super_block *sb, int qtype) {
932
933 struct ext3_sb_info *sbi = EXT3_SB(sb);
934
935 if (sb_any_quota_loaded(sb) &&
936 sbi->s_qf_names[qtype]) {
937 ext3_msg(sb, KERN_ERR, "Cannot change journaled quota options"
938 " when quota turned on");
939 return 0;
940 }
941 /*
942 * The space will be released later when all options are confirmed
943 * to be correct
944 */
945 sbi->s_qf_names[qtype] = NULL;
946 return 1;
947}
948#endif
949
899static int parse_options (char *options, struct super_block *sb, 950static int parse_options (char *options, struct super_block *sb,
900 unsigned int *inum, unsigned long *journal_devnum, 951 unsigned int *inum, unsigned long *journal_devnum,
901 ext3_fsblk_t *n_blocks_count, int is_remount) 952 ext3_fsblk_t *n_blocks_count, int is_remount)
@@ -906,8 +957,7 @@ static int parse_options (char *options, struct super_block *sb,
906 int data_opt = 0; 957 int data_opt = 0;
907 int option; 958 int option;
908#ifdef CONFIG_QUOTA 959#ifdef CONFIG_QUOTA
909 int qtype, qfmt; 960 int qfmt;
910 char *qname;
911#endif 961#endif
912 962
913 if (!options) 963 if (!options)
@@ -1065,20 +1115,19 @@ static int parse_options (char *options, struct super_block *sb,
1065 data_opt = EXT3_MOUNT_WRITEBACK_DATA; 1115 data_opt = EXT3_MOUNT_WRITEBACK_DATA;
1066 datacheck: 1116 datacheck:
1067 if (is_remount) { 1117 if (is_remount) {
1068 if ((sbi->s_mount_opt & EXT3_MOUNT_DATA_FLAGS) 1118 if (test_opt(sb, DATA_FLAGS) == data_opt)
1069 == data_opt)
1070 break; 1119 break;
1071 ext3_msg(sb, KERN_ERR, 1120 ext3_msg(sb, KERN_ERR,
1072 "error: cannot change " 1121 "error: cannot change "
1073 "data mode on remount. The filesystem " 1122 "data mode on remount. The filesystem "
1074 "is mounted in data=%s mode and you " 1123 "is mounted in data=%s mode and you "
1075 "try to remount it in data=%s mode.", 1124 "try to remount it in data=%s mode.",
1076 data_mode_string(sbi->s_mount_opt & 1125 data_mode_string(test_opt(sb,
1077 EXT3_MOUNT_DATA_FLAGS), 1126 DATA_FLAGS)),
1078 data_mode_string(data_opt)); 1127 data_mode_string(data_opt));
1079 return 0; 1128 return 0;
1080 } else { 1129 } else {
1081 sbi->s_mount_opt &= ~EXT3_MOUNT_DATA_FLAGS; 1130 clear_opt(sbi->s_mount_opt, DATA_FLAGS);
1082 sbi->s_mount_opt |= data_opt; 1131 sbi->s_mount_opt |= data_opt;
1083 } 1132 }
1084 break; 1133 break;
@@ -1090,62 +1139,20 @@ static int parse_options (char *options, struct super_block *sb,
1090 break; 1139 break;
1091#ifdef CONFIG_QUOTA 1140#ifdef CONFIG_QUOTA
1092 case Opt_usrjquota: 1141 case Opt_usrjquota:
1093 qtype = USRQUOTA; 1142 if (!set_qf_name(sb, USRQUOTA, &args[0]))
1094 goto set_qf_name;
1095 case Opt_grpjquota:
1096 qtype = GRPQUOTA;
1097set_qf_name:
1098 if (sb_any_quota_loaded(sb) &&
1099 !sbi->s_qf_names[qtype]) {
1100 ext3_msg(sb, KERN_ERR,
1101 "error: cannot change journaled "
1102 "quota options when quota turned on.");
1103 return 0;
1104 }
1105 qname = match_strdup(&args[0]);
1106 if (!qname) {
1107 ext3_msg(sb, KERN_ERR,
1108 "error: not enough memory for "
1109 "storing quotafile name.");
1110 return 0; 1143 return 0;
1111 } 1144 break;
1112 if (sbi->s_qf_names[qtype] && 1145 case Opt_grpjquota:
1113 strcmp(sbi->s_qf_names[qtype], qname)) { 1146 if (!set_qf_name(sb, GRPQUOTA, &args[0]))
1114 ext3_msg(sb, KERN_ERR,
1115 "error: %s quota file already "
1116 "specified.", QTYPE2NAME(qtype));
1117 kfree(qname);
1118 return 0;
1119 }
1120 sbi->s_qf_names[qtype] = qname;
1121 if (strchr(sbi->s_qf_names[qtype], '/')) {
1122 ext3_msg(sb, KERN_ERR,
1123 "error: quotafile must be on "
1124 "filesystem root.");
1125 kfree(sbi->s_qf_names[qtype]);
1126 sbi->s_qf_names[qtype] = NULL;
1127 return 0; 1147 return 0;
1128 }
1129 set_opt(sbi->s_mount_opt, QUOTA);
1130 break; 1148 break;
1131 case Opt_offusrjquota: 1149 case Opt_offusrjquota:
1132 qtype = USRQUOTA; 1150 if (!clear_qf_name(sb, USRQUOTA))
1133 goto clear_qf_name; 1151 return 0;
1152 break;
1134 case Opt_offgrpjquota: 1153 case Opt_offgrpjquota:
1135 qtype = GRPQUOTA; 1154 if (!clear_qf_name(sb, GRPQUOTA))
1136clear_qf_name:
1137 if (sb_any_quota_loaded(sb) &&
1138 sbi->s_qf_names[qtype]) {
1139 ext3_msg(sb, KERN_ERR, "error: cannot change "
1140 "journaled quota options when "
1141 "quota turned on.");
1142 return 0; 1155 return 0;
1143 }
1144 /*
1145 * The space will be released later when all options
1146 * are confirmed to be correct
1147 */
1148 sbi->s_qf_names[qtype] = NULL;
1149 break; 1156 break;
1150 case Opt_jqfmt_vfsold: 1157 case Opt_jqfmt_vfsold:
1151 qfmt = QFMT_VFS_OLD; 1158 qfmt = QFMT_VFS_OLD;
@@ -1244,18 +1251,12 @@ set_qf_format:
1244 } 1251 }
1245#ifdef CONFIG_QUOTA 1252#ifdef CONFIG_QUOTA
1246 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { 1253 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
1247 if ((sbi->s_mount_opt & EXT3_MOUNT_USRQUOTA) && 1254 if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA])
1248 sbi->s_qf_names[USRQUOTA])
1249 clear_opt(sbi->s_mount_opt, USRQUOTA); 1255 clear_opt(sbi->s_mount_opt, USRQUOTA);
1250 1256 if (test_opt(sb, GRPQUOTA) && sbi->s_qf_names[GRPQUOTA])
1251 if ((sbi->s_mount_opt & EXT3_MOUNT_GRPQUOTA) &&
1252 sbi->s_qf_names[GRPQUOTA])
1253 clear_opt(sbi->s_mount_opt, GRPQUOTA); 1257 clear_opt(sbi->s_mount_opt, GRPQUOTA);
1254 1258
1255 if ((sbi->s_qf_names[USRQUOTA] && 1259 if (test_opt(sb, GRPQUOTA) || test_opt(sb, USRQUOTA)) {
1256 (sbi->s_mount_opt & EXT3_MOUNT_GRPQUOTA)) ||
1257 (sbi->s_qf_names[GRPQUOTA] &&
1258 (sbi->s_mount_opt & EXT3_MOUNT_USRQUOTA))) {
1259 ext3_msg(sb, KERN_ERR, "error: old and new quota " 1260 ext3_msg(sb, KERN_ERR, "error: old and new quota "
1260 "format mixing."); 1261 "format mixing.");
1261 return 0; 1262 return 0;
@@ -1478,7 +1479,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1478 } 1479 }
1479 1480
1480 list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan); 1481 list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan);
1481 vfs_dq_init(inode); 1482 dquot_initialize(inode);
1482 if (inode->i_nlink) { 1483 if (inode->i_nlink) {
1483 printk(KERN_DEBUG 1484 printk(KERN_DEBUG
1484 "%s: truncating inode %lu to %Ld bytes\n", 1485 "%s: truncating inode %lu to %Ld bytes\n",
@@ -1671,11 +1672,11 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1671 set_opt(sbi->s_mount_opt, POSIX_ACL); 1672 set_opt(sbi->s_mount_opt, POSIX_ACL);
1672#endif 1673#endif
1673 if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_DATA) 1674 if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_DATA)
1674 sbi->s_mount_opt |= EXT3_MOUNT_JOURNAL_DATA; 1675 set_opt(sbi->s_mount_opt, JOURNAL_DATA);
1675 else if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_ORDERED) 1676 else if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_ORDERED)
1676 sbi->s_mount_opt |= EXT3_MOUNT_ORDERED_DATA; 1677 set_opt(sbi->s_mount_opt, ORDERED_DATA);
1677 else if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_WBACK) 1678 else if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_WBACK)
1678 sbi->s_mount_opt |= EXT3_MOUNT_WRITEBACK_DATA; 1679 set_opt(sbi->s_mount_opt, WRITEBACK_DATA);
1679 1680
1680 if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_PANIC) 1681 if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_PANIC)
1681 set_opt(sbi->s_mount_opt, ERRORS_PANIC); 1682 set_opt(sbi->s_mount_opt, ERRORS_PANIC);
@@ -1694,7 +1695,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1694 goto failed_mount; 1695 goto failed_mount;
1695 1696
1696 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 1697 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1697 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); 1698 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
1698 1699
1699 if (le32_to_cpu(es->s_rev_level) == EXT3_GOOD_OLD_REV && 1700 if (le32_to_cpu(es->s_rev_level) == EXT3_GOOD_OLD_REV &&
1700 (EXT3_HAS_COMPAT_FEATURE(sb, ~0U) || 1701 (EXT3_HAS_COMPAT_FEATURE(sb, ~0U) ||
@@ -2561,11 +2562,11 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2561 goto restore_opts; 2562 goto restore_opts;
2562 } 2563 }
2563 2564
2564 if (sbi->s_mount_opt & EXT3_MOUNT_ABORT) 2565 if (test_opt(sb, ABORT))
2565 ext3_abort(sb, __func__, "Abort forced by user"); 2566 ext3_abort(sb, __func__, "Abort forced by user");
2566 2567
2567 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 2568 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2568 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); 2569 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2569 2570
2570 es = sbi->s_es; 2571 es = sbi->s_es;
2571 2572
@@ -2573,7 +2574,7 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2573 2574
2574 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || 2575 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) ||
2575 n_blocks_count > le32_to_cpu(es->s_blocks_count)) { 2576 n_blocks_count > le32_to_cpu(es->s_blocks_count)) {
2576 if (sbi->s_mount_opt & EXT3_MOUNT_ABORT) { 2577 if (test_opt(sb, ABORT)) {
2577 err = -EROFS; 2578 err = -EROFS;
2578 goto restore_opts; 2579 goto restore_opts;
2579 } 2580 }
@@ -2734,7 +2735,7 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
2734 * Process 1 Process 2 2735 * Process 1 Process 2
2735 * ext3_create() quota_sync() 2736 * ext3_create() quota_sync()
2736 * journal_start() write_dquot() 2737 * journal_start() write_dquot()
2737 * vfs_dq_init() down(dqio_mutex) 2738 * dquot_initialize() down(dqio_mutex)
2738 * down(dqio_mutex) journal_start() 2739 * down(dqio_mutex) journal_start()
2739 * 2740 *
2740 */ 2741 */
@@ -2942,9 +2943,7 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
2942 sector_t blk = off >> EXT3_BLOCK_SIZE_BITS(sb); 2943 sector_t blk = off >> EXT3_BLOCK_SIZE_BITS(sb);
2943 int err = 0; 2944 int err = 0;
2944 int offset = off & (sb->s_blocksize - 1); 2945 int offset = off & (sb->s_blocksize - 1);
2945 int tocopy;
2946 int journal_quota = EXT3_SB(sb)->s_qf_names[type] != NULL; 2946 int journal_quota = EXT3_SB(sb)->s_qf_names[type] != NULL;
2947 size_t towrite = len;
2948 struct buffer_head *bh; 2947 struct buffer_head *bh;
2949 handle_t *handle = journal_current_handle(); 2948 handle_t *handle = journal_current_handle();
2950 2949
@@ -2955,53 +2954,54 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
2955 (unsigned long long)off, (unsigned long long)len); 2954 (unsigned long long)off, (unsigned long long)len);
2956 return -EIO; 2955 return -EIO;
2957 } 2956 }
2957
2958 /*
2959 * Since we account only one data block in transaction credits,
2960 * then it is impossible to cross a block boundary.
2961 */
2962 if (sb->s_blocksize - offset < len) {
2963 ext3_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)"
2964 " cancelled because not block aligned",
2965 (unsigned long long)off, (unsigned long long)len);
2966 return -EIO;
2967 }
2958 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); 2968 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
2959 while (towrite > 0) { 2969 bh = ext3_bread(handle, inode, blk, 1, &err);
2960 tocopy = sb->s_blocksize - offset < towrite ? 2970 if (!bh)
2961 sb->s_blocksize - offset : towrite; 2971 goto out;
2962 bh = ext3_bread(handle, inode, blk, 1, &err); 2972 if (journal_quota) {
2963 if (!bh) 2973 err = ext3_journal_get_write_access(handle, bh);
2974 if (err) {
2975 brelse(bh);
2964 goto out; 2976 goto out;
2965 if (journal_quota) {
2966 err = ext3_journal_get_write_access(handle, bh);
2967 if (err) {
2968 brelse(bh);
2969 goto out;
2970 }
2971 }
2972 lock_buffer(bh);
2973 memcpy(bh->b_data+offset, data, tocopy);
2974 flush_dcache_page(bh->b_page);
2975 unlock_buffer(bh);
2976 if (journal_quota)
2977 err = ext3_journal_dirty_metadata(handle, bh);
2978 else {
2979 /* Always do at least ordered writes for quotas */
2980 err = ext3_journal_dirty_data(handle, bh);
2981 mark_buffer_dirty(bh);
2982 } 2977 }
2983 brelse(bh);
2984 if (err)
2985 goto out;
2986 offset = 0;
2987 towrite -= tocopy;
2988 data += tocopy;
2989 blk++;
2990 } 2978 }
2979 lock_buffer(bh);
2980 memcpy(bh->b_data+offset, data, len);
2981 flush_dcache_page(bh->b_page);
2982 unlock_buffer(bh);
2983 if (journal_quota)
2984 err = ext3_journal_dirty_metadata(handle, bh);
2985 else {
2986 /* Always do at least ordered writes for quotas */
2987 err = ext3_journal_dirty_data(handle, bh);
2988 mark_buffer_dirty(bh);
2989 }
2990 brelse(bh);
2991out: 2991out:
2992 if (len == towrite) { 2992 if (err) {
2993 mutex_unlock(&inode->i_mutex); 2993 mutex_unlock(&inode->i_mutex);
2994 return err; 2994 return err;
2995 } 2995 }
2996 if (inode->i_size < off+len-towrite) { 2996 if (inode->i_size < off + len) {
2997 i_size_write(inode, off+len-towrite); 2997 i_size_write(inode, off + len);
2998 EXT3_I(inode)->i_disksize = inode->i_size; 2998 EXT3_I(inode)->i_disksize = inode->i_size;
2999 } 2999 }
3000 inode->i_version++; 3000 inode->i_version++;
3001 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 3001 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
3002 ext3_mark_inode_dirty(handle, inode); 3002 ext3_mark_inode_dirty(handle, inode);
3003 mutex_unlock(&inode->i_mutex); 3003 mutex_unlock(&inode->i_mutex);
3004 return len - towrite; 3004 return len;
3005} 3005}
3006 3006
3007#endif 3007#endif
diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
index 66895ccf76c7..534a94c3a933 100644
--- a/fs/ext3/xattr.c
+++ b/fs/ext3/xattr.c
@@ -274,7 +274,7 @@ ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
274 void *end; 274 void *end;
275 int error; 275 int error;
276 276
277 if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)) 277 if (!ext3_test_inode_state(inode, EXT3_STATE_XATTR))
278 return -ENODATA; 278 return -ENODATA;
279 error = ext3_get_inode_loc(inode, &iloc); 279 error = ext3_get_inode_loc(inode, &iloc);
280 if (error) 280 if (error)
@@ -403,7 +403,7 @@ ext3_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size)
403 void *end; 403 void *end;
404 int error; 404 int error;
405 405
406 if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)) 406 if (!ext3_test_inode_state(inode, EXT3_STATE_XATTR))
407 return 0; 407 return 0;
408 error = ext3_get_inode_loc(inode, &iloc); 408 error = ext3_get_inode_loc(inode, &iloc);
409 if (error) 409 if (error)
@@ -500,7 +500,7 @@ ext3_xattr_release_block(handle_t *handle, struct inode *inode,
500 error = ext3_journal_dirty_metadata(handle, bh); 500 error = ext3_journal_dirty_metadata(handle, bh);
501 if (IS_SYNC(inode)) 501 if (IS_SYNC(inode))
502 handle->h_sync = 1; 502 handle->h_sync = 1;
503 vfs_dq_free_block(inode, 1); 503 dquot_free_block(inode, 1);
504 ea_bdebug(bh, "refcount now=%d; releasing", 504 ea_bdebug(bh, "refcount now=%d; releasing",
505 le32_to_cpu(BHDR(bh)->h_refcount)); 505 le32_to_cpu(BHDR(bh)->h_refcount));
506 if (ce) 506 if (ce)
@@ -775,8 +775,8 @@ inserted:
775 else { 775 else {
776 /* The old block is released after updating 776 /* The old block is released after updating
777 the inode. */ 777 the inode. */
778 error = -EDQUOT; 778 error = dquot_alloc_block(inode, 1);
779 if (vfs_dq_alloc_block(inode, 1)) 779 if (error)
780 goto cleanup; 780 goto cleanup;
781 error = ext3_journal_get_write_access(handle, 781 error = ext3_journal_get_write_access(handle,
782 new_bh); 782 new_bh);
@@ -850,7 +850,7 @@ cleanup:
850 return error; 850 return error;
851 851
852cleanup_dquot: 852cleanup_dquot:
853 vfs_dq_free_block(inode, 1); 853 dquot_free_block(inode, 1);
854 goto cleanup; 854 goto cleanup;
855 855
856bad_block: 856bad_block:
@@ -882,7 +882,7 @@ ext3_xattr_ibody_find(struct inode *inode, struct ext3_xattr_info *i,
882 is->s.base = is->s.first = IFIRST(header); 882 is->s.base = is->s.first = IFIRST(header);
883 is->s.here = is->s.first; 883 is->s.here = is->s.first;
884 is->s.end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; 884 is->s.end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;
885 if (EXT3_I(inode)->i_state & EXT3_STATE_XATTR) { 885 if (ext3_test_inode_state(inode, EXT3_STATE_XATTR)) {
886 error = ext3_xattr_check_names(IFIRST(header), is->s.end); 886 error = ext3_xattr_check_names(IFIRST(header), is->s.end);
887 if (error) 887 if (error)
888 return error; 888 return error;
@@ -914,10 +914,10 @@ ext3_xattr_ibody_set(handle_t *handle, struct inode *inode,
914 header = IHDR(inode, ext3_raw_inode(&is->iloc)); 914 header = IHDR(inode, ext3_raw_inode(&is->iloc));
915 if (!IS_LAST_ENTRY(s->first)) { 915 if (!IS_LAST_ENTRY(s->first)) {
916 header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC); 916 header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
917 EXT3_I(inode)->i_state |= EXT3_STATE_XATTR; 917 ext3_set_inode_state(inode, EXT3_STATE_XATTR);
918 } else { 918 } else {
919 header->h_magic = cpu_to_le32(0); 919 header->h_magic = cpu_to_le32(0);
920 EXT3_I(inode)->i_state &= ~EXT3_STATE_XATTR; 920 ext3_clear_inode_state(inode, EXT3_STATE_XATTR);
921 } 921 }
922 return 0; 922 return 0;
923} 923}
@@ -967,10 +967,10 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
967 if (error) 967 if (error)
968 goto cleanup; 968 goto cleanup;
969 969
970 if (EXT3_I(inode)->i_state & EXT3_STATE_NEW) { 970 if (ext3_test_inode_state(inode, EXT3_STATE_NEW)) {
971 struct ext3_inode *raw_inode = ext3_raw_inode(&is.iloc); 971 struct ext3_inode *raw_inode = ext3_raw_inode(&is.iloc);
972 memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); 972 memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size);
973 EXT3_I(inode)->i_state &= ~EXT3_STATE_NEW; 973 ext3_clear_inode_state(inode, EXT3_STATE_NEW);
974 } 974 }
975 975
976 error = ext3_xattr_ibody_find(inode, &i, &is); 976 error = ext3_xattr_ibody_find(inode, &i, &is);
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 503a48927402..d0776e410f34 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -23,6 +23,7 @@
23#include <linux/jbd2.h> 23#include <linux/jbd2.h>
24#include <linux/mount.h> 24#include <linux/mount.h>
25#include <linux/path.h> 25#include <linux/path.h>
26#include <linux/quotaops.h>
26#include "ext4.h" 27#include "ext4.h"
27#include "ext4_jbd2.h" 28#include "ext4_jbd2.h"
28#include "xattr.h" 29#include "xattr.h"
@@ -125,7 +126,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
125 sb->s_dirt = 1; 126 sb->s_dirt = 1;
126 } 127 }
127 } 128 }
128 return generic_file_open(inode, filp); 129 return dquot_file_open(inode, filp);
129} 130}
130 131
131const struct file_operations ext4_file_operations = { 132const struct file_operations ext4_file_operations = {
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 004c9da9e5c6..361c0b9962a8 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -214,10 +214,10 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
214 * Note: we must free any quota before locking the superblock, 214 * Note: we must free any quota before locking the superblock,
215 * as writing the quota to disk may need the lock as well. 215 * as writing the quota to disk may need the lock as well.
216 */ 216 */
217 vfs_dq_init(inode); 217 dquot_initialize(inode);
218 ext4_xattr_delete_inode(handle, inode); 218 ext4_xattr_delete_inode(handle, inode);
219 vfs_dq_free_inode(inode); 219 dquot_free_inode(inode);
220 vfs_dq_drop(inode); 220 dquot_drop(inode);
221 221
222 is_directory = S_ISDIR(inode->i_mode); 222 is_directory = S_ISDIR(inode->i_mode);
223 223
@@ -1029,10 +1029,10 @@ got:
1029 ei->i_extra_isize = EXT4_SB(sb)->s_want_extra_isize; 1029 ei->i_extra_isize = EXT4_SB(sb)->s_want_extra_isize;
1030 1030
1031 ret = inode; 1031 ret = inode;
1032 if (vfs_dq_alloc_inode(inode)) { 1032 dquot_initialize(inode);
1033 err = -EDQUOT; 1033 err = dquot_alloc_inode(inode);
1034 if (err)
1034 goto fail_drop; 1035 goto fail_drop;
1035 }
1036 1036
1037 err = ext4_init_acl(handle, inode, dir); 1037 err = ext4_init_acl(handle, inode, dir);
1038 if (err) 1038 if (err)
@@ -1069,10 +1069,10 @@ really_out:
1069 return ret; 1069 return ret;
1070 1070
1071fail_free_drop: 1071fail_free_drop:
1072 vfs_dq_free_inode(inode); 1072 dquot_free_inode(inode);
1073 1073
1074fail_drop: 1074fail_drop:
1075 vfs_dq_drop(inode); 1075 dquot_drop(inode);
1076 inode->i_flags |= S_NOQUOTA; 1076 inode->i_flags |= S_NOQUOTA;
1077 inode->i_nlink = 0; 1077 inode->i_nlink = 0;
1078 unlock_new_inode(inode); 1078 unlock_new_inode(inode);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index f977aade0d1b..986120f30066 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -171,6 +171,9 @@ void ext4_delete_inode(struct inode *inode)
171 handle_t *handle; 171 handle_t *handle;
172 int err; 172 int err;
173 173
174 if (!is_bad_inode(inode))
175 dquot_initialize(inode);
176
174 if (ext4_should_order_data(inode)) 177 if (ext4_should_order_data(inode))
175 ext4_begin_ordered_truncate(inode, 0); 178 ext4_begin_ordered_truncate(inode, 0);
176 truncate_inode_pages(&inode->i_data, 0); 179 truncate_inode_pages(&inode->i_data, 0);
@@ -1108,9 +1111,9 @@ void ext4_da_update_reserve_space(struct inode *inode,
1108 1111
1109 /* Update quota subsystem */ 1112 /* Update quota subsystem */
1110 if (quota_claim) { 1113 if (quota_claim) {
1111 vfs_dq_claim_block(inode, used); 1114 dquot_claim_block(inode, used);
1112 if (mdb_free) 1115 if (mdb_free)
1113 vfs_dq_release_reservation_block(inode, mdb_free); 1116 dquot_release_reservation_block(inode, mdb_free);
1114 } else { 1117 } else {
1115 /* 1118 /*
1116 * We did fallocate with an offset that is already delayed 1119 * We did fallocate with an offset that is already delayed
@@ -1121,8 +1124,8 @@ void ext4_da_update_reserve_space(struct inode *inode,
1121 * that 1124 * that
1122 */ 1125 */
1123 if (allocated_meta_blocks) 1126 if (allocated_meta_blocks)
1124 vfs_dq_claim_block(inode, allocated_meta_blocks); 1127 dquot_claim_block(inode, allocated_meta_blocks);
1125 vfs_dq_release_reservation_block(inode, mdb_free + used); 1128 dquot_release_reservation_block(inode, mdb_free + used);
1126 } 1129 }
1127 1130
1128 /* 1131 /*
@@ -1857,6 +1860,7 @@ static int ext4_da_reserve_space(struct inode *inode, sector_t lblock)
1857 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 1860 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
1858 struct ext4_inode_info *ei = EXT4_I(inode); 1861 struct ext4_inode_info *ei = EXT4_I(inode);
1859 unsigned long md_needed, md_reserved; 1862 unsigned long md_needed, md_reserved;
1863 int ret;
1860 1864
1861 /* 1865 /*
1862 * recalculate the amount of metadata blocks to reserve 1866 * recalculate the amount of metadata blocks to reserve
@@ -1875,11 +1879,12 @@ repeat:
1875 * later. Real quota accounting is done at pages writeout 1879 * later. Real quota accounting is done at pages writeout
1876 * time. 1880 * time.
1877 */ 1881 */
1878 if (vfs_dq_reserve_block(inode, md_needed + 1)) 1882 ret = dquot_reserve_block(inode, md_needed + 1);
1879 return -EDQUOT; 1883 if (ret)
1884 return ret;
1880 1885
1881 if (ext4_claim_free_blocks(sbi, md_needed + 1)) { 1886 if (ext4_claim_free_blocks(sbi, md_needed + 1)) {
1882 vfs_dq_release_reservation_block(inode, md_needed + 1); 1887 dquot_release_reservation_block(inode, md_needed + 1);
1883 if (ext4_should_retry_alloc(inode->i_sb, &retries)) { 1888 if (ext4_should_retry_alloc(inode->i_sb, &retries)) {
1884 yield(); 1889 yield();
1885 goto repeat; 1890 goto repeat;
@@ -1936,7 +1941,7 @@ static void ext4_da_release_space(struct inode *inode, int to_free)
1936 1941
1937 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1942 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
1938 1943
1939 vfs_dq_release_reservation_block(inode, to_free); 1944 dquot_release_reservation_block(inode, to_free);
1940} 1945}
1941 1946
1942static void ext4_da_page_release_reservation(struct page *page, 1947static void ext4_da_page_release_reservation(struct page *page,
@@ -5418,6 +5423,8 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
5418 if (error) 5423 if (error)
5419 return error; 5424 return error;
5420 5425
5426 if (ia_valid & ATTR_SIZE)
5427 dquot_initialize(inode);
5421 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || 5428 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
5422 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) { 5429 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
5423 handle_t *handle; 5430 handle_t *handle;
@@ -5430,7 +5437,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
5430 error = PTR_ERR(handle); 5437 error = PTR_ERR(handle);
5431 goto err_out; 5438 goto err_out;
5432 } 5439 }
5433 error = vfs_dq_transfer(inode, attr) ? -EDQUOT : 0; 5440 error = dquot_transfer(inode, attr);
5434 if (error) { 5441 if (error) {
5435 ext4_journal_stop(handle); 5442 ext4_journal_stop(handle);
5436 return error; 5443 return error;
@@ -5816,7 +5823,7 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode)
5816 * i_size has been changed by generic_commit_write() and we thus need 5823 * i_size has been changed by generic_commit_write() and we thus need
5817 * to include the updated inode in the current transaction. 5824 * to include the updated inode in the current transaction.
5818 * 5825 *
5819 * Also, vfs_dq_alloc_block() will always dirty the inode when blocks 5826 * Also, dquot_alloc_block() will always dirty the inode when blocks
5820 * are allocated to the file. 5827 * are allocated to the file.
5821 * 5828 *
5822 * If the inode is marked synchronous, we don't honour that here - doing 5829 * If the inode is marked synchronous, we don't honour that here - doing
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index abb11e328b65..506713a2ebd8 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4240,7 +4240,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4240 return 0; 4240 return 0;
4241 } 4241 }
4242 reserv_blks = ar->len; 4242 reserv_blks = ar->len;
4243 while (ar->len && vfs_dq_alloc_block(ar->inode, ar->len)) { 4243 while (ar->len && dquot_alloc_block(ar->inode, ar->len)) {
4244 ar->flags |= EXT4_MB_HINT_NOPREALLOC; 4244 ar->flags |= EXT4_MB_HINT_NOPREALLOC;
4245 ar->len--; 4245 ar->len--;
4246 } 4246 }
@@ -4317,7 +4317,7 @@ out2:
4317 kmem_cache_free(ext4_ac_cachep, ac); 4317 kmem_cache_free(ext4_ac_cachep, ac);
4318out1: 4318out1:
4319 if (inquota && ar->len < inquota) 4319 if (inquota && ar->len < inquota)
4320 vfs_dq_free_block(ar->inode, inquota - ar->len); 4320 dquot_free_block(ar->inode, inquota - ar->len);
4321out3: 4321out3:
4322 if (!ar->len) { 4322 if (!ar->len) {
4323 if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag) 4323 if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag)
@@ -4631,7 +4631,7 @@ do_more:
4631 sb->s_dirt = 1; 4631 sb->s_dirt = 1;
4632error_return: 4632error_return:
4633 if (freed) 4633 if (freed)
4634 vfs_dq_free_block(inode, freed); 4634 dquot_free_block(inode, freed);
4635 brelse(bitmap_bh); 4635 brelse(bitmap_bh);
4636 ext4_std_error(sb, err); 4636 ext4_std_error(sb, err);
4637 if (ac) 4637 if (ac)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 608d21f873ec..0c070fabd108 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1759,6 +1759,8 @@ static int ext4_create(struct inode *dir, struct dentry *dentry, int mode,
1759 struct inode *inode; 1759 struct inode *inode;
1760 int err, retries = 0; 1760 int err, retries = 0;
1761 1761
1762 dquot_initialize(dir);
1763
1762retry: 1764retry:
1763 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) + 1765 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1764 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1766 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
@@ -1793,6 +1795,8 @@ static int ext4_mknod(struct inode *dir, struct dentry *dentry,
1793 if (!new_valid_dev(rdev)) 1795 if (!new_valid_dev(rdev))
1794 return -EINVAL; 1796 return -EINVAL;
1795 1797
1798 dquot_initialize(dir);
1799
1796retry: 1800retry:
1797 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) + 1801 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1798 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1802 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
@@ -1830,6 +1834,8 @@ static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1830 if (EXT4_DIR_LINK_MAX(dir)) 1834 if (EXT4_DIR_LINK_MAX(dir))
1831 return -EMLINK; 1835 return -EMLINK;
1832 1836
1837 dquot_initialize(dir);
1838
1833retry: 1839retry:
1834 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) + 1840 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1835 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1841 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
@@ -2137,7 +2143,9 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
2137 2143
2138 /* Initialize quotas before so that eventual writes go in 2144 /* Initialize quotas before so that eventual writes go in
2139 * separate transaction */ 2145 * separate transaction */
2140 vfs_dq_init(dentry->d_inode); 2146 dquot_initialize(dir);
2147 dquot_initialize(dentry->d_inode);
2148
2141 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb)); 2149 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
2142 if (IS_ERR(handle)) 2150 if (IS_ERR(handle))
2143 return PTR_ERR(handle); 2151 return PTR_ERR(handle);
@@ -2196,7 +2204,9 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
2196 2204
2197 /* Initialize quotas before so that eventual writes go 2205 /* Initialize quotas before so that eventual writes go
2198 * in separate transaction */ 2206 * in separate transaction */
2199 vfs_dq_init(dentry->d_inode); 2207 dquot_initialize(dir);
2208 dquot_initialize(dentry->d_inode);
2209
2200 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb)); 2210 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
2201 if (IS_ERR(handle)) 2211 if (IS_ERR(handle))
2202 return PTR_ERR(handle); 2212 return PTR_ERR(handle);
@@ -2251,6 +2261,8 @@ static int ext4_symlink(struct inode *dir,
2251 if (l > dir->i_sb->s_blocksize) 2261 if (l > dir->i_sb->s_blocksize)
2252 return -ENAMETOOLONG; 2262 return -ENAMETOOLONG;
2253 2263
2264 dquot_initialize(dir);
2265
2254retry: 2266retry:
2255 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) + 2267 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
2256 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 5 + 2268 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 5 +
@@ -2309,6 +2321,8 @@ static int ext4_link(struct dentry *old_dentry,
2309 if (inode->i_nlink >= EXT4_LINK_MAX) 2321 if (inode->i_nlink >= EXT4_LINK_MAX)
2310 return -EMLINK; 2322 return -EMLINK;
2311 2323
2324 dquot_initialize(dir);
2325
2312 /* 2326 /*
2313 * Return -ENOENT if we've raced with unlink and i_nlink is 0. Doing 2327 * Return -ENOENT if we've raced with unlink and i_nlink is 0. Doing
2314 * otherwise has the potential to corrupt the orphan inode list. 2328 * otherwise has the potential to corrupt the orphan inode list.
@@ -2359,12 +2373,15 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
2359 struct ext4_dir_entry_2 *old_de, *new_de; 2373 struct ext4_dir_entry_2 *old_de, *new_de;
2360 int retval, force_da_alloc = 0; 2374 int retval, force_da_alloc = 0;
2361 2375
2376 dquot_initialize(old_dir);
2377 dquot_initialize(new_dir);
2378
2362 old_bh = new_bh = dir_bh = NULL; 2379 old_bh = new_bh = dir_bh = NULL;
2363 2380
2364 /* Initialize quotas before so that eventual writes go 2381 /* Initialize quotas before so that eventual writes go
2365 * in separate transaction */ 2382 * in separate transaction */
2366 if (new_dentry->d_inode) 2383 if (new_dentry->d_inode)
2367 vfs_dq_init(new_dentry->d_inode); 2384 dquot_initialize(new_dentry->d_inode);
2368 handle = ext4_journal_start(old_dir, 2 * 2385 handle = ext4_journal_start(old_dir, 2 *
2369 EXT4_DATA_TRANS_BLOCKS(old_dir->i_sb) + 2386 EXT4_DATA_TRANS_BLOCKS(old_dir->i_sb) +
2370 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 2); 2387 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 2);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index ad1ee5f21bab..2b83b96cb2eb 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -798,6 +798,7 @@ static void destroy_inodecache(void)
798 798
799static void ext4_clear_inode(struct inode *inode) 799static void ext4_clear_inode(struct inode *inode)
800{ 800{
801 dquot_drop(inode);
801 ext4_discard_preallocations(inode); 802 ext4_discard_preallocations(inode);
802 if (EXT4_JOURNAL(inode)) 803 if (EXT4_JOURNAL(inode))
803 jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal, 804 jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal,
@@ -1052,19 +1053,9 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
1052 const char *data, size_t len, loff_t off); 1053 const char *data, size_t len, loff_t off);
1053 1054
1054static const struct dquot_operations ext4_quota_operations = { 1055static const struct dquot_operations ext4_quota_operations = {
1055 .initialize = dquot_initialize,
1056 .drop = dquot_drop,
1057 .alloc_space = dquot_alloc_space,
1058 .reserve_space = dquot_reserve_space,
1059 .claim_space = dquot_claim_space,
1060 .release_rsv = dquot_release_reserved_space,
1061#ifdef CONFIG_QUOTA 1056#ifdef CONFIG_QUOTA
1062 .get_reserved_space = ext4_get_reserved_space, 1057 .get_reserved_space = ext4_get_reserved_space,
1063#endif 1058#endif
1064 .alloc_inode = dquot_alloc_inode,
1065 .free_space = dquot_free_space,
1066 .free_inode = dquot_free_inode,
1067 .transfer = dquot_transfer,
1068 .write_dquot = ext4_write_dquot, 1059 .write_dquot = ext4_write_dquot,
1069 .acquire_dquot = ext4_acquire_dquot, 1060 .acquire_dquot = ext4_acquire_dquot,
1070 .release_dquot = ext4_release_dquot, 1061 .release_dquot = ext4_release_dquot,
@@ -2014,7 +2005,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
2014 } 2005 }
2015 2006
2016 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan); 2007 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
2017 vfs_dq_init(inode); 2008 dquot_initialize(inode);
2018 if (inode->i_nlink) { 2009 if (inode->i_nlink) {
2019 ext4_msg(sb, KERN_DEBUG, 2010 ext4_msg(sb, KERN_DEBUG,
2020 "%s: truncating inode %lu to %lld bytes", 2011 "%s: truncating inode %lu to %lld bytes",
@@ -3801,7 +3792,7 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
3801 * Process 1 Process 2 3792 * Process 1 Process 2
3802 * ext4_create() quota_sync() 3793 * ext4_create() quota_sync()
3803 * jbd2_journal_start() write_dquot() 3794 * jbd2_journal_start() write_dquot()
3804 * vfs_dq_init() down(dqio_mutex) 3795 * dquot_initialize() down(dqio_mutex)
3805 * down(dqio_mutex) jbd2_journal_start() 3796 * down(dqio_mutex) jbd2_journal_start()
3806 * 3797 *
3807 */ 3798 */
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index efc16a4b7ceb..b4c5aa8489d8 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -495,7 +495,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,
495 error = ext4_handle_dirty_metadata(handle, inode, bh); 495 error = ext4_handle_dirty_metadata(handle, inode, bh);
496 if (IS_SYNC(inode)) 496 if (IS_SYNC(inode))
497 ext4_handle_sync(handle); 497 ext4_handle_sync(handle);
498 vfs_dq_free_block(inode, 1); 498 dquot_free_block(inode, 1);
499 ea_bdebug(bh, "refcount now=%d; releasing", 499 ea_bdebug(bh, "refcount now=%d; releasing",
500 le32_to_cpu(BHDR(bh)->h_refcount)); 500 le32_to_cpu(BHDR(bh)->h_refcount));
501 if (ce) 501 if (ce)
@@ -787,8 +787,8 @@ inserted:
787 else { 787 else {
788 /* The old block is released after updating 788 /* The old block is released after updating
789 the inode. */ 789 the inode. */
790 error = -EDQUOT; 790 error = dquot_alloc_block(inode, 1);
791 if (vfs_dq_alloc_block(inode, 1)) 791 if (error)
792 goto cleanup; 792 goto cleanup;
793 error = ext4_journal_get_write_access(handle, 793 error = ext4_journal_get_write_access(handle,
794 new_bh); 794 new_bh);
@@ -876,7 +876,7 @@ cleanup:
876 return error; 876 return error;
877 877
878cleanup_dquot: 878cleanup_dquot:
879 vfs_dq_free_block(inode, 1); 879 dquot_free_block(inode, 1);
880 goto cleanup; 880 goto cleanup;
881 881
882bad_block: 882bad_block:
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index e3bf6eab8750..6dbcbad6ab17 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -1083,7 +1083,7 @@ void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
1083 } 1083 }
1084} 1084}
1085 1085
1086int gfs2_quota_sync(struct super_block *sb, int type) 1086int gfs2_quota_sync(struct super_block *sb, int type, int wait)
1087{ 1087{
1088 struct gfs2_sbd *sdp = sb->s_fs_info; 1088 struct gfs2_sbd *sdp = sb->s_fs_info;
1089 struct gfs2_quota_data **qda; 1089 struct gfs2_quota_data **qda;
@@ -1127,6 +1127,11 @@ int gfs2_quota_sync(struct super_block *sb, int type)
1127 return error; 1127 return error;
1128} 1128}
1129 1129
1130static int gfs2_quota_sync_timeo(struct super_block *sb, int type)
1131{
1132 return gfs2_quota_sync(sb, type, 0);
1133}
1134
1130int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, u32 id) 1135int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, u32 id)
1131{ 1136{
1132 struct gfs2_quota_data *qd; 1137 struct gfs2_quota_data *qd;
@@ -1382,7 +1387,7 @@ int gfs2_quotad(void *data)
1382 &tune->gt_statfs_quantum); 1387 &tune->gt_statfs_quantum);
1383 1388
1384 /* Update quota file */ 1389 /* Update quota file */
1385 quotad_check_timeo(sdp, "sync", gfs2_quota_sync, t, 1390 quotad_check_timeo(sdp, "sync", gfs2_quota_sync_timeo, t,
1386 &quotad_timeo, &tune->gt_quota_quantum); 1391 &quotad_timeo, &tune->gt_quota_quantum);
1387 1392
1388 /* Check for & recover partially truncated inodes */ 1393 /* Check for & recover partially truncated inodes */
diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h
index e271fa07ad02..195f60c8bd14 100644
--- a/fs/gfs2/quota.h
+++ b/fs/gfs2/quota.h
@@ -25,7 +25,7 @@ extern int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid);
25extern void gfs2_quota_change(struct gfs2_inode *ip, s64 change, 25extern void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
26 u32 uid, u32 gid); 26 u32 uid, u32 gid);
27 27
28extern int gfs2_quota_sync(struct super_block *sb, int type); 28extern int gfs2_quota_sync(struct super_block *sb, int type, int wait);
29extern int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, u32 id); 29extern int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, u32 id);
30 30
31extern int gfs2_quota_init(struct gfs2_sbd *sdp); 31extern int gfs2_quota_init(struct gfs2_sbd *sdp);
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index ca87598ead7f..50aac606b990 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -764,7 +764,7 @@ static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
764 int error; 764 int error;
765 765
766 flush_workqueue(gfs2_delete_workqueue); 766 flush_workqueue(gfs2_delete_workqueue);
767 gfs2_quota_sync(sdp->sd_vfs, 0); 767 gfs2_quota_sync(sdp->sd_vfs, 0, 1);
768 gfs2_statfs_sync(sdp->sd_vfs, 0); 768 gfs2_statfs_sync(sdp->sd_vfs, 0);
769 769
770 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE, 770 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index a0db1c94317d..b5f1a46133c8 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -167,7 +167,7 @@ static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf,
167 if (simple_strtol(buf, NULL, 0) != 1) 167 if (simple_strtol(buf, NULL, 0) != 1)
168 return -EINVAL; 168 return -EINVAL;
169 169
170 gfs2_quota_sync(sdp->sd_vfs, 0); 170 gfs2_quota_sync(sdp->sd_vfs, 0, 1);
171 return len; 171 return len;
172} 172}
173 173
diff --git a/fs/inode.c b/fs/inode.c
index 03dfeb2e3928..407bf392e20a 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -8,7 +8,6 @@
8#include <linux/mm.h> 8#include <linux/mm.h>
9#include <linux/dcache.h> 9#include <linux/dcache.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/quotaops.h>
12#include <linux/slab.h> 11#include <linux/slab.h>
13#include <linux/writeback.h> 12#include <linux/writeback.h>
14#include <linux/module.h> 13#include <linux/module.h>
@@ -314,7 +313,6 @@ void clear_inode(struct inode *inode)
314 BUG_ON(!(inode->i_state & I_FREEING)); 313 BUG_ON(!(inode->i_state & I_FREEING));
315 BUG_ON(inode->i_state & I_CLEAR); 314 BUG_ON(inode->i_state & I_CLEAR);
316 inode_sync_wait(inode); 315 inode_sync_wait(inode);
317 vfs_dq_drop(inode);
318 if (inode->i_sb->s_op->clear_inode) 316 if (inode->i_sb->s_op->clear_inode)
319 inode->i_sb->s_op->clear_inode(inode); 317 inode->i_sb->s_op->clear_inode(inode);
320 if (S_ISBLK(inode->i_mode) && inode->i_bdev) 318 if (S_ISBLK(inode->i_mode) && inode->i_bdev)
@@ -1211,8 +1209,6 @@ void generic_delete_inode(struct inode *inode)
1211 1209
1212 if (op->delete_inode) { 1210 if (op->delete_inode) {
1213 void (*delete)(struct inode *) = op->delete_inode; 1211 void (*delete)(struct inode *) = op->delete_inode;
1214 if (!is_bad_inode(inode))
1215 vfs_dq_init(inode);
1216 /* Filesystems implementing their own 1212 /* Filesystems implementing their own
1217 * s_op->delete_inode are required to call 1213 * s_op->delete_inode are required to call
1218 * truncate_inode_pages and clear_inode() 1214 * truncate_inode_pages and clear_inode()
diff --git a/fs/jbd/commit.c b/fs/jbd/commit.c
index 4bd882548c45..2c90e3ef625f 100644
--- a/fs/jbd/commit.c
+++ b/fs/jbd/commit.c
@@ -862,12 +862,12 @@ restart_loop:
862 /* A buffer which has been freed while still being 862 /* A buffer which has been freed while still being
863 * journaled by a previous transaction may end up still 863 * journaled by a previous transaction may end up still
864 * being dirty here, but we want to avoid writing back 864 * being dirty here, but we want to avoid writing back
865 * that buffer in the future now that the last use has 865 * that buffer in the future after the "add to orphan"
866 * been committed. That's not only a performance gain, 866 * operation been committed, That's not only a performance
867 * it also stops aliasing problems if the buffer is left 867 * gain, it also stops aliasing problems if the buffer is
868 * behind for writeback and gets reallocated for another 868 * left behind for writeback and gets reallocated for another
869 * use in a different page. */ 869 * use in a different page. */
870 if (buffer_freed(bh)) { 870 if (buffer_freed(bh) && !jh->b_next_transaction) {
871 clear_buffer_freed(bh); 871 clear_buffer_freed(bh);
872 clear_buffer_jbddirty(bh); 872 clear_buffer_jbddirty(bh);
873 } 873 }
diff --git a/fs/jbd/transaction.c b/fs/jbd/transaction.c
index 006f9ad838a2..99e9fea11077 100644
--- a/fs/jbd/transaction.c
+++ b/fs/jbd/transaction.c
@@ -1864,6 +1864,21 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1864 if (!jh) 1864 if (!jh)
1865 goto zap_buffer_no_jh; 1865 goto zap_buffer_no_jh;
1866 1866
1867 /*
1868 * We cannot remove the buffer from checkpoint lists until the
1869 * transaction adding inode to orphan list (let's call it T)
1870 * is committed. Otherwise if the transaction changing the
1871 * buffer would be cleaned from the journal before T is
1872 * committed, a crash will cause that the correct contents of
1873 * the buffer will be lost. On the other hand we have to
1874 * clear the buffer dirty bit at latest at the moment when the
1875 * transaction marking the buffer as freed in the filesystem
1876 * structures is committed because from that moment on the
1877 * buffer can be reallocated and used by a different page.
1878 * Since the block hasn't been freed yet but the inode has
1879 * already been added to orphan list, it is safe for us to add
1880 * the buffer to BJ_Forget list of the newest transaction.
1881 */
1867 transaction = jh->b_transaction; 1882 transaction = jh->b_transaction;
1868 if (transaction == NULL) { 1883 if (transaction == NULL) {
1869 /* First case: not on any transaction. If it 1884 /* First case: not on any transaction. If it
@@ -1929,16 +1944,15 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1929 goto zap_buffer; 1944 goto zap_buffer;
1930 } 1945 }
1931 /* 1946 /*
1932 * If it is committing, we simply cannot touch it. We 1947 * The buffer is committing, we simply cannot touch
1933 * can remove it's next_transaction pointer from the 1948 * it. So we just set j_next_transaction to the
1934 * running transaction if that is set, but nothing 1949 * running transaction (if there is one) and mark
1935 * else. */ 1950 * buffer as freed so that commit code knows it should
1951 * clear dirty bits when it is done with the buffer.
1952 */
1936 set_buffer_freed(bh); 1953 set_buffer_freed(bh);
1937 if (jh->b_next_transaction) { 1954 if (journal->j_running_transaction && buffer_jbddirty(bh))
1938 J_ASSERT(jh->b_next_transaction == 1955 jh->b_next_transaction = journal->j_running_transaction;
1939 journal->j_running_transaction);
1940 jh->b_next_transaction = NULL;
1941 }
1942 journal_put_journal_head(jh); 1956 journal_put_journal_head(jh);
1943 spin_unlock(&journal->j_list_lock); 1957 spin_unlock(&journal->j_list_lock);
1944 jbd_unlock_bh_state(bh); 1958 jbd_unlock_bh_state(bh);
@@ -2120,7 +2134,7 @@ void journal_file_buffer(struct journal_head *jh,
2120 */ 2134 */
2121void __journal_refile_buffer(struct journal_head *jh) 2135void __journal_refile_buffer(struct journal_head *jh)
2122{ 2136{
2123 int was_dirty; 2137 int was_dirty, jlist;
2124 struct buffer_head *bh = jh2bh(jh); 2138 struct buffer_head *bh = jh2bh(jh);
2125 2139
2126 J_ASSERT_JH(jh, jbd_is_locked_bh_state(bh)); 2140 J_ASSERT_JH(jh, jbd_is_locked_bh_state(bh));
@@ -2142,8 +2156,13 @@ void __journal_refile_buffer(struct journal_head *jh)
2142 __journal_temp_unlink_buffer(jh); 2156 __journal_temp_unlink_buffer(jh);
2143 jh->b_transaction = jh->b_next_transaction; 2157 jh->b_transaction = jh->b_next_transaction;
2144 jh->b_next_transaction = NULL; 2158 jh->b_next_transaction = NULL;
2145 __journal_file_buffer(jh, jh->b_transaction, 2159 if (buffer_freed(bh))
2146 jh->b_modified ? BJ_Metadata : BJ_Reserved); 2160 jlist = BJ_Forget;
2161 else if (jh->b_modified)
2162 jlist = BJ_Metadata;
2163 else
2164 jlist = BJ_Reserved;
2165 __journal_file_buffer(jh, jh->b_transaction, jlist);
2147 J_ASSERT_JH(jh, jh->b_transaction->t_state == T_RUNNING); 2166 J_ASSERT_JH(jh, jh->b_transaction->t_state == T_RUNNING);
2148 2167
2149 if (was_dirty) 2168 if (was_dirty)
diff --git a/fs/jfs/acl.c b/fs/jfs/acl.c
index d66477c34306..213169780b6c 100644
--- a/fs/jfs/acl.c
+++ b/fs/jfs/acl.c
@@ -20,7 +20,6 @@
20 20
21#include <linux/sched.h> 21#include <linux/sched.h>
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/quotaops.h>
24#include <linux/posix_acl_xattr.h> 23#include <linux/posix_acl_xattr.h>
25#include "jfs_incore.h" 24#include "jfs_incore.h"
26#include "jfs_txnmgr.h" 25#include "jfs_txnmgr.h"
@@ -174,7 +173,7 @@ cleanup:
174 return rc; 173 return rc;
175} 174}
176 175
177static int jfs_acl_chmod(struct inode *inode) 176int jfs_acl_chmod(struct inode *inode)
178{ 177{
179 struct posix_acl *acl, *clone; 178 struct posix_acl *acl, *clone;
180 int rc; 179 int rc;
@@ -205,26 +204,3 @@ static int jfs_acl_chmod(struct inode *inode)
205 posix_acl_release(clone); 204 posix_acl_release(clone);
206 return rc; 205 return rc;
207} 206}
208
209int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
210{
211 struct inode *inode = dentry->d_inode;
212 int rc;
213
214 rc = inode_change_ok(inode, iattr);
215 if (rc)
216 return rc;
217
218 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
219 (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
220 if (vfs_dq_transfer(inode, iattr))
221 return -EDQUOT;
222 }
223
224 rc = inode_setattr(inode, iattr);
225
226 if (!rc && (iattr->ia_valid & ATTR_MODE))
227 rc = jfs_acl_chmod(inode);
228
229 return rc;
230}
diff --git a/fs/jfs/file.c b/fs/jfs/file.c
index 2b70fa78e4a7..14ba982b3f24 100644
--- a/fs/jfs/file.c
+++ b/fs/jfs/file.c
@@ -18,6 +18,7 @@
18 */ 18 */
19 19
20#include <linux/fs.h> 20#include <linux/fs.h>
21#include <linux/quotaops.h>
21#include "jfs_incore.h" 22#include "jfs_incore.h"
22#include "jfs_inode.h" 23#include "jfs_inode.h"
23#include "jfs_dmap.h" 24#include "jfs_dmap.h"
@@ -47,7 +48,7 @@ static int jfs_open(struct inode *inode, struct file *file)
47{ 48{
48 int rc; 49 int rc;
49 50
50 if ((rc = generic_file_open(inode, file))) 51 if ((rc = dquot_file_open(inode, file)))
51 return rc; 52 return rc;
52 53
53 /* 54 /*
@@ -88,14 +89,40 @@ static int jfs_release(struct inode *inode, struct file *file)
88 return 0; 89 return 0;
89} 90}
90 91
92int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
93{
94 struct inode *inode = dentry->d_inode;
95 int rc;
96
97 rc = inode_change_ok(inode, iattr);
98 if (rc)
99 return rc;
100
101 if (iattr->ia_valid & ATTR_SIZE)
102 dquot_initialize(inode);
103 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
104 (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
105 rc = dquot_transfer(inode, iattr);
106 if (rc)
107 return rc;
108 }
109
110 rc = inode_setattr(inode, iattr);
111
112 if (!rc && (iattr->ia_valid & ATTR_MODE))
113 rc = jfs_acl_chmod(inode);
114
115 return rc;
116}
117
91const struct inode_operations jfs_file_inode_operations = { 118const struct inode_operations jfs_file_inode_operations = {
92 .truncate = jfs_truncate, 119 .truncate = jfs_truncate,
93 .setxattr = jfs_setxattr, 120 .setxattr = jfs_setxattr,
94 .getxattr = jfs_getxattr, 121 .getxattr = jfs_getxattr,
95 .listxattr = jfs_listxattr, 122 .listxattr = jfs_listxattr,
96 .removexattr = jfs_removexattr, 123 .removexattr = jfs_removexattr,
97#ifdef CONFIG_JFS_POSIX_ACL
98 .setattr = jfs_setattr, 124 .setattr = jfs_setattr,
125#ifdef CONFIG_JFS_POSIX_ACL
99 .check_acl = jfs_check_acl, 126 .check_acl = jfs_check_acl,
100#endif 127#endif
101}; 128};
diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index 182b78cc3e62..9dd126276c9f 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -149,6 +149,9 @@ void jfs_delete_inode(struct inode *inode)
149{ 149{
150 jfs_info("In jfs_delete_inode, inode = 0x%p", inode); 150 jfs_info("In jfs_delete_inode, inode = 0x%p", inode);
151 151
152 if (!is_bad_inode(inode))
153 dquot_initialize(inode);
154
152 if (!is_bad_inode(inode) && 155 if (!is_bad_inode(inode) &&
153 (JFS_IP(inode)->fileset == FILESYSTEM_I)) { 156 (JFS_IP(inode)->fileset == FILESYSTEM_I)) {
154 truncate_inode_pages(&inode->i_data, 0); 157 truncate_inode_pages(&inode->i_data, 0);
@@ -161,9 +164,9 @@ void jfs_delete_inode(struct inode *inode)
161 /* 164 /*
162 * Free the inode from the quota allocation. 165 * Free the inode from the quota allocation.
163 */ 166 */
164 vfs_dq_init(inode); 167 dquot_initialize(inode);
165 vfs_dq_free_inode(inode); 168 dquot_free_inode(inode);
166 vfs_dq_drop(inode); 169 dquot_drop(inode);
167 } 170 }
168 171
169 clear_inode(inode); 172 clear_inode(inode);
diff --git a/fs/jfs/jfs_acl.h b/fs/jfs/jfs_acl.h
index b07bd417ef85..54e07559878d 100644
--- a/fs/jfs/jfs_acl.h
+++ b/fs/jfs/jfs_acl.h
@@ -22,7 +22,7 @@
22 22
23int jfs_check_acl(struct inode *, int); 23int jfs_check_acl(struct inode *, int);
24int jfs_init_acl(tid_t, struct inode *, struct inode *); 24int jfs_init_acl(tid_t, struct inode *, struct inode *);
25int jfs_setattr(struct dentry *, struct iattr *); 25int jfs_acl_chmod(struct inode *inode);
26 26
27#else 27#else
28 28
@@ -32,5 +32,10 @@ static inline int jfs_init_acl(tid_t tid, struct inode *inode,
32 return 0; 32 return 0;
33} 33}
34 34
35static inline int jfs_acl_chmod(struct inode *inode)
36{
37 return 0;
38}
39
35#endif 40#endif
36#endif /* _H_JFS_ACL */ 41#endif /* _H_JFS_ACL */
diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
index 925871e9887b..0e4623be70ce 100644
--- a/fs/jfs/jfs_dtree.c
+++ b/fs/jfs/jfs_dtree.c
@@ -381,10 +381,10 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot)
381 * It's time to move the inline table to an external 381 * It's time to move the inline table to an external
382 * page and begin to build the xtree 382 * page and begin to build the xtree
383 */ 383 */
384 if (vfs_dq_alloc_block(ip, sbi->nbperpage)) 384 if (dquot_alloc_block(ip, sbi->nbperpage))
385 goto clean_up; 385 goto clean_up;
386 if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) { 386 if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
387 vfs_dq_free_block(ip, sbi->nbperpage); 387 dquot_free_block(ip, sbi->nbperpage);
388 goto clean_up; 388 goto clean_up;
389 } 389 }
390 390
@@ -408,7 +408,7 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot)
408 memcpy(&jfs_ip->i_dirtable, temp_table, 408 memcpy(&jfs_ip->i_dirtable, temp_table,
409 sizeof (temp_table)); 409 sizeof (temp_table));
410 dbFree(ip, xaddr, sbi->nbperpage); 410 dbFree(ip, xaddr, sbi->nbperpage);
411 vfs_dq_free_block(ip, sbi->nbperpage); 411 dquot_free_block(ip, sbi->nbperpage);
412 goto clean_up; 412 goto clean_up;
413 } 413 }
414 ip->i_size = PSIZE; 414 ip->i_size = PSIZE;
@@ -1027,10 +1027,9 @@ static int dtSplitUp(tid_t tid,
1027 n = xlen; 1027 n = xlen;
1028 1028
1029 /* Allocate blocks to quota. */ 1029 /* Allocate blocks to quota. */
1030 if (vfs_dq_alloc_block(ip, n)) { 1030 rc = dquot_alloc_block(ip, n);
1031 rc = -EDQUOT; 1031 if (rc)
1032 goto extendOut; 1032 goto extendOut;
1033 }
1034 quota_allocation += n; 1033 quota_allocation += n;
1035 1034
1036 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen, 1035 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
@@ -1308,7 +1307,7 @@ static int dtSplitUp(tid_t tid,
1308 1307
1309 /* Rollback quota allocation */ 1308 /* Rollback quota allocation */
1310 if (rc && quota_allocation) 1309 if (rc && quota_allocation)
1311 vfs_dq_free_block(ip, quota_allocation); 1310 dquot_free_block(ip, quota_allocation);
1312 1311
1313 dtSplitUp_Exit: 1312 dtSplitUp_Exit:
1314 1313
@@ -1369,9 +1368,10 @@ static int dtSplitPage(tid_t tid, struct inode *ip, struct dtsplit * split,
1369 return -EIO; 1368 return -EIO;
1370 1369
1371 /* Allocate blocks to quota. */ 1370 /* Allocate blocks to quota. */
1372 if (vfs_dq_alloc_block(ip, lengthPXD(pxd))) { 1371 rc = dquot_alloc_block(ip, lengthPXD(pxd));
1372 if (rc) {
1373 release_metapage(rmp); 1373 release_metapage(rmp);
1374 return -EDQUOT; 1374 return rc;
1375 } 1375 }
1376 1376
1377 jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp); 1377 jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
@@ -1892,6 +1892,7 @@ static int dtSplitRoot(tid_t tid,
1892 struct dt_lock *dtlck; 1892 struct dt_lock *dtlck;
1893 struct tlock *tlck; 1893 struct tlock *tlck;
1894 struct lv *lv; 1894 struct lv *lv;
1895 int rc;
1895 1896
1896 /* get split root page */ 1897 /* get split root page */
1897 smp = split->mp; 1898 smp = split->mp;
@@ -1916,9 +1917,10 @@ static int dtSplitRoot(tid_t tid,
1916 rp = rmp->data; 1917 rp = rmp->data;
1917 1918
1918 /* Allocate blocks to quota. */ 1919 /* Allocate blocks to quota. */
1919 if (vfs_dq_alloc_block(ip, lengthPXD(pxd))) { 1920 rc = dquot_alloc_block(ip, lengthPXD(pxd));
1921 if (rc) {
1920 release_metapage(rmp); 1922 release_metapage(rmp);
1921 return -EDQUOT; 1923 return rc;
1922 } 1924 }
1923 1925
1924 BT_MARK_DIRTY(rmp, ip); 1926 BT_MARK_DIRTY(rmp, ip);
@@ -2287,7 +2289,7 @@ static int dtDeleteUp(tid_t tid, struct inode *ip,
2287 xlen = lengthPXD(&fp->header.self); 2289 xlen = lengthPXD(&fp->header.self);
2288 2290
2289 /* Free quota allocation. */ 2291 /* Free quota allocation. */
2290 vfs_dq_free_block(ip, xlen); 2292 dquot_free_block(ip, xlen);
2291 2293
2292 /* free/invalidate its buffer page */ 2294 /* free/invalidate its buffer page */
2293 discard_metapage(fmp); 2295 discard_metapage(fmp);
@@ -2363,7 +2365,7 @@ static int dtDeleteUp(tid_t tid, struct inode *ip,
2363 xlen = lengthPXD(&p->header.self); 2365 xlen = lengthPXD(&p->header.self);
2364 2366
2365 /* Free quota allocation */ 2367 /* Free quota allocation */
2366 vfs_dq_free_block(ip, xlen); 2368 dquot_free_block(ip, xlen);
2367 2369
2368 /* free/invalidate its buffer page */ 2370 /* free/invalidate its buffer page */
2369 discard_metapage(mp); 2371 discard_metapage(mp);
diff --git a/fs/jfs/jfs_extent.c b/fs/jfs/jfs_extent.c
index 41d6045dbeb0..5d3bbd10f8db 100644
--- a/fs/jfs/jfs_extent.c
+++ b/fs/jfs/jfs_extent.c
@@ -141,10 +141,11 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, bool abnr)
141 } 141 }
142 142
143 /* Allocate blocks to quota. */ 143 /* Allocate blocks to quota. */
144 if (vfs_dq_alloc_block(ip, nxlen)) { 144 rc = dquot_alloc_block(ip, nxlen);
145 if (rc) {
145 dbFree(ip, nxaddr, (s64) nxlen); 146 dbFree(ip, nxaddr, (s64) nxlen);
146 mutex_unlock(&JFS_IP(ip)->commit_mutex); 147 mutex_unlock(&JFS_IP(ip)->commit_mutex);
147 return -EDQUOT; 148 return rc;
148 } 149 }
149 150
150 /* determine the value of the extent flag */ 151 /* determine the value of the extent flag */
@@ -164,7 +165,7 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, bool abnr)
164 */ 165 */
165 if (rc) { 166 if (rc) {
166 dbFree(ip, nxaddr, nxlen); 167 dbFree(ip, nxaddr, nxlen);
167 vfs_dq_free_block(ip, nxlen); 168 dquot_free_block(ip, nxlen);
168 mutex_unlock(&JFS_IP(ip)->commit_mutex); 169 mutex_unlock(&JFS_IP(ip)->commit_mutex);
169 return (rc); 170 return (rc);
170 } 171 }
@@ -256,10 +257,11 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, bool abnr)
256 goto exit; 257 goto exit;
257 258
258 /* Allocat blocks to quota. */ 259 /* Allocat blocks to quota. */
259 if (vfs_dq_alloc_block(ip, nxlen)) { 260 rc = dquot_alloc_block(ip, nxlen);
261 if (rc) {
260 dbFree(ip, nxaddr, (s64) nxlen); 262 dbFree(ip, nxaddr, (s64) nxlen);
261 mutex_unlock(&JFS_IP(ip)->commit_mutex); 263 mutex_unlock(&JFS_IP(ip)->commit_mutex);
262 return -EDQUOT; 264 return rc;
263 } 265 }
264 266
265 delta = nxlen - xlen; 267 delta = nxlen - xlen;
@@ -297,7 +299,7 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, bool abnr)
297 /* extend the extent */ 299 /* extend the extent */
298 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) { 300 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
299 dbFree(ip, xaddr + xlen, delta); 301 dbFree(ip, xaddr + xlen, delta);
300 vfs_dq_free_block(ip, nxlen); 302 dquot_free_block(ip, nxlen);
301 goto exit; 303 goto exit;
302 } 304 }
303 } else { 305 } else {
@@ -308,7 +310,7 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, bool abnr)
308 */ 310 */
309 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) { 311 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
310 dbFree(ip, nxaddr, nxlen); 312 dbFree(ip, nxaddr, nxlen);
311 vfs_dq_free_block(ip, nxlen); 313 dquot_free_block(ip, nxlen);
312 goto exit; 314 goto exit;
313 } 315 }
314 } 316 }
diff --git a/fs/jfs/jfs_inode.c b/fs/jfs/jfs_inode.c
index dc0e02159ac9..829921b67765 100644
--- a/fs/jfs/jfs_inode.c
+++ b/fs/jfs/jfs_inode.c
@@ -116,10 +116,10 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
116 /* 116 /*
117 * Allocate inode to quota. 117 * Allocate inode to quota.
118 */ 118 */
119 if (vfs_dq_alloc_inode(inode)) { 119 dquot_initialize(inode);
120 rc = -EDQUOT; 120 rc = dquot_alloc_inode(inode);
121 if (rc)
121 goto fail_drop; 122 goto fail_drop;
122 }
123 123
124 inode->i_mode = mode; 124 inode->i_mode = mode;
125 /* inherit flags from parent */ 125 /* inherit flags from parent */
@@ -162,7 +162,7 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
162 return inode; 162 return inode;
163 163
164fail_drop: 164fail_drop:
165 vfs_dq_drop(inode); 165 dquot_drop(inode);
166 inode->i_flags |= S_NOQUOTA; 166 inode->i_flags |= S_NOQUOTA;
167fail_unlock: 167fail_unlock:
168 inode->i_nlink = 0; 168 inode->i_nlink = 0;
diff --git a/fs/jfs/jfs_inode.h b/fs/jfs/jfs_inode.h
index 15902b03c2a7..79e2c79661df 100644
--- a/fs/jfs/jfs_inode.h
+++ b/fs/jfs/jfs_inode.h
@@ -40,6 +40,7 @@ extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
40 int fh_len, int fh_type); 40 int fh_len, int fh_type);
41extern void jfs_set_inode_flags(struct inode *); 41extern void jfs_set_inode_flags(struct inode *);
42extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int); 42extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
43extern int jfs_setattr(struct dentry *, struct iattr *);
43 44
44extern const struct address_space_operations jfs_aops; 45extern const struct address_space_operations jfs_aops;
45extern const struct inode_operations jfs_dir_inode_operations; 46extern const struct inode_operations jfs_dir_inode_operations;
diff --git a/fs/jfs/jfs_xtree.c b/fs/jfs/jfs_xtree.c
index d654a6458648..6c50871e6220 100644
--- a/fs/jfs/jfs_xtree.c
+++ b/fs/jfs/jfs_xtree.c
@@ -585,10 +585,10 @@ int xtInsert(tid_t tid, /* transaction id */
585 hint = addressXAD(xad) + lengthXAD(xad) - 1; 585 hint = addressXAD(xad) + lengthXAD(xad) - 1;
586 } else 586 } else
587 hint = 0; 587 hint = 0;
588 if ((rc = vfs_dq_alloc_block(ip, xlen))) 588 if ((rc = dquot_alloc_block(ip, xlen)))
589 goto out; 589 goto out;
590 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) { 590 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
591 vfs_dq_free_block(ip, xlen); 591 dquot_free_block(ip, xlen);
592 goto out; 592 goto out;
593 } 593 }
594 } 594 }
@@ -617,7 +617,7 @@ int xtInsert(tid_t tid, /* transaction id */
617 /* undo data extent allocation */ 617 /* undo data extent allocation */
618 if (*xaddrp == 0) { 618 if (*xaddrp == 0) {
619 dbFree(ip, xaddr, (s64) xlen); 619 dbFree(ip, xaddr, (s64) xlen);
620 vfs_dq_free_block(ip, xlen); 620 dquot_free_block(ip, xlen);
621 } 621 }
622 return rc; 622 return rc;
623 } 623 }
@@ -985,10 +985,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
985 rbn = addressPXD(pxd); 985 rbn = addressPXD(pxd);
986 986
987 /* Allocate blocks to quota. */ 987 /* Allocate blocks to quota. */
988 if (vfs_dq_alloc_block(ip, lengthPXD(pxd))) { 988 rc = dquot_alloc_block(ip, lengthPXD(pxd));
989 rc = -EDQUOT; 989 if (rc)
990 goto clean_up; 990 goto clean_up;
991 }
992 991
993 quota_allocation += lengthPXD(pxd); 992 quota_allocation += lengthPXD(pxd);
994 993
@@ -1195,7 +1194,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
1195 1194
1196 /* Rollback quota allocation. */ 1195 /* Rollback quota allocation. */
1197 if (quota_allocation) 1196 if (quota_allocation)
1198 vfs_dq_free_block(ip, quota_allocation); 1197 dquot_free_block(ip, quota_allocation);
1199 1198
1200 return (rc); 1199 return (rc);
1201} 1200}
@@ -1235,6 +1234,7 @@ xtSplitRoot(tid_t tid,
1235 struct pxdlist *pxdlist; 1234 struct pxdlist *pxdlist;
1236 struct tlock *tlck; 1235 struct tlock *tlck;
1237 struct xtlock *xtlck; 1236 struct xtlock *xtlck;
1237 int rc;
1238 1238
1239 sp = &JFS_IP(ip)->i_xtroot; 1239 sp = &JFS_IP(ip)->i_xtroot;
1240 1240
@@ -1252,9 +1252,10 @@ xtSplitRoot(tid_t tid,
1252 return -EIO; 1252 return -EIO;
1253 1253
1254 /* Allocate blocks to quota. */ 1254 /* Allocate blocks to quota. */
1255 if (vfs_dq_alloc_block(ip, lengthPXD(pxd))) { 1255 rc = dquot_alloc_block(ip, lengthPXD(pxd));
1256 if (rc) {
1256 release_metapage(rmp); 1257 release_metapage(rmp);
1257 return -EDQUOT; 1258 return rc;
1258 } 1259 }
1259 1260
1260 jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp); 1261 jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
@@ -3680,7 +3681,7 @@ s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)
3680 ip->i_size = newsize; 3681 ip->i_size = newsize;
3681 3682
3682 /* update quota allocation to reflect freed blocks */ 3683 /* update quota allocation to reflect freed blocks */
3683 vfs_dq_free_block(ip, nfreed); 3684 dquot_free_block(ip, nfreed);
3684 3685
3685 /* 3686 /*
3686 * free tlock of invalidated pages 3687 * free tlock of invalidated pages
diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index c79a4270f083..4a3e9f39c21d 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -85,6 +85,8 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
85 85
86 jfs_info("jfs_create: dip:0x%p name:%s", dip, dentry->d_name.name); 86 jfs_info("jfs_create: dip:0x%p name:%s", dip, dentry->d_name.name);
87 87
88 dquot_initialize(dip);
89
88 /* 90 /*
89 * search parent directory for entry/freespace 91 * search parent directory for entry/freespace
90 * (dtSearch() returns parent directory page pinned) 92 * (dtSearch() returns parent directory page pinned)
@@ -215,6 +217,8 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
215 217
216 jfs_info("jfs_mkdir: dip:0x%p name:%s", dip, dentry->d_name.name); 218 jfs_info("jfs_mkdir: dip:0x%p name:%s", dip, dentry->d_name.name);
217 219
220 dquot_initialize(dip);
221
218 /* link count overflow on parent directory ? */ 222 /* link count overflow on parent directory ? */
219 if (dip->i_nlink == JFS_LINK_MAX) { 223 if (dip->i_nlink == JFS_LINK_MAX) {
220 rc = -EMLINK; 224 rc = -EMLINK;
@@ -356,7 +360,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
356 jfs_info("jfs_rmdir: dip:0x%p name:%s", dip, dentry->d_name.name); 360 jfs_info("jfs_rmdir: dip:0x%p name:%s", dip, dentry->d_name.name);
357 361
358 /* Init inode for quota operations. */ 362 /* Init inode for quota operations. */
359 vfs_dq_init(ip); 363 dquot_initialize(dip);
364 dquot_initialize(ip);
360 365
361 /* directory must be empty to be removed */ 366 /* directory must be empty to be removed */
362 if (!dtEmpty(ip)) { 367 if (!dtEmpty(ip)) {
@@ -483,7 +488,8 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
483 jfs_info("jfs_unlink: dip:0x%p name:%s", dip, dentry->d_name.name); 488 jfs_info("jfs_unlink: dip:0x%p name:%s", dip, dentry->d_name.name);
484 489
485 /* Init inode for quota operations. */ 490 /* Init inode for quota operations. */
486 vfs_dq_init(ip); 491 dquot_initialize(dip);
492 dquot_initialize(ip);
487 493
488 if ((rc = get_UCSname(&dname, dentry))) 494 if ((rc = get_UCSname(&dname, dentry)))
489 goto out; 495 goto out;
@@ -805,6 +811,8 @@ static int jfs_link(struct dentry *old_dentry,
805 if (ip->i_nlink == 0) 811 if (ip->i_nlink == 0)
806 return -ENOENT; 812 return -ENOENT;
807 813
814 dquot_initialize(dir);
815
808 tid = txBegin(ip->i_sb, 0); 816 tid = txBegin(ip->i_sb, 0);
809 817
810 mutex_lock_nested(&JFS_IP(dir)->commit_mutex, COMMIT_MUTEX_PARENT); 818 mutex_lock_nested(&JFS_IP(dir)->commit_mutex, COMMIT_MUTEX_PARENT);
@@ -896,6 +904,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
896 904
897 jfs_info("jfs_symlink: dip:0x%p name:%s", dip, name); 905 jfs_info("jfs_symlink: dip:0x%p name:%s", dip, name);
898 906
907 dquot_initialize(dip);
908
899 ssize = strlen(name) + 1; 909 ssize = strlen(name) + 1;
900 910
901 /* 911 /*
@@ -1087,6 +1097,9 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1087 jfs_info("jfs_rename: %s %s", old_dentry->d_name.name, 1097 jfs_info("jfs_rename: %s %s", old_dentry->d_name.name,
1088 new_dentry->d_name.name); 1098 new_dentry->d_name.name);
1089 1099
1100 dquot_initialize(old_dir);
1101 dquot_initialize(new_dir);
1102
1090 old_ip = old_dentry->d_inode; 1103 old_ip = old_dentry->d_inode;
1091 new_ip = new_dentry->d_inode; 1104 new_ip = new_dentry->d_inode;
1092 1105
@@ -1136,7 +1149,7 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1136 } else if (new_ip) { 1149 } else if (new_ip) {
1137 IWRITE_LOCK(new_ip, RDWRLOCK_NORMAL); 1150 IWRITE_LOCK(new_ip, RDWRLOCK_NORMAL);
1138 /* Init inode for quota operations. */ 1151 /* Init inode for quota operations. */
1139 vfs_dq_init(new_ip); 1152 dquot_initialize(new_ip);
1140 } 1153 }
1141 1154
1142 /* 1155 /*
@@ -1360,6 +1373,8 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
1360 1373
1361 jfs_info("jfs_mknod: %s", dentry->d_name.name); 1374 jfs_info("jfs_mknod: %s", dentry->d_name.name);
1362 1375
1376 dquot_initialize(dir);
1377
1363 if ((rc = get_UCSname(&dname, dentry))) 1378 if ((rc = get_UCSname(&dname, dentry)))
1364 goto out; 1379 goto out;
1365 1380
@@ -1541,8 +1556,8 @@ const struct inode_operations jfs_dir_inode_operations = {
1541 .getxattr = jfs_getxattr, 1556 .getxattr = jfs_getxattr,
1542 .listxattr = jfs_listxattr, 1557 .listxattr = jfs_listxattr,
1543 .removexattr = jfs_removexattr, 1558 .removexattr = jfs_removexattr,
1544#ifdef CONFIG_JFS_POSIX_ACL
1545 .setattr = jfs_setattr, 1559 .setattr = jfs_setattr,
1560#ifdef CONFIG_JFS_POSIX_ACL
1546 .check_acl = jfs_check_acl, 1561 .check_acl = jfs_check_acl,
1547#endif 1562#endif
1548}; 1563};
diff --git a/fs/jfs/super.c b/fs/jfs/super.c
index d929a822a74e..266699deb1c6 100644
--- a/fs/jfs/super.c
+++ b/fs/jfs/super.c
@@ -131,6 +131,11 @@ static void jfs_destroy_inode(struct inode *inode)
131 kmem_cache_free(jfs_inode_cachep, ji); 131 kmem_cache_free(jfs_inode_cachep, ji);
132} 132}
133 133
134static void jfs_clear_inode(struct inode *inode)
135{
136 dquot_drop(inode);
137}
138
134static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf) 139static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
135{ 140{
136 struct jfs_sb_info *sbi = JFS_SBI(dentry->d_sb); 141 struct jfs_sb_info *sbi = JFS_SBI(dentry->d_sb);
@@ -745,6 +750,7 @@ static const struct super_operations jfs_super_operations = {
745 .dirty_inode = jfs_dirty_inode, 750 .dirty_inode = jfs_dirty_inode,
746 .write_inode = jfs_write_inode, 751 .write_inode = jfs_write_inode,
747 .delete_inode = jfs_delete_inode, 752 .delete_inode = jfs_delete_inode,
753 .clear_inode = jfs_clear_inode,
748 .put_super = jfs_put_super, 754 .put_super = jfs_put_super,
749 .sync_fs = jfs_sync_fs, 755 .sync_fs = jfs_sync_fs,
750 .freeze_fs = jfs_freeze, 756 .freeze_fs = jfs_freeze,
diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index fad364548bc9..1f594ab21895 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -260,14 +260,14 @@ static int ea_write(struct inode *ip, struct jfs_ea_list *ealist, int size,
260 nblocks = (size + (sb->s_blocksize - 1)) >> sb->s_blocksize_bits; 260 nblocks = (size + (sb->s_blocksize - 1)) >> sb->s_blocksize_bits;
261 261
262 /* Allocate new blocks to quota. */ 262 /* Allocate new blocks to quota. */
263 if (vfs_dq_alloc_block(ip, nblocks)) { 263 rc = dquot_alloc_block(ip, nblocks);
264 return -EDQUOT; 264 if (rc)
265 } 265 return rc;
266 266
267 rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno); 267 rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
268 if (rc) { 268 if (rc) {
269 /*Rollback quota allocation. */ 269 /*Rollback quota allocation. */
270 vfs_dq_free_block(ip, nblocks); 270 dquot_free_block(ip, nblocks);
271 return rc; 271 return rc;
272 } 272 }
273 273
@@ -332,7 +332,7 @@ static int ea_write(struct inode *ip, struct jfs_ea_list *ealist, int size,
332 332
333 failed: 333 failed:
334 /* Rollback quota allocation. */ 334 /* Rollback quota allocation. */
335 vfs_dq_free_block(ip, nblocks); 335 dquot_free_block(ip, nblocks);
336 336
337 dbFree(ip, blkno, nblocks); 337 dbFree(ip, blkno, nblocks);
338 return rc; 338 return rc;
@@ -538,7 +538,8 @@ static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
538 538
539 if (blocks_needed > current_blocks) { 539 if (blocks_needed > current_blocks) {
540 /* Allocate new blocks to quota. */ 540 /* Allocate new blocks to quota. */
541 if (vfs_dq_alloc_block(inode, blocks_needed)) 541 rc = dquot_alloc_block(inode, blocks_needed);
542 if (rc)
542 return -EDQUOT; 543 return -EDQUOT;
543 544
544 quota_allocation = blocks_needed; 545 quota_allocation = blocks_needed;
@@ -602,7 +603,7 @@ static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
602 clean_up: 603 clean_up:
603 /* Rollback quota allocation */ 604 /* Rollback quota allocation */
604 if (quota_allocation) 605 if (quota_allocation)
605 vfs_dq_free_block(inode, quota_allocation); 606 dquot_free_block(inode, quota_allocation);
606 607
607 return (rc); 608 return (rc);
608} 609}
@@ -677,7 +678,7 @@ static int ea_put(tid_t tid, struct inode *inode, struct ea_buffer *ea_buf,
677 678
678 /* If old blocks exist, they must be removed from quota allocation. */ 679 /* If old blocks exist, they must be removed from quota allocation. */
679 if (old_blocks) 680 if (old_blocks)
680 vfs_dq_free_block(inode, old_blocks); 681 dquot_free_block(inode, old_blocks);
681 682
682 inode->i_ctime = CURRENT_TIME; 683 inode->i_ctime = CURRENT_TIME;
683 684
diff --git a/fs/namei.c b/fs/namei.c
index 9a6456099f1e..3d9d2f965f84 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -19,7 +19,6 @@
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/fs.h> 20#include <linux/fs.h>
21#include <linux/namei.h> 21#include <linux/namei.h>
22#include <linux/quotaops.h>
23#include <linux/pagemap.h> 22#include <linux/pagemap.h>
24#include <linux/fsnotify.h> 23#include <linux/fsnotify.h>
25#include <linux/personality.h> 24#include <linux/personality.h>
@@ -1416,7 +1415,6 @@ int vfs_create(struct inode *dir, struct dentry *dentry, int mode,
1416 error = security_inode_create(dir, dentry, mode); 1415 error = security_inode_create(dir, dentry, mode);
1417 if (error) 1416 if (error)
1418 return error; 1417 return error;
1419 vfs_dq_init(dir);
1420 error = dir->i_op->create(dir, dentry, mode, nd); 1418 error = dir->i_op->create(dir, dentry, mode, nd);
1421 if (!error) 1419 if (!error)
1422 fsnotify_create(dir, dentry); 1420 fsnotify_create(dir, dentry);
@@ -1586,9 +1584,6 @@ static struct file *finish_open(struct nameidata *nd,
1586 } 1584 }
1587 } 1585 }
1588 if (!IS_ERR(filp)) { 1586 if (!IS_ERR(filp)) {
1589 if (acc_mode & MAY_WRITE)
1590 vfs_dq_init(nd->path.dentry->d_inode);
1591
1592 if (will_truncate) { 1587 if (will_truncate) {
1593 error = handle_truncate(&nd->path); 1588 error = handle_truncate(&nd->path);
1594 if (error) { 1589 if (error) {
@@ -1986,7 +1981,6 @@ int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
1986 if (error) 1981 if (error)
1987 return error; 1982 return error;
1988 1983
1989 vfs_dq_init(dir);
1990 error = dir->i_op->mknod(dir, dentry, mode, dev); 1984 error = dir->i_op->mknod(dir, dentry, mode, dev);
1991 if (!error) 1985 if (!error)
1992 fsnotify_create(dir, dentry); 1986 fsnotify_create(dir, dentry);
@@ -2085,7 +2079,6 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
2085 if (error) 2079 if (error)
2086 return error; 2080 return error;
2087 2081
2088 vfs_dq_init(dir);
2089 error = dir->i_op->mkdir(dir, dentry, mode); 2082 error = dir->i_op->mkdir(dir, dentry, mode);
2090 if (!error) 2083 if (!error)
2091 fsnotify_mkdir(dir, dentry); 2084 fsnotify_mkdir(dir, dentry);
@@ -2171,8 +2164,6 @@ int vfs_rmdir(struct inode *dir, struct dentry *dentry)
2171 if (!dir->i_op->rmdir) 2164 if (!dir->i_op->rmdir)
2172 return -EPERM; 2165 return -EPERM;
2173 2166
2174 vfs_dq_init(dir);
2175
2176 mutex_lock(&dentry->d_inode->i_mutex); 2167 mutex_lock(&dentry->d_inode->i_mutex);
2177 dentry_unhash(dentry); 2168 dentry_unhash(dentry);
2178 if (d_mountpoint(dentry)) 2169 if (d_mountpoint(dentry))
@@ -2258,8 +2249,6 @@ int vfs_unlink(struct inode *dir, struct dentry *dentry)
2258 if (!dir->i_op->unlink) 2249 if (!dir->i_op->unlink)
2259 return -EPERM; 2250 return -EPERM;
2260 2251
2261 vfs_dq_init(dir);
2262
2263 mutex_lock(&dentry->d_inode->i_mutex); 2252 mutex_lock(&dentry->d_inode->i_mutex);
2264 if (d_mountpoint(dentry)) 2253 if (d_mountpoint(dentry))
2265 error = -EBUSY; 2254 error = -EBUSY;
@@ -2372,7 +2361,6 @@ int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname)
2372 if (error) 2361 if (error)
2373 return error; 2362 return error;
2374 2363
2375 vfs_dq_init(dir);
2376 error = dir->i_op->symlink(dir, dentry, oldname); 2364 error = dir->i_op->symlink(dir, dentry, oldname);
2377 if (!error) 2365 if (!error)
2378 fsnotify_create(dir, dentry); 2366 fsnotify_create(dir, dentry);
@@ -2456,7 +2444,6 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
2456 return error; 2444 return error;
2457 2445
2458 mutex_lock(&inode->i_mutex); 2446 mutex_lock(&inode->i_mutex);
2459 vfs_dq_init(dir);
2460 error = dir->i_op->link(old_dentry, dir, new_dentry); 2447 error = dir->i_op->link(old_dentry, dir, new_dentry);
2461 mutex_unlock(&inode->i_mutex); 2448 mutex_unlock(&inode->i_mutex);
2462 if (!error) 2449 if (!error)
@@ -2657,9 +2644,6 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
2657 if (!old_dir->i_op->rename) 2644 if (!old_dir->i_op->rename)
2658 return -EPERM; 2645 return -EPERM;
2659 2646
2660 vfs_dq_init(old_dir);
2661 vfs_dq_init(new_dir);
2662
2663 old_name = fsnotify_oldname_init(old_dentry->d_name.name); 2647 old_name = fsnotify_oldname_init(old_dentry->d_name.name);
2664 2648
2665 if (is_dir) 2649 if (is_dir)
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 15dc2deaac5f..8eca17df4f63 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -20,7 +20,6 @@
20#include <linux/fcntl.h> 20#include <linux/fcntl.h>
21#include <linux/namei.h> 21#include <linux/namei.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/quotaops.h>
24#include <linux/fsnotify.h> 23#include <linux/fsnotify.h>
25#include <linux/posix_acl_xattr.h> 24#include <linux/posix_acl_xattr.h>
26#include <linux/xattr.h> 25#include <linux/xattr.h>
@@ -377,7 +376,6 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
377 put_write_access(inode); 376 put_write_access(inode);
378 goto out_nfserr; 377 goto out_nfserr;
379 } 378 }
380 vfs_dq_init(inode);
381 } 379 }
382 380
383 /* sanitize the mode change */ 381 /* sanitize the mode change */
@@ -745,8 +743,6 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
745 flags = O_RDWR|O_LARGEFILE; 743 flags = O_RDWR|O_LARGEFILE;
746 else 744 else
747 flags = O_WRONLY|O_LARGEFILE; 745 flags = O_WRONLY|O_LARGEFILE;
748
749 vfs_dq_init(inode);
750 } 746 }
751 *filp = dentry_open(dget(dentry), mntget(fhp->fh_export->ex_path.mnt), 747 *filp = dentry_open(dget(dentry), mntget(fhp->fh_export->ex_path.mnt),
752 flags, current_cred()); 748 flags, current_cred());
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 2bbe1ecc08c0..9f8bd913c51e 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -5713,7 +5713,7 @@ int ocfs2_remove_btree_range(struct inode *inode,
5713 goto out; 5713 goto out;
5714 } 5714 }
5715 5715
5716 vfs_dq_free_space_nodirty(inode, 5716 dquot_free_space_nodirty(inode,
5717 ocfs2_clusters_to_bytes(inode->i_sb, len)); 5717 ocfs2_clusters_to_bytes(inode->i_sb, len));
5718 5718
5719 ret = ocfs2_remove_extent(handle, et, cpos, len, meta_ac, dealloc); 5719 ret = ocfs2_remove_extent(handle, et, cpos, len, meta_ac, dealloc);
@@ -6936,7 +6936,7 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb,
6936 goto bail; 6936 goto bail;
6937 } 6937 }
6938 6938
6939 vfs_dq_free_space_nodirty(inode, 6939 dquot_free_space_nodirty(inode,
6940 ocfs2_clusters_to_bytes(osb->sb, clusters_to_del)); 6940 ocfs2_clusters_to_bytes(osb->sb, clusters_to_del));
6941 spin_lock(&OCFS2_I(inode)->ip_lock); 6941 spin_lock(&OCFS2_I(inode)->ip_lock);
6942 OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters) - 6942 OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters) -
@@ -7301,11 +7301,10 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
7301 unsigned int page_end; 7301 unsigned int page_end;
7302 u64 phys; 7302 u64 phys;
7303 7303
7304 if (vfs_dq_alloc_space_nodirty(inode, 7304 ret = dquot_alloc_space_nodirty(inode,
7305 ocfs2_clusters_to_bytes(osb->sb, 1))) { 7305 ocfs2_clusters_to_bytes(osb->sb, 1));
7306 ret = -EDQUOT; 7306 if (ret)
7307 goto out_commit; 7307 goto out_commit;
7308 }
7309 did_quota = 1; 7308 did_quota = 1;
7310 7309
7311 ret = ocfs2_claim_clusters(osb, handle, data_ac, 1, &bit_off, 7310 ret = ocfs2_claim_clusters(osb, handle, data_ac, 1, &bit_off,
@@ -7381,7 +7380,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
7381 7380
7382out_commit: 7381out_commit:
7383 if (ret < 0 && did_quota) 7382 if (ret < 0 && did_quota)
7384 vfs_dq_free_space_nodirty(inode, 7383 dquot_free_space_nodirty(inode,
7385 ocfs2_clusters_to_bytes(osb->sb, 1)); 7384 ocfs2_clusters_to_bytes(osb->sb, 1));
7386 7385
7387 ocfs2_commit_trans(osb, handle); 7386 ocfs2_commit_trans(osb, handle);
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 4c2a6d282c4d..21441ddb5506 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -1764,10 +1764,11 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
1764 1764
1765 wc->w_handle = handle; 1765 wc->w_handle = handle;
1766 1766
1767 if (clusters_to_alloc && vfs_dq_alloc_space_nodirty(inode, 1767 if (clusters_to_alloc) {
1768 ocfs2_clusters_to_bytes(osb->sb, clusters_to_alloc))) { 1768 ret = dquot_alloc_space_nodirty(inode,
1769 ret = -EDQUOT; 1769 ocfs2_clusters_to_bytes(osb->sb, clusters_to_alloc));
1770 goto out_commit; 1770 if (ret)
1771 goto out_commit;
1771 } 1772 }
1772 /* 1773 /*
1773 * We don't want this to fail in ocfs2_write_end(), so do it 1774 * We don't want this to fail in ocfs2_write_end(), so do it
@@ -1810,7 +1811,7 @@ success:
1810 return 0; 1811 return 0;
1811out_quota: 1812out_quota:
1812 if (clusters_to_alloc) 1813 if (clusters_to_alloc)
1813 vfs_dq_free_space(inode, 1814 dquot_free_space(inode,
1814 ocfs2_clusters_to_bytes(osb->sb, clusters_to_alloc)); 1815 ocfs2_clusters_to_bytes(osb->sb, clusters_to_alloc));
1815out_commit: 1816out_commit:
1816 ocfs2_commit_trans(osb, handle); 1817 ocfs2_commit_trans(osb, handle);
diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
index 765d66c70989..efd77d071c80 100644
--- a/fs/ocfs2/dir.c
+++ b/fs/ocfs2/dir.c
@@ -2964,12 +2964,10 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
2964 goto out; 2964 goto out;
2965 } 2965 }
2966 2966
2967 if (vfs_dq_alloc_space_nodirty(dir, 2967 ret = dquot_alloc_space_nodirty(dir,
2968 ocfs2_clusters_to_bytes(osb->sb, 2968 ocfs2_clusters_to_bytes(osb->sb, alloc + dx_alloc));
2969 alloc + dx_alloc))) { 2969 if (ret)
2970 ret = -EDQUOT;
2971 goto out_commit; 2970 goto out_commit;
2972 }
2973 did_quota = 1; 2971 did_quota = 1;
2974 2972
2975 if (ocfs2_supports_indexed_dirs(osb) && !dx_inline) { 2973 if (ocfs2_supports_indexed_dirs(osb) && !dx_inline) {
@@ -3178,7 +3176,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
3178 3176
3179out_commit: 3177out_commit:
3180 if (ret < 0 && did_quota) 3178 if (ret < 0 && did_quota)
3181 vfs_dq_free_space_nodirty(dir, bytes_allocated); 3179 dquot_free_space_nodirty(dir, bytes_allocated);
3182 3180
3183 ocfs2_commit_trans(osb, handle); 3181 ocfs2_commit_trans(osb, handle);
3184 3182
@@ -3221,11 +3219,10 @@ static int ocfs2_do_extend_dir(struct super_block *sb,
3221 if (extend) { 3219 if (extend) {
3222 u32 offset = OCFS2_I(dir)->ip_clusters; 3220 u32 offset = OCFS2_I(dir)->ip_clusters;
3223 3221
3224 if (vfs_dq_alloc_space_nodirty(dir, 3222 status = dquot_alloc_space_nodirty(dir,
3225 ocfs2_clusters_to_bytes(sb, 1))) { 3223 ocfs2_clusters_to_bytes(sb, 1));
3226 status = -EDQUOT; 3224 if (status)
3227 goto bail; 3225 goto bail;
3228 }
3229 did_quota = 1; 3226 did_quota = 1;
3230 3227
3231 status = ocfs2_add_inode_data(OCFS2_SB(sb), dir, &offset, 3228 status = ocfs2_add_inode_data(OCFS2_SB(sb), dir, &offset,
@@ -3254,7 +3251,7 @@ static int ocfs2_do_extend_dir(struct super_block *sb,
3254 status = 0; 3251 status = 0;
3255bail: 3252bail:
3256 if (did_quota && status < 0) 3253 if (did_quota && status < 0)
3257 vfs_dq_free_space_nodirty(dir, ocfs2_clusters_to_bytes(sb, 1)); 3254 dquot_free_space_nodirty(dir, ocfs2_clusters_to_bytes(sb, 1));
3258 mlog_exit(status); 3255 mlog_exit(status);
3259 return status; 3256 return status;
3260} 3257}
@@ -3889,11 +3886,10 @@ static int ocfs2_dx_dir_rebalance(struct ocfs2_super *osb, struct inode *dir,
3889 goto out; 3886 goto out;
3890 } 3887 }
3891 3888
3892 if (vfs_dq_alloc_space_nodirty(dir, 3889 ret = dquot_alloc_space_nodirty(dir,
3893 ocfs2_clusters_to_bytes(dir->i_sb, 1))) { 3890 ocfs2_clusters_to_bytes(dir->i_sb, 1));
3894 ret = -EDQUOT; 3891 if (ret)
3895 goto out_commit; 3892 goto out_commit;
3896 }
3897 did_quota = 1; 3893 did_quota = 1;
3898 3894
3899 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), dx_leaf_bh, 3895 ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), dx_leaf_bh,
@@ -3983,7 +3979,7 @@ static int ocfs2_dx_dir_rebalance(struct ocfs2_super *osb, struct inode *dir,
3983 3979
3984out_commit: 3980out_commit:
3985 if (ret < 0 && did_quota) 3981 if (ret < 0 && did_quota)
3986 vfs_dq_free_space_nodirty(dir, 3982 dquot_free_space_nodirty(dir,
3987 ocfs2_clusters_to_bytes(dir->i_sb, 1)); 3983 ocfs2_clusters_to_bytes(dir->i_sb, 1));
3988 3984
3989 ocfs2_commit_trans(osb, handle); 3985 ocfs2_commit_trans(osb, handle);
@@ -4165,11 +4161,10 @@ static int ocfs2_expand_inline_dx_root(struct inode *dir,
4165 goto out; 4161 goto out;
4166 } 4162 }
4167 4163
4168 if (vfs_dq_alloc_space_nodirty(dir, 4164 ret = dquot_alloc_space_nodirty(dir,
4169 ocfs2_clusters_to_bytes(osb->sb, 1))) { 4165 ocfs2_clusters_to_bytes(osb->sb, 1));
4170 ret = -EDQUOT; 4166 if (ret)
4171 goto out_commit; 4167 goto out_commit;
4172 }
4173 did_quota = 1; 4168 did_quota = 1;
4174 4169
4175 /* 4170 /*
@@ -4229,7 +4224,7 @@ static int ocfs2_expand_inline_dx_root(struct inode *dir,
4229 4224
4230out_commit: 4225out_commit:
4231 if (ret < 0 && did_quota) 4226 if (ret < 0 && did_quota)
4232 vfs_dq_free_space_nodirty(dir, 4227 dquot_free_space_nodirty(dir,
4233 ocfs2_clusters_to_bytes(dir->i_sb, 1)); 4228 ocfs2_clusters_to_bytes(dir->i_sb, 1));
4234 4229
4235 ocfs2_commit_trans(osb, handle); 4230 ocfs2_commit_trans(osb, handle);
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 5b52547d6299..17947dc8341e 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -107,6 +107,9 @@ static int ocfs2_file_open(struct inode *inode, struct file *file)
107 mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file, 107 mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file,
108 file->f_path.dentry->d_name.len, file->f_path.dentry->d_name.name); 108 file->f_path.dentry->d_name.len, file->f_path.dentry->d_name.name);
109 109
110 if (file->f_mode & FMODE_WRITE)
111 dquot_initialize(inode);
112
110 spin_lock(&oi->ip_lock); 113 spin_lock(&oi->ip_lock);
111 114
112 /* Check that the inode hasn't been wiped from disk by another 115 /* Check that the inode hasn't been wiped from disk by another
@@ -629,11 +632,10 @@ restart_all:
629 } 632 }
630 633
631restarted_transaction: 634restarted_transaction:
632 if (vfs_dq_alloc_space_nodirty(inode, ocfs2_clusters_to_bytes(osb->sb, 635 status = dquot_alloc_space_nodirty(inode,
633 clusters_to_add))) { 636 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add));
634 status = -EDQUOT; 637 if (status)
635 goto leave; 638 goto leave;
636 }
637 did_quota = 1; 639 did_quota = 1;
638 640
639 /* reserve a write to the file entry early on - that we if we 641 /* reserve a write to the file entry early on - that we if we
@@ -674,7 +676,7 @@ restarted_transaction:
674 clusters_to_add -= (OCFS2_I(inode)->ip_clusters - prev_clusters); 676 clusters_to_add -= (OCFS2_I(inode)->ip_clusters - prev_clusters);
675 spin_unlock(&OCFS2_I(inode)->ip_lock); 677 spin_unlock(&OCFS2_I(inode)->ip_lock);
676 /* Release unused quota reservation */ 678 /* Release unused quota reservation */
677 vfs_dq_free_space(inode, 679 dquot_free_space(inode,
678 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add)); 680 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add));
679 did_quota = 0; 681 did_quota = 0;
680 682
@@ -710,7 +712,7 @@ restarted_transaction:
710 712
711leave: 713leave:
712 if (status < 0 && did_quota) 714 if (status < 0 && did_quota)
713 vfs_dq_free_space(inode, 715 dquot_free_space(inode,
714 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add)); 716 ocfs2_clusters_to_bytes(osb->sb, clusters_to_add));
715 if (handle) { 717 if (handle) {
716 ocfs2_commit_trans(osb, handle); 718 ocfs2_commit_trans(osb, handle);
@@ -978,6 +980,8 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
978 980
979 size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE; 981 size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
980 if (size_change) { 982 if (size_change) {
983 dquot_initialize(inode);
984
981 status = ocfs2_rw_lock(inode, 1); 985 status = ocfs2_rw_lock(inode, 1);
982 if (status < 0) { 986 if (status < 0) {
983 mlog_errno(status); 987 mlog_errno(status);
@@ -1020,7 +1024,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1020 /* 1024 /*
1021 * Gather pointers to quota structures so that allocation / 1025 * Gather pointers to quota structures so that allocation /
1022 * freeing of quota structures happens here and not inside 1026 * freeing of quota structures happens here and not inside
1023 * vfs_dq_transfer() where we have problems with lock ordering 1027 * dquot_transfer() where we have problems with lock ordering
1024 */ 1028 */
1025 if (attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid 1029 if (attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid
1026 && OCFS2_HAS_RO_COMPAT_FEATURE(sb, 1030 && OCFS2_HAS_RO_COMPAT_FEATURE(sb,
@@ -1053,7 +1057,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1053 mlog_errno(status); 1057 mlog_errno(status);
1054 goto bail_unlock; 1058 goto bail_unlock;
1055 } 1059 }
1056 status = vfs_dq_transfer(inode, attr) ? -EDQUOT : 0; 1060 status = dquot_transfer(inode, attr);
1057 if (status < 0) 1061 if (status < 0)
1058 goto bail_commit; 1062 goto bail_commit;
1059 } else { 1063 } else {
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index 88459bdd1ff3..278a223aae14 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -665,7 +665,7 @@ static int ocfs2_remove_inode(struct inode *inode,
665 } 665 }
666 666
667 ocfs2_remove_from_cache(INODE_CACHE(inode), di_bh); 667 ocfs2_remove_from_cache(INODE_CACHE(inode), di_bh);
668 vfs_dq_free_inode(inode); 668 dquot_free_inode(inode);
669 669
670 status = ocfs2_free_dinode(handle, inode_alloc_inode, 670 status = ocfs2_free_dinode(handle, inode_alloc_inode,
671 inode_alloc_bh, di); 671 inode_alloc_bh, di);
@@ -971,6 +971,8 @@ void ocfs2_delete_inode(struct inode *inode)
971 goto bail; 971 goto bail;
972 } 972 }
973 973
974 dquot_initialize(inode);
975
974 if (!ocfs2_inode_is_valid_to_delete(inode)) { 976 if (!ocfs2_inode_is_valid_to_delete(inode)) {
975 /* It's probably not necessary to truncate_inode_pages 977 /* It's probably not necessary to truncate_inode_pages
976 * here but we do it for safety anyway (it will most 978 * here but we do it for safety anyway (it will most
@@ -1087,6 +1089,8 @@ void ocfs2_clear_inode(struct inode *inode)
1087 mlog_bug_on_msg(OCFS2_SB(inode->i_sb) == NULL, 1089 mlog_bug_on_msg(OCFS2_SB(inode->i_sb) == NULL,
1088 "Inode=%lu\n", inode->i_ino); 1090 "Inode=%lu\n", inode->i_ino);
1089 1091
1092 dquot_drop(inode);
1093
1090 /* To preven remote deletes we hold open lock before, now it 1094 /* To preven remote deletes we hold open lock before, now it
1091 * is time to unlock PR and EX open locks. */ 1095 * is time to unlock PR and EX open locks. */
1092 ocfs2_open_unlock(inode); 1096 ocfs2_open_unlock(inode);
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 50fb26a6a5f5..d9cd4e373a53 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -212,7 +212,7 @@ static struct inode *ocfs2_get_init_inode(struct inode *dir, int mode)
212 } else 212 } else
213 inode->i_gid = current_fsgid(); 213 inode->i_gid = current_fsgid();
214 inode->i_mode = mode; 214 inode->i_mode = mode;
215 vfs_dq_init(inode); 215 dquot_initialize(inode);
216 return inode; 216 return inode;
217} 217}
218 218
@@ -244,6 +244,8 @@ static int ocfs2_mknod(struct inode *dir,
244 (unsigned long)dev, dentry->d_name.len, 244 (unsigned long)dev, dentry->d_name.len,
245 dentry->d_name.name); 245 dentry->d_name.name);
246 246
247 dquot_initialize(dir);
248
247 /* get our super block */ 249 /* get our super block */
248 osb = OCFS2_SB(dir->i_sb); 250 osb = OCFS2_SB(dir->i_sb);
249 251
@@ -348,13 +350,9 @@ static int ocfs2_mknod(struct inode *dir,
348 goto leave; 350 goto leave;
349 } 351 }
350 352
351 /* We don't use standard VFS wrapper because we don't want vfs_dq_init 353 status = dquot_alloc_inode(inode);
352 * to be called. */ 354 if (status)
353 if (sb_any_quota_active(osb->sb) &&
354 osb->sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
355 status = -EDQUOT;
356 goto leave; 355 goto leave;
357 }
358 did_quota_inode = 1; 356 did_quota_inode = 1;
359 357
360 mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, 358 mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry,
@@ -431,7 +429,7 @@ static int ocfs2_mknod(struct inode *dir,
431 status = 0; 429 status = 0;
432leave: 430leave:
433 if (status < 0 && did_quota_inode) 431 if (status < 0 && did_quota_inode)
434 vfs_dq_free_inode(inode); 432 dquot_free_inode(inode);
435 if (handle) 433 if (handle)
436 ocfs2_commit_trans(osb, handle); 434 ocfs2_commit_trans(osb, handle);
437 435
@@ -636,6 +634,8 @@ static int ocfs2_link(struct dentry *old_dentry,
636 if (S_ISDIR(inode->i_mode)) 634 if (S_ISDIR(inode->i_mode))
637 return -EPERM; 635 return -EPERM;
638 636
637 dquot_initialize(dir);
638
639 err = ocfs2_inode_lock_nested(dir, &parent_fe_bh, 1, OI_LS_PARENT); 639 err = ocfs2_inode_lock_nested(dir, &parent_fe_bh, 1, OI_LS_PARENT);
640 if (err < 0) { 640 if (err < 0) {
641 if (err != -ENOENT) 641 if (err != -ENOENT)
@@ -791,6 +791,8 @@ static int ocfs2_unlink(struct inode *dir,
791 mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry, 791 mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry,
792 dentry->d_name.len, dentry->d_name.name); 792 dentry->d_name.len, dentry->d_name.name);
793 793
794 dquot_initialize(dir);
795
794 BUG_ON(dentry->d_parent->d_inode != dir); 796 BUG_ON(dentry->d_parent->d_inode != dir);
795 797
796 mlog(0, "ino = %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno); 798 mlog(0, "ino = %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno);
@@ -1051,6 +1053,9 @@ static int ocfs2_rename(struct inode *old_dir,
1051 old_dentry->d_name.len, old_dentry->d_name.name, 1053 old_dentry->d_name.len, old_dentry->d_name.name,
1052 new_dentry->d_name.len, new_dentry->d_name.name); 1054 new_dentry->d_name.len, new_dentry->d_name.name);
1053 1055
1056 dquot_initialize(old_dir);
1057 dquot_initialize(new_dir);
1058
1054 osb = OCFS2_SB(old_dir->i_sb); 1059 osb = OCFS2_SB(old_dir->i_sb);
1055 1060
1056 if (new_inode) { 1061 if (new_inode) {
@@ -1599,6 +1604,8 @@ static int ocfs2_symlink(struct inode *dir,
1599 mlog_entry("(0x%p, 0x%p, symname='%s' actual='%.*s')\n", dir, 1604 mlog_entry("(0x%p, 0x%p, symname='%s' actual='%.*s')\n", dir,
1600 dentry, symname, dentry->d_name.len, dentry->d_name.name); 1605 dentry, symname, dentry->d_name.len, dentry->d_name.name);
1601 1606
1607 dquot_initialize(dir);
1608
1602 sb = dir->i_sb; 1609 sb = dir->i_sb;
1603 osb = OCFS2_SB(sb); 1610 osb = OCFS2_SB(sb);
1604 1611
@@ -1688,13 +1695,9 @@ static int ocfs2_symlink(struct inode *dir,
1688 goto bail; 1695 goto bail;
1689 } 1696 }
1690 1697
1691 /* We don't use standard VFS wrapper because we don't want vfs_dq_init 1698 status = dquot_alloc_inode(inode);
1692 * to be called. */ 1699 if (status)
1693 if (sb_any_quota_active(osb->sb) &&
1694 osb->sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
1695 status = -EDQUOT;
1696 goto bail; 1700 goto bail;
1697 }
1698 did_quota_inode = 1; 1701 did_quota_inode = 1;
1699 1702
1700 mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry, 1703 mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry,
@@ -1716,11 +1719,10 @@ static int ocfs2_symlink(struct inode *dir,
1716 u32 offset = 0; 1719 u32 offset = 0;
1717 1720
1718 inode->i_op = &ocfs2_symlink_inode_operations; 1721 inode->i_op = &ocfs2_symlink_inode_operations;
1719 if (vfs_dq_alloc_space_nodirty(inode, 1722 status = dquot_alloc_space_nodirty(inode,
1720 ocfs2_clusters_to_bytes(osb->sb, 1))) { 1723 ocfs2_clusters_to_bytes(osb->sb, 1));
1721 status = -EDQUOT; 1724 if (status)
1722 goto bail; 1725 goto bail;
1723 }
1724 did_quota = 1; 1726 did_quota = 1;
1725 status = ocfs2_add_inode_data(osb, inode, &offset, 1, 0, 1727 status = ocfs2_add_inode_data(osb, inode, &offset, 1, 0,
1726 new_fe_bh, 1728 new_fe_bh,
@@ -1788,10 +1790,10 @@ static int ocfs2_symlink(struct inode *dir,
1788 d_instantiate(dentry, inode); 1790 d_instantiate(dentry, inode);
1789bail: 1791bail:
1790 if (status < 0 && did_quota) 1792 if (status < 0 && did_quota)
1791 vfs_dq_free_space_nodirty(inode, 1793 dquot_free_space_nodirty(inode,
1792 ocfs2_clusters_to_bytes(osb->sb, 1)); 1794 ocfs2_clusters_to_bytes(osb->sb, 1));
1793 if (status < 0 && did_quota_inode) 1795 if (status < 0 && did_quota_inode)
1794 vfs_dq_free_inode(inode); 1796 dquot_free_inode(inode);
1795 if (handle) 1797 if (handle)
1796 ocfs2_commit_trans(osb, handle); 1798 ocfs2_commit_trans(osb, handle);
1797 1799
@@ -2099,13 +2101,9 @@ int ocfs2_create_inode_in_orphan(struct inode *dir,
2099 goto leave; 2101 goto leave;
2100 } 2102 }
2101 2103
2102 /* We don't use standard VFS wrapper because we don't want vfs_dq_init 2104 status = dquot_alloc_inode(inode);
2103 * to be called. */ 2105 if (status)
2104 if (sb_any_quota_active(osb->sb) &&
2105 osb->sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
2106 status = -EDQUOT;
2107 goto leave; 2106 goto leave;
2108 }
2109 did_quota_inode = 1; 2107 did_quota_inode = 1;
2110 2108
2111 inode->i_nlink = 0; 2109 inode->i_nlink = 0;
@@ -2140,7 +2138,7 @@ int ocfs2_create_inode_in_orphan(struct inode *dir,
2140 insert_inode_hash(inode); 2138 insert_inode_hash(inode);
2141leave: 2139leave:
2142 if (status < 0 && did_quota_inode) 2140 if (status < 0 && did_quota_inode)
2143 vfs_dq_free_inode(inode); 2141 dquot_free_inode(inode);
2144 if (handle) 2142 if (handle)
2145 ocfs2_commit_trans(osb, handle); 2143 ocfs2_commit_trans(osb, handle);
2146 2144
diff --git a/fs/ocfs2/quota_global.c b/fs/ocfs2/quota_global.c
index b437dc0c4cad..355f41d1d520 100644
--- a/fs/ocfs2/quota_global.c
+++ b/fs/ocfs2/quota_global.c
@@ -851,13 +851,6 @@ static void ocfs2_destroy_dquot(struct dquot *dquot)
851} 851}
852 852
853const struct dquot_operations ocfs2_quota_operations = { 853const struct dquot_operations ocfs2_quota_operations = {
854 .initialize = dquot_initialize,
855 .drop = dquot_drop,
856 .alloc_space = dquot_alloc_space,
857 .alloc_inode = dquot_alloc_inode,
858 .free_space = dquot_free_space,
859 .free_inode = dquot_free_inode,
860 .transfer = dquot_transfer,
861 .write_dquot = ocfs2_write_dquot, 854 .write_dquot = ocfs2_write_dquot,
862 .acquire_dquot = ocfs2_acquire_dquot, 855 .acquire_dquot = ocfs2_acquire_dquot,
863 .release_dquot = ocfs2_release_dquot, 856 .release_dquot = ocfs2_release_dquot,
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index fb6aa7acf54b..9e96921dffda 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -4390,7 +4390,7 @@ static int ocfs2_vfs_reflink(struct dentry *old_dentry, struct inode *dir,
4390 } 4390 }
4391 4391
4392 mutex_lock(&inode->i_mutex); 4392 mutex_lock(&inode->i_mutex);
4393 vfs_dq_init(dir); 4393 dquot_initialize(dir);
4394 error = ocfs2_reflink(old_dentry, dir, new_dentry, preserve); 4394 error = ocfs2_reflink(old_dentry, dir, new_dentry, preserve);
4395 mutex_unlock(&inode->i_mutex); 4395 mutex_unlock(&inode->i_mutex);
4396 if (!error) 4396 if (!error)
diff --git a/fs/open.c b/fs/open.c
index e0b2d88b0380..e17f54454b50 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -8,7 +8,6 @@
8#include <linux/mm.h> 8#include <linux/mm.h>
9#include <linux/file.h> 9#include <linux/file.h>
10#include <linux/fdtable.h> 10#include <linux/fdtable.h>
11#include <linux/quotaops.h>
12#include <linux/fsnotify.h> 11#include <linux/fsnotify.h>
13#include <linux/module.h> 12#include <linux/module.h>
14#include <linux/slab.h> 13#include <linux/slab.h>
@@ -278,10 +277,8 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
278 error = locks_verify_truncate(inode, NULL, length); 277 error = locks_verify_truncate(inode, NULL, length);
279 if (!error) 278 if (!error)
280 error = security_path_truncate(&path, length, 0); 279 error = security_path_truncate(&path, length, 0);
281 if (!error) { 280 if (!error)
282 vfs_dq_init(inode);
283 error = do_truncate(path.dentry, length, 0, NULL); 281 error = do_truncate(path.dentry, length, 0, NULL);
284 }
285 282
286put_write_and_out: 283put_write_and_out:
287 put_write_access(inode); 284 put_write_access(inode);
diff --git a/fs/quota/Kconfig b/fs/quota/Kconfig
index efc02ebb8c70..dad7fb247ddc 100644
--- a/fs/quota/Kconfig
+++ b/fs/quota/Kconfig
@@ -59,3 +59,8 @@ config QUOTACTL
59 bool 59 bool
60 depends on XFS_QUOTA || QUOTA 60 depends on XFS_QUOTA || QUOTA
61 default y 61 default y
62
63config QUOTACTL_COMPAT
64 bool
65 depends on QUOTACTL && COMPAT_FOR_U64_ALIGNMENT
66 default y
diff --git a/fs/quota/Makefile b/fs/quota/Makefile
index 68d4f6dc0578..5f9e9e276af0 100644
--- a/fs/quota/Makefile
+++ b/fs/quota/Makefile
@@ -3,3 +3,5 @@ obj-$(CONFIG_QFMT_V1) += quota_v1.o
3obj-$(CONFIG_QFMT_V2) += quota_v2.o 3obj-$(CONFIG_QFMT_V2) += quota_v2.o
4obj-$(CONFIG_QUOTA_TREE) += quota_tree.o 4obj-$(CONFIG_QUOTA_TREE) += quota_tree.o
5obj-$(CONFIG_QUOTACTL) += quota.o 5obj-$(CONFIG_QUOTACTL) += quota.o
6obj-$(CONFIG_QUOTACTL_COMPAT) += compat.o
7obj-$(CONFIG_QUOTA_NETLINK_INTERFACE) += netlink.o
diff --git a/fs/quota/compat.c b/fs/quota/compat.c
new file mode 100644
index 000000000000..fb1892fe3e56
--- /dev/null
+++ b/fs/quota/compat.c
@@ -0,0 +1,118 @@
1
2#include <linux/syscalls.h>
3#include <linux/compat.h>
4#include <linux/quotaops.h>
5
6/*
7 * This code works only for 32 bit quota tools over 64 bit OS (x86_64, ia64)
8 * and is necessary due to alignment problems.
9 */
10struct compat_if_dqblk {
11 compat_u64 dqb_bhardlimit;
12 compat_u64 dqb_bsoftlimit;
13 compat_u64 dqb_curspace;
14 compat_u64 dqb_ihardlimit;
15 compat_u64 dqb_isoftlimit;
16 compat_u64 dqb_curinodes;
17 compat_u64 dqb_btime;
18 compat_u64 dqb_itime;
19 compat_uint_t dqb_valid;
20};
21
22/* XFS structures */
23struct compat_fs_qfilestat {
24 compat_u64 dqb_bhardlimit;
25 compat_u64 qfs_nblks;
26 compat_uint_t qfs_nextents;
27};
28
29struct compat_fs_quota_stat {
30 __s8 qs_version;
31 __u16 qs_flags;
32 __s8 qs_pad;
33 struct compat_fs_qfilestat qs_uquota;
34 struct compat_fs_qfilestat qs_gquota;
35 compat_uint_t qs_incoredqs;
36 compat_int_t qs_btimelimit;
37 compat_int_t qs_itimelimit;
38 compat_int_t qs_rtbtimelimit;
39 __u16 qs_bwarnlimit;
40 __u16 qs_iwarnlimit;
41};
42
43asmlinkage long sys32_quotactl(unsigned int cmd, const char __user *special,
44 qid_t id, void __user *addr)
45{
46 unsigned int cmds;
47 struct if_dqblk __user *dqblk;
48 struct compat_if_dqblk __user *compat_dqblk;
49 struct fs_quota_stat __user *fsqstat;
50 struct compat_fs_quota_stat __user *compat_fsqstat;
51 compat_uint_t data;
52 u16 xdata;
53 long ret;
54
55 cmds = cmd >> SUBCMDSHIFT;
56
57 switch (cmds) {
58 case Q_GETQUOTA:
59 dqblk = compat_alloc_user_space(sizeof(struct if_dqblk));
60 compat_dqblk = addr;
61 ret = sys_quotactl(cmd, special, id, dqblk);
62 if (ret)
63 break;
64 if (copy_in_user(compat_dqblk, dqblk, sizeof(*compat_dqblk)) ||
65 get_user(data, &dqblk->dqb_valid) ||
66 put_user(data, &compat_dqblk->dqb_valid))
67 ret = -EFAULT;
68 break;
69 case Q_SETQUOTA:
70 dqblk = compat_alloc_user_space(sizeof(struct if_dqblk));
71 compat_dqblk = addr;
72 ret = -EFAULT;
73 if (copy_in_user(dqblk, compat_dqblk, sizeof(*compat_dqblk)) ||
74 get_user(data, &compat_dqblk->dqb_valid) ||
75 put_user(data, &dqblk->dqb_valid))
76 break;
77 ret = sys_quotactl(cmd, special, id, dqblk);
78 break;
79 case Q_XGETQSTAT:
80 fsqstat = compat_alloc_user_space(sizeof(struct fs_quota_stat));
81 compat_fsqstat = addr;
82 ret = sys_quotactl(cmd, special, id, fsqstat);
83 if (ret)
84 break;
85 ret = -EFAULT;
86 /* Copying qs_version, qs_flags, qs_pad */
87 if (copy_in_user(compat_fsqstat, fsqstat,
88 offsetof(struct compat_fs_quota_stat, qs_uquota)))
89 break;
90 /* Copying qs_uquota */
91 if (copy_in_user(&compat_fsqstat->qs_uquota,
92 &fsqstat->qs_uquota,
93 sizeof(compat_fsqstat->qs_uquota)) ||
94 get_user(data, &fsqstat->qs_uquota.qfs_nextents) ||
95 put_user(data, &compat_fsqstat->qs_uquota.qfs_nextents))
96 break;
97 /* Copying qs_gquota */
98 if (copy_in_user(&compat_fsqstat->qs_gquota,
99 &fsqstat->qs_gquota,
100 sizeof(compat_fsqstat->qs_gquota)) ||
101 get_user(data, &fsqstat->qs_gquota.qfs_nextents) ||
102 put_user(data, &compat_fsqstat->qs_gquota.qfs_nextents))
103 break;
104 /* Copying the rest */
105 if (copy_in_user(&compat_fsqstat->qs_incoredqs,
106 &fsqstat->qs_incoredqs,
107 sizeof(struct compat_fs_quota_stat) -
108 offsetof(struct compat_fs_quota_stat, qs_incoredqs)) ||
109 get_user(xdata, &fsqstat->qs_iwarnlimit) ||
110 put_user(xdata, &compat_fsqstat->qs_iwarnlimit))
111 break;
112 ret = 0;
113 break;
114 default:
115 ret = sys_quotactl(cmd, special, id, addr);
116 }
117 return ret;
118}
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 3fc62b097bed..e0b870f4749f 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -100,9 +100,13 @@
100 * 100 *
101 * Any operation working on dquots via inode pointers must hold dqptr_sem. If 101 * Any operation working on dquots via inode pointers must hold dqptr_sem. If
102 * operation is just reading pointers from inode (or not using them at all) the 102 * operation is just reading pointers from inode (or not using them at all) the
103 * read lock is enough. If pointers are altered function must hold write lock 103 * read lock is enough. If pointers are altered function must hold write lock.
104 * (these locking rules also apply for S_NOQUOTA flag in the inode - note that 104 * Special care needs to be taken about S_NOQUOTA inode flag (marking that
105 * for altering the flag i_mutex is also needed). 105 * inode is a quota file). Functions adding pointers from inode to dquots have
106 * to check this flag under dqptr_sem and then (if S_NOQUOTA is not set) they
107 * have to do all pointer modifications before dropping dqptr_sem. This makes
108 * sure they cannot race with quotaon which first sets S_NOQUOTA flag and
109 * then drops all pointers to dquots from an inode.
106 * 110 *
107 * Each dquot has its dq_lock mutex. Locked dquots might not be referenced 111 * Each dquot has its dq_lock mutex. Locked dquots might not be referenced
108 * from inodes (dquot_alloc_space() and such don't check the dq_lock). 112 * from inodes (dquot_alloc_space() and such don't check the dq_lock).
@@ -225,6 +229,9 @@ static struct hlist_head *dquot_hash;
225struct dqstats dqstats; 229struct dqstats dqstats;
226EXPORT_SYMBOL(dqstats); 230EXPORT_SYMBOL(dqstats);
227 231
232static qsize_t inode_get_rsv_space(struct inode *inode);
233static void __dquot_initialize(struct inode *inode, int type);
234
228static inline unsigned int 235static inline unsigned int
229hashfn(const struct super_block *sb, unsigned int id, int type) 236hashfn(const struct super_block *sb, unsigned int id, int type)
230{ 237{
@@ -564,7 +571,7 @@ out:
564} 571}
565EXPORT_SYMBOL(dquot_scan_active); 572EXPORT_SYMBOL(dquot_scan_active);
566 573
567int vfs_quota_sync(struct super_block *sb, int type) 574int vfs_quota_sync(struct super_block *sb, int type, int wait)
568{ 575{
569 struct list_head *dirty; 576 struct list_head *dirty;
570 struct dquot *dquot; 577 struct dquot *dquot;
@@ -609,6 +616,33 @@ int vfs_quota_sync(struct super_block *sb, int type)
609 spin_unlock(&dq_list_lock); 616 spin_unlock(&dq_list_lock);
610 mutex_unlock(&dqopt->dqonoff_mutex); 617 mutex_unlock(&dqopt->dqonoff_mutex);
611 618
619 if (!wait || (sb_dqopt(sb)->flags & DQUOT_QUOTA_SYS_FILE))
620 return 0;
621
622 /* This is not very clever (and fast) but currently I don't know about
623 * any other simple way of getting quota data to disk and we must get
624 * them there for userspace to be visible... */
625 if (sb->s_op->sync_fs)
626 sb->s_op->sync_fs(sb, 1);
627 sync_blockdev(sb->s_bdev);
628
629 /*
630 * Now when everything is written we can discard the pagecache so
631 * that userspace sees the changes.
632 */
633 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
634 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
635 if (type != -1 && cnt != type)
636 continue;
637 if (!sb_has_quota_active(sb, cnt))
638 continue;
639 mutex_lock_nested(&sb_dqopt(sb)->files[cnt]->i_mutex,
640 I_MUTEX_QUOTA);
641 truncate_inode_pages(&sb_dqopt(sb)->files[cnt]->i_data, 0);
642 mutex_unlock(&sb_dqopt(sb)->files[cnt]->i_mutex);
643 }
644 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
645
612 return 0; 646 return 0;
613} 647}
614EXPORT_SYMBOL(vfs_quota_sync); 648EXPORT_SYMBOL(vfs_quota_sync);
@@ -840,11 +874,14 @@ static int dqinit_needed(struct inode *inode, int type)
840static void add_dquot_ref(struct super_block *sb, int type) 874static void add_dquot_ref(struct super_block *sb, int type)
841{ 875{
842 struct inode *inode, *old_inode = NULL; 876 struct inode *inode, *old_inode = NULL;
877 int reserved = 0;
843 878
844 spin_lock(&inode_lock); 879 spin_lock(&inode_lock);
845 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { 880 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
846 if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE|I_NEW)) 881 if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE|I_NEW))
847 continue; 882 continue;
883 if (unlikely(inode_get_rsv_space(inode) > 0))
884 reserved = 1;
848 if (!atomic_read(&inode->i_writecount)) 885 if (!atomic_read(&inode->i_writecount))
849 continue; 886 continue;
850 if (!dqinit_needed(inode, type)) 887 if (!dqinit_needed(inode, type))
@@ -854,7 +891,7 @@ static void add_dquot_ref(struct super_block *sb, int type)
854 spin_unlock(&inode_lock); 891 spin_unlock(&inode_lock);
855 892
856 iput(old_inode); 893 iput(old_inode);
857 sb->dq_op->initialize(inode, type); 894 __dquot_initialize(inode, type);
858 /* We hold a reference to 'inode' so it couldn't have been 895 /* We hold a reference to 'inode' so it couldn't have been
859 * removed from s_inodes list while we dropped the inode_lock. 896 * removed from s_inodes list while we dropped the inode_lock.
860 * We cannot iput the inode now as we can be holding the last 897 * We cannot iput the inode now as we can be holding the last
@@ -865,6 +902,12 @@ static void add_dquot_ref(struct super_block *sb, int type)
865 } 902 }
866 spin_unlock(&inode_lock); 903 spin_unlock(&inode_lock);
867 iput(old_inode); 904 iput(old_inode);
905
906 if (reserved) {
907 printk(KERN_WARNING "VFS (%s): Writes happened before quota"
908 " was turned on thus quota information is probably "
909 "inconsistent. Please run quotacheck(8).\n", sb->s_id);
910 }
868} 911}
869 912
870/* 913/*
@@ -978,10 +1021,12 @@ static inline void dquot_resv_space(struct dquot *dquot, qsize_t number)
978/* 1021/*
979 * Claim reserved quota space 1022 * Claim reserved quota space
980 */ 1023 */
981static void dquot_claim_reserved_space(struct dquot *dquot, 1024static void dquot_claim_reserved_space(struct dquot *dquot, qsize_t number)
982 qsize_t number)
983{ 1025{
984 WARN_ON(dquot->dq_dqb.dqb_rsvspace < number); 1026 if (dquot->dq_dqb.dqb_rsvspace < number) {
1027 WARN_ON_ONCE(1);
1028 number = dquot->dq_dqb.dqb_rsvspace;
1029 }
985 dquot->dq_dqb.dqb_curspace += number; 1030 dquot->dq_dqb.dqb_curspace += number;
986 dquot->dq_dqb.dqb_rsvspace -= number; 1031 dquot->dq_dqb.dqb_rsvspace -= number;
987} 1032}
@@ -989,7 +1034,12 @@ static void dquot_claim_reserved_space(struct dquot *dquot,
989static inline 1034static inline
990void dquot_free_reserved_space(struct dquot *dquot, qsize_t number) 1035void dquot_free_reserved_space(struct dquot *dquot, qsize_t number)
991{ 1036{
992 dquot->dq_dqb.dqb_rsvspace -= number; 1037 if (dquot->dq_dqb.dqb_rsvspace >= number)
1038 dquot->dq_dqb.dqb_rsvspace -= number;
1039 else {
1040 WARN_ON_ONCE(1);
1041 dquot->dq_dqb.dqb_rsvspace = 0;
1042 }
993} 1043}
994 1044
995static void dquot_decr_inodes(struct dquot *dquot, qsize_t number) 1045static void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
@@ -1131,13 +1181,13 @@ static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
1131 *warntype = QUOTA_NL_NOWARN; 1181 *warntype = QUOTA_NL_NOWARN;
1132 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) || 1182 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) ||
1133 test_bit(DQ_FAKE_B, &dquot->dq_flags)) 1183 test_bit(DQ_FAKE_B, &dquot->dq_flags))
1134 return QUOTA_OK; 1184 return 0;
1135 1185
1136 if (dquot->dq_dqb.dqb_ihardlimit && 1186 if (dquot->dq_dqb.dqb_ihardlimit &&
1137 newinodes > dquot->dq_dqb.dqb_ihardlimit && 1187 newinodes > dquot->dq_dqb.dqb_ihardlimit &&
1138 !ignore_hardlimit(dquot)) { 1188 !ignore_hardlimit(dquot)) {
1139 *warntype = QUOTA_NL_IHARDWARN; 1189 *warntype = QUOTA_NL_IHARDWARN;
1140 return NO_QUOTA; 1190 return -EDQUOT;
1141 } 1191 }
1142 1192
1143 if (dquot->dq_dqb.dqb_isoftlimit && 1193 if (dquot->dq_dqb.dqb_isoftlimit &&
@@ -1146,7 +1196,7 @@ static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
1146 get_seconds() >= dquot->dq_dqb.dqb_itime && 1196 get_seconds() >= dquot->dq_dqb.dqb_itime &&
1147 !ignore_hardlimit(dquot)) { 1197 !ignore_hardlimit(dquot)) {
1148 *warntype = QUOTA_NL_ISOFTLONGWARN; 1198 *warntype = QUOTA_NL_ISOFTLONGWARN;
1149 return NO_QUOTA; 1199 return -EDQUOT;
1150 } 1200 }
1151 1201
1152 if (dquot->dq_dqb.dqb_isoftlimit && 1202 if (dquot->dq_dqb.dqb_isoftlimit &&
@@ -1157,7 +1207,7 @@ static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
1157 sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace; 1207 sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
1158 } 1208 }
1159 1209
1160 return QUOTA_OK; 1210 return 0;
1161} 1211}
1162 1212
1163/* needs dq_data_lock */ 1213/* needs dq_data_lock */
@@ -1169,7 +1219,7 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *war
1169 *warntype = QUOTA_NL_NOWARN; 1219 *warntype = QUOTA_NL_NOWARN;
1170 if (!sb_has_quota_limits_enabled(sb, dquot->dq_type) || 1220 if (!sb_has_quota_limits_enabled(sb, dquot->dq_type) ||
1171 test_bit(DQ_FAKE_B, &dquot->dq_flags)) 1221 test_bit(DQ_FAKE_B, &dquot->dq_flags))
1172 return QUOTA_OK; 1222 return 0;
1173 1223
1174 tspace = dquot->dq_dqb.dqb_curspace + dquot->dq_dqb.dqb_rsvspace 1224 tspace = dquot->dq_dqb.dqb_curspace + dquot->dq_dqb.dqb_rsvspace
1175 + space; 1225 + space;
@@ -1179,7 +1229,7 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *war
1179 !ignore_hardlimit(dquot)) { 1229 !ignore_hardlimit(dquot)) {
1180 if (!prealloc) 1230 if (!prealloc)
1181 *warntype = QUOTA_NL_BHARDWARN; 1231 *warntype = QUOTA_NL_BHARDWARN;
1182 return NO_QUOTA; 1232 return -EDQUOT;
1183 } 1233 }
1184 1234
1185 if (dquot->dq_dqb.dqb_bsoftlimit && 1235 if (dquot->dq_dqb.dqb_bsoftlimit &&
@@ -1189,7 +1239,7 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *war
1189 !ignore_hardlimit(dquot)) { 1239 !ignore_hardlimit(dquot)) {
1190 if (!prealloc) 1240 if (!prealloc)
1191 *warntype = QUOTA_NL_BSOFTLONGWARN; 1241 *warntype = QUOTA_NL_BSOFTLONGWARN;
1192 return NO_QUOTA; 1242 return -EDQUOT;
1193 } 1243 }
1194 1244
1195 if (dquot->dq_dqb.dqb_bsoftlimit && 1245 if (dquot->dq_dqb.dqb_bsoftlimit &&
@@ -1205,10 +1255,10 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *war
1205 * We don't allow preallocation to exceed softlimit so exceeding will 1255 * We don't allow preallocation to exceed softlimit so exceeding will
1206 * be always printed 1256 * be always printed
1207 */ 1257 */
1208 return NO_QUOTA; 1258 return -EDQUOT;
1209 } 1259 }
1210 1260
1211 return QUOTA_OK; 1261 return 0;
1212} 1262}
1213 1263
1214static int info_idq_free(struct dquot *dquot, qsize_t inodes) 1264static int info_idq_free(struct dquot *dquot, qsize_t inodes)
@@ -1242,25 +1292,32 @@ static int info_bdq_free(struct dquot *dquot, qsize_t space)
1242 return QUOTA_NL_BHARDBELOW; 1292 return QUOTA_NL_BHARDBELOW;
1243 return QUOTA_NL_NOWARN; 1293 return QUOTA_NL_NOWARN;
1244} 1294}
1295
1245/* 1296/*
1246 * Initialize quota pointers in inode 1297 * Initialize quota pointers in inode
1247 * We do things in a bit complicated way but by that we avoid calling 1298 *
1248 * dqget() and thus filesystem callbacks under dqptr_sem. 1299 * We do things in a bit complicated way but by that we avoid calling
1300 * dqget() and thus filesystem callbacks under dqptr_sem.
1301 *
1302 * It is better to call this function outside of any transaction as it
1303 * might need a lot of space in journal for dquot structure allocation.
1249 */ 1304 */
1250int dquot_initialize(struct inode *inode, int type) 1305static void __dquot_initialize(struct inode *inode, int type)
1251{ 1306{
1252 unsigned int id = 0; 1307 unsigned int id = 0;
1253 int cnt, ret = 0; 1308 int cnt;
1254 struct dquot *got[MAXQUOTAS] = { NULL, NULL }; 1309 struct dquot *got[MAXQUOTAS];
1255 struct super_block *sb = inode->i_sb; 1310 struct super_block *sb = inode->i_sb;
1311 qsize_t rsv;
1256 1312
1257 /* First test before acquiring mutex - solves deadlocks when we 1313 /* First test before acquiring mutex - solves deadlocks when we
1258 * re-enter the quota code and are already holding the mutex */ 1314 * re-enter the quota code and are already holding the mutex */
1259 if (IS_NOQUOTA(inode)) 1315 if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode))
1260 return 0; 1316 return;
1261 1317
1262 /* First get references to structures we might need. */ 1318 /* First get references to structures we might need. */
1263 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1319 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1320 got[cnt] = NULL;
1264 if (type != -1 && cnt != type) 1321 if (type != -1 && cnt != type)
1265 continue; 1322 continue;
1266 switch (cnt) { 1323 switch (cnt) {
@@ -1275,7 +1332,6 @@ int dquot_initialize(struct inode *inode, int type)
1275 } 1332 }
1276 1333
1277 down_write(&sb_dqopt(sb)->dqptr_sem); 1334 down_write(&sb_dqopt(sb)->dqptr_sem);
1278 /* Having dqptr_sem we know NOQUOTA flags can't be altered... */
1279 if (IS_NOQUOTA(inode)) 1335 if (IS_NOQUOTA(inode))
1280 goto out_err; 1336 goto out_err;
1281 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1337 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
@@ -1287,20 +1343,31 @@ int dquot_initialize(struct inode *inode, int type)
1287 if (!inode->i_dquot[cnt]) { 1343 if (!inode->i_dquot[cnt]) {
1288 inode->i_dquot[cnt] = got[cnt]; 1344 inode->i_dquot[cnt] = got[cnt];
1289 got[cnt] = NULL; 1345 got[cnt] = NULL;
1346 /*
1347 * Make quota reservation system happy if someone
1348 * did a write before quota was turned on
1349 */
1350 rsv = inode_get_rsv_space(inode);
1351 if (unlikely(rsv))
1352 dquot_resv_space(inode->i_dquot[cnt], rsv);
1290 } 1353 }
1291 } 1354 }
1292out_err: 1355out_err:
1293 up_write(&sb_dqopt(sb)->dqptr_sem); 1356 up_write(&sb_dqopt(sb)->dqptr_sem);
1294 /* Drop unused references */ 1357 /* Drop unused references */
1295 dqput_all(got); 1358 dqput_all(got);
1296 return ret; 1359}
1360
1361void dquot_initialize(struct inode *inode)
1362{
1363 __dquot_initialize(inode, -1);
1297} 1364}
1298EXPORT_SYMBOL(dquot_initialize); 1365EXPORT_SYMBOL(dquot_initialize);
1299 1366
1300/* 1367/*
1301 * Release all quotas referenced by inode 1368 * Release all quotas referenced by inode
1302 */ 1369 */
1303int dquot_drop(struct inode *inode) 1370static void __dquot_drop(struct inode *inode)
1304{ 1371{
1305 int cnt; 1372 int cnt;
1306 struct dquot *put[MAXQUOTAS]; 1373 struct dquot *put[MAXQUOTAS];
@@ -1312,32 +1379,31 @@ int dquot_drop(struct inode *inode)
1312 } 1379 }
1313 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1380 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1314 dqput_all(put); 1381 dqput_all(put);
1315 return 0;
1316} 1382}
1317EXPORT_SYMBOL(dquot_drop);
1318 1383
1319/* Wrapper to remove references to quota structures from inode */ 1384void dquot_drop(struct inode *inode)
1320void vfs_dq_drop(struct inode *inode) 1385{
1321{ 1386 int cnt;
1322 /* Here we can get arbitrary inode from clear_inode() so we have 1387
1323 * to be careful. OTOH we don't need locking as quota operations 1388 if (IS_NOQUOTA(inode))
1324 * are allowed to change only at mount time */ 1389 return;
1325 if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op 1390
1326 && inode->i_sb->dq_op->drop) { 1391 /*
1327 int cnt; 1392 * Test before calling to rule out calls from proc and such
1328 /* Test before calling to rule out calls from proc and such 1393 * where we are not allowed to block. Note that this is
1329 * where we are not allowed to block. Note that this is 1394 * actually reliable test even without the lock - the caller
1330 * actually reliable test even without the lock - the caller 1395 * must assure that nobody can come after the DQUOT_DROP and
1331 * must assure that nobody can come after the DQUOT_DROP and 1396 * add quota pointers back anyway.
1332 * add quota pointers back anyway */ 1397 */
1333 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1398 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1334 if (inode->i_dquot[cnt]) 1399 if (inode->i_dquot[cnt])
1335 break; 1400 break;
1336 if (cnt < MAXQUOTAS) 1401 }
1337 inode->i_sb->dq_op->drop(inode); 1402
1338 } 1403 if (cnt < MAXQUOTAS)
1339} 1404 __dquot_drop(inode);
1340EXPORT_SYMBOL(vfs_dq_drop); 1405}
1406EXPORT_SYMBOL(dquot_drop);
1341 1407
1342/* 1408/*
1343 * inode_reserved_space is managed internally by quota, and protected by 1409 * inode_reserved_space is managed internally by quota, and protected by
@@ -1351,28 +1417,30 @@ static qsize_t *inode_reserved_space(struct inode * inode)
1351 return inode->i_sb->dq_op->get_reserved_space(inode); 1417 return inode->i_sb->dq_op->get_reserved_space(inode);
1352} 1418}
1353 1419
1354static void inode_add_rsv_space(struct inode *inode, qsize_t number) 1420void inode_add_rsv_space(struct inode *inode, qsize_t number)
1355{ 1421{
1356 spin_lock(&inode->i_lock); 1422 spin_lock(&inode->i_lock);
1357 *inode_reserved_space(inode) += number; 1423 *inode_reserved_space(inode) += number;
1358 spin_unlock(&inode->i_lock); 1424 spin_unlock(&inode->i_lock);
1359} 1425}
1426EXPORT_SYMBOL(inode_add_rsv_space);
1360 1427
1361 1428void inode_claim_rsv_space(struct inode *inode, qsize_t number)
1362static void inode_claim_rsv_space(struct inode *inode, qsize_t number)
1363{ 1429{
1364 spin_lock(&inode->i_lock); 1430 spin_lock(&inode->i_lock);
1365 *inode_reserved_space(inode) -= number; 1431 *inode_reserved_space(inode) -= number;
1366 __inode_add_bytes(inode, number); 1432 __inode_add_bytes(inode, number);
1367 spin_unlock(&inode->i_lock); 1433 spin_unlock(&inode->i_lock);
1368} 1434}
1435EXPORT_SYMBOL(inode_claim_rsv_space);
1369 1436
1370static void inode_sub_rsv_space(struct inode *inode, qsize_t number) 1437void inode_sub_rsv_space(struct inode *inode, qsize_t number)
1371{ 1438{
1372 spin_lock(&inode->i_lock); 1439 spin_lock(&inode->i_lock);
1373 *inode_reserved_space(inode) -= number; 1440 *inode_reserved_space(inode) -= number;
1374 spin_unlock(&inode->i_lock); 1441 spin_unlock(&inode->i_lock);
1375} 1442}
1443EXPORT_SYMBOL(inode_sub_rsv_space);
1376 1444
1377static qsize_t inode_get_rsv_space(struct inode *inode) 1445static qsize_t inode_get_rsv_space(struct inode *inode)
1378{ 1446{
@@ -1404,38 +1472,34 @@ static void inode_decr_space(struct inode *inode, qsize_t number, int reserve)
1404} 1472}
1405 1473
1406/* 1474/*
1407 * Following four functions update i_blocks+i_bytes fields and 1475 * This functions updates i_blocks+i_bytes fields and quota information
1408 * quota information (together with appropriate checks) 1476 * (together with appropriate checks).
1409 * NOTE: We absolutely rely on the fact that caller dirties 1477 *
1410 * the inode (usually macros in quotaops.h care about this) and 1478 * NOTE: We absolutely rely on the fact that caller dirties the inode
1411 * holds a handle for the current transaction so that dquot write and 1479 * (usually helpers in quotaops.h care about this) and holds a handle for
1412 * inode write go into the same transaction. 1480 * the current transaction so that dquot write and inode write go into the
1481 * same transaction.
1413 */ 1482 */
1414 1483
1415/* 1484/*
1416 * This operation can block, but only after everything is updated 1485 * This operation can block, but only after everything is updated
1417 */ 1486 */
1418int __dquot_alloc_space(struct inode *inode, qsize_t number, 1487int __dquot_alloc_space(struct inode *inode, qsize_t number,
1419 int warn, int reserve) 1488 int warn, int reserve)
1420{ 1489{
1421 int cnt, ret = QUOTA_OK; 1490 int cnt, ret = 0;
1422 char warntype[MAXQUOTAS]; 1491 char warntype[MAXQUOTAS];
1423 1492
1424 /* 1493 /*
1425 * First test before acquiring mutex - solves deadlocks when we 1494 * First test before acquiring mutex - solves deadlocks when we
1426 * re-enter the quota code and are already holding the mutex 1495 * re-enter the quota code and are already holding the mutex
1427 */ 1496 */
1428 if (IS_NOQUOTA(inode)) { 1497 if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode)) {
1429 inode_incr_space(inode, number, reserve); 1498 inode_incr_space(inode, number, reserve);
1430 goto out; 1499 goto out;
1431 } 1500 }
1432 1501
1433 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1502 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1434 if (IS_NOQUOTA(inode)) {
1435 inode_incr_space(inode, number, reserve);
1436 goto out_unlock;
1437 }
1438
1439 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1503 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1440 warntype[cnt] = QUOTA_NL_NOWARN; 1504 warntype[cnt] = QUOTA_NL_NOWARN;
1441 1505
@@ -1443,9 +1507,9 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number,
1443 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1507 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1444 if (!inode->i_dquot[cnt]) 1508 if (!inode->i_dquot[cnt])
1445 continue; 1509 continue;
1446 if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) 1510 ret = check_bdq(inode->i_dquot[cnt], number, !warn,
1447 == NO_QUOTA) { 1511 warntype+cnt);
1448 ret = NO_QUOTA; 1512 if (ret) {
1449 spin_unlock(&dq_data_lock); 1513 spin_unlock(&dq_data_lock);
1450 goto out_flush_warn; 1514 goto out_flush_warn;
1451 } 1515 }
@@ -1466,61 +1530,45 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number,
1466 mark_all_dquot_dirty(inode->i_dquot); 1530 mark_all_dquot_dirty(inode->i_dquot);
1467out_flush_warn: 1531out_flush_warn:
1468 flush_warnings(inode->i_dquot, warntype); 1532 flush_warnings(inode->i_dquot, warntype);
1469out_unlock:
1470 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1533 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1471out: 1534out:
1472 return ret; 1535 return ret;
1473} 1536}
1474 1537EXPORT_SYMBOL(__dquot_alloc_space);
1475int dquot_alloc_space(struct inode *inode, qsize_t number, int warn)
1476{
1477 return __dquot_alloc_space(inode, number, warn, 0);
1478}
1479EXPORT_SYMBOL(dquot_alloc_space);
1480
1481int dquot_reserve_space(struct inode *inode, qsize_t number, int warn)
1482{
1483 return __dquot_alloc_space(inode, number, warn, 1);
1484}
1485EXPORT_SYMBOL(dquot_reserve_space);
1486 1538
1487/* 1539/*
1488 * This operation can block, but only after everything is updated 1540 * This operation can block, but only after everything is updated
1489 */ 1541 */
1490int dquot_alloc_inode(const struct inode *inode, qsize_t number) 1542int dquot_alloc_inode(const struct inode *inode)
1491{ 1543{
1492 int cnt, ret = NO_QUOTA; 1544 int cnt, ret = 0;
1493 char warntype[MAXQUOTAS]; 1545 char warntype[MAXQUOTAS];
1494 1546
1495 /* First test before acquiring mutex - solves deadlocks when we 1547 /* First test before acquiring mutex - solves deadlocks when we
1496 * re-enter the quota code and are already holding the mutex */ 1548 * re-enter the quota code and are already holding the mutex */
1497 if (IS_NOQUOTA(inode)) 1549 if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode))
1498 return QUOTA_OK; 1550 return 0;
1499 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1551 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1500 warntype[cnt] = QUOTA_NL_NOWARN; 1552 warntype[cnt] = QUOTA_NL_NOWARN;
1501 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1553 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1502 if (IS_NOQUOTA(inode)) {
1503 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1504 return QUOTA_OK;
1505 }
1506 spin_lock(&dq_data_lock); 1554 spin_lock(&dq_data_lock);
1507 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1555 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1508 if (!inode->i_dquot[cnt]) 1556 if (!inode->i_dquot[cnt])
1509 continue; 1557 continue;
1510 if (check_idq(inode->i_dquot[cnt], number, warntype+cnt) 1558 ret = check_idq(inode->i_dquot[cnt], 1, warntype + cnt);
1511 == NO_QUOTA) 1559 if (ret)
1512 goto warn_put_all; 1560 goto warn_put_all;
1513 } 1561 }
1514 1562
1515 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1563 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1516 if (!inode->i_dquot[cnt]) 1564 if (!inode->i_dquot[cnt])
1517 continue; 1565 continue;
1518 dquot_incr_inodes(inode->i_dquot[cnt], number); 1566 dquot_incr_inodes(inode->i_dquot[cnt], 1);
1519 } 1567 }
1520 ret = QUOTA_OK; 1568
1521warn_put_all: 1569warn_put_all:
1522 spin_unlock(&dq_data_lock); 1570 spin_unlock(&dq_data_lock);
1523 if (ret == QUOTA_OK) 1571 if (ret == 0)
1524 mark_all_dquot_dirty(inode->i_dquot); 1572 mark_all_dquot_dirty(inode->i_dquot);
1525 flush_warnings(inode->i_dquot, warntype); 1573 flush_warnings(inode->i_dquot, warntype);
1526 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1574 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
@@ -1528,23 +1576,19 @@ warn_put_all:
1528} 1576}
1529EXPORT_SYMBOL(dquot_alloc_inode); 1577EXPORT_SYMBOL(dquot_alloc_inode);
1530 1578
1531int dquot_claim_space(struct inode *inode, qsize_t number) 1579/*
1580 * Convert in-memory reserved quotas to real consumed quotas
1581 */
1582int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
1532{ 1583{
1533 int cnt; 1584 int cnt;
1534 int ret = QUOTA_OK;
1535 1585
1536 if (IS_NOQUOTA(inode)) { 1586 if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode)) {
1537 inode_claim_rsv_space(inode, number); 1587 inode_claim_rsv_space(inode, number);
1538 goto out; 1588 return 0;
1539 } 1589 }
1540 1590
1541 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1591 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1542 if (IS_NOQUOTA(inode)) {
1543 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1544 inode_claim_rsv_space(inode, number);
1545 goto out;
1546 }
1547
1548 spin_lock(&dq_data_lock); 1592 spin_lock(&dq_data_lock);
1549 /* Claim reserved quotas to allocated quotas */ 1593 /* Claim reserved quotas to allocated quotas */
1550 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1594 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
@@ -1557,33 +1601,26 @@ int dquot_claim_space(struct inode *inode, qsize_t number)
1557 spin_unlock(&dq_data_lock); 1601 spin_unlock(&dq_data_lock);
1558 mark_all_dquot_dirty(inode->i_dquot); 1602 mark_all_dquot_dirty(inode->i_dquot);
1559 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1603 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1560out: 1604 return 0;
1561 return ret;
1562} 1605}
1563EXPORT_SYMBOL(dquot_claim_space); 1606EXPORT_SYMBOL(dquot_claim_space_nodirty);
1564 1607
1565/* 1608/*
1566 * This operation can block, but only after everything is updated 1609 * This operation can block, but only after everything is updated
1567 */ 1610 */
1568int __dquot_free_space(struct inode *inode, qsize_t number, int reserve) 1611void __dquot_free_space(struct inode *inode, qsize_t number, int reserve)
1569{ 1612{
1570 unsigned int cnt; 1613 unsigned int cnt;
1571 char warntype[MAXQUOTAS]; 1614 char warntype[MAXQUOTAS];
1572 1615
1573 /* First test before acquiring mutex - solves deadlocks when we 1616 /* First test before acquiring mutex - solves deadlocks when we
1574 * re-enter the quota code and are already holding the mutex */ 1617 * re-enter the quota code and are already holding the mutex */
1575 if (IS_NOQUOTA(inode)) { 1618 if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode)) {
1576out_sub:
1577 inode_decr_space(inode, number, reserve); 1619 inode_decr_space(inode, number, reserve);
1578 return QUOTA_OK; 1620 return;
1579 } 1621 }
1580 1622
1581 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1623 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1582 /* Now recheck reliably when holding dqptr_sem */
1583 if (IS_NOQUOTA(inode)) {
1584 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1585 goto out_sub;
1586 }
1587 spin_lock(&dq_data_lock); 1624 spin_lock(&dq_data_lock);
1588 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1625 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1589 if (!inode->i_dquot[cnt]) 1626 if (!inode->i_dquot[cnt])
@@ -1603,56 +1640,34 @@ out_sub:
1603out_unlock: 1640out_unlock:
1604 flush_warnings(inode->i_dquot, warntype); 1641 flush_warnings(inode->i_dquot, warntype);
1605 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1642 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1606 return QUOTA_OK;
1607}
1608
1609int dquot_free_space(struct inode *inode, qsize_t number)
1610{
1611 return __dquot_free_space(inode, number, 0);
1612} 1643}
1613EXPORT_SYMBOL(dquot_free_space); 1644EXPORT_SYMBOL(__dquot_free_space);
1614
1615/*
1616 * Release reserved quota space
1617 */
1618void dquot_release_reserved_space(struct inode *inode, qsize_t number)
1619{
1620 __dquot_free_space(inode, number, 1);
1621
1622}
1623EXPORT_SYMBOL(dquot_release_reserved_space);
1624 1645
1625/* 1646/*
1626 * This operation can block, but only after everything is updated 1647 * This operation can block, but only after everything is updated
1627 */ 1648 */
1628int dquot_free_inode(const struct inode *inode, qsize_t number) 1649void dquot_free_inode(const struct inode *inode)
1629{ 1650{
1630 unsigned int cnt; 1651 unsigned int cnt;
1631 char warntype[MAXQUOTAS]; 1652 char warntype[MAXQUOTAS];
1632 1653
1633 /* First test before acquiring mutex - solves deadlocks when we 1654 /* First test before acquiring mutex - solves deadlocks when we
1634 * re-enter the quota code and are already holding the mutex */ 1655 * re-enter the quota code and are already holding the mutex */
1635 if (IS_NOQUOTA(inode)) 1656 if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode))
1636 return QUOTA_OK; 1657 return;
1637 1658
1638 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1659 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1639 /* Now recheck reliably when holding dqptr_sem */
1640 if (IS_NOQUOTA(inode)) {
1641 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1642 return QUOTA_OK;
1643 }
1644 spin_lock(&dq_data_lock); 1660 spin_lock(&dq_data_lock);
1645 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1661 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1646 if (!inode->i_dquot[cnt]) 1662 if (!inode->i_dquot[cnt])
1647 continue; 1663 continue;
1648 warntype[cnt] = info_idq_free(inode->i_dquot[cnt], number); 1664 warntype[cnt] = info_idq_free(inode->i_dquot[cnt], 1);
1649 dquot_decr_inodes(inode->i_dquot[cnt], number); 1665 dquot_decr_inodes(inode->i_dquot[cnt], 1);
1650 } 1666 }
1651 spin_unlock(&dq_data_lock); 1667 spin_unlock(&dq_data_lock);
1652 mark_all_dquot_dirty(inode->i_dquot); 1668 mark_all_dquot_dirty(inode->i_dquot);
1653 flush_warnings(inode->i_dquot, warntype); 1669 flush_warnings(inode->i_dquot, warntype);
1654 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1670 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1655 return QUOTA_OK;
1656} 1671}
1657EXPORT_SYMBOL(dquot_free_inode); 1672EXPORT_SYMBOL(dquot_free_inode);
1658 1673
@@ -1662,37 +1677,31 @@ EXPORT_SYMBOL(dquot_free_inode);
1662 * This operation can block, but only after everything is updated 1677 * This operation can block, but only after everything is updated
1663 * A transaction must be started when entering this function. 1678 * A transaction must be started when entering this function.
1664 */ 1679 */
1665int dquot_transfer(struct inode *inode, struct iattr *iattr) 1680static int __dquot_transfer(struct inode *inode, qid_t *chid, unsigned long mask)
1666{ 1681{
1667 qsize_t space, cur_space; 1682 qsize_t space, cur_space;
1668 qsize_t rsv_space = 0; 1683 qsize_t rsv_space = 0;
1669 struct dquot *transfer_from[MAXQUOTAS]; 1684 struct dquot *transfer_from[MAXQUOTAS];
1670 struct dquot *transfer_to[MAXQUOTAS]; 1685 struct dquot *transfer_to[MAXQUOTAS];
1671 int cnt, ret = QUOTA_OK; 1686 int cnt, ret = 0;
1672 int chuid = iattr->ia_valid & ATTR_UID && inode->i_uid != iattr->ia_uid,
1673 chgid = iattr->ia_valid & ATTR_GID && inode->i_gid != iattr->ia_gid;
1674 char warntype_to[MAXQUOTAS]; 1687 char warntype_to[MAXQUOTAS];
1675 char warntype_from_inodes[MAXQUOTAS], warntype_from_space[MAXQUOTAS]; 1688 char warntype_from_inodes[MAXQUOTAS], warntype_from_space[MAXQUOTAS];
1676 1689
1677 /* First test before acquiring mutex - solves deadlocks when we 1690 /* First test before acquiring mutex - solves deadlocks when we
1678 * re-enter the quota code and are already holding the mutex */ 1691 * re-enter the quota code and are already holding the mutex */
1679 if (IS_NOQUOTA(inode)) 1692 if (IS_NOQUOTA(inode))
1680 return QUOTA_OK; 1693 return 0;
1681 /* Initialize the arrays */ 1694 /* Initialize the arrays */
1682 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1695 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1683 transfer_from[cnt] = NULL; 1696 transfer_from[cnt] = NULL;
1684 transfer_to[cnt] = NULL; 1697 transfer_to[cnt] = NULL;
1685 warntype_to[cnt] = QUOTA_NL_NOWARN; 1698 warntype_to[cnt] = QUOTA_NL_NOWARN;
1686 } 1699 }
1687 if (chuid) 1700 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1688 transfer_to[USRQUOTA] = dqget(inode->i_sb, iattr->ia_uid, 1701 if (mask & (1 << cnt))
1689 USRQUOTA); 1702 transfer_to[cnt] = dqget(inode->i_sb, chid[cnt], cnt);
1690 if (chgid) 1703 }
1691 transfer_to[GRPQUOTA] = dqget(inode->i_sb, iattr->ia_gid,
1692 GRPQUOTA);
1693
1694 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1704 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1695 /* Now recheck reliably when holding dqptr_sem */
1696 if (IS_NOQUOTA(inode)) { /* File without quota accounting? */ 1705 if (IS_NOQUOTA(inode)) { /* File without quota accounting? */
1697 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1706 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1698 goto put_all; 1707 goto put_all;
@@ -1706,9 +1715,11 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
1706 if (!transfer_to[cnt]) 1715 if (!transfer_to[cnt])
1707 continue; 1716 continue;
1708 transfer_from[cnt] = inode->i_dquot[cnt]; 1717 transfer_from[cnt] = inode->i_dquot[cnt];
1709 if (check_idq(transfer_to[cnt], 1, warntype_to + cnt) == 1718 ret = check_idq(transfer_to[cnt], 1, warntype_to + cnt);
1710 NO_QUOTA || check_bdq(transfer_to[cnt], space, 0, 1719 if (ret)
1711 warntype_to + cnt) == NO_QUOTA) 1720 goto over_quota;
1721 ret = check_bdq(transfer_to[cnt], space, 0, warntype_to + cnt);
1722 if (ret)
1712 goto over_quota; 1723 goto over_quota;
1713 } 1724 }
1714 1725
@@ -1762,22 +1773,32 @@ over_quota:
1762 /* Clear dquot pointers we don't want to dqput() */ 1773 /* Clear dquot pointers we don't want to dqput() */
1763 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1774 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1764 transfer_from[cnt] = NULL; 1775 transfer_from[cnt] = NULL;
1765 ret = NO_QUOTA;
1766 goto warn_put_all; 1776 goto warn_put_all;
1767} 1777}
1768EXPORT_SYMBOL(dquot_transfer);
1769 1778
1770/* Wrapper for transferring ownership of an inode */ 1779/* Wrapper for transferring ownership of an inode for uid/gid only
1771int vfs_dq_transfer(struct inode *inode, struct iattr *iattr) 1780 * Called from FSXXX_setattr()
1781 */
1782int dquot_transfer(struct inode *inode, struct iattr *iattr)
1772{ 1783{
1784 qid_t chid[MAXQUOTAS];
1785 unsigned long mask = 0;
1786
1787 if (iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) {
1788 mask |= 1 << USRQUOTA;
1789 chid[USRQUOTA] = iattr->ia_uid;
1790 }
1791 if (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) {
1792 mask |= 1 << GRPQUOTA;
1793 chid[GRPQUOTA] = iattr->ia_gid;
1794 }
1773 if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) { 1795 if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) {
1774 vfs_dq_init(inode); 1796 dquot_initialize(inode);
1775 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA) 1797 return __dquot_transfer(inode, chid, mask);
1776 return 1;
1777 } 1798 }
1778 return 0; 1799 return 0;
1779} 1800}
1780EXPORT_SYMBOL(vfs_dq_transfer); 1801EXPORT_SYMBOL(dquot_transfer);
1781 1802
1782/* 1803/*
1783 * Write info of quota file to disk 1804 * Write info of quota file to disk
@@ -1798,13 +1819,6 @@ EXPORT_SYMBOL(dquot_commit_info);
1798 * Definitions of diskquota operations. 1819 * Definitions of diskquota operations.
1799 */ 1820 */
1800const struct dquot_operations dquot_operations = { 1821const struct dquot_operations dquot_operations = {
1801 .initialize = dquot_initialize,
1802 .drop = dquot_drop,
1803 .alloc_space = dquot_alloc_space,
1804 .alloc_inode = dquot_alloc_inode,
1805 .free_space = dquot_free_space,
1806 .free_inode = dquot_free_inode,
1807 .transfer = dquot_transfer,
1808 .write_dquot = dquot_commit, 1822 .write_dquot = dquot_commit,
1809 .acquire_dquot = dquot_acquire, 1823 .acquire_dquot = dquot_acquire,
1810 .release_dquot = dquot_release, 1824 .release_dquot = dquot_release,
@@ -1815,6 +1829,20 @@ const struct dquot_operations dquot_operations = {
1815}; 1829};
1816 1830
1817/* 1831/*
1832 * Generic helper for ->open on filesystems supporting disk quotas.
1833 */
1834int dquot_file_open(struct inode *inode, struct file *file)
1835{
1836 int error;
1837
1838 error = generic_file_open(inode, file);
1839 if (!error && (file->f_mode & FMODE_WRITE))
1840 dquot_initialize(inode);
1841 return error;
1842}
1843EXPORT_SYMBOL(dquot_file_open);
1844
1845/*
1818 * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount) 1846 * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount)
1819 */ 1847 */
1820int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags) 1848int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags)
@@ -1993,11 +2021,13 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,
1993 } 2021 }
1994 2022
1995 if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) { 2023 if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) {
1996 /* As we bypass the pagecache we must now flush the inode so 2024 /* As we bypass the pagecache we must now flush all the
1997 * that we see all the changes from userspace... */ 2025 * dirty data and invalidate caches so that kernel sees
1998 write_inode_now(inode, 1); 2026 * changes from userspace. It is not enough to just flush
1999 /* And now flush the block cache so that kernel sees the 2027 * the quota file since if blocksize < pagesize, invalidation
2000 * changes */ 2028 * of the cache could fail because of other unrelated dirty
2029 * data */
2030 sync_filesystem(sb);
2001 invalidate_bdev(sb->s_bdev); 2031 invalidate_bdev(sb->s_bdev);
2002 } 2032 }
2003 mutex_lock(&dqopt->dqonoff_mutex); 2033 mutex_lock(&dqopt->dqonoff_mutex);
@@ -2010,14 +2040,16 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,
2010 /* We don't want quota and atime on quota files (deadlocks 2040 /* We don't want quota and atime on quota files (deadlocks
2011 * possible) Also nobody should write to the file - we use 2041 * possible) Also nobody should write to the file - we use
2012 * special IO operations which ignore the immutable bit. */ 2042 * special IO operations which ignore the immutable bit. */
2013 down_write(&dqopt->dqptr_sem);
2014 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); 2043 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
2015 oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE | 2044 oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE |
2016 S_NOQUOTA); 2045 S_NOQUOTA);
2017 inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE; 2046 inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE;
2018 mutex_unlock(&inode->i_mutex); 2047 mutex_unlock(&inode->i_mutex);
2019 up_write(&dqopt->dqptr_sem); 2048 /*
2020 sb->dq_op->drop(inode); 2049 * When S_NOQUOTA is set, remove dquot references as no more
2050 * references can be added
2051 */
2052 __dquot_drop(inode);
2021 } 2053 }
2022 2054
2023 error = -EIO; 2055 error = -EIO;
@@ -2053,14 +2085,12 @@ out_file_init:
2053 iput(inode); 2085 iput(inode);
2054out_lock: 2086out_lock:
2055 if (oldflags != -1) { 2087 if (oldflags != -1) {
2056 down_write(&dqopt->dqptr_sem);
2057 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); 2088 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
2058 /* Set the flags back (in the case of accidental quotaon() 2089 /* Set the flags back (in the case of accidental quotaon()
2059 * on a wrong file we don't want to mess up the flags) */ 2090 * on a wrong file we don't want to mess up the flags) */
2060 inode->i_flags &= ~(S_NOATIME | S_NOQUOTA | S_IMMUTABLE); 2091 inode->i_flags &= ~(S_NOATIME | S_NOQUOTA | S_IMMUTABLE);
2061 inode->i_flags |= oldflags; 2092 inode->i_flags |= oldflags;
2062 mutex_unlock(&inode->i_mutex); 2093 mutex_unlock(&inode->i_mutex);
2063 up_write(&dqopt->dqptr_sem);
2064 } 2094 }
2065 mutex_unlock(&dqopt->dqonoff_mutex); 2095 mutex_unlock(&dqopt->dqonoff_mutex);
2066out_fmt: 2096out_fmt:
diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
new file mode 100644
index 000000000000..2663ed90fb03
--- /dev/null
+++ b/fs/quota/netlink.c
@@ -0,0 +1,95 @@
1
2#include <linux/cred.h>
3#include <linux/init.h>
4#include <linux/module.h>
5#include <linux/kernel.h>
6#include <linux/quotaops.h>
7#include <linux/sched.h>
8#include <net/netlink.h>
9#include <net/genetlink.h>
10
11/* Netlink family structure for quota */
12static struct genl_family quota_genl_family = {
13 .id = GENL_ID_GENERATE,
14 .hdrsize = 0,
15 .name = "VFS_DQUOT",
16 .version = 1,
17 .maxattr = QUOTA_NL_A_MAX,
18};
19
20/**
21 * quota_send_warning - Send warning to userspace about exceeded quota
22 * @type: The quota type: USRQQUOTA, GRPQUOTA,...
23 * @id: The user or group id of the quota that was exceeded
24 * @dev: The device on which the fs is mounted (sb->s_dev)
25 * @warntype: The type of the warning: QUOTA_NL_...
26 *
27 * This can be used by filesystems (including those which don't use
28 * dquot) to send a message to userspace relating to quota limits.
29 *
30 */
31
32void quota_send_warning(short type, unsigned int id, dev_t dev,
33 const char warntype)
34{
35 static atomic_t seq;
36 struct sk_buff *skb;
37 void *msg_head;
38 int ret;
39 int msg_size = 4 * nla_total_size(sizeof(u32)) +
40 2 * nla_total_size(sizeof(u64));
41
42 /* We have to allocate using GFP_NOFS as we are called from a
43 * filesystem performing write and thus further recursion into
44 * the fs to free some data could cause deadlocks. */
45 skb = genlmsg_new(msg_size, GFP_NOFS);
46 if (!skb) {
47 printk(KERN_ERR
48 "VFS: Not enough memory to send quota warning.\n");
49 return;
50 }
51 msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
52 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
53 if (!msg_head) {
54 printk(KERN_ERR
55 "VFS: Cannot store netlink header in quota warning.\n");
56 goto err_out;
57 }
58 ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, type);
59 if (ret)
60 goto attr_err_out;
61 ret = nla_put_u64(skb, QUOTA_NL_A_EXCESS_ID, id);
62 if (ret)
63 goto attr_err_out;
64 ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype);
65 if (ret)
66 goto attr_err_out;
67 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MAJOR, MAJOR(dev));
68 if (ret)
69 goto attr_err_out;
70 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR, MINOR(dev));
71 if (ret)
72 goto attr_err_out;
73 ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current_uid());
74 if (ret)
75 goto attr_err_out;
76 genlmsg_end(skb, msg_head);
77
78 genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
79 return;
80attr_err_out:
81 printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
82err_out:
83 kfree_skb(skb);
84}
85EXPORT_SYMBOL(quota_send_warning);
86
87static int __init quota_init(void)
88{
89 if (genl_register_family(&quota_genl_family) != 0)
90 printk(KERN_ERR
91 "VFS: Failed to create quota netlink interface.\n");
92 return 0;
93};
94
95module_init(quota_init);
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index ee91e2756950..95388f9b7356 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -10,7 +10,6 @@
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <asm/current.h> 11#include <asm/current.h>
12#include <asm/uaccess.h> 12#include <asm/uaccess.h>
13#include <linux/compat.h>
14#include <linux/kernel.h> 13#include <linux/kernel.h>
15#include <linux/security.h> 14#include <linux/security.h>
16#include <linux/syscalls.h> 15#include <linux/syscalls.h>
@@ -18,220 +17,205 @@
18#include <linux/capability.h> 17#include <linux/capability.h>
19#include <linux/quotaops.h> 18#include <linux/quotaops.h>
20#include <linux/types.h> 19#include <linux/types.h>
21#include <net/netlink.h> 20#include <linux/writeback.h>
22#include <net/genetlink.h>
23 21
24/* Check validity of generic quotactl commands */ 22static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
25static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, 23 qid_t id)
26 qid_t id)
27{ 24{
28 if (type >= MAXQUOTAS)
29 return -EINVAL;
30 if (!sb && cmd != Q_SYNC)
31 return -ENODEV;
32 /* Is operation supported? */
33 if (sb && !sb->s_qcop)
34 return -ENOSYS;
35
36 switch (cmd) { 25 switch (cmd) {
37 case Q_GETFMT: 26 /* these commands do not require any special privilegues */
38 break; 27 case Q_GETFMT:
39 case Q_QUOTAON: 28 case Q_SYNC:
40 if (!sb->s_qcop->quota_on) 29 case Q_GETINFO:
41 return -ENOSYS; 30 case Q_XGETQSTAT:
42 break; 31 case Q_XQUOTASYNC:
43 case Q_QUOTAOFF: 32 break;
44 if (!sb->s_qcop->quota_off) 33 /* allow to query information for dquots we "own" */
45 return -ENOSYS; 34 case Q_GETQUOTA:
46 break; 35 case Q_XGETQUOTA:
47 case Q_SETINFO: 36 if ((type == USRQUOTA && current_euid() == id) ||
48 if (!sb->s_qcop->set_info) 37 (type == GRPQUOTA && in_egroup_p(id)))
49 return -ENOSYS;
50 break;
51 case Q_GETINFO:
52 if (!sb->s_qcop->get_info)
53 return -ENOSYS;
54 break;
55 case Q_SETQUOTA:
56 if (!sb->s_qcop->set_dqblk)
57 return -ENOSYS;
58 break;
59 case Q_GETQUOTA:
60 if (!sb->s_qcop->get_dqblk)
61 return -ENOSYS;
62 break;
63 case Q_SYNC:
64 if (sb && !sb->s_qcop->quota_sync)
65 return -ENOSYS;
66 break; 38 break;
67 default: 39 /*FALLTHROUGH*/
68 return -EINVAL; 40 default:
41 if (!capable(CAP_SYS_ADMIN))
42 return -EPERM;
69 } 43 }
70 44
71 /* Is quota turned on for commands which need it? */ 45 return security_quotactl(cmd, type, id, sb);
72 switch (cmd) { 46}
73 case Q_GETFMT:
74 case Q_GETINFO:
75 case Q_SETINFO:
76 case Q_SETQUOTA:
77 case Q_GETQUOTA:
78 /* This is just an informative test so we are satisfied
79 * without the lock */
80 if (!sb_has_quota_active(sb, type))
81 return -ESRCH;
82 }
83 47
84 /* Check privileges */ 48static int quota_sync_all(int type)
85 if (cmd == Q_GETQUOTA) { 49{
86 if (((type == USRQUOTA && current_euid() != id) || 50 struct super_block *sb;
87 (type == GRPQUOTA && !in_egroup_p(id))) && 51 int ret;
88 !capable(CAP_SYS_ADMIN)) 52
89 return -EPERM; 53 if (type >= MAXQUOTAS)
54 return -EINVAL;
55 ret = security_quotactl(Q_SYNC, type, 0, NULL);
56 if (ret)
57 return ret;
58
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;
90 } 74 }
91 else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO) 75 spin_unlock(&sb_lock);
92 if (!capable(CAP_SYS_ADMIN))
93 return -EPERM;
94 76
95 return 0; 77 return 0;
96} 78}
97 79
98/* Check validity of XFS Quota Manager commands */ 80static int quota_quotaon(struct super_block *sb, int type, int cmd, qid_t id,
99static int xqm_quotactl_valid(struct super_block *sb, int type, int cmd, 81 void __user *addr)
100 qid_t id)
101{ 82{
102 if (type >= XQM_MAXQUOTAS) 83 char *pathname;
103 return -EINVAL; 84 int ret = -ENOSYS;
104 if (!sb) 85
105 return -ENODEV; 86 pathname = getname(addr);
106 if (!sb->s_qcop) 87 if (IS_ERR(pathname))
107 return -ENOSYS; 88 return PTR_ERR(pathname);
89 if (sb->s_qcop->quota_on)
90 ret = sb->s_qcop->quota_on(sb, type, id, pathname, 0);
91 putname(pathname);
92 return ret;
93}
108 94
109 switch (cmd) { 95static int quota_getfmt(struct super_block *sb, int type, void __user *addr)
110 case Q_XQUOTAON: 96{
111 case Q_XQUOTAOFF: 97 __u32 fmt;
112 case Q_XQUOTARM:
113 if (!sb->s_qcop->set_xstate)
114 return -ENOSYS;
115 break;
116 case Q_XGETQSTAT:
117 if (!sb->s_qcop->get_xstate)
118 return -ENOSYS;
119 break;
120 case Q_XSETQLIM:
121 if (!sb->s_qcop->set_xquota)
122 return -ENOSYS;
123 break;
124 case Q_XGETQUOTA:
125 if (!sb->s_qcop->get_xquota)
126 return -ENOSYS;
127 break;
128 case Q_XQUOTASYNC:
129 if (!sb->s_qcop->quota_sync)
130 return -ENOSYS;
131 break;
132 default:
133 return -EINVAL;
134 }
135 98
136 /* Check privileges */ 99 down_read(&sb_dqopt(sb)->dqptr_sem);
137 if (cmd == Q_XGETQUOTA) { 100 if (!sb_has_quota_active(sb, type)) {
138 if (((type == XQM_USRQUOTA && current_euid() != id) || 101 up_read(&sb_dqopt(sb)->dqptr_sem);
139 (type == XQM_GRPQUOTA && !in_egroup_p(id))) && 102 return -ESRCH;
140 !capable(CAP_SYS_ADMIN))
141 return -EPERM;
142 } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
143 if (!capable(CAP_SYS_ADMIN))
144 return -EPERM;
145 } 103 }
104 fmt = sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id;
105 up_read(&sb_dqopt(sb)->dqptr_sem);
106 if (copy_to_user(addr, &fmt, sizeof(fmt)))
107 return -EFAULT;
108 return 0;
109}
146 110
111static int quota_getinfo(struct super_block *sb, int type, void __user *addr)
112{
113 struct if_dqinfo info;
114 int ret;
115
116 if (!sb_has_quota_active(sb, type))
117 return -ESRCH;
118 if (!sb->s_qcop->get_info)
119 return -ENOSYS;
120 ret = sb->s_qcop->get_info(sb, type, &info);
121 if (!ret && copy_to_user(addr, &info, sizeof(info)))
122 return -EFAULT;
123 return ret;
124}
125
126static int quota_setinfo(struct super_block *sb, int type, void __user *addr)
127{
128 struct if_dqinfo info;
129
130 if (copy_from_user(&info, addr, sizeof(info)))
131 return -EFAULT;
132 if (!sb_has_quota_active(sb, type))
133 return -ESRCH;
134 if (!sb->s_qcop->set_info)
135 return -ENOSYS;
136 return sb->s_qcop->set_info(sb, type, &info);
137}
138
139static int quota_getquota(struct super_block *sb, int type, qid_t id,
140 void __user *addr)
141{
142 struct if_dqblk idq;
143 int ret;
144
145 if (!sb_has_quota_active(sb, type))
146 return -ESRCH;
147 if (!sb->s_qcop->get_dqblk)
148 return -ENOSYS;
149 ret = sb->s_qcop->get_dqblk(sb, type, id, &idq);
150 if (ret)
151 return ret;
152 if (copy_to_user(addr, &idq, sizeof(idq)))
153 return -EFAULT;
147 return 0; 154 return 0;
148} 155}
149 156
150static int check_quotactl_valid(struct super_block *sb, int type, int cmd, 157static int quota_setquota(struct super_block *sb, int type, qid_t id,
151 qid_t id) 158 void __user *addr)
152{ 159{
153 int error; 160 struct if_dqblk idq;
154 161
155 if (XQM_COMMAND(cmd)) 162 if (copy_from_user(&idq, addr, sizeof(idq)))
156 error = xqm_quotactl_valid(sb, type, cmd, id); 163 return -EFAULT;
157 else 164 if (!sb_has_quota_active(sb, type))
158 error = generic_quotactl_valid(sb, type, cmd, id); 165 return -ESRCH;
159 if (!error) 166 if (!sb->s_qcop->set_dqblk)
160 error = security_quotactl(cmd, type, id, sb); 167 return -ENOSYS;
161 return error; 168 return sb->s_qcop->set_dqblk(sb, type, id, &idq);
162} 169}
163 170
164#ifdef CONFIG_QUOTA 171static int quota_setxstate(struct super_block *sb, int cmd, void __user *addr)
165void sync_quota_sb(struct super_block *sb, int type)
166{ 172{
167 int cnt; 173 __u32 flags;
168 174
169 if (!sb->s_qcop->quota_sync) 175 if (copy_from_user(&flags, addr, sizeof(flags)))
170 return; 176 return -EFAULT;
177 if (!sb->s_qcop->set_xstate)
178 return -ENOSYS;
179 return sb->s_qcop->set_xstate(sb, flags, cmd);
180}
171 181
172 sb->s_qcop->quota_sync(sb, type); 182static int quota_getxstate(struct super_block *sb, void __user *addr)
183{
184 struct fs_quota_stat fqs;
185 int ret;
173 186
174 if (sb_dqopt(sb)->flags & DQUOT_QUOTA_SYS_FILE) 187 if (!sb->s_qcop->get_xstate)
175 return; 188 return -ENOSYS;
176 /* This is not very clever (and fast) but currently I don't know about 189 ret = sb->s_qcop->get_xstate(sb, &fqs);
177 * any other simple way of getting quota data to disk and we must get 190 if (!ret && copy_to_user(addr, &fqs, sizeof(fqs)))
178 * them there for userspace to be visible... */ 191 return -EFAULT;
179 if (sb->s_op->sync_fs) 192 return ret;
180 sb->s_op->sync_fs(sb, 1); 193}
181 sync_blockdev(sb->s_bdev);
182 194
183 /* 195static int quota_setxquota(struct super_block *sb, int type, qid_t id,
184 * Now when everything is written we can discard the pagecache so 196 void __user *addr)
185 * that userspace sees the changes. 197{
186 */ 198 struct fs_disk_quota fdq;
187 mutex_lock(&sb_dqopt(sb)->dqonoff_mutex); 199
188 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 200 if (copy_from_user(&fdq, addr, sizeof(fdq)))
189 if (type != -1 && cnt != type) 201 return -EFAULT;
190 continue; 202 if (!sb->s_qcop->set_xquota)
191 if (!sb_has_quota_active(sb, cnt)) 203 return -ENOSYS;
192 continue; 204 return sb->s_qcop->set_xquota(sb, type, id, &fdq);
193 mutex_lock_nested(&sb_dqopt(sb)->files[cnt]->i_mutex,
194 I_MUTEX_QUOTA);
195 truncate_inode_pages(&sb_dqopt(sb)->files[cnt]->i_data, 0);
196 mutex_unlock(&sb_dqopt(sb)->files[cnt]->i_mutex);
197 }
198 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
199} 205}
200#endif
201 206
202static void sync_dquots(int type) 207static int quota_getxquota(struct super_block *sb, int type, qid_t id,
208 void __user *addr)
203{ 209{
204 struct super_block *sb; 210 struct fs_disk_quota fdq;
205 int cnt; 211 int ret;
206 212
207 spin_lock(&sb_lock); 213 if (!sb->s_qcop->get_xquota)
208restart: 214 return -ENOSYS;
209 list_for_each_entry(sb, &super_blocks, s_list) { 215 ret = sb->s_qcop->get_xquota(sb, type, id, &fdq);
210 /* This test just improves performance so it needn't be 216 if (!ret && copy_to_user(addr, &fdq, sizeof(fdq)))
211 * reliable... */ 217 return -EFAULT;
212 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 218 return ret;
213 if (type != -1 && type != cnt)
214 continue;
215 if (!sb_has_quota_active(sb, cnt))
216 continue;
217 if (!info_dirty(&sb_dqopt(sb)->info[cnt]) &&
218 list_empty(&sb_dqopt(sb)->info[cnt].dqi_dirty_list))
219 continue;
220 break;
221 }
222 if (cnt == MAXQUOTAS)
223 continue;
224 sb->s_count++;
225 spin_unlock(&sb_lock);
226 down_read(&sb->s_umount);
227 if (sb->s_root)
228 sync_quota_sb(sb, type);
229 up_read(&sb->s_umount);
230 spin_lock(&sb_lock);
231 if (__put_super_and_need_restart(sb))
232 goto restart;
233 }
234 spin_unlock(&sb_lock);
235} 219}
236 220
237/* Copy parameters and call proper function */ 221/* Copy parameters and call proper function */
@@ -240,117 +224,55 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
240{ 224{
241 int ret; 225 int ret;
242 226
227 if (type >= (XQM_COMMAND(cmd) ? XQM_MAXQUOTAS : MAXQUOTAS))
228 return -EINVAL;
229 if (!sb->s_qcop)
230 return -ENOSYS;
231
232 ret = check_quotactl_permission(sb, type, cmd, id);
233 if (ret < 0)
234 return ret;
235
243 switch (cmd) { 236 switch (cmd) {
244 case Q_QUOTAON: { 237 case Q_QUOTAON:
245 char *pathname; 238 return quota_quotaon(sb, type, cmd, id, addr);
246 239 case Q_QUOTAOFF:
247 pathname = getname(addr); 240 if (!sb->s_qcop->quota_off)
248 if (IS_ERR(pathname)) 241 return -ENOSYS;
249 return PTR_ERR(pathname); 242 return sb->s_qcop->quota_off(sb, type, 0);
250 ret = sb->s_qcop->quota_on(sb, type, id, pathname, 0); 243 case Q_GETFMT:
251 putname(pathname); 244 return quota_getfmt(sb, type, addr);
252 return ret; 245 case Q_GETINFO:
253 } 246 return quota_getinfo(sb, type, addr);
254 case Q_QUOTAOFF: 247 case Q_SETINFO:
255 return sb->s_qcop->quota_off(sb, type, 0); 248 return quota_setinfo(sb, type, addr);
256 249 case Q_GETQUOTA:
257 case Q_GETFMT: { 250 return quota_getquota(sb, type, id, addr);
258 __u32 fmt; 251 case Q_SETQUOTA:
259 252 return quota_setquota(sb, type, id, addr);
260 down_read(&sb_dqopt(sb)->dqptr_sem); 253 case Q_SYNC:
261 if (!sb_has_quota_active(sb, type)) { 254 if (!sb->s_qcop->quota_sync)
262 up_read(&sb_dqopt(sb)->dqptr_sem); 255 return -ENOSYS;
263 return -ESRCH; 256 return sb->s_qcop->quota_sync(sb, type, 1);
264 } 257 case Q_XQUOTAON:
265 fmt = sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id; 258 case Q_XQUOTAOFF:
266 up_read(&sb_dqopt(sb)->dqptr_sem); 259 case Q_XQUOTARM:
267 if (copy_to_user(addr, &fmt, sizeof(fmt))) 260 return quota_setxstate(sb, cmd, addr);
268 return -EFAULT; 261 case Q_XGETQSTAT:
269 return 0; 262 return quota_getxstate(sb, addr);
270 } 263 case Q_XSETQLIM:
271 case Q_GETINFO: { 264 return quota_setxquota(sb, type, id, addr);
272 struct if_dqinfo info; 265 case Q_XGETQUOTA:
273 266 return quota_getxquota(sb, type, id, addr);
274 ret = sb->s_qcop->get_info(sb, type, &info); 267 case Q_XQUOTASYNC:
275 if (ret) 268 /* caller already holds s_umount */
276 return ret; 269 if (sb->s_flags & MS_RDONLY)
277 if (copy_to_user(addr, &info, sizeof(info))) 270 return -EROFS;
278 return -EFAULT; 271 writeback_inodes_sb(sb);
279 return 0; 272 return 0;
280 } 273 default:
281 case Q_SETINFO: { 274 return -EINVAL;
282 struct if_dqinfo info;
283
284 if (copy_from_user(&info, addr, sizeof(info)))
285 return -EFAULT;
286 return sb->s_qcop->set_info(sb, type, &info);
287 }
288 case Q_GETQUOTA: {
289 struct if_dqblk idq;
290
291 ret = sb->s_qcop->get_dqblk(sb, type, id, &idq);
292 if (ret)
293 return ret;
294 if (copy_to_user(addr, &idq, sizeof(idq)))
295 return -EFAULT;
296 return 0;
297 }
298 case Q_SETQUOTA: {
299 struct if_dqblk idq;
300
301 if (copy_from_user(&idq, addr, sizeof(idq)))
302 return -EFAULT;
303 return sb->s_qcop->set_dqblk(sb, type, id, &idq);
304 }
305 case Q_SYNC:
306 if (sb)
307 sync_quota_sb(sb, type);
308 else
309 sync_dquots(type);
310 return 0;
311
312 case Q_XQUOTAON:
313 case Q_XQUOTAOFF:
314 case Q_XQUOTARM: {
315 __u32 flags;
316
317 if (copy_from_user(&flags, addr, sizeof(flags)))
318 return -EFAULT;
319 return sb->s_qcop->set_xstate(sb, flags, cmd);
320 }
321 case Q_XGETQSTAT: {
322 struct fs_quota_stat fqs;
323
324 if ((ret = sb->s_qcop->get_xstate(sb, &fqs)))
325 return ret;
326 if (copy_to_user(addr, &fqs, sizeof(fqs)))
327 return -EFAULT;
328 return 0;
329 }
330 case Q_XSETQLIM: {
331 struct fs_disk_quota fdq;
332
333 if (copy_from_user(&fdq, addr, sizeof(fdq)))
334 return -EFAULT;
335 return sb->s_qcop->set_xquota(sb, type, id, &fdq);
336 }
337 case Q_XGETQUOTA: {
338 struct fs_disk_quota fdq;
339
340 ret = sb->s_qcop->get_xquota(sb, type, id, &fdq);
341 if (ret)
342 return ret;
343 if (copy_to_user(addr, &fdq, sizeof(fdq)))
344 return -EFAULT;
345 return 0;
346 }
347 case Q_XQUOTASYNC:
348 return sb->s_qcop->quota_sync(sb, type);
349 /* We never reach here unless validity check is broken */
350 default:
351 BUG();
352 } 275 }
353 return 0;
354} 276}
355 277
356/* 278/*
@@ -397,224 +319,23 @@ SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
397 cmds = cmd >> SUBCMDSHIFT; 319 cmds = cmd >> SUBCMDSHIFT;
398 type = cmd & SUBCMDMASK; 320 type = cmd & SUBCMDMASK;
399 321
400 if (cmds != Q_SYNC || special) { 322 /*
401 sb = quotactl_block(special); 323 * As a special case Q_SYNC can be called without a specific device.
402 if (IS_ERR(sb)) 324 * It will iterate all superblocks that have quota enabled and call
403 return PTR_ERR(sb); 325 * the sync action on each of them.
326 */
327 if (!special) {
328 if (cmds == Q_SYNC)
329 return quota_sync_all(type);
330 return -ENODEV;
404 } 331 }
405 332
406 ret = check_quotactl_valid(sb, type, cmds, id); 333 sb = quotactl_block(special);
407 if (ret >= 0) 334 if (IS_ERR(sb))
408 ret = do_quotactl(sb, type, cmds, id, addr); 335 return PTR_ERR(sb);
409 if (sb)
410 drop_super(sb);
411 336
412 return ret; 337 ret = do_quotactl(sb, type, cmds, id, addr);
413}
414
415#if defined(CONFIG_COMPAT_FOR_U64_ALIGNMENT)
416/*
417 * This code works only for 32 bit quota tools over 64 bit OS (x86_64, ia64)
418 * and is necessary due to alignment problems.
419 */
420struct compat_if_dqblk {
421 compat_u64 dqb_bhardlimit;
422 compat_u64 dqb_bsoftlimit;
423 compat_u64 dqb_curspace;
424 compat_u64 dqb_ihardlimit;
425 compat_u64 dqb_isoftlimit;
426 compat_u64 dqb_curinodes;
427 compat_u64 dqb_btime;
428 compat_u64 dqb_itime;
429 compat_uint_t dqb_valid;
430};
431
432/* XFS structures */
433struct compat_fs_qfilestat {
434 compat_u64 dqb_bhardlimit;
435 compat_u64 qfs_nblks;
436 compat_uint_t qfs_nextents;
437};
438
439struct compat_fs_quota_stat {
440 __s8 qs_version;
441 __u16 qs_flags;
442 __s8 qs_pad;
443 struct compat_fs_qfilestat qs_uquota;
444 struct compat_fs_qfilestat qs_gquota;
445 compat_uint_t qs_incoredqs;
446 compat_int_t qs_btimelimit;
447 compat_int_t qs_itimelimit;
448 compat_int_t qs_rtbtimelimit;
449 __u16 qs_bwarnlimit;
450 __u16 qs_iwarnlimit;
451};
452
453asmlinkage long sys32_quotactl(unsigned int cmd, const char __user *special,
454 qid_t id, void __user *addr)
455{
456 unsigned int cmds;
457 struct if_dqblk __user *dqblk;
458 struct compat_if_dqblk __user *compat_dqblk;
459 struct fs_quota_stat __user *fsqstat;
460 struct compat_fs_quota_stat __user *compat_fsqstat;
461 compat_uint_t data;
462 u16 xdata;
463 long ret;
464 338
465 cmds = cmd >> SUBCMDSHIFT; 339 drop_super(sb);
466
467 switch (cmds) {
468 case Q_GETQUOTA:
469 dqblk = compat_alloc_user_space(sizeof(struct if_dqblk));
470 compat_dqblk = addr;
471 ret = sys_quotactl(cmd, special, id, dqblk);
472 if (ret)
473 break;
474 if (copy_in_user(compat_dqblk, dqblk, sizeof(*compat_dqblk)) ||
475 get_user(data, &dqblk->dqb_valid) ||
476 put_user(data, &compat_dqblk->dqb_valid))
477 ret = -EFAULT;
478 break;
479 case Q_SETQUOTA:
480 dqblk = compat_alloc_user_space(sizeof(struct if_dqblk));
481 compat_dqblk = addr;
482 ret = -EFAULT;
483 if (copy_in_user(dqblk, compat_dqblk, sizeof(*compat_dqblk)) ||
484 get_user(data, &compat_dqblk->dqb_valid) ||
485 put_user(data, &dqblk->dqb_valid))
486 break;
487 ret = sys_quotactl(cmd, special, id, dqblk);
488 break;
489 case Q_XGETQSTAT:
490 fsqstat = compat_alloc_user_space(sizeof(struct fs_quota_stat));
491 compat_fsqstat = addr;
492 ret = sys_quotactl(cmd, special, id, fsqstat);
493 if (ret)
494 break;
495 ret = -EFAULT;
496 /* Copying qs_version, qs_flags, qs_pad */
497 if (copy_in_user(compat_fsqstat, fsqstat,
498 offsetof(struct compat_fs_quota_stat, qs_uquota)))
499 break;
500 /* Copying qs_uquota */
501 if (copy_in_user(&compat_fsqstat->qs_uquota,
502 &fsqstat->qs_uquota,
503 sizeof(compat_fsqstat->qs_uquota)) ||
504 get_user(data, &fsqstat->qs_uquota.qfs_nextents) ||
505 put_user(data, &compat_fsqstat->qs_uquota.qfs_nextents))
506 break;
507 /* Copying qs_gquota */
508 if (copy_in_user(&compat_fsqstat->qs_gquota,
509 &fsqstat->qs_gquota,
510 sizeof(compat_fsqstat->qs_gquota)) ||
511 get_user(data, &fsqstat->qs_gquota.qfs_nextents) ||
512 put_user(data, &compat_fsqstat->qs_gquota.qfs_nextents))
513 break;
514 /* Copying the rest */
515 if (copy_in_user(&compat_fsqstat->qs_incoredqs,
516 &fsqstat->qs_incoredqs,
517 sizeof(struct compat_fs_quota_stat) -
518 offsetof(struct compat_fs_quota_stat, qs_incoredqs)) ||
519 get_user(xdata, &fsqstat->qs_iwarnlimit) ||
520 put_user(xdata, &compat_fsqstat->qs_iwarnlimit))
521 break;
522 ret = 0;
523 break;
524 default:
525 ret = sys_quotactl(cmd, special, id, addr);
526 }
527 return ret; 340 return ret;
528} 341}
529#endif
530
531
532#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
533
534/* Netlink family structure for quota */
535static struct genl_family quota_genl_family = {
536 .id = GENL_ID_GENERATE,
537 .hdrsize = 0,
538 .name = "VFS_DQUOT",
539 .version = 1,
540 .maxattr = QUOTA_NL_A_MAX,
541};
542
543/**
544 * quota_send_warning - Send warning to userspace about exceeded quota
545 * @type: The quota type: USRQQUOTA, GRPQUOTA,...
546 * @id: The user or group id of the quota that was exceeded
547 * @dev: The device on which the fs is mounted (sb->s_dev)
548 * @warntype: The type of the warning: QUOTA_NL_...
549 *
550 * This can be used by filesystems (including those which don't use
551 * dquot) to send a message to userspace relating to quota limits.
552 *
553 */
554
555void quota_send_warning(short type, unsigned int id, dev_t dev,
556 const char warntype)
557{
558 static atomic_t seq;
559 struct sk_buff *skb;
560 void *msg_head;
561 int ret;
562 int msg_size = 4 * nla_total_size(sizeof(u32)) +
563 2 * nla_total_size(sizeof(u64));
564
565 /* We have to allocate using GFP_NOFS as we are called from a
566 * filesystem performing write and thus further recursion into
567 * the fs to free some data could cause deadlocks. */
568 skb = genlmsg_new(msg_size, GFP_NOFS);
569 if (!skb) {
570 printk(KERN_ERR
571 "VFS: Not enough memory to send quota warning.\n");
572 return;
573 }
574 msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
575 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
576 if (!msg_head) {
577 printk(KERN_ERR
578 "VFS: Cannot store netlink header in quota warning.\n");
579 goto err_out;
580 }
581 ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, type);
582 if (ret)
583 goto attr_err_out;
584 ret = nla_put_u64(skb, QUOTA_NL_A_EXCESS_ID, id);
585 if (ret)
586 goto attr_err_out;
587 ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype);
588 if (ret)
589 goto attr_err_out;
590 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MAJOR, MAJOR(dev));
591 if (ret)
592 goto attr_err_out;
593 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR, MINOR(dev));
594 if (ret)
595 goto attr_err_out;
596 ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current_uid());
597 if (ret)
598 goto attr_err_out;
599 genlmsg_end(skb, msg_head);
600
601 genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
602 return;
603attr_err_out:
604 printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
605err_out:
606 kfree_skb(skb);
607}
608EXPORT_SYMBOL(quota_send_warning);
609
610static int __init quota_init(void)
611{
612 if (genl_register_family(&quota_genl_family) != 0)
613 printk(KERN_ERR
614 "VFS: Failed to create quota netlink interface.\n");
615 return 0;
616};
617
618module_init(quota_init);
619#endif
620
diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c
index 65c872761177..dc014f7def05 100644
--- a/fs/reiserfs/bitmap.c
+++ b/fs/reiserfs/bitmap.c
@@ -425,7 +425,7 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
425 425
426 journal_mark_dirty(th, s, sbh); 426 journal_mark_dirty(th, s, sbh);
427 if (for_unformatted) 427 if (for_unformatted)
428 vfs_dq_free_block_nodirty(inode, 1); 428 dquot_free_block_nodirty(inode, 1);
429} 429}
430 430
431void reiserfs_free_block(struct reiserfs_transaction_handle *th, 431void reiserfs_free_block(struct reiserfs_transaction_handle *th,
@@ -1049,7 +1049,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
1049 amount_needed, hint->inode->i_uid); 1049 amount_needed, hint->inode->i_uid);
1050#endif 1050#endif
1051 quota_ret = 1051 quota_ret =
1052 vfs_dq_alloc_block_nodirty(hint->inode, amount_needed); 1052 dquot_alloc_block_nodirty(hint->inode, amount_needed);
1053 if (quota_ret) /* Quota exceeded? */ 1053 if (quota_ret) /* Quota exceeded? */
1054 return QUOTA_EXCEEDED; 1054 return QUOTA_EXCEEDED;
1055 if (hint->preallocate && hint->prealloc_size) { 1055 if (hint->preallocate && hint->prealloc_size) {
@@ -1058,7 +1058,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
1058 "reiserquota: allocating (prealloc) %d blocks id=%u", 1058 "reiserquota: allocating (prealloc) %d blocks id=%u",
1059 hint->prealloc_size, hint->inode->i_uid); 1059 hint->prealloc_size, hint->inode->i_uid);
1060#endif 1060#endif
1061 quota_ret = vfs_dq_prealloc_block_nodirty(hint->inode, 1061 quota_ret = dquot_prealloc_block_nodirty(hint->inode,
1062 hint->prealloc_size); 1062 hint->prealloc_size);
1063 if (quota_ret) 1063 if (quota_ret)
1064 hint->preallocate = hint->prealloc_size = 0; 1064 hint->preallocate = hint->prealloc_size = 0;
@@ -1092,7 +1092,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
1092 hint->inode->i_uid); 1092 hint->inode->i_uid);
1093#endif 1093#endif
1094 /* Free not allocated blocks */ 1094 /* Free not allocated blocks */
1095 vfs_dq_free_block_nodirty(hint->inode, 1095 dquot_free_block_nodirty(hint->inode,
1096 amount_needed + hint->prealloc_size - 1096 amount_needed + hint->prealloc_size -
1097 nr_allocated); 1097 nr_allocated);
1098 } 1098 }
@@ -1125,7 +1125,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
1125 REISERFS_I(hint->inode)->i_prealloc_count, 1125 REISERFS_I(hint->inode)->i_prealloc_count,
1126 hint->inode->i_uid); 1126 hint->inode->i_uid);
1127#endif 1127#endif
1128 vfs_dq_free_block_nodirty(hint->inode, amount_needed + 1128 dquot_free_block_nodirty(hint->inode, amount_needed +
1129 hint->prealloc_size - nr_allocated - 1129 hint->prealloc_size - nr_allocated -
1130 REISERFS_I(hint->inode)-> 1130 REISERFS_I(hint->inode)->
1131 i_prealloc_count); 1131 i_prealloc_count);
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index da2dba082e2d..1d9c12714c5c 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -289,7 +289,7 @@ const struct file_operations reiserfs_file_operations = {
289 .compat_ioctl = reiserfs_compat_ioctl, 289 .compat_ioctl = reiserfs_compat_ioctl,
290#endif 290#endif
291 .mmap = reiserfs_file_mmap, 291 .mmap = reiserfs_file_mmap,
292 .open = generic_file_open, 292 .open = dquot_file_open,
293 .release = reiserfs_file_release, 293 .release = reiserfs_file_release,
294 .fsync = reiserfs_sync_file, 294 .fsync = reiserfs_sync_file,
295 .aio_read = generic_file_aio_read, 295 .aio_read = generic_file_aio_read,
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 0d651f980a8d..d1da94b82d8f 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -34,6 +34,9 @@ void reiserfs_delete_inode(struct inode *inode)
34 int depth; 34 int depth;
35 int err; 35 int err;
36 36
37 if (!is_bad_inode(inode))
38 dquot_initialize(inode);
39
37 truncate_inode_pages(&inode->i_data, 0); 40 truncate_inode_pages(&inode->i_data, 0);
38 41
39 depth = reiserfs_write_lock_once(inode->i_sb); 42 depth = reiserfs_write_lock_once(inode->i_sb);
@@ -54,7 +57,7 @@ void reiserfs_delete_inode(struct inode *inode)
54 * after delete_object so that quota updates go into the same transaction as 57 * after delete_object so that quota updates go into the same transaction as
55 * stat data deletion */ 58 * stat data deletion */
56 if (!err) 59 if (!err)
57 vfs_dq_free_inode(inode); 60 dquot_free_inode(inode);
58 61
59 if (journal_end(&th, inode->i_sb, jbegin_count)) 62 if (journal_end(&th, inode->i_sb, jbegin_count))
60 goto out; 63 goto out;
@@ -1765,10 +1768,10 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1765 1768
1766 BUG_ON(!th->t_trans_id); 1769 BUG_ON(!th->t_trans_id);
1767 1770
1768 if (vfs_dq_alloc_inode(inode)) { 1771 dquot_initialize(inode);
1769 err = -EDQUOT; 1772 err = dquot_alloc_inode(inode);
1773 if (err)
1770 goto out_end_trans; 1774 goto out_end_trans;
1771 }
1772 if (!dir->i_nlink) { 1775 if (!dir->i_nlink) {
1773 err = -EPERM; 1776 err = -EPERM;
1774 goto out_bad_inode; 1777 goto out_bad_inode;
@@ -1959,12 +1962,12 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1959 INODE_PKEY(inode)->k_objectid = 0; 1962 INODE_PKEY(inode)->k_objectid = 0;
1960 1963
1961 /* Quota change must be inside a transaction for journaling */ 1964 /* Quota change must be inside a transaction for journaling */
1962 vfs_dq_free_inode(inode); 1965 dquot_free_inode(inode);
1963 1966
1964 out_end_trans: 1967 out_end_trans:
1965 journal_end(th, th->t_super, th->t_blocks_allocated); 1968 journal_end(th, th->t_super, th->t_blocks_allocated);
1966 /* Drop can be outside and it needs more credits so it's better to have it outside */ 1969 /* Drop can be outside and it needs more credits so it's better to have it outside */
1967 vfs_dq_drop(inode); 1970 dquot_drop(inode);
1968 inode->i_flags |= S_NOQUOTA; 1971 inode->i_flags |= S_NOQUOTA;
1969 make_bad_inode(inode); 1972 make_bad_inode(inode);
1970 1973
@@ -3073,6 +3076,8 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
3073 3076
3074 depth = reiserfs_write_lock_once(inode->i_sb); 3077 depth = reiserfs_write_lock_once(inode->i_sb);
3075 if (attr->ia_valid & ATTR_SIZE) { 3078 if (attr->ia_valid & ATTR_SIZE) {
3079 dquot_initialize(inode);
3080
3076 /* version 2 items will be caught by the s_maxbytes check 3081 /* version 2 items will be caught by the s_maxbytes check
3077 ** done for us in vmtruncate 3082 ** done for us in vmtruncate
3078 */ 3083 */
@@ -3134,8 +3139,7 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
3134 jbegin_count); 3139 jbegin_count);
3135 if (error) 3140 if (error)
3136 goto out; 3141 goto out;
3137 error = 3142 error = dquot_transfer(inode, attr);
3138 vfs_dq_transfer(inode, attr) ? -EDQUOT : 0;
3139 if (error) { 3143 if (error) {
3140 journal_end(&th, inode->i_sb, 3144 journal_end(&th, inode->i_sb,
3141 jbegin_count); 3145 jbegin_count);
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index 9d4dcf0b07cb..96e4cbbfaa18 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -546,7 +546,7 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
546*/ 546*/
547static int drop_new_inode(struct inode *inode) 547static int drop_new_inode(struct inode *inode)
548{ 548{
549 vfs_dq_drop(inode); 549 dquot_drop(inode);
550 make_bad_inode(inode); 550 make_bad_inode(inode);
551 inode->i_flags |= S_NOQUOTA; 551 inode->i_flags |= S_NOQUOTA;
552 iput(inode); 552 iput(inode);
@@ -554,7 +554,7 @@ static int drop_new_inode(struct inode *inode)
554} 554}
555 555
556/* utility function that does setup for reiserfs_new_inode. 556/* utility function that does setup for reiserfs_new_inode.
557** vfs_dq_init needs lots of credits so it's better to have it 557** dquot_initialize needs lots of credits so it's better to have it
558** outside of a transaction, so we had to pull some bits of 558** outside of a transaction, so we had to pull some bits of
559** reiserfs_new_inode out into this func. 559** reiserfs_new_inode out into this func.
560*/ 560*/
@@ -577,7 +577,7 @@ static int new_inode_init(struct inode *inode, struct inode *dir, int mode)
577 } else { 577 } else {
578 inode->i_gid = current_fsgid(); 578 inode->i_gid = current_fsgid();
579 } 579 }
580 vfs_dq_init(inode); 580 dquot_initialize(inode);
581 return 0; 581 return 0;
582} 582}
583 583
@@ -594,6 +594,8 @@ static int reiserfs_create(struct inode *dir, struct dentry *dentry, int mode,
594 struct reiserfs_transaction_handle th; 594 struct reiserfs_transaction_handle th;
595 struct reiserfs_security_handle security; 595 struct reiserfs_security_handle security;
596 596
597 dquot_initialize(dir);
598
597 if (!(inode = new_inode(dir->i_sb))) { 599 if (!(inode = new_inode(dir->i_sb))) {
598 return -ENOMEM; 600 return -ENOMEM;
599 } 601 }
@@ -666,6 +668,8 @@ static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
666 if (!new_valid_dev(rdev)) 668 if (!new_valid_dev(rdev))
667 return -EINVAL; 669 return -EINVAL;
668 670
671 dquot_initialize(dir);
672
669 if (!(inode = new_inode(dir->i_sb))) { 673 if (!(inode = new_inode(dir->i_sb))) {
670 return -ENOMEM; 674 return -ENOMEM;
671 } 675 }
@@ -739,6 +743,8 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
739 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) + 743 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
740 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); 744 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
741 745
746 dquot_initialize(dir);
747
742#ifdef DISPLACE_NEW_PACKING_LOCALITIES 748#ifdef DISPLACE_NEW_PACKING_LOCALITIES
743 /* set flag that new packing locality created and new blocks for the content * of that directory are not displaced yet */ 749 /* set flag that new packing locality created and new blocks for the content * of that directory are not displaced yet */
744 REISERFS_I(dir)->new_packing_locality = 1; 750 REISERFS_I(dir)->new_packing_locality = 1;
@@ -842,6 +848,8 @@ static int reiserfs_rmdir(struct inode *dir, struct dentry *dentry)
842 JOURNAL_PER_BALANCE_CNT * 2 + 2 + 848 JOURNAL_PER_BALANCE_CNT * 2 + 2 +
843 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); 849 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
844 850
851 dquot_initialize(dir);
852
845 reiserfs_write_lock(dir->i_sb); 853 reiserfs_write_lock(dir->i_sb);
846 retval = journal_begin(&th, dir->i_sb, jbegin_count); 854 retval = journal_begin(&th, dir->i_sb, jbegin_count);
847 if (retval) 855 if (retval)
@@ -923,6 +931,8 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
923 unsigned long savelink; 931 unsigned long savelink;
924 int depth; 932 int depth;
925 933
934 dquot_initialize(dir);
935
926 inode = dentry->d_inode; 936 inode = dentry->d_inode;
927 937
928 /* in this transaction we can be doing at max two balancings and update 938 /* in this transaction we can be doing at max two balancings and update
@@ -1024,6 +1034,8 @@ static int reiserfs_symlink(struct inode *parent_dir,
1024 2 * (REISERFS_QUOTA_INIT_BLOCKS(parent_dir->i_sb) + 1034 2 * (REISERFS_QUOTA_INIT_BLOCKS(parent_dir->i_sb) +
1025 REISERFS_QUOTA_TRANS_BLOCKS(parent_dir->i_sb)); 1035 REISERFS_QUOTA_TRANS_BLOCKS(parent_dir->i_sb));
1026 1036
1037 dquot_initialize(parent_dir);
1038
1027 if (!(inode = new_inode(parent_dir->i_sb))) { 1039 if (!(inode = new_inode(parent_dir->i_sb))) {
1028 return -ENOMEM; 1040 return -ENOMEM;
1029 } 1041 }
@@ -1111,6 +1123,8 @@ static int reiserfs_link(struct dentry *old_dentry, struct inode *dir,
1111 JOURNAL_PER_BALANCE_CNT * 3 + 1123 JOURNAL_PER_BALANCE_CNT * 3 +
1112 2 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); 1124 2 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
1113 1125
1126 dquot_initialize(dir);
1127
1114 reiserfs_write_lock(dir->i_sb); 1128 reiserfs_write_lock(dir->i_sb);
1115 if (inode->i_nlink >= REISERFS_LINK_MAX) { 1129 if (inode->i_nlink >= REISERFS_LINK_MAX) {
1116 //FIXME: sd_nlink is 32 bit for new files 1130 //FIXME: sd_nlink is 32 bit for new files
@@ -1235,6 +1249,9 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1235 JOURNAL_PER_BALANCE_CNT * 3 + 5 + 1249 JOURNAL_PER_BALANCE_CNT * 3 + 5 +
1236 4 * REISERFS_QUOTA_TRANS_BLOCKS(old_dir->i_sb); 1250 4 * REISERFS_QUOTA_TRANS_BLOCKS(old_dir->i_sb);
1237 1251
1252 dquot_initialize(old_dir);
1253 dquot_initialize(new_dir);
1254
1238 old_inode = old_dentry->d_inode; 1255 old_inode = old_dentry->d_inode;
1239 new_dentry_inode = new_dentry->d_inode; 1256 new_dentry_inode = new_dentry->d_inode;
1240 1257
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index 5fa7118f04e1..313d39d639eb 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -1299,7 +1299,7 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1299 "reiserquota delete_item(): freeing %u, id=%u type=%c", 1299 "reiserquota delete_item(): freeing %u, id=%u type=%c",
1300 quota_cut_bytes, inode->i_uid, head2type(&s_ih)); 1300 quota_cut_bytes, inode->i_uid, head2type(&s_ih));
1301#endif 1301#endif
1302 vfs_dq_free_space_nodirty(inode, quota_cut_bytes); 1302 dquot_free_space_nodirty(inode, quota_cut_bytes);
1303 1303
1304 /* Return deleted body length */ 1304 /* Return deleted body length */
1305 return ret_value; 1305 return ret_value;
@@ -1383,7 +1383,7 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
1383 quota_cut_bytes, inode->i_uid, 1383 quota_cut_bytes, inode->i_uid,
1384 key2type(key)); 1384 key2type(key));
1385#endif 1385#endif
1386 vfs_dq_free_space_nodirty(inode, 1386 dquot_free_space_nodirty(inode,
1387 quota_cut_bytes); 1387 quota_cut_bytes);
1388 } 1388 }
1389 break; 1389 break;
@@ -1733,7 +1733,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1733 "reiserquota cut_from_item(): freeing %u id=%u type=%c", 1733 "reiserquota cut_from_item(): freeing %u id=%u type=%c",
1734 quota_cut_bytes, inode->i_uid, '?'); 1734 quota_cut_bytes, inode->i_uid, '?');
1735#endif 1735#endif
1736 vfs_dq_free_space_nodirty(inode, quota_cut_bytes); 1736 dquot_free_space_nodirty(inode, quota_cut_bytes);
1737 return ret_value; 1737 return ret_value;
1738} 1738}
1739 1739
@@ -1968,9 +1968,10 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1968 key2type(&(key->on_disk_key))); 1968 key2type(&(key->on_disk_key)));
1969#endif 1969#endif
1970 1970
1971 if (vfs_dq_alloc_space_nodirty(inode, pasted_size)) { 1971 retval = dquot_alloc_space_nodirty(inode, pasted_size);
1972 if (retval) {
1972 pathrelse(search_path); 1973 pathrelse(search_path);
1973 return -EDQUOT; 1974 return retval;
1974 } 1975 }
1975 init_tb_struct(th, &s_paste_balance, th->t_super, search_path, 1976 init_tb_struct(th, &s_paste_balance, th->t_super, search_path,
1976 pasted_size); 1977 pasted_size);
@@ -2024,7 +2025,7 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
2024 pasted_size, inode->i_uid, 2025 pasted_size, inode->i_uid,
2025 key2type(&(key->on_disk_key))); 2026 key2type(&(key->on_disk_key)));
2026#endif 2027#endif
2027 vfs_dq_free_space_nodirty(inode, pasted_size); 2028 dquot_free_space_nodirty(inode, pasted_size);
2028 return retval; 2029 return retval;
2029} 2030}
2030 2031
@@ -2062,9 +2063,10 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
2062#endif 2063#endif
2063 /* We can't dirty inode here. It would be immediately written but 2064 /* We can't dirty inode here. It would be immediately written but
2064 * appropriate stat item isn't inserted yet... */ 2065 * appropriate stat item isn't inserted yet... */
2065 if (vfs_dq_alloc_space_nodirty(inode, quota_bytes)) { 2066 retval = dquot_alloc_space_nodirty(inode, quota_bytes);
2067 if (retval) {
2066 pathrelse(path); 2068 pathrelse(path);
2067 return -EDQUOT; 2069 return retval;
2068 } 2070 }
2069 } 2071 }
2070 init_tb_struct(th, &s_ins_balance, th->t_super, path, 2072 init_tb_struct(th, &s_ins_balance, th->t_super, path,
@@ -2113,6 +2115,6 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
2113 quota_bytes, inode->i_uid, head2type(ih)); 2115 quota_bytes, inode->i_uid, head2type(ih));
2114#endif 2116#endif
2115 if (inode) 2117 if (inode)
2116 vfs_dq_free_space_nodirty(inode, quota_bytes); 2118 dquot_free_space_nodirty(inode, quota_bytes);
2117 return retval; 2119 return retval;
2118} 2120}
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index b4a7dd03bdb9..04bf5d791bda 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -246,7 +246,7 @@ static int finish_unfinished(struct super_block *s)
246 retval = remove_save_link_only(s, &save_link_key, 0); 246 retval = remove_save_link_only(s, &save_link_key, 0);
247 continue; 247 continue;
248 } 248 }
249 vfs_dq_init(inode); 249 dquot_initialize(inode);
250 250
251 if (truncate && S_ISDIR(inode->i_mode)) { 251 if (truncate && S_ISDIR(inode->i_mode)) {
252 /* We got a truncate request for a dir which is impossible. 252 /* We got a truncate request for a dir which is impossible.
@@ -578,6 +578,11 @@ out:
578 reiserfs_write_unlock_once(inode->i_sb, lock_depth); 578 reiserfs_write_unlock_once(inode->i_sb, lock_depth);
579} 579}
580 580
581static void reiserfs_clear_inode(struct inode *inode)
582{
583 dquot_drop(inode);
584}
585
581#ifdef CONFIG_QUOTA 586#ifdef CONFIG_QUOTA
582static ssize_t reiserfs_quota_write(struct super_block *, int, const char *, 587static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
583 size_t, loff_t); 588 size_t, loff_t);
@@ -590,6 +595,7 @@ static const struct super_operations reiserfs_sops = {
590 .destroy_inode = reiserfs_destroy_inode, 595 .destroy_inode = reiserfs_destroy_inode,
591 .write_inode = reiserfs_write_inode, 596 .write_inode = reiserfs_write_inode,
592 .dirty_inode = reiserfs_dirty_inode, 597 .dirty_inode = reiserfs_dirty_inode,
598 .clear_inode = reiserfs_clear_inode,
593 .delete_inode = reiserfs_delete_inode, 599 .delete_inode = reiserfs_delete_inode,
594 .put_super = reiserfs_put_super, 600 .put_super = reiserfs_put_super,
595 .write_super = reiserfs_write_super, 601 .write_super = reiserfs_write_super,
@@ -616,13 +622,6 @@ static int reiserfs_write_info(struct super_block *, int);
616static int reiserfs_quota_on(struct super_block *, int, int, char *, int); 622static int reiserfs_quota_on(struct super_block *, int, int, char *, int);
617 623
618static const struct dquot_operations reiserfs_quota_operations = { 624static const struct dquot_operations reiserfs_quota_operations = {
619 .initialize = dquot_initialize,
620 .drop = dquot_drop,
621 .alloc_space = dquot_alloc_space,
622 .alloc_inode = dquot_alloc_inode,
623 .free_space = dquot_free_space,
624 .free_inode = dquot_free_inode,
625 .transfer = dquot_transfer,
626 .write_dquot = reiserfs_write_dquot, 625 .write_dquot = reiserfs_write_dquot,
627 .acquire_dquot = reiserfs_acquire_dquot, 626 .acquire_dquot = reiserfs_acquire_dquot,
628 .release_dquot = reiserfs_release_dquot, 627 .release_dquot = reiserfs_release_dquot,
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index 81f09fab8ae4..37d034ca7d99 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -61,7 +61,6 @@
61static int xattr_create(struct inode *dir, struct dentry *dentry, int mode) 61static int xattr_create(struct inode *dir, struct dentry *dentry, int mode)
62{ 62{
63 BUG_ON(!mutex_is_locked(&dir->i_mutex)); 63 BUG_ON(!mutex_is_locked(&dir->i_mutex));
64 vfs_dq_init(dir);
65 return dir->i_op->create(dir, dentry, mode, NULL); 64 return dir->i_op->create(dir, dentry, mode, NULL);
66} 65}
67#endif 66#endif
@@ -69,7 +68,6 @@ static int xattr_create(struct inode *dir, struct dentry *dentry, int mode)
69static int xattr_mkdir(struct inode *dir, struct dentry *dentry, int mode) 68static int xattr_mkdir(struct inode *dir, struct dentry *dentry, int mode)
70{ 69{
71 BUG_ON(!mutex_is_locked(&dir->i_mutex)); 70 BUG_ON(!mutex_is_locked(&dir->i_mutex));
72 vfs_dq_init(dir);
73 return dir->i_op->mkdir(dir, dentry, mode); 71 return dir->i_op->mkdir(dir, dentry, mode);
74} 72}
75 73
@@ -81,7 +79,6 @@ static int xattr_unlink(struct inode *dir, struct dentry *dentry)
81{ 79{
82 int error; 80 int error;
83 BUG_ON(!mutex_is_locked(&dir->i_mutex)); 81 BUG_ON(!mutex_is_locked(&dir->i_mutex));
84 vfs_dq_init(dir);
85 82
86 reiserfs_mutex_lock_nested_safe(&dentry->d_inode->i_mutex, 83 reiserfs_mutex_lock_nested_safe(&dentry->d_inode->i_mutex,
87 I_MUTEX_CHILD, dir->i_sb); 84 I_MUTEX_CHILD, dir->i_sb);
@@ -97,7 +94,6 @@ static int xattr_rmdir(struct inode *dir, struct dentry *dentry)
97{ 94{
98 int error; 95 int error;
99 BUG_ON(!mutex_is_locked(&dir->i_mutex)); 96 BUG_ON(!mutex_is_locked(&dir->i_mutex));
100 vfs_dq_init(dir);
101 97
102 reiserfs_mutex_lock_nested_safe(&dentry->d_inode->i_mutex, 98 reiserfs_mutex_lock_nested_safe(&dentry->d_inode->i_mutex,
103 I_MUTEX_CHILD, dir->i_sb); 99 I_MUTEX_CHILD, dir->i_sb);
diff --git a/fs/sync.c b/fs/sync.c
index 418727a2a239..f557d71cb097 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -34,14 +34,14 @@ static int __sync_filesystem(struct super_block *sb, int wait)
34 if (!sb->s_bdi) 34 if (!sb->s_bdi)
35 return 0; 35 return 0;
36 36
37 /* Avoid doing twice syncing and cache pruning for quota sync */ 37 if (sb->s_qcop && sb->s_qcop->quota_sync)
38 if (!wait) { 38 sb->s_qcop->quota_sync(sb, -1, wait);
39 writeout_quota_sb(sb, -1); 39
40 writeback_inodes_sb(sb); 40 if (wait)
41 } else {
42 sync_quota_sb(sb, -1);
43 sync_inodes_sb(sb); 41 sync_inodes_sb(sb);
44 } 42 else
43 writeback_inodes_sb(sb);
44
45 if (sb->s_op->sync_fs) 45 if (sb->s_op->sync_fs)
46 sb->s_op->sync_fs(sb, wait); 46 sb->s_op->sync_fs(sb, wait);
47 return __sync_blockdev(sb->s_bdev, wait); 47 return __sync_blockdev(sb->s_bdev, wait);
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
index b2d96f45c12b..ccc3ad7242d4 100644
--- a/fs/udf/balloc.c
+++ b/fs/udf/balloc.c
@@ -208,7 +208,7 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
208 ((char *)bh->b_data)[(bit + i) >> 3]); 208 ((char *)bh->b_data)[(bit + i) >> 3]);
209 } else { 209 } else {
210 if (inode) 210 if (inode)
211 vfs_dq_free_block(inode, 1); 211 dquot_free_block(inode, 1);
212 udf_add_free_space(sb, sbi->s_partition, 1); 212 udf_add_free_space(sb, sbi->s_partition, 1);
213 } 213 }
214 } 214 }
@@ -260,11 +260,11 @@ static int udf_bitmap_prealloc_blocks(struct super_block *sb,
260 while (bit < (sb->s_blocksize << 3) && block_count > 0) { 260 while (bit < (sb->s_blocksize << 3) && block_count > 0) {
261 if (!udf_test_bit(bit, bh->b_data)) 261 if (!udf_test_bit(bit, bh->b_data))
262 goto out; 262 goto out;
263 else if (vfs_dq_prealloc_block(inode, 1)) 263 else if (dquot_prealloc_block(inode, 1))
264 goto out; 264 goto out;
265 else if (!udf_clear_bit(bit, bh->b_data)) { 265 else if (!udf_clear_bit(bit, bh->b_data)) {
266 udf_debug("bit already cleared for block %d\n", bit); 266 udf_debug("bit already cleared for block %d\n", bit);
267 vfs_dq_free_block(inode, 1); 267 dquot_free_block(inode, 1);
268 goto out; 268 goto out;
269 } 269 }
270 block_count--; 270 block_count--;
@@ -390,10 +390,14 @@ got_block:
390 /* 390 /*
391 * Check quota for allocation of this block. 391 * Check quota for allocation of this block.
392 */ 392 */
393 if (inode && vfs_dq_alloc_block(inode, 1)) { 393 if (inode) {
394 mutex_unlock(&sbi->s_alloc_mutex); 394 int ret = dquot_alloc_block(inode, 1);
395 *err = -EDQUOT; 395
396 return 0; 396 if (ret) {
397 mutex_unlock(&sbi->s_alloc_mutex);
398 *err = ret;
399 return 0;
400 }
397 } 401 }
398 402
399 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) - 403 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
@@ -449,7 +453,7 @@ static void udf_table_free_blocks(struct super_block *sb,
449 /* We do this up front - There are some error conditions that 453 /* We do this up front - There are some error conditions that
450 could occure, but.. oh well */ 454 could occure, but.. oh well */
451 if (inode) 455 if (inode)
452 vfs_dq_free_block(inode, count); 456 dquot_free_block(inode, count);
453 udf_add_free_space(sb, sbi->s_partition, count); 457 udf_add_free_space(sb, sbi->s_partition, count);
454 458
455 start = bloc->logicalBlockNum + offset; 459 start = bloc->logicalBlockNum + offset;
@@ -694,7 +698,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
694 epos.offset -= adsize; 698 epos.offset -= adsize;
695 699
696 alloc_count = (elen >> sb->s_blocksize_bits); 700 alloc_count = (elen >> sb->s_blocksize_bits);
697 if (inode && vfs_dq_prealloc_block(inode, 701 if (inode && dquot_prealloc_block(inode,
698 alloc_count > block_count ? block_count : alloc_count)) 702 alloc_count > block_count ? block_count : alloc_count))
699 alloc_count = 0; 703 alloc_count = 0;
700 else if (alloc_count > block_count) { 704 else if (alloc_count > block_count) {
@@ -797,12 +801,13 @@ static int udf_table_new_block(struct super_block *sb,
797 newblock = goal_eloc.logicalBlockNum; 801 newblock = goal_eloc.logicalBlockNum;
798 goal_eloc.logicalBlockNum++; 802 goal_eloc.logicalBlockNum++;
799 goal_elen -= sb->s_blocksize; 803 goal_elen -= sb->s_blocksize;
800 804 if (inode) {
801 if (inode && vfs_dq_alloc_block(inode, 1)) { 805 *err = dquot_alloc_block(inode, 1);
802 brelse(goal_epos.bh); 806 if (*err) {
803 mutex_unlock(&sbi->s_alloc_mutex); 807 brelse(goal_epos.bh);
804 *err = -EDQUOT; 808 mutex_unlock(&sbi->s_alloc_mutex);
805 return 0; 809 return 0;
810 }
806 } 811 }
807 812
808 if (goal_elen) 813 if (goal_elen)
diff --git a/fs/udf/file.c b/fs/udf/file.c
index f311d509b6a3..1eb06774ed90 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -34,6 +34,7 @@
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/smp_lock.h> 35#include <linux/smp_lock.h>
36#include <linux/pagemap.h> 36#include <linux/pagemap.h>
37#include <linux/quotaops.h>
37#include <linux/buffer_head.h> 38#include <linux/buffer_head.h>
38#include <linux/aio.h> 39#include <linux/aio.h>
39 40
@@ -207,7 +208,7 @@ const struct file_operations udf_file_operations = {
207 .read = do_sync_read, 208 .read = do_sync_read,
208 .aio_read = generic_file_aio_read, 209 .aio_read = generic_file_aio_read,
209 .ioctl = udf_ioctl, 210 .ioctl = udf_ioctl,
210 .open = generic_file_open, 211 .open = dquot_file_open,
211 .mmap = generic_file_mmap, 212 .mmap = generic_file_mmap,
212 .write = do_sync_write, 213 .write = do_sync_write,
213 .aio_write = udf_file_aio_write, 214 .aio_write = udf_file_aio_write,
@@ -217,6 +218,29 @@ const struct file_operations udf_file_operations = {
217 .llseek = generic_file_llseek, 218 .llseek = generic_file_llseek,
218}; 219};
219 220
221static int udf_setattr(struct dentry *dentry, struct iattr *iattr)
222{
223 struct inode *inode = dentry->d_inode;
224 int error;
225
226 error = inode_change_ok(inode, iattr);
227 if (error)
228 return error;
229
230 if (iattr->ia_valid & ATTR_SIZE)
231 dquot_initialize(inode);
232
233 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
234 (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
235 error = dquot_transfer(inode, iattr);
236 if (error)
237 return error;
238 }
239
240 return inode_setattr(inode, iattr);
241}
242
220const struct inode_operations udf_file_inode_operations = { 243const struct inode_operations udf_file_inode_operations = {
221 .truncate = udf_truncate, 244 .truncate = udf_truncate,
245 .setattr = udf_setattr,
222}; 246};
diff --git a/fs/udf/ialloc.c b/fs/udf/ialloc.c
index c10fa39f97e2..fb68c9cd0c3e 100644
--- a/fs/udf/ialloc.c
+++ b/fs/udf/ialloc.c
@@ -36,8 +36,8 @@ void udf_free_inode(struct inode *inode)
36 * Note: we must free any quota before locking the superblock, 36 * Note: we must free any quota before locking the superblock,
37 * as writing the quota to disk may need the lock as well. 37 * as writing the quota to disk may need the lock as well.
38 */ 38 */
39 vfs_dq_free_inode(inode); 39 dquot_free_inode(inode);
40 vfs_dq_drop(inode); 40 dquot_drop(inode);
41 41
42 clear_inode(inode); 42 clear_inode(inode);
43 43
@@ -61,7 +61,7 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
61 struct super_block *sb = dir->i_sb; 61 struct super_block *sb = dir->i_sb;
62 struct udf_sb_info *sbi = UDF_SB(sb); 62 struct udf_sb_info *sbi = UDF_SB(sb);
63 struct inode *inode; 63 struct inode *inode;
64 int block; 64 int block, ret;
65 uint32_t start = UDF_I(dir)->i_location.logicalBlockNum; 65 uint32_t start = UDF_I(dir)->i_location.logicalBlockNum;
66 struct udf_inode_info *iinfo; 66 struct udf_inode_info *iinfo;
67 struct udf_inode_info *dinfo = UDF_I(dir); 67 struct udf_inode_info *dinfo = UDF_I(dir);
@@ -153,12 +153,14 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
153 insert_inode_hash(inode); 153 insert_inode_hash(inode);
154 mark_inode_dirty(inode); 154 mark_inode_dirty(inode);
155 155
156 if (vfs_dq_alloc_inode(inode)) { 156 dquot_initialize(inode);
157 vfs_dq_drop(inode); 157 ret = dquot_alloc_inode(inode);
158 if (ret) {
159 dquot_drop(inode);
158 inode->i_flags |= S_NOQUOTA; 160 inode->i_flags |= S_NOQUOTA;
159 inode->i_nlink = 0; 161 inode->i_nlink = 0;
160 iput(inode); 162 iput(inode);
161 *err = -EDQUOT; 163 *err = ret;
162 return NULL; 164 return NULL;
163 } 165 }
164 166
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index b02089247296..b57ab0402d89 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -36,6 +36,7 @@
36#include <linux/pagemap.h> 36#include <linux/pagemap.h>
37#include <linux/buffer_head.h> 37#include <linux/buffer_head.h>
38#include <linux/writeback.h> 38#include <linux/writeback.h>
39#include <linux/quotaops.h>
39#include <linux/slab.h> 40#include <linux/slab.h>
40#include <linux/crc-itu-t.h> 41#include <linux/crc-itu-t.h>
41 42
@@ -70,6 +71,9 @@ static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
70 71
71void udf_delete_inode(struct inode *inode) 72void udf_delete_inode(struct inode *inode)
72{ 73{
74 if (!is_bad_inode(inode))
75 dquot_initialize(inode);
76
73 truncate_inode_pages(&inode->i_data, 0); 77 truncate_inode_pages(&inode->i_data, 0);
74 78
75 if (is_bad_inode(inode)) 79 if (is_bad_inode(inode))
@@ -108,6 +112,8 @@ void udf_clear_inode(struct inode *inode)
108 (unsigned long long)inode->i_size, 112 (unsigned long long)inode->i_size,
109 (unsigned long long)iinfo->i_lenExtents); 113 (unsigned long long)iinfo->i_lenExtents);
110 } 114 }
115
116 dquot_drop(inode);
111 kfree(iinfo->i_ext.i_data); 117 kfree(iinfo->i_ext.i_data);
112 iinfo->i_ext.i_data = NULL; 118 iinfo->i_ext.i_data = NULL;
113} 119}
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 7c56ff00cd53..db423ab078b1 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -563,6 +563,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
563 int err; 563 int err;
564 struct udf_inode_info *iinfo; 564 struct udf_inode_info *iinfo;
565 565
566 dquot_initialize(dir);
567
566 lock_kernel(); 568 lock_kernel();
567 inode = udf_new_inode(dir, mode, &err); 569 inode = udf_new_inode(dir, mode, &err);
568 if (!inode) { 570 if (!inode) {
@@ -616,6 +618,8 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
616 if (!old_valid_dev(rdev)) 618 if (!old_valid_dev(rdev))
617 return -EINVAL; 619 return -EINVAL;
618 620
621 dquot_initialize(dir);
622
619 lock_kernel(); 623 lock_kernel();
620 err = -EIO; 624 err = -EIO;
621 inode = udf_new_inode(dir, mode, &err); 625 inode = udf_new_inode(dir, mode, &err);
@@ -662,6 +666,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
662 struct udf_inode_info *dinfo = UDF_I(dir); 666 struct udf_inode_info *dinfo = UDF_I(dir);
663 struct udf_inode_info *iinfo; 667 struct udf_inode_info *iinfo;
664 668
669 dquot_initialize(dir);
670
665 lock_kernel(); 671 lock_kernel();
666 err = -EMLINK; 672 err = -EMLINK;
667 if (dir->i_nlink >= (256 << sizeof(dir->i_nlink)) - 1) 673 if (dir->i_nlink >= (256 << sizeof(dir->i_nlink)) - 1)
@@ -799,6 +805,8 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry)
799 struct fileIdentDesc *fi, cfi; 805 struct fileIdentDesc *fi, cfi;
800 struct kernel_lb_addr tloc; 806 struct kernel_lb_addr tloc;
801 807
808 dquot_initialize(dir);
809
802 retval = -ENOENT; 810 retval = -ENOENT;
803 lock_kernel(); 811 lock_kernel();
804 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi); 812 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi);
@@ -845,6 +853,8 @@ static int udf_unlink(struct inode *dir, struct dentry *dentry)
845 struct fileIdentDesc cfi; 853 struct fileIdentDesc cfi;
846 struct kernel_lb_addr tloc; 854 struct kernel_lb_addr tloc;
847 855
856 dquot_initialize(dir);
857
848 retval = -ENOENT; 858 retval = -ENOENT;
849 lock_kernel(); 859 lock_kernel();
850 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi); 860 fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi);
@@ -899,6 +909,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
899 struct buffer_head *bh; 909 struct buffer_head *bh;
900 struct udf_inode_info *iinfo; 910 struct udf_inode_info *iinfo;
901 911
912 dquot_initialize(dir);
913
902 lock_kernel(); 914 lock_kernel();
903 inode = udf_new_inode(dir, S_IFLNK, &err); 915 inode = udf_new_inode(dir, S_IFLNK, &err);
904 if (!inode) 916 if (!inode)
@@ -1069,6 +1081,8 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
1069 int err; 1081 int err;
1070 struct buffer_head *bh; 1082 struct buffer_head *bh;
1071 1083
1084 dquot_initialize(dir);
1085
1072 lock_kernel(); 1086 lock_kernel();
1073 if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) { 1087 if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) {
1074 unlock_kernel(); 1088 unlock_kernel();
@@ -1131,6 +1145,9 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
1131 struct kernel_lb_addr tloc; 1145 struct kernel_lb_addr tloc;
1132 struct udf_inode_info *old_iinfo = UDF_I(old_inode); 1146 struct udf_inode_info *old_iinfo = UDF_I(old_inode);
1133 1147
1148 dquot_initialize(old_dir);
1149 dquot_initialize(new_dir);
1150
1134 lock_kernel(); 1151 lock_kernel();
1135 ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi); 1152 ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi);
1136 if (ofi) { 1153 if (ofi) {
diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c
index 54c16ec95dff..5cfa4d85ccf2 100644
--- a/fs/ufs/balloc.c
+++ b/fs/ufs/balloc.c
@@ -85,7 +85,7 @@ void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count)
85 "bit already cleared for fragment %u", i); 85 "bit already cleared for fragment %u", i);
86 } 86 }
87 87
88 vfs_dq_free_block(inode, count); 88 dquot_free_block(inode, count);
89 89
90 90
91 fs32_add(sb, &ucg->cg_cs.cs_nffree, count); 91 fs32_add(sb, &ucg->cg_cs.cs_nffree, count);
@@ -195,7 +195,7 @@ do_more:
195 ubh_setblock(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno); 195 ubh_setblock(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno);
196 if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD) 196 if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
197 ufs_clusteracct (sb, ucpi, blkno, 1); 197 ufs_clusteracct (sb, ucpi, blkno, 1);
198 vfs_dq_free_block(inode, uspi->s_fpb); 198 dquot_free_block(inode, uspi->s_fpb);
199 199
200 fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1); 200 fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1);
201 uspi->cs_total.cs_nbfree++; 201 uspi->cs_total.cs_nbfree++;
@@ -511,6 +511,7 @@ static u64 ufs_add_fragments(struct inode *inode, u64 fragment,
511 struct ufs_cg_private_info * ucpi; 511 struct ufs_cg_private_info * ucpi;
512 struct ufs_cylinder_group * ucg; 512 struct ufs_cylinder_group * ucg;
513 unsigned cgno, fragno, fragoff, count, fragsize, i; 513 unsigned cgno, fragno, fragoff, count, fragsize, i;
514 int ret;
514 515
515 UFSD("ENTER, fragment %llu, oldcount %u, newcount %u\n", 516 UFSD("ENTER, fragment %llu, oldcount %u, newcount %u\n",
516 (unsigned long long)fragment, oldcount, newcount); 517 (unsigned long long)fragment, oldcount, newcount);
@@ -556,8 +557,9 @@ static u64 ufs_add_fragments(struct inode *inode, u64 fragment,
556 fs32_add(sb, &ucg->cg_frsum[fragsize - count], 1); 557 fs32_add(sb, &ucg->cg_frsum[fragsize - count], 1);
557 for (i = oldcount; i < newcount; i++) 558 for (i = oldcount; i < newcount; i++)
558 ubh_clrbit (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i); 559 ubh_clrbit (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i);
559 if (vfs_dq_alloc_block(inode, count)) { 560 ret = dquot_alloc_block(inode, count);
560 *err = -EDQUOT; 561 if (ret) {
562 *err = ret;
561 return 0; 563 return 0;
562 } 564 }
563 565
@@ -596,6 +598,7 @@ static u64 ufs_alloc_fragments(struct inode *inode, unsigned cgno,
596 struct ufs_cylinder_group * ucg; 598 struct ufs_cylinder_group * ucg;
597 unsigned oldcg, i, j, k, allocsize; 599 unsigned oldcg, i, j, k, allocsize;
598 u64 result; 600 u64 result;
601 int ret;
599 602
600 UFSD("ENTER, ino %lu, cgno %u, goal %llu, count %u\n", 603 UFSD("ENTER, ino %lu, cgno %u, goal %llu, count %u\n",
601 inode->i_ino, cgno, (unsigned long long)goal, count); 604 inode->i_ino, cgno, (unsigned long long)goal, count);
@@ -664,7 +667,7 @@ cg_found:
664 for (i = count; i < uspi->s_fpb; i++) 667 for (i = count; i < uspi->s_fpb; i++)
665 ubh_setbit (UCPI_UBH(ucpi), ucpi->c_freeoff, goal + i); 668 ubh_setbit (UCPI_UBH(ucpi), ucpi->c_freeoff, goal + i);
666 i = uspi->s_fpb - count; 669 i = uspi->s_fpb - count;
667 vfs_dq_free_block(inode, i); 670 dquot_free_block(inode, i);
668 671
669 fs32_add(sb, &ucg->cg_cs.cs_nffree, i); 672 fs32_add(sb, &ucg->cg_cs.cs_nffree, i);
670 uspi->cs_total.cs_nffree += i; 673 uspi->cs_total.cs_nffree += i;
@@ -676,8 +679,9 @@ cg_found:
676 result = ufs_bitmap_search (sb, ucpi, goal, allocsize); 679 result = ufs_bitmap_search (sb, ucpi, goal, allocsize);
677 if (result == INVBLOCK) 680 if (result == INVBLOCK)
678 return 0; 681 return 0;
679 if (vfs_dq_alloc_block(inode, count)) { 682 ret = dquot_alloc_block(inode, count);
680 *err = -EDQUOT; 683 if (ret) {
684 *err = ret;
681 return 0; 685 return 0;
682 } 686 }
683 for (i = 0; i < count; i++) 687 for (i = 0; i < count; i++)
@@ -714,6 +718,7 @@ static u64 ufs_alloccg_block(struct inode *inode,
714 struct ufs_super_block_first * usb1; 718 struct ufs_super_block_first * usb1;
715 struct ufs_cylinder_group * ucg; 719 struct ufs_cylinder_group * ucg;
716 u64 result, blkno; 720 u64 result, blkno;
721 int ret;
717 722
718 UFSD("ENTER, goal %llu\n", (unsigned long long)goal); 723 UFSD("ENTER, goal %llu\n", (unsigned long long)goal);
719 724
@@ -747,8 +752,9 @@ gotit:
747 ubh_clrblock (UCPI_UBH(ucpi), ucpi->c_freeoff, blkno); 752 ubh_clrblock (UCPI_UBH(ucpi), ucpi->c_freeoff, blkno);
748 if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD) 753 if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
749 ufs_clusteracct (sb, ucpi, blkno, -1); 754 ufs_clusteracct (sb, ucpi, blkno, -1);
750 if (vfs_dq_alloc_block(inode, uspi->s_fpb)) { 755 ret = dquot_alloc_block(inode, uspi->s_fpb);
751 *err = -EDQUOT; 756 if (ret) {
757 *err = ret;
752 return INVBLOCK; 758 return INVBLOCK;
753 } 759 }
754 760
diff --git a/fs/ufs/file.c b/fs/ufs/file.c
index 73655c61240a..a8962cecde5b 100644
--- a/fs/ufs/file.c
+++ b/fs/ufs/file.c
@@ -24,6 +24,7 @@
24 */ 24 */
25 25
26#include <linux/fs.h> 26#include <linux/fs.h>
27#include <linux/quotaops.h>
27 28
28#include "ufs_fs.h" 29#include "ufs_fs.h"
29#include "ufs.h" 30#include "ufs.h"
@@ -40,7 +41,7 @@ const struct file_operations ufs_file_operations = {
40 .write = do_sync_write, 41 .write = do_sync_write,
41 .aio_write = generic_file_aio_write, 42 .aio_write = generic_file_aio_write,
42 .mmap = generic_file_mmap, 43 .mmap = generic_file_mmap,
43 .open = generic_file_open, 44 .open = dquot_file_open,
44 .fsync = simple_fsync, 45 .fsync = simple_fsync,
45 .splice_read = generic_file_splice_read, 46 .splice_read = generic_file_splice_read,
46}; 47};
diff --git a/fs/ufs/ialloc.c b/fs/ufs/ialloc.c
index 3527c00fef0d..230ecf608026 100644
--- a/fs/ufs/ialloc.c
+++ b/fs/ufs/ialloc.c
@@ -95,8 +95,8 @@ void ufs_free_inode (struct inode * inode)
95 95
96 is_directory = S_ISDIR(inode->i_mode); 96 is_directory = S_ISDIR(inode->i_mode);
97 97
98 vfs_dq_free_inode(inode); 98 dquot_free_inode(inode);
99 vfs_dq_drop(inode); 99 dquot_drop(inode);
100 100
101 clear_inode (inode); 101 clear_inode (inode);
102 102
@@ -355,9 +355,10 @@ cg_found:
355 355
356 unlock_super (sb); 356 unlock_super (sb);
357 357
358 if (vfs_dq_alloc_inode(inode)) { 358 dquot_initialize(inode);
359 vfs_dq_drop(inode); 359 err = dquot_alloc_inode(inode);
360 err = -EDQUOT; 360 if (err) {
361 dquot_drop(inode);
361 goto fail_without_unlock; 362 goto fail_without_unlock;
362 } 363 }
363 364
diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index 0a627e08610b..80b68c3702d1 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -37,6 +37,7 @@
37#include <linux/smp_lock.h> 37#include <linux/smp_lock.h>
38#include <linux/buffer_head.h> 38#include <linux/buffer_head.h>
39#include <linux/writeback.h> 39#include <linux/writeback.h>
40#include <linux/quotaops.h>
40 41
41#include "ufs_fs.h" 42#include "ufs_fs.h"
42#include "ufs.h" 43#include "ufs.h"
@@ -909,6 +910,9 @@ void ufs_delete_inode (struct inode * inode)
909{ 910{
910 loff_t old_i_size; 911 loff_t old_i_size;
911 912
913 if (!is_bad_inode(inode))
914 dquot_initialize(inode);
915
912 truncate_inode_pages(&inode->i_data, 0); 916 truncate_inode_pages(&inode->i_data, 0);
913 if (is_bad_inode(inode)) 917 if (is_bad_inode(inode))
914 goto no_delete; 918 goto no_delete;
diff --git a/fs/ufs/namei.c b/fs/ufs/namei.c
index 4c26d9e8bc94..118556243e7a 100644
--- a/fs/ufs/namei.c
+++ b/fs/ufs/namei.c
@@ -30,6 +30,7 @@
30#include <linux/time.h> 30#include <linux/time.h>
31#include <linux/fs.h> 31#include <linux/fs.h>
32#include <linux/smp_lock.h> 32#include <linux/smp_lock.h>
33#include <linux/quotaops.h>
33 34
34#include "ufs_fs.h" 35#include "ufs_fs.h"
35#include "ufs.h" 36#include "ufs.h"
@@ -84,6 +85,9 @@ static int ufs_create (struct inode * dir, struct dentry * dentry, int mode,
84 int err; 85 int err;
85 86
86 UFSD("BEGIN\n"); 87 UFSD("BEGIN\n");
88
89 dquot_initialize(dir);
90
87 inode = ufs_new_inode(dir, mode); 91 inode = ufs_new_inode(dir, mode);
88 err = PTR_ERR(inode); 92 err = PTR_ERR(inode);
89 93
@@ -107,6 +111,9 @@ static int ufs_mknod (struct inode * dir, struct dentry *dentry, int mode, dev_t
107 111
108 if (!old_valid_dev(rdev)) 112 if (!old_valid_dev(rdev))
109 return -EINVAL; 113 return -EINVAL;
114
115 dquot_initialize(dir);
116
110 inode = ufs_new_inode(dir, mode); 117 inode = ufs_new_inode(dir, mode);
111 err = PTR_ERR(inode); 118 err = PTR_ERR(inode);
112 if (!IS_ERR(inode)) { 119 if (!IS_ERR(inode)) {
@@ -131,6 +138,8 @@ static int ufs_symlink (struct inode * dir, struct dentry * dentry,
131 if (l > sb->s_blocksize) 138 if (l > sb->s_blocksize)
132 goto out_notlocked; 139 goto out_notlocked;
133 140
141 dquot_initialize(dir);
142
134 lock_kernel(); 143 lock_kernel();
135 inode = ufs_new_inode(dir, S_IFLNK | S_IRWXUGO); 144 inode = ufs_new_inode(dir, S_IFLNK | S_IRWXUGO);
136 err = PTR_ERR(inode); 145 err = PTR_ERR(inode);
@@ -176,6 +185,8 @@ static int ufs_link (struct dentry * old_dentry, struct inode * dir,
176 return -EMLINK; 185 return -EMLINK;
177 } 186 }
178 187
188 dquot_initialize(dir);
189
179 inode->i_ctime = CURRENT_TIME_SEC; 190 inode->i_ctime = CURRENT_TIME_SEC;
180 inode_inc_link_count(inode); 191 inode_inc_link_count(inode);
181 atomic_inc(&inode->i_count); 192 atomic_inc(&inode->i_count);
@@ -193,6 +204,8 @@ static int ufs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
193 if (dir->i_nlink >= UFS_LINK_MAX) 204 if (dir->i_nlink >= UFS_LINK_MAX)
194 goto out; 205 goto out;
195 206
207 dquot_initialize(dir);
208
196 lock_kernel(); 209 lock_kernel();
197 inode_inc_link_count(dir); 210 inode_inc_link_count(dir);
198 211
@@ -237,6 +250,8 @@ static int ufs_unlink(struct inode *dir, struct dentry *dentry)
237 struct page *page; 250 struct page *page;
238 int err = -ENOENT; 251 int err = -ENOENT;
239 252
253 dquot_initialize(dir);
254
240 de = ufs_find_entry(dir, &dentry->d_name, &page); 255 de = ufs_find_entry(dir, &dentry->d_name, &page);
241 if (!de) 256 if (!de)
242 goto out; 257 goto out;
@@ -281,6 +296,9 @@ static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry,
281 struct ufs_dir_entry *old_de; 296 struct ufs_dir_entry *old_de;
282 int err = -ENOENT; 297 int err = -ENOENT;
283 298
299 dquot_initialize(old_dir);
300 dquot_initialize(new_dir);
301
284 old_de = ufs_find_entry(old_dir, &old_dentry->d_name, &old_page); 302 old_de = ufs_find_entry(old_dir, &old_dentry->d_name, &old_page);
285 if (!old_de) 303 if (!old_de)
286 goto out; 304 goto out;
diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index 143c20bfb04b..66b63a751615 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -1432,6 +1432,11 @@ static void destroy_inodecache(void)
1432 kmem_cache_destroy(ufs_inode_cachep); 1432 kmem_cache_destroy(ufs_inode_cachep);
1433} 1433}
1434 1434
1435static void ufs_clear_inode(struct inode *inode)
1436{
1437 dquot_drop(inode);
1438}
1439
1435#ifdef CONFIG_QUOTA 1440#ifdef CONFIG_QUOTA
1436static ssize_t ufs_quota_read(struct super_block *, int, char *,size_t, loff_t); 1441static ssize_t ufs_quota_read(struct super_block *, int, char *,size_t, loff_t);
1437static ssize_t ufs_quota_write(struct super_block *, int, const char *, size_t, loff_t); 1442static ssize_t ufs_quota_write(struct super_block *, int, const char *, size_t, loff_t);
@@ -1442,6 +1447,7 @@ static const struct super_operations ufs_super_ops = {
1442 .destroy_inode = ufs_destroy_inode, 1447 .destroy_inode = ufs_destroy_inode,
1443 .write_inode = ufs_write_inode, 1448 .write_inode = ufs_write_inode,
1444 .delete_inode = ufs_delete_inode, 1449 .delete_inode = ufs_delete_inode,
1450 .clear_inode = ufs_clear_inode,
1445 .put_super = ufs_put_super, 1451 .put_super = ufs_put_super,
1446 .write_super = ufs_write_super, 1452 .write_super = ufs_write_super,
1447 .sync_fs = ufs_sync_fs, 1453 .sync_fs = ufs_sync_fs,
diff --git a/fs/ufs/truncate.c b/fs/ufs/truncate.c
index 41dd431ce228..d3b6270cb377 100644
--- a/fs/ufs/truncate.c
+++ b/fs/ufs/truncate.c
@@ -44,6 +44,7 @@
44#include <linux/buffer_head.h> 44#include <linux/buffer_head.h>
45#include <linux/blkdev.h> 45#include <linux/blkdev.h>
46#include <linux/sched.h> 46#include <linux/sched.h>
47#include <linux/quotaops.h>
47 48
48#include "ufs_fs.h" 49#include "ufs_fs.h"
49#include "ufs.h" 50#include "ufs.h"
@@ -517,9 +518,18 @@ static int ufs_setattr(struct dentry *dentry, struct iattr *attr)
517 if (error) 518 if (error)
518 return error; 519 return error;
519 520
521 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
522 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
523 error = dquot_transfer(inode, attr);
524 if (error)
525 return error;
526 }
520 if (ia_valid & ATTR_SIZE && 527 if (ia_valid & ATTR_SIZE &&
521 attr->ia_size != i_size_read(inode)) { 528 attr->ia_size != i_size_read(inode)) {
522 loff_t old_i_size = inode->i_size; 529 loff_t old_i_size = inode->i_size;
530
531 dquot_initialize(inode);
532
523 error = vmtruncate(inode, attr->ia_size); 533 error = vmtruncate(inode, attr->ia_size);
524 if (error) 534 if (error)
525 return error; 535 return error;
diff --git a/fs/xfs/linux-2.6/xfs_quotaops.c b/fs/xfs/linux-2.6/xfs_quotaops.c
index 3d4a0c84d634..1947514ce1ad 100644
--- a/fs/xfs/linux-2.6/xfs_quotaops.c
+++ b/fs/xfs/linux-2.6/xfs_quotaops.c
@@ -44,20 +44,6 @@ xfs_quota_type(int type)
44} 44}
45 45
46STATIC int 46STATIC int
47xfs_fs_quota_sync(
48 struct super_block *sb,
49 int type)
50{
51 struct xfs_mount *mp = XFS_M(sb);
52
53 if (sb->s_flags & MS_RDONLY)
54 return -EROFS;
55 if (!XFS_IS_QUOTA_RUNNING(mp))
56 return -ENOSYS;
57 return -xfs_sync_data(mp, 0);
58}
59
60STATIC int
61xfs_fs_get_xstate( 47xfs_fs_get_xstate(
62 struct super_block *sb, 48 struct super_block *sb,
63 struct fs_quota_stat *fqs) 49 struct fs_quota_stat *fqs)
@@ -82,8 +68,6 @@ xfs_fs_set_xstate(
82 return -EROFS; 68 return -EROFS;
83 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp)) 69 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
84 return -ENOSYS; 70 return -ENOSYS;
85 if (!capable(CAP_SYS_ADMIN))
86 return -EPERM;
87 71
88 if (uflags & XFS_QUOTA_UDQ_ACCT) 72 if (uflags & XFS_QUOTA_UDQ_ACCT)
89 flags |= XFS_UQUOTA_ACCT; 73 flags |= XFS_UQUOTA_ACCT;
@@ -144,14 +128,11 @@ xfs_fs_set_xquota(
144 return -ENOSYS; 128 return -ENOSYS;
145 if (!XFS_IS_QUOTA_ON(mp)) 129 if (!XFS_IS_QUOTA_ON(mp))
146 return -ESRCH; 130 return -ESRCH;
147 if (!capable(CAP_SYS_ADMIN))
148 return -EPERM;
149 131
150 return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq); 132 return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq);
151} 133}
152 134
153const struct quotactl_ops xfs_quotactl_operations = { 135const struct quotactl_ops xfs_quotactl_operations = {
154 .quota_sync = xfs_fs_quota_sync,
155 .get_xstate = xfs_fs_get_xstate, 136 .get_xstate = xfs_fs_get_xstate,
156 .set_xstate = xfs_fs_set_xstate, 137 .set_xstate = xfs_fs_set_xstate,
157 .get_xquota = xfs_fs_get_xquota, 138 .get_xquota = xfs_fs_get_xquota,