aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-01-08 16:07:54 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-01-08 16:07:54 -0500
commit1619ed8f60959829d070d8f39cd2f8ca0e7135ce (patch)
treeaa2599110827affb10e64a12e85a9d11f45854b1
parent29ad0de279002f9b6a63df5ba85328f5b633b842 (diff)
parent46cc1e5fce46e71f27e542125e045827a6bb776e (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw
* git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw: GFS2: local functions should be static GFS2: We only need one ACL getting function GFS2: Fix multi-block allocation GFS2: decouple quota allocations from block allocations GFS2: split function rgblk_search GFS2: Fix up "off by one" in the previous patch GFS2: move toward a generic multi-block allocator GFS2: O_(D)SYNC support for fallocate GFS2: remove vestigial al_alloced GFS2: combine gfs2_alloc_block and gfs2_alloc_di GFS2: Add non-try locks back to get_local_rgrp GFS2: f_ra is always valid in dir readahead function GFS2: Fix very unlikley memory leak in ACL xattr code GFS2: More automated code analysis fixes GFS2: Add readahead to sequential directory traversal GFS2: Fix up REQ flags
-rw-r--r--fs/gfs2/acl.c14
-rw-r--r--fs/gfs2/aops.c18
-rw-r--r--fs/gfs2/bmap.c26
-rw-r--r--fs/gfs2/dir.c64
-rw-r--r--fs/gfs2/dir.h2
-rw-r--r--fs/gfs2/export.c3
-rw-r--r--fs/gfs2/file.c34
-rw-r--r--fs/gfs2/incore.h20
-rw-r--r--fs/gfs2/inode.c72
-rw-r--r--fs/gfs2/log.c2
-rw-r--r--fs/gfs2/main.c3
-rw-r--r--fs/gfs2/meta_io.c4
-rw-r--r--fs/gfs2/ops_fstype.c2
-rw-r--r--fs/gfs2/quota.c87
-rw-r--r--fs/gfs2/rgrp.c293
-rw-r--r--fs/gfs2/rgrp.h16
-rw-r--r--fs/gfs2/super.c14
-rw-r--r--fs/gfs2/trans.h6
-rw-r--r--fs/gfs2/xattr.c48
19 files changed, 394 insertions, 334 deletions
diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c
index 65978d7885c8..230eb0f005b6 100644
--- a/fs/gfs2/acl.c
+++ b/fs/gfs2/acl.c
@@ -38,8 +38,9 @@ static const char *gfs2_acl_name(int type)
38 return NULL; 38 return NULL;
39} 39}
40 40
41static struct posix_acl *gfs2_acl_get(struct gfs2_inode *ip, int type) 41struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
42{ 42{
43 struct gfs2_inode *ip = GFS2_I(inode);
43 struct posix_acl *acl; 44 struct posix_acl *acl;
44 const char *name; 45 const char *name;
45 char *data; 46 char *data;
@@ -67,11 +68,6 @@ static struct posix_acl *gfs2_acl_get(struct gfs2_inode *ip, int type)
67 return acl; 68 return acl;
68} 69}
69 70
70struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
71{
72 return gfs2_acl_get(GFS2_I(inode), type);
73}
74
75static int gfs2_set_mode(struct inode *inode, umode_t mode) 71static int gfs2_set_mode(struct inode *inode, umode_t mode)
76{ 72{
77 int error = 0; 73 int error = 0;
@@ -125,7 +121,7 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct inode *inode)
125 if (S_ISLNK(inode->i_mode)) 121 if (S_ISLNK(inode->i_mode))
126 return 0; 122 return 0;
127 123
128 acl = gfs2_acl_get(dip, ACL_TYPE_DEFAULT); 124 acl = gfs2_get_acl(&dip->i_inode, ACL_TYPE_DEFAULT);
129 if (IS_ERR(acl)) 125 if (IS_ERR(acl))
130 return PTR_ERR(acl); 126 return PTR_ERR(acl);
131 if (!acl) { 127 if (!acl) {
@@ -166,7 +162,7 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
166 unsigned int len; 162 unsigned int len;
167 int error; 163 int error;
168 164
169 acl = gfs2_acl_get(ip, ACL_TYPE_ACCESS); 165 acl = gfs2_get_acl(&ip->i_inode, ACL_TYPE_ACCESS);
170 if (IS_ERR(acl)) 166 if (IS_ERR(acl))
171 return PTR_ERR(acl); 167 return PTR_ERR(acl);
172 if (!acl) 168 if (!acl)
@@ -216,7 +212,7 @@ static int gfs2_xattr_system_get(struct dentry *dentry, const char *name,
216 if (type < 0) 212 if (type < 0)
217 return type; 213 return type;
218 214
219 acl = gfs2_acl_get(GFS2_I(inode), type); 215 acl = gfs2_get_acl(inode, type);
220 if (IS_ERR(acl)) 216 if (IS_ERR(acl))
221 return PTR_ERR(acl); 217 return PTR_ERR(acl);
222 if (acl == NULL) 218 if (acl == NULL)
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index 4858e1fed8b1..501e5cba09b3 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -615,7 +615,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
615 unsigned int data_blocks = 0, ind_blocks = 0, rblocks; 615 unsigned int data_blocks = 0, ind_blocks = 0, rblocks;
616 int alloc_required; 616 int alloc_required;
617 int error = 0; 617 int error = 0;
618 struct gfs2_alloc *al = NULL; 618 struct gfs2_qadata *qa = NULL;
619 pgoff_t index = pos >> PAGE_CACHE_SHIFT; 619 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
620 unsigned from = pos & (PAGE_CACHE_SIZE - 1); 620 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
621 struct page *page; 621 struct page *page;
@@ -639,8 +639,8 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
639 gfs2_write_calc_reserv(ip, len, &data_blocks, &ind_blocks); 639 gfs2_write_calc_reserv(ip, len, &data_blocks, &ind_blocks);
640 640
641 if (alloc_required) { 641 if (alloc_required) {
642 al = gfs2_alloc_get(ip); 642 qa = gfs2_qadata_get(ip);
643 if (!al) { 643 if (!qa) {
644 error = -ENOMEM; 644 error = -ENOMEM;
645 goto out_unlock; 645 goto out_unlock;
646 } 646 }
@@ -649,8 +649,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
649 if (error) 649 if (error)
650 goto out_alloc_put; 650 goto out_alloc_put;
651 651
652 al->al_requested = data_blocks + ind_blocks; 652 error = gfs2_inplace_reserve(ip, data_blocks + ind_blocks);
653 error = gfs2_inplace_reserve(ip);
654 if (error) 653 if (error)
655 goto out_qunlock; 654 goto out_qunlock;
656 } 655 }
@@ -711,7 +710,7 @@ out_trans_fail:
711out_qunlock: 710out_qunlock:
712 gfs2_quota_unlock(ip); 711 gfs2_quota_unlock(ip);
713out_alloc_put: 712out_alloc_put:
714 gfs2_alloc_put(ip); 713 gfs2_qadata_put(ip);
715 } 714 }
716out_unlock: 715out_unlock:
717 if (&ip->i_inode == sdp->sd_rindex) { 716 if (&ip->i_inode == sdp->sd_rindex) {
@@ -848,7 +847,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
848 struct gfs2_sbd *sdp = GFS2_SB(inode); 847 struct gfs2_sbd *sdp = GFS2_SB(inode);
849 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); 848 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
850 struct buffer_head *dibh; 849 struct buffer_head *dibh;
851 struct gfs2_alloc *al = ip->i_alloc; 850 struct gfs2_qadata *qa = ip->i_qadata;
852 unsigned int from = pos & (PAGE_CACHE_SIZE - 1); 851 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
853 unsigned int to = from + len; 852 unsigned int to = from + len;
854 int ret; 853 int ret;
@@ -880,10 +879,11 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
880 brelse(dibh); 879 brelse(dibh);
881failed: 880failed:
882 gfs2_trans_end(sdp); 881 gfs2_trans_end(sdp);
883 if (al) { 882 if (ip->i_res)
884 gfs2_inplace_release(ip); 883 gfs2_inplace_release(ip);
884 if (qa) {
885 gfs2_quota_unlock(ip); 885 gfs2_quota_unlock(ip);
886 gfs2_alloc_put(ip); 886 gfs2_qadata_put(ip);
887 } 887 }
888 if (inode == sdp->sd_rindex) { 888 if (inode == sdp->sd_rindex) {
889 gfs2_glock_dq(&m_ip->i_gh); 889 gfs2_glock_dq(&m_ip->i_gh);
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 41d494d79709..14a704015970 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -133,7 +133,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
133 and write it out to disk */ 133 and write it out to disk */
134 134
135 unsigned int n = 1; 135 unsigned int n = 1;
136 error = gfs2_alloc_block(ip, &block, &n); 136 error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL);
137 if (error) 137 if (error)
138 goto out_brelse; 138 goto out_brelse;
139 if (isdir) { 139 if (isdir) {
@@ -503,7 +503,7 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,
503 do { 503 do {
504 int error; 504 int error;
505 n = blks - alloced; 505 n = blks - alloced;
506 error = gfs2_alloc_block(ip, &bn, &n); 506 error = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL);
507 if (error) 507 if (error)
508 return error; 508 return error;
509 alloced += n; 509 alloced += n;
@@ -743,9 +743,6 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
743 else if (ip->i_depth) 743 else if (ip->i_depth)
744 revokes = sdp->sd_inptrs; 744 revokes = sdp->sd_inptrs;
745 745
746 if (error)
747 return error;
748
749 memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); 746 memset(&rlist, 0, sizeof(struct gfs2_rgrp_list));
750 bstart = 0; 747 bstart = 0;
751 blen = 0; 748 blen = 0;
@@ -1044,7 +1041,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, u64 size)
1044 lblock = (size - 1) >> sdp->sd_sb.sb_bsize_shift; 1041 lblock = (size - 1) >> sdp->sd_sb.sb_bsize_shift;
1045 1042
1046 find_metapath(sdp, lblock, &mp, ip->i_height); 1043 find_metapath(sdp, lblock, &mp, ip->i_height);
1047 if (!gfs2_alloc_get(ip)) 1044 if (!gfs2_qadata_get(ip))
1048 return -ENOMEM; 1045 return -ENOMEM;
1049 1046
1050 error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); 1047 error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
@@ -1064,7 +1061,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, u64 size)
1064 gfs2_quota_unhold(ip); 1061 gfs2_quota_unhold(ip);
1065 1062
1066out: 1063out:
1067 gfs2_alloc_put(ip); 1064 gfs2_qadata_put(ip);
1068 return error; 1065 return error;
1069} 1066}
1070 1067
@@ -1166,21 +1163,20 @@ static int do_grow(struct inode *inode, u64 size)
1166 struct gfs2_inode *ip = GFS2_I(inode); 1163 struct gfs2_inode *ip = GFS2_I(inode);
1167 struct gfs2_sbd *sdp = GFS2_SB(inode); 1164 struct gfs2_sbd *sdp = GFS2_SB(inode);
1168 struct buffer_head *dibh; 1165 struct buffer_head *dibh;
1169 struct gfs2_alloc *al = NULL; 1166 struct gfs2_qadata *qa = NULL;
1170 int error; 1167 int error;
1171 1168
1172 if (gfs2_is_stuffed(ip) && 1169 if (gfs2_is_stuffed(ip) &&
1173 (size > (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)))) { 1170 (size > (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)))) {
1174 al = gfs2_alloc_get(ip); 1171 qa = gfs2_qadata_get(ip);
1175 if (al == NULL) 1172 if (qa == NULL)
1176 return -ENOMEM; 1173 return -ENOMEM;
1177 1174
1178 error = gfs2_quota_lock_check(ip); 1175 error = gfs2_quota_lock_check(ip);
1179 if (error) 1176 if (error)
1180 goto do_grow_alloc_put; 1177 goto do_grow_alloc_put;
1181 1178
1182 al->al_requested = 1; 1179 error = gfs2_inplace_reserve(ip, 1);
1183 error = gfs2_inplace_reserve(ip);
1184 if (error) 1180 if (error)
1185 goto do_grow_qunlock; 1181 goto do_grow_qunlock;
1186 } 1182 }
@@ -1189,7 +1185,7 @@ static int do_grow(struct inode *inode, u64 size)
1189 if (error) 1185 if (error)
1190 goto do_grow_release; 1186 goto do_grow_release;
1191 1187
1192 if (al) { 1188 if (qa) {
1193 error = gfs2_unstuff_dinode(ip, NULL); 1189 error = gfs2_unstuff_dinode(ip, NULL);
1194 if (error) 1190 if (error)
1195 goto do_end_trans; 1191 goto do_end_trans;
@@ -1208,12 +1204,12 @@ static int do_grow(struct inode *inode, u64 size)
1208do_end_trans: 1204do_end_trans:
1209 gfs2_trans_end(sdp); 1205 gfs2_trans_end(sdp);
1210do_grow_release: 1206do_grow_release:
1211 if (al) { 1207 if (qa) {
1212 gfs2_inplace_release(ip); 1208 gfs2_inplace_release(ip);
1213do_grow_qunlock: 1209do_grow_qunlock:
1214 gfs2_quota_unlock(ip); 1210 gfs2_quota_unlock(ip);
1215do_grow_alloc_put: 1211do_grow_alloc_put:
1216 gfs2_alloc_put(ip); 1212 gfs2_qadata_put(ip);
1217 } 1213 }
1218 return error; 1214 return error;
1219} 1215}
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 8ccad2467cb6..c35573abd371 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -76,6 +76,8 @@
76#define IS_LEAF 1 /* Hashed (leaf) directory */ 76#define IS_LEAF 1 /* Hashed (leaf) directory */
77#define IS_DINODE 2 /* Linear (stuffed dinode block) directory */ 77#define IS_DINODE 2 /* Linear (stuffed dinode block) directory */
78 78
79#define MAX_RA_BLOCKS 32 /* max read-ahead blocks */
80
79#define gfs2_disk_hash2offset(h) (((u64)(h)) >> 1) 81#define gfs2_disk_hash2offset(h) (((u64)(h)) >> 1)
80#define gfs2_dir_offset2hash(p) ((u32)(((u64)(p)) << 1)) 82#define gfs2_dir_offset2hash(p) ((u32)(((u64)(p)) << 1))
81 83
@@ -821,7 +823,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
821 struct gfs2_dirent *dent; 823 struct gfs2_dirent *dent;
822 struct qstr name = { .name = "", .len = 0, .hash = 0 }; 824 struct qstr name = { .name = "", .len = 0, .hash = 0 };
823 825
824 error = gfs2_alloc_block(ip, &bn, &n); 826 error = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL);
825 if (error) 827 if (error)
826 return NULL; 828 return NULL;
827 bh = gfs2_meta_new(ip->i_gl, bn); 829 bh = gfs2_meta_new(ip->i_gl, bn);
@@ -1376,6 +1378,52 @@ out:
1376 return error; 1378 return error;
1377} 1379}
1378 1380
1381/**
1382 * gfs2_dir_readahead - Issue read-ahead requests for leaf blocks.
1383 *
1384 * Note: we can't calculate each index like dir_e_read can because we don't
1385 * have the leaf, and therefore we don't have the depth, and therefore we
1386 * don't have the length. So we have to just read enough ahead to make up
1387 * for the loss of information.
1388 */
1389static void gfs2_dir_readahead(struct inode *inode, unsigned hsize, u32 index,
1390 struct file_ra_state *f_ra)
1391{
1392 struct gfs2_inode *ip = GFS2_I(inode);
1393 struct gfs2_glock *gl = ip->i_gl;
1394 struct buffer_head *bh;
1395 u64 blocknr = 0, last;
1396 unsigned count;
1397
1398 /* First check if we've already read-ahead for the whole range. */
1399 if (index + MAX_RA_BLOCKS < f_ra->start)
1400 return;
1401
1402 f_ra->start = max((pgoff_t)index, f_ra->start);
1403 for (count = 0; count < MAX_RA_BLOCKS; count++) {
1404 if (f_ra->start >= hsize) /* if exceeded the hash table */
1405 break;
1406
1407 last = blocknr;
1408 blocknr = be64_to_cpu(ip->i_hash_cache[f_ra->start]);
1409 f_ra->start++;
1410 if (blocknr == last)
1411 continue;
1412
1413 bh = gfs2_getbuf(gl, blocknr, 1);
1414 if (trylock_buffer(bh)) {
1415 if (buffer_uptodate(bh)) {
1416 unlock_buffer(bh);
1417 brelse(bh);
1418 continue;
1419 }
1420 bh->b_end_io = end_buffer_read_sync;
1421 submit_bh(READA | REQ_META, bh);
1422 continue;
1423 }
1424 brelse(bh);
1425 }
1426}
1379 1427
1380/** 1428/**
1381 * dir_e_read - Reads the entries from a directory into a filldir buffer 1429 * dir_e_read - Reads the entries from a directory into a filldir buffer
@@ -1388,7 +1436,7 @@ out:
1388 */ 1436 */
1389 1437
1390static int dir_e_read(struct inode *inode, u64 *offset, void *opaque, 1438static int dir_e_read(struct inode *inode, u64 *offset, void *opaque,
1391 filldir_t filldir) 1439 filldir_t filldir, struct file_ra_state *f_ra)
1392{ 1440{
1393 struct gfs2_inode *dip = GFS2_I(inode); 1441 struct gfs2_inode *dip = GFS2_I(inode);
1394 u32 hsize, len = 0; 1442 u32 hsize, len = 0;
@@ -1402,10 +1450,14 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque,
1402 hash = gfs2_dir_offset2hash(*offset); 1450 hash = gfs2_dir_offset2hash(*offset);
1403 index = hash >> (32 - dip->i_depth); 1451 index = hash >> (32 - dip->i_depth);
1404 1452
1453 if (dip->i_hash_cache == NULL)
1454 f_ra->start = 0;
1405 lp = gfs2_dir_get_hash_table(dip); 1455 lp = gfs2_dir_get_hash_table(dip);
1406 if (IS_ERR(lp)) 1456 if (IS_ERR(lp))
1407 return PTR_ERR(lp); 1457 return PTR_ERR(lp);
1408 1458
1459 gfs2_dir_readahead(inode, hsize, index, f_ra);
1460
1409 while (index < hsize) { 1461 while (index < hsize) {
1410 error = gfs2_dir_read_leaf(inode, offset, opaque, filldir, 1462 error = gfs2_dir_read_leaf(inode, offset, opaque, filldir,
1411 &copied, &depth, 1463 &copied, &depth,
@@ -1423,7 +1475,7 @@ static int dir_e_read(struct inode *inode, u64 *offset, void *opaque,
1423} 1475}
1424 1476
1425int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque, 1477int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
1426 filldir_t filldir) 1478 filldir_t filldir, struct file_ra_state *f_ra)
1427{ 1479{
1428 struct gfs2_inode *dip = GFS2_I(inode); 1480 struct gfs2_inode *dip = GFS2_I(inode);
1429 struct gfs2_sbd *sdp = GFS2_SB(inode); 1481 struct gfs2_sbd *sdp = GFS2_SB(inode);
@@ -1437,7 +1489,7 @@ int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
1437 return 0; 1489 return 0;
1438 1490
1439 if (dip->i_diskflags & GFS2_DIF_EXHASH) 1491 if (dip->i_diskflags & GFS2_DIF_EXHASH)
1440 return dir_e_read(inode, offset, opaque, filldir); 1492 return dir_e_read(inode, offset, opaque, filldir, f_ra);
1441 1493
1442 if (!gfs2_is_stuffed(dip)) { 1494 if (!gfs2_is_stuffed(dip)) {
1443 gfs2_consist_inode(dip); 1495 gfs2_consist_inode(dip);
@@ -1798,7 +1850,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len,
1798 if (!ht) 1850 if (!ht)
1799 return -ENOMEM; 1851 return -ENOMEM;
1800 1852
1801 if (!gfs2_alloc_get(dip)) { 1853 if (!gfs2_qadata_get(dip)) {
1802 error = -ENOMEM; 1854 error = -ENOMEM;
1803 goto out; 1855 goto out;
1804 } 1856 }
@@ -1887,7 +1939,7 @@ out_rlist:
1887 gfs2_rlist_free(&rlist); 1939 gfs2_rlist_free(&rlist);
1888 gfs2_quota_unhold(dip); 1940 gfs2_quota_unhold(dip);
1889out_put: 1941out_put:
1890 gfs2_alloc_put(dip); 1942 gfs2_qadata_put(dip);
1891out: 1943out:
1892 kfree(ht); 1944 kfree(ht);
1893 return error; 1945 return error;
diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h
index ff5772fbf024..98c960beab35 100644
--- a/fs/gfs2/dir.h
+++ b/fs/gfs2/dir.h
@@ -25,7 +25,7 @@ extern int gfs2_dir_add(struct inode *inode, const struct qstr *filename,
25 const struct gfs2_inode *ip); 25 const struct gfs2_inode *ip);
26extern int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry); 26extern int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry);
27extern int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque, 27extern int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
28 filldir_t filldir); 28 filldir_t filldir, struct file_ra_state *f_ra);
29extern int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename, 29extern int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
30 const struct gfs2_inode *nip, unsigned int new_type); 30 const struct gfs2_inode *nip, unsigned int new_type);
31 31
diff --git a/fs/gfs2/export.c b/fs/gfs2/export.c
index fe9945f2ff72..70ba891654f8 100644
--- a/fs/gfs2/export.c
+++ b/fs/gfs2/export.c
@@ -99,6 +99,7 @@ static int gfs2_get_name(struct dentry *parent, char *name,
99 struct gfs2_holder gh; 99 struct gfs2_holder gh;
100 u64 offset = 0; 100 u64 offset = 0;
101 int error; 101 int error;
102 struct file_ra_state f_ra = { .start = 0 };
102 103
103 if (!dir) 104 if (!dir)
104 return -EINVAL; 105 return -EINVAL;
@@ -118,7 +119,7 @@ static int gfs2_get_name(struct dentry *parent, char *name,
118 if (error) 119 if (error)
119 return error; 120 return error;
120 121
121 error = gfs2_dir_read(dir, &offset, &gnfd, get_name_filldir); 122 error = gfs2_dir_read(dir, &offset, &gnfd, get_name_filldir, &f_ra);
122 123
123 gfs2_glock_dq_uninit(&gh); 124 gfs2_glock_dq_uninit(&gh);
124 125
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
index b8927d4f3bf2..c5fb3597f696 100644
--- a/fs/gfs2/file.c
+++ b/fs/gfs2/file.c
@@ -105,7 +105,7 @@ static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir)
105 return error; 105 return error;
106 } 106 }
107 107
108 error = gfs2_dir_read(dir, &offset, dirent, filldir); 108 error = gfs2_dir_read(dir, &offset, dirent, filldir, &file->f_ra);
109 109
110 gfs2_glock_dq_uninit(&d_gh); 110 gfs2_glock_dq_uninit(&d_gh);
111 111
@@ -365,7 +365,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
365 u64 pos = page->index << PAGE_CACHE_SHIFT; 365 u64 pos = page->index << PAGE_CACHE_SHIFT;
366 unsigned int data_blocks, ind_blocks, rblocks; 366 unsigned int data_blocks, ind_blocks, rblocks;
367 struct gfs2_holder gh; 367 struct gfs2_holder gh;
368 struct gfs2_alloc *al; 368 struct gfs2_qadata *qa;
369 loff_t size; 369 loff_t size;
370 int ret; 370 int ret;
371 371
@@ -393,16 +393,15 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
393 } 393 }
394 394
395 ret = -ENOMEM; 395 ret = -ENOMEM;
396 al = gfs2_alloc_get(ip); 396 qa = gfs2_qadata_get(ip);
397 if (al == NULL) 397 if (qa == NULL)
398 goto out_unlock; 398 goto out_unlock;
399 399
400 ret = gfs2_quota_lock_check(ip); 400 ret = gfs2_quota_lock_check(ip);
401 if (ret) 401 if (ret)
402 goto out_alloc_put; 402 goto out_alloc_put;
403 gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks); 403 gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks);
404 al->al_requested = data_blocks + ind_blocks; 404 ret = gfs2_inplace_reserve(ip, data_blocks + ind_blocks);
405 ret = gfs2_inplace_reserve(ip);
406 if (ret) 405 if (ret)
407 goto out_quota_unlock; 406 goto out_quota_unlock;
408 407
@@ -448,7 +447,7 @@ out_trans_fail:
448out_quota_unlock: 447out_quota_unlock:
449 gfs2_quota_unlock(ip); 448 gfs2_quota_unlock(ip);
450out_alloc_put: 449out_alloc_put:
451 gfs2_alloc_put(ip); 450 gfs2_qadata_put(ip);
452out_unlock: 451out_unlock:
453 gfs2_glock_dq(&gh); 452 gfs2_glock_dq(&gh);
454out: 453out:
@@ -609,7 +608,7 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
609 struct inode *inode = mapping->host; 608 struct inode *inode = mapping->host;
610 int sync_state = inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC); 609 int sync_state = inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC);
611 struct gfs2_inode *ip = GFS2_I(inode); 610 struct gfs2_inode *ip = GFS2_I(inode);
612 int ret, ret1 = 0; 611 int ret = 0, ret1 = 0;
613 612
614 if (mapping->nrpages) { 613 if (mapping->nrpages) {
615 ret1 = filemap_fdatawrite_range(mapping, start, end); 614 ret1 = filemap_fdatawrite_range(mapping, start, end);
@@ -750,8 +749,10 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset,
750 struct gfs2_inode *ip = GFS2_I(inode); 749 struct gfs2_inode *ip = GFS2_I(inode);
751 unsigned int data_blocks = 0, ind_blocks = 0, rblocks; 750 unsigned int data_blocks = 0, ind_blocks = 0, rblocks;
752 loff_t bytes, max_bytes; 751 loff_t bytes, max_bytes;
753 struct gfs2_alloc *al; 752 struct gfs2_qadata *qa;
754 int error; 753 int error;
754 const loff_t pos = offset;
755 const loff_t count = len;
755 loff_t bsize_mask = ~((loff_t)sdp->sd_sb.sb_bsize - 1); 756 loff_t bsize_mask = ~((loff_t)sdp->sd_sb.sb_bsize - 1);
756 loff_t next = (offset + len - 1) >> sdp->sd_sb.sb_bsize_shift; 757 loff_t next = (offset + len - 1) >> sdp->sd_sb.sb_bsize_shift;
757 loff_t max_chunk_size = UINT_MAX & bsize_mask; 758 loff_t max_chunk_size = UINT_MAX & bsize_mask;
@@ -782,8 +783,8 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset,
782 while (len > 0) { 783 while (len > 0) {
783 if (len < bytes) 784 if (len < bytes)
784 bytes = len; 785 bytes = len;
785 al = gfs2_alloc_get(ip); 786 qa = gfs2_qadata_get(ip);
786 if (!al) { 787 if (!qa) {
787 error = -ENOMEM; 788 error = -ENOMEM;
788 goto out_unlock; 789 goto out_unlock;
789 } 790 }
@@ -795,8 +796,7 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset,
795retry: 796retry:
796 gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks); 797 gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks);
797 798
798 al->al_requested = data_blocks + ind_blocks; 799 error = gfs2_inplace_reserve(ip, data_blocks + ind_blocks);
799 error = gfs2_inplace_reserve(ip);
800 if (error) { 800 if (error) {
801 if (error == -ENOSPC && bytes > sdp->sd_sb.sb_bsize) { 801 if (error == -ENOSPC && bytes > sdp->sd_sb.sb_bsize) {
802 bytes >>= 1; 802 bytes >>= 1;
@@ -810,7 +810,6 @@ retry:
810 max_bytes = bytes; 810 max_bytes = bytes;
811 calc_max_reserv(ip, (len > max_chunk_size)? max_chunk_size: len, 811 calc_max_reserv(ip, (len > max_chunk_size)? max_chunk_size: len,
812 &max_bytes, &data_blocks, &ind_blocks); 812 &max_bytes, &data_blocks, &ind_blocks);
813 al->al_requested = data_blocks + ind_blocks;
814 813
815 rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + 814 rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA +
816 RES_RG_HDR + gfs2_rg_blocks(ip); 815 RES_RG_HDR + gfs2_rg_blocks(ip);
@@ -832,8 +831,11 @@ retry:
832 offset += max_bytes; 831 offset += max_bytes;
833 gfs2_inplace_release(ip); 832 gfs2_inplace_release(ip);
834 gfs2_quota_unlock(ip); 833 gfs2_quota_unlock(ip);
835 gfs2_alloc_put(ip); 834 gfs2_qadata_put(ip);
836 } 835 }
836
837 if (error == 0)
838 error = generic_write_sync(file, pos, count);
837 goto out_unlock; 839 goto out_unlock;
838 840
839out_trans_fail: 841out_trans_fail:
@@ -841,7 +843,7 @@ out_trans_fail:
841out_qunlock: 843out_qunlock:
842 gfs2_quota_unlock(ip); 844 gfs2_quota_unlock(ip);
843out_alloc_put: 845out_alloc_put:
844 gfs2_alloc_put(ip); 846 gfs2_qadata_put(ip);
845out_unlock: 847out_unlock:
846 gfs2_glock_dq(&ip->i_gh); 848 gfs2_glock_dq(&ip->i_gh);
847out_uninit: 849out_uninit:
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 7389dfdcc9ef..e1d3bb59945c 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -244,17 +244,16 @@ struct gfs2_glock {
244 244
245#define GFS2_MIN_LVB_SIZE 32 /* Min size of LVB that gfs2 supports */ 245#define GFS2_MIN_LVB_SIZE 32 /* Min size of LVB that gfs2 supports */
246 246
247struct gfs2_alloc { 247struct gfs2_qadata { /* quota allocation data */
248 /* Quota stuff */ 248 /* Quota stuff */
249 struct gfs2_quota_data *al_qd[2*MAXQUOTAS]; 249 struct gfs2_quota_data *qa_qd[2*MAXQUOTAS];
250 struct gfs2_holder al_qd_ghs[2*MAXQUOTAS]; 250 struct gfs2_holder qa_qd_ghs[2*MAXQUOTAS];
251 unsigned int al_qd_num; 251 unsigned int qa_qd_num;
252 252};
253 u32 al_requested; /* Filled in by caller of gfs2_inplace_reserve() */
254 u32 al_alloced; /* Filled in by gfs2_alloc_*() */
255 253
256 /* Filled in by gfs2_inplace_reserve() */ 254struct gfs2_blkreserv {
257 struct gfs2_holder al_rgd_gh; 255 u32 rs_requested; /* Filled in by caller of gfs2_inplace_reserve() */
256 struct gfs2_holder rs_rgd_gh; /* Filled in by gfs2_inplace_reserve() */
258}; 257};
259 258
260enum { 259enum {
@@ -275,7 +274,8 @@ struct gfs2_inode {
275 struct gfs2_glock *i_gl; /* Move into i_gh? */ 274 struct gfs2_glock *i_gl; /* Move into i_gh? */
276 struct gfs2_holder i_iopen_gh; 275 struct gfs2_holder i_iopen_gh;
277 struct gfs2_holder i_gh; /* for prepare/commit_write only */ 276 struct gfs2_holder i_gh; /* for prepare/commit_write only */
278 struct gfs2_alloc *i_alloc; 277 struct gfs2_qadata *i_qadata; /* quota allocation data */
278 struct gfs2_blkreserv *i_res; /* resource group block reservation */
279 struct gfs2_rgrpd *i_rgd; 279 struct gfs2_rgrpd *i_rgd;
280 u64 i_goal; /* goal block for allocations */ 280 u64 i_goal; /* goal block for allocations */
281 struct rw_semaphore i_rw_mutex; 281 struct rw_semaphore i_rw_mutex;
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 4b0e59e0a249..017960cf1d7a 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -389,12 +389,13 @@ static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation)
389{ 389{
390 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 390 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
391 int error; 391 int error;
392 int dblocks = 1;
392 393
393 if (gfs2_alloc_get(dip) == NULL) 394 error = gfs2_rindex_update(sdp);
394 return -ENOMEM; 395 if (error)
396 fs_warn(sdp, "rindex update returns %d\n", error);
395 397
396 dip->i_alloc->al_requested = RES_DINODE; 398 error = gfs2_inplace_reserve(dip, RES_DINODE);
397 error = gfs2_inplace_reserve(dip);
398 if (error) 399 if (error)
399 goto out; 400 goto out;
400 401
@@ -402,14 +403,13 @@ static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation)
402 if (error) 403 if (error)
403 goto out_ipreserv; 404 goto out_ipreserv;
404 405
405 error = gfs2_alloc_di(dip, no_addr, generation); 406 error = gfs2_alloc_blocks(dip, no_addr, &dblocks, 1, generation);
406 407
407 gfs2_trans_end(sdp); 408 gfs2_trans_end(sdp);
408 409
409out_ipreserv: 410out_ipreserv:
410 gfs2_inplace_release(dip); 411 gfs2_inplace_release(dip);
411out: 412out:
412 gfs2_alloc_put(dip);
413 return error; 413 return error;
414} 414}
415 415
@@ -525,7 +525,7 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
525 int error; 525 int error;
526 526
527 munge_mode_uid_gid(dip, &mode, &uid, &gid); 527 munge_mode_uid_gid(dip, &mode, &uid, &gid);
528 if (!gfs2_alloc_get(dip)) 528 if (!gfs2_qadata_get(dip))
529 return -ENOMEM; 529 return -ENOMEM;
530 530
531 error = gfs2_quota_lock(dip, uid, gid); 531 error = gfs2_quota_lock(dip, uid, gid);
@@ -547,7 +547,7 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
547out_quota: 547out_quota:
548 gfs2_quota_unlock(dip); 548 gfs2_quota_unlock(dip);
549out: 549out:
550 gfs2_alloc_put(dip); 550 gfs2_qadata_put(dip);
551 return error; 551 return error;
552} 552}
553 553
@@ -555,13 +555,13 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
555 struct gfs2_inode *ip) 555 struct gfs2_inode *ip)
556{ 556{
557 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 557 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
558 struct gfs2_alloc *al; 558 struct gfs2_qadata *qa;
559 int alloc_required; 559 int alloc_required;
560 struct buffer_head *dibh; 560 struct buffer_head *dibh;
561 int error; 561 int error;
562 562
563 al = gfs2_alloc_get(dip); 563 qa = gfs2_qadata_get(dip);
564 if (!al) 564 if (!qa)
565 return -ENOMEM; 565 return -ENOMEM;
566 566
567 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); 567 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
@@ -576,9 +576,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
576 if (error) 576 if (error)
577 goto fail_quota_locks; 577 goto fail_quota_locks;
578 578
579 al->al_requested = sdp->sd_max_dirres; 579 error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres);
580
581 error = gfs2_inplace_reserve(dip);
582 if (error) 580 if (error)
583 goto fail_quota_locks; 581 goto fail_quota_locks;
584 582
@@ -619,11 +617,11 @@ fail_quota_locks:
619 gfs2_quota_unlock(dip); 617 gfs2_quota_unlock(dip);
620 618
621fail: 619fail:
622 gfs2_alloc_put(dip); 620 gfs2_qadata_put(dip);
623 return error; 621 return error;
624} 622}
625 623
626int gfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array, 624static int gfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
627 void *fs_info) 625 void *fs_info)
628{ 626{
629 const struct xattr *xattr; 627 const struct xattr *xattr;
@@ -728,9 +726,12 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
728 brelse(bh); 726 brelse(bh);
729 727
730 gfs2_trans_end(sdp); 728 gfs2_trans_end(sdp);
731 gfs2_inplace_release(dip); 729 /* Check if we reserved space in the rgrp. Function link_dinode may
730 not, depending on whether alloc is required. */
731 if (dip->i_res)
732 gfs2_inplace_release(dip);
732 gfs2_quota_unlock(dip); 733 gfs2_quota_unlock(dip);
733 gfs2_alloc_put(dip); 734 gfs2_qadata_put(dip);
734 mark_inode_dirty(inode); 735 mark_inode_dirty(inode);
735 gfs2_glock_dq_uninit_m(2, ghs); 736 gfs2_glock_dq_uninit_m(2, ghs);
736 d_instantiate(dentry, inode); 737 d_instantiate(dentry, inode);
@@ -875,8 +876,9 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
875 error = 0; 876 error = 0;
876 877
877 if (alloc_required) { 878 if (alloc_required) {
878 struct gfs2_alloc *al = gfs2_alloc_get(dip); 879 struct gfs2_qadata *qa = gfs2_qadata_get(dip);
879 if (!al) { 880
881 if (!qa) {
880 error = -ENOMEM; 882 error = -ENOMEM;
881 goto out_gunlock; 883 goto out_gunlock;
882 } 884 }
@@ -885,9 +887,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
885 if (error) 887 if (error)
886 goto out_alloc; 888 goto out_alloc;
887 889
888 al->al_requested = sdp->sd_max_dirres; 890 error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres);
889
890 error = gfs2_inplace_reserve(dip);
891 if (error) 891 if (error)
892 goto out_gunlock_q; 892 goto out_gunlock_q;
893 893
@@ -930,7 +930,7 @@ out_gunlock_q:
930 gfs2_quota_unlock(dip); 930 gfs2_quota_unlock(dip);
931out_alloc: 931out_alloc:
932 if (alloc_required) 932 if (alloc_required)
933 gfs2_alloc_put(dip); 933 gfs2_qadata_put(dip);
934out_gunlock: 934out_gunlock:
935 gfs2_glock_dq(ghs + 1); 935 gfs2_glock_dq(ghs + 1);
936out_child: 936out_child:
@@ -1037,12 +1037,14 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
1037 struct buffer_head *bh; 1037 struct buffer_head *bh;
1038 struct gfs2_holder ghs[3]; 1038 struct gfs2_holder ghs[3];
1039 struct gfs2_rgrpd *rgd; 1039 struct gfs2_rgrpd *rgd;
1040 int error; 1040 int error = -EROFS;
1041 1041
1042 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 1042 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
1043 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); 1043 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
1044 1044
1045 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); 1045 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
1046 if (!rgd)
1047 goto out_inodes;
1046 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2); 1048 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
1047 1049
1048 1050
@@ -1088,12 +1090,13 @@ out_end_trans:
1088out_gunlock: 1090out_gunlock:
1089 gfs2_glock_dq(ghs + 2); 1091 gfs2_glock_dq(ghs + 2);
1090out_rgrp: 1092out_rgrp:
1091 gfs2_holder_uninit(ghs + 2);
1092 gfs2_glock_dq(ghs + 1); 1093 gfs2_glock_dq(ghs + 1);
1093out_child: 1094out_child:
1094 gfs2_holder_uninit(ghs + 1);
1095 gfs2_glock_dq(ghs); 1095 gfs2_glock_dq(ghs);
1096out_parent: 1096out_parent:
1097 gfs2_holder_uninit(ghs + 2);
1098out_inodes:
1099 gfs2_holder_uninit(ghs + 1);
1097 gfs2_holder_uninit(ghs); 1100 gfs2_holder_uninit(ghs);
1098 return error; 1101 return error;
1099} 1102}
@@ -1350,8 +1353,9 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1350 error = 0; 1353 error = 0;
1351 1354
1352 if (alloc_required) { 1355 if (alloc_required) {
1353 struct gfs2_alloc *al = gfs2_alloc_get(ndip); 1356 struct gfs2_qadata *qa = gfs2_qadata_get(ndip);
1354 if (!al) { 1357
1358 if (!qa) {
1355 error = -ENOMEM; 1359 error = -ENOMEM;
1356 goto out_gunlock; 1360 goto out_gunlock;
1357 } 1361 }
@@ -1360,9 +1364,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1360 if (error) 1364 if (error)
1361 goto out_alloc; 1365 goto out_alloc;
1362 1366
1363 al->al_requested = sdp->sd_max_dirres; 1367 error = gfs2_inplace_reserve(ndip, sdp->sd_max_dirres);
1364
1365 error = gfs2_inplace_reserve(ndip);
1366 if (error) 1368 if (error)
1367 goto out_gunlock_q; 1369 goto out_gunlock_q;
1368 1370
@@ -1423,7 +1425,7 @@ out_gunlock_q:
1423 gfs2_quota_unlock(ndip); 1425 gfs2_quota_unlock(ndip);
1424out_alloc: 1426out_alloc:
1425 if (alloc_required) 1427 if (alloc_required)
1426 gfs2_alloc_put(ndip); 1428 gfs2_qadata_put(ndip);
1427out_gunlock: 1429out_gunlock:
1428 while (x--) { 1430 while (x--) {
1429 gfs2_glock_dq(ghs + x); 1431 gfs2_glock_dq(ghs + x);
@@ -1584,7 +1586,7 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
1584 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid) 1586 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
1585 ogid = ngid = NO_QUOTA_CHANGE; 1587 ogid = ngid = NO_QUOTA_CHANGE;
1586 1588
1587 if (!gfs2_alloc_get(ip)) 1589 if (!gfs2_qadata_get(ip))
1588 return -ENOMEM; 1590 return -ENOMEM;
1589 1591
1590 error = gfs2_quota_lock(ip, nuid, ngid); 1592 error = gfs2_quota_lock(ip, nuid, ngid);
@@ -1616,7 +1618,7 @@ out_end_trans:
1616out_gunlock_q: 1618out_gunlock_q:
1617 gfs2_quota_unlock(ip); 1619 gfs2_quota_unlock(ip);
1618out_alloc: 1620out_alloc:
1619 gfs2_alloc_put(ip); 1621 gfs2_qadata_put(ip);
1620 return error; 1622 return error;
1621} 1623}
1622 1624
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 598646434362..2731e657cf7f 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -626,7 +626,7 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull)
626 if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) 626 if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags))
627 submit_bh(WRITE_SYNC | REQ_META | REQ_PRIO, bh); 627 submit_bh(WRITE_SYNC | REQ_META | REQ_PRIO, bh);
628 else 628 else
629 submit_bh(WRITE_FLUSH_FUA | REQ_META | REQ_PRIO, bh); 629 submit_bh(WRITE_FLUSH_FUA | REQ_META, bh);
630 wait_on_buffer(bh); 630 wait_on_buffer(bh);
631 631
632 if (!buffer_uptodate(bh)) 632 if (!buffer_uptodate(bh))
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index 8a139ff1919f..c150298e2d8e 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -40,7 +40,8 @@ static void gfs2_init_inode_once(void *foo)
40 inode_init_once(&ip->i_inode); 40 inode_init_once(&ip->i_inode);
41 init_rwsem(&ip->i_rw_mutex); 41 init_rwsem(&ip->i_rw_mutex);
42 INIT_LIST_HEAD(&ip->i_trunc_list); 42 INIT_LIST_HEAD(&ip->i_trunc_list);
43 ip->i_alloc = NULL; 43 ip->i_qadata = NULL;
44 ip->i_res = NULL;
44 ip->i_hash_cache = NULL; 45 ip->i_hash_cache = NULL;
45} 46}
46 47
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index be29858900f6..181586e673f9 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -435,7 +435,7 @@ struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen)
435 if (buffer_uptodate(first_bh)) 435 if (buffer_uptodate(first_bh))
436 goto out; 436 goto out;
437 if (!buffer_locked(first_bh)) 437 if (!buffer_locked(first_bh))
438 ll_rw_block(READ_SYNC | REQ_META | REQ_PRIO, 1, &first_bh); 438 ll_rw_block(READ_SYNC | REQ_META, 1, &first_bh);
439 439
440 dblock++; 440 dblock++;
441 extlen--; 441 extlen--;
@@ -444,7 +444,7 @@ struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen)
444 bh = gfs2_getbuf(gl, dblock, CREATE); 444 bh = gfs2_getbuf(gl, dblock, CREATE);
445 445
446 if (!buffer_uptodate(bh) && !buffer_locked(bh)) 446 if (!buffer_uptodate(bh) && !buffer_locked(bh))
447 ll_rw_block(READA, 1, &bh); 447 ll_rw_block(READA | REQ_META, 1, &bh);
448 brelse(bh); 448 brelse(bh);
449 dblock++; 449 dblock++;
450 extlen--; 450 extlen--;
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index cb23c2be731a..fe72e79e6ff9 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -224,7 +224,7 @@ static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector, int silent)
224 224
225 bio->bi_end_io = end_bio_io_page; 225 bio->bi_end_io = end_bio_io_page;
226 bio->bi_private = page; 226 bio->bi_private = page;
227 submit_bio(READ_SYNC | REQ_META | REQ_PRIO, bio); 227 submit_bio(READ_SYNC | REQ_META, bio);
228 wait_on_page_locked(page); 228 wait_on_page_locked(page);
229 bio_put(bio); 229 bio_put(bio);
230 if (!PageUptodate(page)) { 230 if (!PageUptodate(page)) {
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 7e528dc14f85..98a01db1f6dc 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -494,11 +494,11 @@ static void qdsb_put(struct gfs2_quota_data *qd)
494int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid) 494int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
495{ 495{
496 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 496 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
497 struct gfs2_alloc *al = ip->i_alloc; 497 struct gfs2_qadata *qa = ip->i_qadata;
498 struct gfs2_quota_data **qd = al->al_qd; 498 struct gfs2_quota_data **qd = qa->qa_qd;
499 int error; 499 int error;
500 500
501 if (gfs2_assert_warn(sdp, !al->al_qd_num) || 501 if (gfs2_assert_warn(sdp, !qa->qa_qd_num) ||
502 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags))) 502 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)))
503 return -EIO; 503 return -EIO;
504 504
@@ -508,20 +508,20 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
508 error = qdsb_get(sdp, QUOTA_USER, ip->i_inode.i_uid, qd); 508 error = qdsb_get(sdp, QUOTA_USER, ip->i_inode.i_uid, qd);
509 if (error) 509 if (error)
510 goto out; 510 goto out;
511 al->al_qd_num++; 511 qa->qa_qd_num++;
512 qd++; 512 qd++;
513 513
514 error = qdsb_get(sdp, QUOTA_GROUP, ip->i_inode.i_gid, qd); 514 error = qdsb_get(sdp, QUOTA_GROUP, ip->i_inode.i_gid, qd);
515 if (error) 515 if (error)
516 goto out; 516 goto out;
517 al->al_qd_num++; 517 qa->qa_qd_num++;
518 qd++; 518 qd++;
519 519
520 if (uid != NO_QUOTA_CHANGE && uid != ip->i_inode.i_uid) { 520 if (uid != NO_QUOTA_CHANGE && uid != ip->i_inode.i_uid) {
521 error = qdsb_get(sdp, QUOTA_USER, uid, qd); 521 error = qdsb_get(sdp, QUOTA_USER, uid, qd);
522 if (error) 522 if (error)
523 goto out; 523 goto out;
524 al->al_qd_num++; 524 qa->qa_qd_num++;
525 qd++; 525 qd++;
526 } 526 }
527 527
@@ -529,7 +529,7 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
529 error = qdsb_get(sdp, QUOTA_GROUP, gid, qd); 529 error = qdsb_get(sdp, QUOTA_GROUP, gid, qd);
530 if (error) 530 if (error)
531 goto out; 531 goto out;
532 al->al_qd_num++; 532 qa->qa_qd_num++;
533 qd++; 533 qd++;
534 } 534 }
535 535
@@ -542,16 +542,16 @@ out:
542void gfs2_quota_unhold(struct gfs2_inode *ip) 542void gfs2_quota_unhold(struct gfs2_inode *ip)
543{ 543{
544 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 544 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
545 struct gfs2_alloc *al = ip->i_alloc; 545 struct gfs2_qadata *qa = ip->i_qadata;
546 unsigned int x; 546 unsigned int x;
547 547
548 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)); 548 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags));
549 549
550 for (x = 0; x < al->al_qd_num; x++) { 550 for (x = 0; x < qa->qa_qd_num; x++) {
551 qdsb_put(al->al_qd[x]); 551 qdsb_put(qa->qa_qd[x]);
552 al->al_qd[x] = NULL; 552 qa->qa_qd[x] = NULL;
553 } 553 }
554 al->al_qd_num = 0; 554 qa->qa_qd_num = 0;
555} 555}
556 556
557static int sort_qd(const void *a, const void *b) 557static int sort_qd(const void *a, const void *b)
@@ -712,7 +712,7 @@ get_a_page:
712 set_buffer_uptodate(bh); 712 set_buffer_uptodate(bh);
713 713
714 if (!buffer_uptodate(bh)) { 714 if (!buffer_uptodate(bh)) {
715 ll_rw_block(READ | REQ_META | REQ_PRIO, 1, &bh); 715 ll_rw_block(READ | REQ_META, 1, &bh);
716 wait_on_buffer(bh); 716 wait_on_buffer(bh);
717 if (!buffer_uptodate(bh)) 717 if (!buffer_uptodate(bh))
718 goto unlock_out; 718 goto unlock_out;
@@ -762,7 +762,6 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
762 struct gfs2_quota_data *qd; 762 struct gfs2_quota_data *qd;
763 loff_t offset; 763 loff_t offset;
764 unsigned int nalloc = 0, blocks; 764 unsigned int nalloc = 0, blocks;
765 struct gfs2_alloc *al = NULL;
766 int error; 765 int error;
767 766
768 gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota), 767 gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota),
@@ -792,26 +791,19 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
792 nalloc++; 791 nalloc++;
793 } 792 }
794 793
795 al = gfs2_alloc_get(ip);
796 if (!al) {
797 error = -ENOMEM;
798 goto out_gunlock;
799 }
800 /* 794 /*
801 * 1 blk for unstuffing inode if stuffed. We add this extra 795 * 1 blk for unstuffing inode if stuffed. We add this extra
802 * block to the reservation unconditionally. If the inode 796 * block to the reservation unconditionally. If the inode
803 * doesn't need unstuffing, the block will be released to the 797 * doesn't need unstuffing, the block will be released to the
804 * rgrp since it won't be allocated during the transaction 798 * rgrp since it won't be allocated during the transaction
805 */ 799 */
806 al->al_requested = 1;
807 /* +3 in the end for unstuffing block, inode size update block 800 /* +3 in the end for unstuffing block, inode size update block
808 * and another block in case quota straddles page boundary and 801 * and another block in case quota straddles page boundary and
809 * two blocks need to be updated instead of 1 */ 802 * two blocks need to be updated instead of 1 */
810 blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3; 803 blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3;
811 804
812 if (nalloc) 805 error = gfs2_inplace_reserve(ip, 1 +
813 al->al_requested += nalloc * (data_blocks + ind_blocks); 806 (nalloc * (data_blocks + ind_blocks)));
814 error = gfs2_inplace_reserve(ip);
815 if (error) 807 if (error)
816 goto out_alloc; 808 goto out_alloc;
817 809
@@ -840,8 +832,6 @@ out_end_trans:
840out_ipres: 832out_ipres:
841 gfs2_inplace_release(ip); 833 gfs2_inplace_release(ip);
842out_alloc: 834out_alloc:
843 gfs2_alloc_put(ip);
844out_gunlock:
845 gfs2_glock_dq_uninit(&i_gh); 835 gfs2_glock_dq_uninit(&i_gh);
846out: 836out:
847 while (qx--) 837 while (qx--)
@@ -925,7 +915,7 @@ fail:
925int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid) 915int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
926{ 916{
927 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 917 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
928 struct gfs2_alloc *al = ip->i_alloc; 918 struct gfs2_qadata *qa = ip->i_qadata;
929 struct gfs2_quota_data *qd; 919 struct gfs2_quota_data *qd;
930 unsigned int x; 920 unsigned int x;
931 int error = 0; 921 int error = 0;
@@ -938,15 +928,15 @@ int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
938 sdp->sd_args.ar_quota != GFS2_QUOTA_ON) 928 sdp->sd_args.ar_quota != GFS2_QUOTA_ON)
939 return 0; 929 return 0;
940 930
941 sort(al->al_qd, al->al_qd_num, sizeof(struct gfs2_quota_data *), 931 sort(qa->qa_qd, qa->qa_qd_num, sizeof(struct gfs2_quota_data *),
942 sort_qd, NULL); 932 sort_qd, NULL);
943 933
944 for (x = 0; x < al->al_qd_num; x++) { 934 for (x = 0; x < qa->qa_qd_num; x++) {
945 int force = NO_FORCE; 935 int force = NO_FORCE;
946 qd = al->al_qd[x]; 936 qd = qa->qa_qd[x];
947 if (test_and_clear_bit(QDF_REFRESH, &qd->qd_flags)) 937 if (test_and_clear_bit(QDF_REFRESH, &qd->qd_flags))
948 force = FORCE; 938 force = FORCE;
949 error = do_glock(qd, force, &al->al_qd_ghs[x]); 939 error = do_glock(qd, force, &qa->qa_qd_ghs[x]);
950 if (error) 940 if (error)
951 break; 941 break;
952 } 942 }
@@ -955,7 +945,7 @@ int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
955 set_bit(GIF_QD_LOCKED, &ip->i_flags); 945 set_bit(GIF_QD_LOCKED, &ip->i_flags);
956 else { 946 else {
957 while (x--) 947 while (x--)
958 gfs2_glock_dq_uninit(&al->al_qd_ghs[x]); 948 gfs2_glock_dq_uninit(&qa->qa_qd_ghs[x]);
959 gfs2_quota_unhold(ip); 949 gfs2_quota_unhold(ip);
960 } 950 }
961 951
@@ -1000,7 +990,7 @@ static int need_sync(struct gfs2_quota_data *qd)
1000 990
1001void gfs2_quota_unlock(struct gfs2_inode *ip) 991void gfs2_quota_unlock(struct gfs2_inode *ip)
1002{ 992{
1003 struct gfs2_alloc *al = ip->i_alloc; 993 struct gfs2_qadata *qa = ip->i_qadata;
1004 struct gfs2_quota_data *qda[4]; 994 struct gfs2_quota_data *qda[4];
1005 unsigned int count = 0; 995 unsigned int count = 0;
1006 unsigned int x; 996 unsigned int x;
@@ -1008,14 +998,14 @@ void gfs2_quota_unlock(struct gfs2_inode *ip)
1008 if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags)) 998 if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags))
1009 goto out; 999 goto out;
1010 1000
1011 for (x = 0; x < al->al_qd_num; x++) { 1001 for (x = 0; x < qa->qa_qd_num; x++) {
1012 struct gfs2_quota_data *qd; 1002 struct gfs2_quota_data *qd;
1013 int sync; 1003 int sync;
1014 1004
1015 qd = al->al_qd[x]; 1005 qd = qa->qa_qd[x];
1016 sync = need_sync(qd); 1006 sync = need_sync(qd);
1017 1007
1018 gfs2_glock_dq_uninit(&al->al_qd_ghs[x]); 1008 gfs2_glock_dq_uninit(&qa->qa_qd_ghs[x]);
1019 1009
1020 if (sync && qd_trylock(qd)) 1010 if (sync && qd_trylock(qd))
1021 qda[count++] = qd; 1011 qda[count++] = qd;
@@ -1048,7 +1038,7 @@ static int print_message(struct gfs2_quota_data *qd, char *type)
1048int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid) 1038int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
1049{ 1039{
1050 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1040 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1051 struct gfs2_alloc *al = ip->i_alloc; 1041 struct gfs2_qadata *qa = ip->i_qadata;
1052 struct gfs2_quota_data *qd; 1042 struct gfs2_quota_data *qd;
1053 s64 value; 1043 s64 value;
1054 unsigned int x; 1044 unsigned int x;
@@ -1060,8 +1050,8 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
1060 if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON) 1050 if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON)
1061 return 0; 1051 return 0;
1062 1052
1063 for (x = 0; x < al->al_qd_num; x++) { 1053 for (x = 0; x < qa->qa_qd_num; x++) {
1064 qd = al->al_qd[x]; 1054 qd = qa->qa_qd[x];
1065 1055
1066 if (!((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) || 1056 if (!((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) ||
1067 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags)))) 1057 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))))
@@ -1099,7 +1089,7 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
1099void gfs2_quota_change(struct gfs2_inode *ip, s64 change, 1089void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
1100 u32 uid, u32 gid) 1090 u32 uid, u32 gid)
1101{ 1091{
1102 struct gfs2_alloc *al = ip->i_alloc; 1092 struct gfs2_qadata *qa = ip->i_qadata;
1103 struct gfs2_quota_data *qd; 1093 struct gfs2_quota_data *qd;
1104 unsigned int x; 1094 unsigned int x;
1105 1095
@@ -1108,8 +1098,8 @@ void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
1108 if (ip->i_diskflags & GFS2_DIF_SYSTEM) 1098 if (ip->i_diskflags & GFS2_DIF_SYSTEM)
1109 return; 1099 return;
1110 1100
1111 for (x = 0; x < al->al_qd_num; x++) { 1101 for (x = 0; x < qa->qa_qd_num; x++) {
1112 qd = al->al_qd[x]; 1102 qd = qa->qa_qd[x];
1113 1103
1114 if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) || 1104 if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) ||
1115 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) { 1105 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) {
@@ -1529,7 +1519,6 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
1529 unsigned int data_blocks, ind_blocks; 1519 unsigned int data_blocks, ind_blocks;
1530 unsigned int blocks = 0; 1520 unsigned int blocks = 0;
1531 int alloc_required; 1521 int alloc_required;
1532 struct gfs2_alloc *al;
1533 loff_t offset; 1522 loff_t offset;
1534 int error; 1523 int error;
1535 1524
@@ -1594,15 +1583,12 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
1594 if (gfs2_is_stuffed(ip)) 1583 if (gfs2_is_stuffed(ip))
1595 alloc_required = 1; 1584 alloc_required = 1;
1596 if (alloc_required) { 1585 if (alloc_required) {
1597 al = gfs2_alloc_get(ip);
1598 if (al == NULL)
1599 goto out_i;
1600 gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota), 1586 gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota),
1601 &data_blocks, &ind_blocks); 1587 &data_blocks, &ind_blocks);
1602 blocks = al->al_requested = 1 + data_blocks + ind_blocks; 1588 blocks = 1 + data_blocks + ind_blocks;
1603 error = gfs2_inplace_reserve(ip); 1589 error = gfs2_inplace_reserve(ip, blocks);
1604 if (error) 1590 if (error)
1605 goto out_alloc; 1591 goto out_i;
1606 blocks += gfs2_rg_blocks(ip); 1592 blocks += gfs2_rg_blocks(ip);
1607 } 1593 }
1608 1594
@@ -1617,11 +1603,8 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
1617 1603
1618 gfs2_trans_end(sdp); 1604 gfs2_trans_end(sdp);
1619out_release: 1605out_release:
1620 if (alloc_required) { 1606 if (alloc_required)
1621 gfs2_inplace_release(ip); 1607 gfs2_inplace_release(ip);
1622out_alloc:
1623 gfs2_alloc_put(ip);
1624 }
1625out_i: 1608out_i:
1626 gfs2_glock_dq_uninit(&i_gh); 1609 gfs2_glock_dq_uninit(&i_gh);
1627out_q: 1610out_q:
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 96bd6d759f29..22234627f684 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -65,8 +65,8 @@ static const char valid_change[16] = {
65}; 65};
66 66
67static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, 67static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
68 unsigned char old_state, unsigned char new_state, 68 unsigned char old_state,
69 unsigned int *n); 69 struct gfs2_bitmap **rbi);
70 70
71/** 71/**
72 * gfs2_setbit - Set a bit in the bitmaps 72 * gfs2_setbit - Set a bit in the bitmaps
@@ -860,22 +860,36 @@ fail:
860} 860}
861 861
862/** 862/**
863 * gfs2_alloc_get - get the struct gfs2_alloc structure for an inode 863 * gfs2_qadata_get - get the struct gfs2_qadata structure for an inode
864 * @ip: the incore GFS2 inode structure 864 * @ip: the incore GFS2 inode structure
865 * 865 *
866 * Returns: the struct gfs2_alloc 866 * Returns: the struct gfs2_qadata
867 */ 867 */
868 868
869struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip) 869struct gfs2_qadata *gfs2_qadata_get(struct gfs2_inode *ip)
870{ 870{
871 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 871 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
872 int error; 872 int error;
873 BUG_ON(ip->i_alloc != NULL); 873 BUG_ON(ip->i_qadata != NULL);
874 ip->i_alloc = kzalloc(sizeof(struct gfs2_alloc), GFP_NOFS); 874 ip->i_qadata = kzalloc(sizeof(struct gfs2_qadata), GFP_NOFS);
875 error = gfs2_rindex_update(sdp); 875 error = gfs2_rindex_update(sdp);
876 if (error) 876 if (error)
877 fs_warn(sdp, "rindex update returns %d\n", error); 877 fs_warn(sdp, "rindex update returns %d\n", error);
878 return ip->i_alloc; 878 return ip->i_qadata;
879}
880
881/**
882 * gfs2_blkrsv_get - get the struct gfs2_blkreserv structure for an inode
883 * @ip: the incore GFS2 inode structure
884 *
885 * Returns: the struct gfs2_qadata
886 */
887
888static struct gfs2_blkreserv *gfs2_blkrsv_get(struct gfs2_inode *ip)
889{
890 BUG_ON(ip->i_res != NULL);
891 ip->i_res = kzalloc(sizeof(struct gfs2_blkreserv), GFP_NOFS);
892 return ip->i_res;
879} 893}
880 894
881/** 895/**
@@ -890,15 +904,20 @@ struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip)
890 904
891static int try_rgrp_fit(const struct gfs2_rgrpd *rgd, const struct gfs2_inode *ip) 905static int try_rgrp_fit(const struct gfs2_rgrpd *rgd, const struct gfs2_inode *ip)
892{ 906{
893 const struct gfs2_alloc *al = ip->i_alloc; 907 const struct gfs2_blkreserv *rs = ip->i_res;
894 908
895 if (rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR)) 909 if (rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR))
896 return 0; 910 return 0;
897 if (rgd->rd_free_clone >= al->al_requested) 911 if (rgd->rd_free_clone >= rs->rs_requested)
898 return 1; 912 return 1;
899 return 0; 913 return 0;
900} 914}
901 915
916static inline u32 gfs2_bi2rgd_blk(struct gfs2_bitmap *bi, u32 blk)
917{
918 return (bi->bi_start * GFS2_NBBY) + blk;
919}
920
902/** 921/**
903 * try_rgrp_unlink - Look for any unlinked, allocated, but unused inodes 922 * try_rgrp_unlink - Look for any unlinked, allocated, but unused inodes
904 * @rgd: The rgrp 923 * @rgd: The rgrp
@@ -912,20 +931,20 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
912 u32 goal = 0, block; 931 u32 goal = 0, block;
913 u64 no_addr; 932 u64 no_addr;
914 struct gfs2_sbd *sdp = rgd->rd_sbd; 933 struct gfs2_sbd *sdp = rgd->rd_sbd;
915 unsigned int n;
916 struct gfs2_glock *gl; 934 struct gfs2_glock *gl;
917 struct gfs2_inode *ip; 935 struct gfs2_inode *ip;
918 int error; 936 int error;
919 int found = 0; 937 int found = 0;
938 struct gfs2_bitmap *bi;
920 939
921 while (goal < rgd->rd_data) { 940 while (goal < rgd->rd_data) {
922 down_write(&sdp->sd_log_flush_lock); 941 down_write(&sdp->sd_log_flush_lock);
923 n = 1; 942 block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, &bi);
924 block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED,
925 GFS2_BLKST_UNLINKED, &n);
926 up_write(&sdp->sd_log_flush_lock); 943 up_write(&sdp->sd_log_flush_lock);
927 if (block == BFITNOENT) 944 if (block == BFITNOENT)
928 break; 945 break;
946
947 block = gfs2_bi2rgd_blk(bi, block);
929 /* rgblk_search can return a block < goal, so we need to 948 /* rgblk_search can return a block < goal, so we need to
930 keep it marching forward. */ 949 keep it marching forward. */
931 no_addr = block + rgd->rd_data0; 950 no_addr = block + rgd->rd_data0;
@@ -977,8 +996,8 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
977{ 996{
978 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 997 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
979 struct gfs2_rgrpd *rgd, *begin = NULL; 998 struct gfs2_rgrpd *rgd, *begin = NULL;
980 struct gfs2_alloc *al = ip->i_alloc; 999 struct gfs2_blkreserv *rs = ip->i_res;
981 int error, rg_locked; 1000 int error, rg_locked, flags = LM_FLAG_TRY;
982 int loops = 0; 1001 int loops = 0;
983 1002
984 if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, ip->i_goal)) 1003 if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, ip->i_goal))
@@ -997,7 +1016,7 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
997 error = 0; 1016 error = 0;
998 } else { 1017 } else {
999 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 1018 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE,
1000 LM_FLAG_TRY, &al->al_rgd_gh); 1019 flags, &rs->rs_rgd_gh);
1001 } 1020 }
1002 switch (error) { 1021 switch (error) {
1003 case 0: 1022 case 0:
@@ -1008,12 +1027,14 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
1008 if (rgd->rd_flags & GFS2_RDF_CHECK) 1027 if (rgd->rd_flags & GFS2_RDF_CHECK)
1009 try_rgrp_unlink(rgd, last_unlinked, ip->i_no_addr); 1028 try_rgrp_unlink(rgd, last_unlinked, ip->i_no_addr);
1010 if (!rg_locked) 1029 if (!rg_locked)
1011 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1030 gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
1012 /* fall through */ 1031 /* fall through */
1013 case GLR_TRYFAILED: 1032 case GLR_TRYFAILED:
1014 rgd = gfs2_rgrpd_get_next(rgd); 1033 rgd = gfs2_rgrpd_get_next(rgd);
1015 if (rgd == begin) 1034 if (rgd == begin) {
1035 flags = 0;
1016 loops++; 1036 loops++;
1037 }
1017 break; 1038 break;
1018 default: 1039 default:
1019 return error; 1040 return error;
@@ -1023,6 +1044,13 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
1023 return -ENOSPC; 1044 return -ENOSPC;
1024} 1045}
1025 1046
1047static void gfs2_blkrsv_put(struct gfs2_inode *ip)
1048{
1049 BUG_ON(ip->i_res == NULL);
1050 kfree(ip->i_res);
1051 ip->i_res = NULL;
1052}
1053
1026/** 1054/**
1027 * gfs2_inplace_reserve - Reserve space in the filesystem 1055 * gfs2_inplace_reserve - Reserve space in the filesystem
1028 * @ip: the inode to reserve space for 1056 * @ip: the inode to reserve space for
@@ -1030,16 +1058,23 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
1030 * Returns: errno 1058 * Returns: errno
1031 */ 1059 */
1032 1060
1033int gfs2_inplace_reserve(struct gfs2_inode *ip) 1061int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested)
1034{ 1062{
1035 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1063 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1036 struct gfs2_alloc *al = ip->i_alloc; 1064 struct gfs2_blkreserv *rs;
1037 int error = 0; 1065 int error = 0;
1038 u64 last_unlinked = NO_BLOCK; 1066 u64 last_unlinked = NO_BLOCK;
1039 int tries = 0; 1067 int tries = 0;
1040 1068
1041 if (gfs2_assert_warn(sdp, al->al_requested)) 1069 rs = gfs2_blkrsv_get(ip);
1042 return -EINVAL; 1070 if (!rs)
1071 return -ENOMEM;
1072
1073 rs->rs_requested = requested;
1074 if (gfs2_assert_warn(sdp, requested)) {
1075 error = -EINVAL;
1076 goto out;
1077 }
1043 1078
1044 do { 1079 do {
1045 error = get_local_rgrp(ip, &last_unlinked); 1080 error = get_local_rgrp(ip, &last_unlinked);
@@ -1056,6 +1091,9 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip)
1056 gfs2_log_flush(sdp, NULL); 1091 gfs2_log_flush(sdp, NULL);
1057 } while (tries++ < 3); 1092 } while (tries++ < 3);
1058 1093
1094out:
1095 if (error)
1096 gfs2_blkrsv_put(ip);
1059 return error; 1097 return error;
1060} 1098}
1061 1099
@@ -1068,10 +1106,11 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip)
1068 1106
1069void gfs2_inplace_release(struct gfs2_inode *ip) 1107void gfs2_inplace_release(struct gfs2_inode *ip)
1070{ 1108{
1071 struct gfs2_alloc *al = ip->i_alloc; 1109 struct gfs2_blkreserv *rs = ip->i_res;
1072 1110
1073 if (al->al_rgd_gh.gh_gl) 1111 gfs2_blkrsv_put(ip);
1074 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1112 if (rs->rs_rgd_gh.gh_gl)
1113 gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
1075} 1114}
1076 1115
1077/** 1116/**
@@ -1108,39 +1147,35 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
1108} 1147}
1109 1148
1110/** 1149/**
1111 * rgblk_search - find a block in @old_state, change allocation 1150 * rgblk_search - find a block in @state
1112 * state to @new_state
1113 * @rgd: the resource group descriptor 1151 * @rgd: the resource group descriptor
1114 * @goal: the goal block within the RG (start here to search for avail block) 1152 * @goal: the goal block within the RG (start here to search for avail block)
1115 * @old_state: GFS2_BLKST_XXX the before-allocation state to find 1153 * @state: GFS2_BLKST_XXX the before-allocation state to find
1116 * @new_state: GFS2_BLKST_XXX the after-allocation block state 1154 * @dinode: TRUE if the first block we allocate is for a dinode
1117 * @n: The extent length 1155 * @rbi: address of the pointer to the bitmap containing the block found
1118 * 1156 *
1119 * Walk rgrp's bitmap to find bits that represent a block in @old_state. 1157 * Walk rgrp's bitmap to find bits that represent a block in @state.
1120 * Add the found bitmap buffer to the transaction.
1121 * Set the found bits to @new_state to change block's allocation state.
1122 * 1158 *
1123 * This function never fails, because we wouldn't call it unless we 1159 * This function never fails, because we wouldn't call it unless we
1124 * know (from reservation results, etc.) that a block is available. 1160 * know (from reservation results, etc.) that a block is available.
1125 * 1161 *
1126 * Scope of @goal and returned block is just within rgrp, not the whole 1162 * Scope of @goal is just within rgrp, not the whole filesystem.
1127 * filesystem. 1163 * Scope of @returned block is just within bitmap, not the whole filesystem.
1128 * 1164 *
1129 * Returns: the block number allocated 1165 * Returns: the block number found relative to the bitmap rbi
1130 */ 1166 */
1131 1167
1132static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, 1168static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
1133 unsigned char old_state, unsigned char new_state, 1169 unsigned char state,
1134 unsigned int *n) 1170 struct gfs2_bitmap **rbi)
1135{ 1171{
1136 struct gfs2_bitmap *bi = NULL; 1172 struct gfs2_bitmap *bi = NULL;
1137 const u32 length = rgd->rd_length; 1173 const u32 length = rgd->rd_length;
1138 u32 blk = BFITNOENT; 1174 u32 blk = BFITNOENT;
1139 unsigned int buf, x; 1175 unsigned int buf, x;
1140 const unsigned int elen = *n;
1141 const u8 *buffer = NULL; 1176 const u8 *buffer = NULL;
1142 1177
1143 *n = 0; 1178 *rbi = NULL;
1144 /* Find bitmap block that contains bits for goal block */ 1179 /* Find bitmap block that contains bits for goal block */
1145 for (buf = 0; buf < length; buf++) { 1180 for (buf = 0; buf < length; buf++) {
1146 bi = rgd->rd_bits + buf; 1181 bi = rgd->rd_bits + buf;
@@ -1163,21 +1198,21 @@ do_search:
1163 bi = rgd->rd_bits + buf; 1198 bi = rgd->rd_bits + buf;
1164 1199
1165 if (test_bit(GBF_FULL, &bi->bi_flags) && 1200 if (test_bit(GBF_FULL, &bi->bi_flags) &&
1166 (old_state == GFS2_BLKST_FREE)) 1201 (state == GFS2_BLKST_FREE))
1167 goto skip; 1202 goto skip;
1168 1203
1169 /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone 1204 /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone
1170 bitmaps, so we must search the originals for that. */ 1205 bitmaps, so we must search the originals for that. */
1171 buffer = bi->bi_bh->b_data + bi->bi_offset; 1206 buffer = bi->bi_bh->b_data + bi->bi_offset;
1172 WARN_ON(!buffer_uptodate(bi->bi_bh)); 1207 WARN_ON(!buffer_uptodate(bi->bi_bh));
1173 if (old_state != GFS2_BLKST_UNLINKED && bi->bi_clone) 1208 if (state != GFS2_BLKST_UNLINKED && bi->bi_clone)
1174 buffer = bi->bi_clone + bi->bi_offset; 1209 buffer = bi->bi_clone + bi->bi_offset;
1175 1210
1176 blk = gfs2_bitfit(buffer, bi->bi_len, goal, old_state); 1211 blk = gfs2_bitfit(buffer, bi->bi_len, goal, state);
1177 if (blk != BFITNOENT) 1212 if (blk != BFITNOENT)
1178 break; 1213 break;
1179 1214
1180 if ((goal == 0) && (old_state == GFS2_BLKST_FREE)) 1215 if ((goal == 0) && (state == GFS2_BLKST_FREE))
1181 set_bit(GBF_FULL, &bi->bi_flags); 1216 set_bit(GBF_FULL, &bi->bi_flags);
1182 1217
1183 /* Try next bitmap block (wrap back to rgrp header if at end) */ 1218 /* Try next bitmap block (wrap back to rgrp header if at end) */
@@ -1187,16 +1222,37 @@ skip:
1187 goal = 0; 1222 goal = 0;
1188 } 1223 }
1189 1224
1190 if (blk == BFITNOENT) 1225 if (blk != BFITNOENT)
1191 return blk; 1226 *rbi = bi;
1192 1227
1193 *n = 1; 1228 return blk;
1194 if (old_state == new_state) 1229}
1195 goto out; 1230
1231/**
1232 * gfs2_alloc_extent - allocate an extent from a given bitmap
1233 * @rgd: the resource group descriptor
1234 * @bi: the bitmap within the rgrp
1235 * @blk: the block within the bitmap
1236 * @dinode: TRUE if the first block we allocate is for a dinode
1237 * @n: The extent length
1238 *
1239 * Add the found bitmap buffer to the transaction.
1240 * Set the found bits to @new_state to change block's allocation state.
1241 * Returns: starting block number of the extent (fs scope)
1242 */
1243static u64 gfs2_alloc_extent(struct gfs2_rgrpd *rgd, struct gfs2_bitmap *bi,
1244 u32 blk, bool dinode, unsigned int *n)
1245{
1246 const unsigned int elen = *n;
1247 u32 goal;
1248 const u8 *buffer = NULL;
1196 1249
1250 *n = 0;
1251 buffer = bi->bi_bh->b_data + bi->bi_offset;
1197 gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); 1252 gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1);
1198 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset, 1253 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset,
1199 bi, blk, new_state); 1254 bi, blk, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
1255 (*n)++;
1200 goal = blk; 1256 goal = blk;
1201 while (*n < elen) { 1257 while (*n < elen) {
1202 goal++; 1258 goal++;
@@ -1206,11 +1262,12 @@ skip:
1206 GFS2_BLKST_FREE) 1262 GFS2_BLKST_FREE)
1207 break; 1263 break;
1208 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset, 1264 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset,
1209 bi, goal, new_state); 1265 bi, goal, GFS2_BLKST_USED);
1210 (*n)++; 1266 (*n)++;
1211 } 1267 }
1212out: 1268 blk = gfs2_bi2rgd_blk(bi, blk);
1213 return (bi->bi_start * GFS2_NBBY) + blk; 1269 rgd->rd_last_alloc = blk + *n - 1;
1270 return rgd->rd_data0 + blk;
1214} 1271}
1215 1272
1216/** 1273/**
@@ -1298,121 +1355,93 @@ static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd)
1298} 1355}
1299 1356
1300/** 1357/**
1301 * gfs2_alloc_block - Allocate one or more blocks 1358 * gfs2_alloc_blocks - Allocate one or more blocks of data and/or a dinode
1302 * @ip: the inode to allocate the block for 1359 * @ip: the inode to allocate the block for
1303 * @bn: Used to return the starting block number 1360 * @bn: Used to return the starting block number
1304 * @n: requested number of blocks/extent length (value/result) 1361 * @ndata: requested number of blocks/extent length (value/result)
1362 * @dinode: 1 if we're allocating a dinode block, else 0
1363 * @generation: the generation number of the inode
1305 * 1364 *
1306 * Returns: 0 or error 1365 * Returns: 0 or error
1307 */ 1366 */
1308 1367
1309int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n) 1368int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
1369 bool dinode, u64 *generation)
1310{ 1370{
1311 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1371 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1312 struct buffer_head *dibh; 1372 struct buffer_head *dibh;
1313 struct gfs2_alloc *al = ip->i_alloc;
1314 struct gfs2_rgrpd *rgd; 1373 struct gfs2_rgrpd *rgd;
1315 u32 goal, blk; 1374 unsigned int ndata;
1316 u64 block; 1375 u32 goal, blk; /* block, within the rgrp scope */
1376 u64 block; /* block, within the file system scope */
1317 int error; 1377 int error;
1378 struct gfs2_bitmap *bi;
1318 1379
1319 /* Only happens if there is a bug in gfs2, return something distinctive 1380 /* Only happens if there is a bug in gfs2, return something distinctive
1320 * to ensure that it is noticed. 1381 * to ensure that it is noticed.
1321 */ 1382 */
1322 if (al == NULL) 1383 if (ip->i_res == NULL)
1323 return -ECANCELED; 1384 return -ECANCELED;
1324 1385
1325 rgd = ip->i_rgd; 1386 rgd = ip->i_rgd;
1326 1387
1327 if (rgrp_contains_block(rgd, ip->i_goal)) 1388 if (!dinode && rgrp_contains_block(rgd, ip->i_goal))
1328 goal = ip->i_goal - rgd->rd_data0; 1389 goal = ip->i_goal - rgd->rd_data0;
1329 else 1390 else
1330 goal = rgd->rd_last_alloc; 1391 goal = rgd->rd_last_alloc;
1331 1392
1332 blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, GFS2_BLKST_USED, n); 1393 blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, &bi);
1333 1394
1334 /* Since all blocks are reserved in advance, this shouldn't happen */ 1395 /* Since all blocks are reserved in advance, this shouldn't happen */
1335 if (blk == BFITNOENT) 1396 if (blk == BFITNOENT)
1336 goto rgrp_error; 1397 goto rgrp_error;
1337 1398
1338 rgd->rd_last_alloc = blk; 1399 block = gfs2_alloc_extent(rgd, bi, blk, dinode, nblocks);
1339 block = rgd->rd_data0 + blk; 1400 ndata = *nblocks;
1340 ip->i_goal = block + *n - 1; 1401 if (dinode)
1341 error = gfs2_meta_inode_buffer(ip, &dibh); 1402 ndata--;
1342 if (error == 0) { 1403
1343 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data; 1404 if (!dinode) {
1344 gfs2_trans_add_bh(ip->i_gl, dibh, 1); 1405 ip->i_goal = block + ndata - 1;
1345 di->di_goal_meta = di->di_goal_data = cpu_to_be64(ip->i_goal); 1406 error = gfs2_meta_inode_buffer(ip, &dibh);
1346 brelse(dibh); 1407 if (error == 0) {
1408 struct gfs2_dinode *di =
1409 (struct gfs2_dinode *)dibh->b_data;
1410 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
1411 di->di_goal_meta = di->di_goal_data =
1412 cpu_to_be64(ip->i_goal);
1413 brelse(dibh);
1414 }
1347 } 1415 }
1348 if (rgd->rd_free < *n) 1416 if (rgd->rd_free < *nblocks)
1349 goto rgrp_error; 1417 goto rgrp_error;
1350 1418
1351 rgd->rd_free -= *n; 1419 rgd->rd_free -= *nblocks;
1352 1420 if (dinode) {
1353 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); 1421 rgd->rd_dinodes++;
1354 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
1355
1356 al->al_alloced += *n;
1357
1358 gfs2_statfs_change(sdp, 0, -(s64)*n, 0);
1359 gfs2_quota_change(ip, *n, ip->i_inode.i_uid, ip->i_inode.i_gid);
1360
1361 rgd->rd_free_clone -= *n;
1362 trace_gfs2_block_alloc(ip, block, *n, GFS2_BLKST_USED);
1363 *bn = block;
1364 return 0;
1365
1366rgrp_error:
1367 gfs2_rgrp_error(rgd);
1368 return -EIO;
1369}
1370
1371/**
1372 * gfs2_alloc_di - Allocate a dinode
1373 * @dip: the directory that the inode is going in
1374 * @bn: the block number which is allocated
1375 * @generation: the generation number of the inode
1376 *
1377 * Returns: 0 on success or error
1378 */
1379
1380int gfs2_alloc_di(struct gfs2_inode *dip, u64 *bn, u64 *generation)
1381{
1382 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1383 struct gfs2_alloc *al = dip->i_alloc;
1384 struct gfs2_rgrpd *rgd = dip->i_rgd;
1385 u32 blk;
1386 u64 block;
1387 unsigned int n = 1;
1388
1389 blk = rgblk_search(rgd, rgd->rd_last_alloc,
1390 GFS2_BLKST_FREE, GFS2_BLKST_DINODE, &n);
1391
1392 /* Since all blocks are reserved in advance, this shouldn't happen */
1393 if (blk == BFITNOENT)
1394 goto rgrp_error;
1395
1396 rgd->rd_last_alloc = blk;
1397 block = rgd->rd_data0 + blk;
1398 if (rgd->rd_free == 0)
1399 goto rgrp_error;
1400
1401 rgd->rd_free--;
1402 rgd->rd_dinodes++;
1403 *generation = rgd->rd_igeneration++;
1404 if (*generation == 0)
1405 *generation = rgd->rd_igeneration++; 1422 *generation = rgd->rd_igeneration++;
1423 if (*generation == 0)
1424 *generation = rgd->rd_igeneration++;
1425 }
1426
1406 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); 1427 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
1407 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); 1428 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
1408 1429
1409 al->al_alloced++; 1430 gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0);
1431 if (dinode)
1432 gfs2_trans_add_unrevoke(sdp, block, 1);
1410 1433
1411 gfs2_statfs_change(sdp, 0, -1, +1); 1434 /*
1412 gfs2_trans_add_unrevoke(sdp, block, 1); 1435 * This needs reviewing to see why we cannot do the quota change
1436 * at this point in the dinode case.
1437 */
1438 if (ndata)
1439 gfs2_quota_change(ip, ndata, ip->i_inode.i_uid,
1440 ip->i_inode.i_gid);
1413 1441
1414 rgd->rd_free_clone--; 1442 rgd->rd_free_clone -= *nblocks;
1415 trace_gfs2_block_alloc(dip, block, 1, GFS2_BLKST_DINODE); 1443 trace_gfs2_block_alloc(ip, block, *nblocks,
1444 dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
1416 *bn = block; 1445 *bn = block;
1417 return 0; 1446 return 0;
1418 1447
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index cf5c50180192..ceec9106cdf4 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -28,19 +28,19 @@ extern void gfs2_free_clones(struct gfs2_rgrpd *rgd);
28extern int gfs2_rgrp_go_lock(struct gfs2_holder *gh); 28extern int gfs2_rgrp_go_lock(struct gfs2_holder *gh);
29extern void gfs2_rgrp_go_unlock(struct gfs2_holder *gh); 29extern void gfs2_rgrp_go_unlock(struct gfs2_holder *gh);
30 30
31extern struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip); 31extern struct gfs2_qadata *gfs2_qadata_get(struct gfs2_inode *ip);
32static inline void gfs2_alloc_put(struct gfs2_inode *ip) 32static inline void gfs2_qadata_put(struct gfs2_inode *ip)
33{ 33{
34 BUG_ON(ip->i_alloc == NULL); 34 BUG_ON(ip->i_qadata == NULL);
35 kfree(ip->i_alloc); 35 kfree(ip->i_qadata);
36 ip->i_alloc = NULL; 36 ip->i_qadata = NULL;
37} 37}
38 38
39extern int gfs2_inplace_reserve(struct gfs2_inode *ip); 39extern int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested);
40extern void gfs2_inplace_release(struct gfs2_inode *ip); 40extern void gfs2_inplace_release(struct gfs2_inode *ip);
41 41
42extern int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n); 42extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
43extern int gfs2_alloc_di(struct gfs2_inode *ip, u64 *bn, u64 *generation); 43 bool dinode, u64 *generation);
44 44
45extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta); 45extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta);
46extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen); 46extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen);
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 10c7733a899b..4553ce515f62 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1399,8 +1399,9 @@ static void gfs2_final_release_pages(struct gfs2_inode *ip)
1399static int gfs2_dinode_dealloc(struct gfs2_inode *ip) 1399static int gfs2_dinode_dealloc(struct gfs2_inode *ip)
1400{ 1400{
1401 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1401 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1402 struct gfs2_alloc *al; 1402 struct gfs2_qadata *qa;
1403 struct gfs2_rgrpd *rgd; 1403 struct gfs2_rgrpd *rgd;
1404 struct gfs2_holder gh;
1404 int error; 1405 int error;
1405 1406
1406 if (gfs2_get_inode_blocks(&ip->i_inode) != 1) { 1407 if (gfs2_get_inode_blocks(&ip->i_inode) != 1) {
@@ -1408,8 +1409,8 @@ static int gfs2_dinode_dealloc(struct gfs2_inode *ip)
1408 return -EIO; 1409 return -EIO;
1409 } 1410 }
1410 1411
1411 al = gfs2_alloc_get(ip); 1412 qa = gfs2_qadata_get(ip);
1412 if (!al) 1413 if (!qa)
1413 return -ENOMEM; 1414 return -ENOMEM;
1414 1415
1415 error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); 1416 error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
@@ -1423,8 +1424,7 @@ static int gfs2_dinode_dealloc(struct gfs2_inode *ip)
1423 goto out_qs; 1424 goto out_qs;
1424 } 1425 }
1425 1426
1426 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, 1427 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &gh);
1427 &al->al_rgd_gh);
1428 if (error) 1428 if (error)
1429 goto out_qs; 1429 goto out_qs;
1430 1430
@@ -1440,11 +1440,11 @@ static int gfs2_dinode_dealloc(struct gfs2_inode *ip)
1440 gfs2_trans_end(sdp); 1440 gfs2_trans_end(sdp);
1441 1441
1442out_rg_gunlock: 1442out_rg_gunlock:
1443 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1443 gfs2_glock_dq_uninit(&gh);
1444out_qs: 1444out_qs:
1445 gfs2_quota_unhold(ip); 1445 gfs2_quota_unhold(ip);
1446out: 1446out:
1447 gfs2_alloc_put(ip); 1447 gfs2_qadata_put(ip);
1448 return error; 1448 return error;
1449} 1449}
1450 1450
diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h
index f8f101ef600c..125d4572e1c0 100644
--- a/fs/gfs2/trans.h
+++ b/fs/gfs2/trans.h
@@ -30,9 +30,9 @@ struct gfs2_glock;
30 * block, or all of the blocks in the rg, whichever is smaller */ 30 * block, or all of the blocks in the rg, whichever is smaller */
31static inline unsigned int gfs2_rg_blocks(const struct gfs2_inode *ip) 31static inline unsigned int gfs2_rg_blocks(const struct gfs2_inode *ip)
32{ 32{
33 const struct gfs2_alloc *al = ip->i_alloc; 33 const struct gfs2_blkreserv *rs = ip->i_res;
34 if (al->al_requested < ip->i_rgd->rd_length) 34 if (rs->rs_requested < ip->i_rgd->rd_length)
35 return al->al_requested + 1; 35 return rs->rs_requested + 1;
36 return ip->i_rgd->rd_length; 36 return ip->i_rgd->rd_length;
37} 37}
38 38
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c
index 71d7bf830c09..e9636591b5d5 100644
--- a/fs/gfs2/xattr.c
+++ b/fs/gfs2/xattr.c
@@ -321,11 +321,11 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
321 struct gfs2_ea_header *ea, 321 struct gfs2_ea_header *ea,
322 struct gfs2_ea_header *prev, int leave) 322 struct gfs2_ea_header *prev, int leave)
323{ 323{
324 struct gfs2_alloc *al; 324 struct gfs2_qadata *qa;
325 int error; 325 int error;
326 326
327 al = gfs2_alloc_get(ip); 327 qa = gfs2_qadata_get(ip);
328 if (!al) 328 if (!qa)
329 return -ENOMEM; 329 return -ENOMEM;
330 330
331 error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); 331 error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
@@ -336,7 +336,7 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
336 336
337 gfs2_quota_unhold(ip); 337 gfs2_quota_unhold(ip);
338out_alloc: 338out_alloc:
339 gfs2_alloc_put(ip); 339 gfs2_qadata_put(ip);
340 return error; 340 return error;
341} 341}
342 342
@@ -549,9 +549,10 @@ int gfs2_xattr_acl_get(struct gfs2_inode *ip, const char *name, char **ppdata)
549 goto out; 549 goto out;
550 550
551 error = gfs2_ea_get_copy(ip, &el, data, len); 551 error = gfs2_ea_get_copy(ip, &el, data, len);
552 if (error == 0) 552 if (error < 0)
553 error = len; 553 kfree(data);
554 *ppdata = data; 554 else
555 *ppdata = data;
555out: 556out:
556 brelse(el.el_bh); 557 brelse(el.el_bh);
557 return error; 558 return error;
@@ -609,7 +610,7 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp)
609 u64 block; 610 u64 block;
610 int error; 611 int error;
611 612
612 error = gfs2_alloc_block(ip, &block, &n); 613 error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL);
613 if (error) 614 if (error)
614 return error; 615 return error;
615 gfs2_trans_add_unrevoke(sdp, block, 1); 616 gfs2_trans_add_unrevoke(sdp, block, 1);
@@ -671,7 +672,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
671 int mh_size = sizeof(struct gfs2_meta_header); 672 int mh_size = sizeof(struct gfs2_meta_header);
672 unsigned int n = 1; 673 unsigned int n = 1;
673 674
674 error = gfs2_alloc_block(ip, &block, &n); 675 error = gfs2_alloc_blocks(ip, &block, &n, 0, NULL);
675 if (error) 676 if (error)
676 return error; 677 return error;
677 gfs2_trans_add_unrevoke(sdp, block, 1); 678 gfs2_trans_add_unrevoke(sdp, block, 1);
@@ -708,21 +709,19 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
708 unsigned int blks, 709 unsigned int blks,
709 ea_skeleton_call_t skeleton_call, void *private) 710 ea_skeleton_call_t skeleton_call, void *private)
710{ 711{
711 struct gfs2_alloc *al; 712 struct gfs2_qadata *qa;
712 struct buffer_head *dibh; 713 struct buffer_head *dibh;
713 int error; 714 int error;
714 715
715 al = gfs2_alloc_get(ip); 716 qa = gfs2_qadata_get(ip);
716 if (!al) 717 if (!qa)
717 return -ENOMEM; 718 return -ENOMEM;
718 719
719 error = gfs2_quota_lock_check(ip); 720 error = gfs2_quota_lock_check(ip);
720 if (error) 721 if (error)
721 goto out; 722 goto out;
722 723
723 al->al_requested = blks; 724 error = gfs2_inplace_reserve(ip, blks);
724
725 error = gfs2_inplace_reserve(ip);
726 if (error) 725 if (error)
727 goto out_gunlock_q; 726 goto out_gunlock_q;
728 727
@@ -751,7 +750,7 @@ out_ipres:
751out_gunlock_q: 750out_gunlock_q:
752 gfs2_quota_unlock(ip); 751 gfs2_quota_unlock(ip);
753out: 752out:
754 gfs2_alloc_put(ip); 753 gfs2_qadata_put(ip);
755 return error; 754 return error;
756} 755}
757 756
@@ -991,7 +990,7 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er,
991 } else { 990 } else {
992 u64 blk; 991 u64 blk;
993 unsigned int n = 1; 992 unsigned int n = 1;
994 error = gfs2_alloc_block(ip, &blk, &n); 993 error = gfs2_alloc_blocks(ip, &blk, &n, 0, NULL);
995 if (error) 994 if (error)
996 return error; 995 return error;
997 gfs2_trans_add_unrevoke(sdp, blk, 1); 996 gfs2_trans_add_unrevoke(sdp, blk, 1);
@@ -1435,9 +1434,9 @@ out:
1435static int ea_dealloc_block(struct gfs2_inode *ip) 1434static int ea_dealloc_block(struct gfs2_inode *ip)
1436{ 1435{
1437 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1436 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1438 struct gfs2_alloc *al = ip->i_alloc;
1439 struct gfs2_rgrpd *rgd; 1437 struct gfs2_rgrpd *rgd;
1440 struct buffer_head *dibh; 1438 struct buffer_head *dibh;
1439 struct gfs2_holder gh;
1441 int error; 1440 int error;
1442 1441
1443 rgd = gfs2_blk2rgrpd(sdp, ip->i_eattr); 1442 rgd = gfs2_blk2rgrpd(sdp, ip->i_eattr);
@@ -1446,8 +1445,7 @@ static int ea_dealloc_block(struct gfs2_inode *ip)
1446 return -EIO; 1445 return -EIO;
1447 } 1446 }
1448 1447
1449 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, 1448 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &gh);
1450 &al->al_rgd_gh);
1451 if (error) 1449 if (error)
1452 return error; 1450 return error;
1453 1451
@@ -1471,7 +1469,7 @@ static int ea_dealloc_block(struct gfs2_inode *ip)
1471 gfs2_trans_end(sdp); 1469 gfs2_trans_end(sdp);
1472 1470
1473out_gunlock: 1471out_gunlock:
1474 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1472 gfs2_glock_dq_uninit(&gh);
1475 return error; 1473 return error;
1476} 1474}
1477 1475
@@ -1484,11 +1482,11 @@ out_gunlock:
1484 1482
1485int gfs2_ea_dealloc(struct gfs2_inode *ip) 1483int gfs2_ea_dealloc(struct gfs2_inode *ip)
1486{ 1484{
1487 struct gfs2_alloc *al; 1485 struct gfs2_qadata *qa;
1488 int error; 1486 int error;
1489 1487
1490 al = gfs2_alloc_get(ip); 1488 qa = gfs2_qadata_get(ip);
1491 if (!al) 1489 if (!qa)
1492 return -ENOMEM; 1490 return -ENOMEM;
1493 1491
1494 error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); 1492 error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
@@ -1510,7 +1508,7 @@ int gfs2_ea_dealloc(struct gfs2_inode *ip)
1510out_quota: 1508out_quota:
1511 gfs2_quota_unhold(ip); 1509 gfs2_quota_unhold(ip);
1512out_alloc: 1510out_alloc:
1513 gfs2_alloc_put(ip); 1511 gfs2_qadata_put(ip);
1514 return error; 1512 return error;
1515} 1513}
1516 1514