aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2
diff options
context:
space:
mode:
authorSteven Whitehouse <swhiteho@redhat.com>2006-06-14 15:32:57 -0400
committerSteven Whitehouse <swhiteho@redhat.com>2006-06-14 15:32:57 -0400
commitfeaa7bba026c181ce071d5a4884f7f9dd26207a1 (patch)
treec858deb225917265cb07820730e9764674d133e8 /fs/gfs2
parent22da645fd6675b7abc55cf937ddf6132f343e5b9 (diff)
[GFS2] Fix unlinked file handling
This patch fixes the way we have been dealing with unlinked, but still open files. It removes all limits (other than memory for inodes, as per every other filesystem) on numbers of these which we can support on GFS2. It also means that (like other fs) its the responsibility of the last process to close the file to deallocate the storage, rather than the person who did the unlinking. Note that with GFS2, those two events might take place on different nodes. Also there are a number of other changes: o We use the Linux inode subsystem as it was intended to be used, wrt allocating GFS2 inodes o The Linux inode cache is now the point which we use for local enforcement of only holding one copy of the inode in core at once (previous to this we used the glock layer). o We no longer use the unlinked "special" file. We just ignore it completely. This makes unlinking more efficient. o We now use the 4th block allocation state. The previously unused state is used to track unlinked but still open inodes. o gfs2_inoded is no longer needed o Several fields are now no longer needed (and removed) from the in core struct gfs2_inode o Several fields are no longer needed (and removed) from the in core superblock There are a number of future possible optimisations and clean ups which have been made possible by this patch. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2')
-rw-r--r--fs/gfs2/Makefile2
-rw-r--r--fs/gfs2/acl.c10
-rw-r--r--fs/gfs2/bmap.c44
-rw-r--r--fs/gfs2/daemon.c27
-rw-r--r--fs/gfs2/daemon.h1
-rw-r--r--fs/gfs2/dir.c66
-rw-r--r--fs/gfs2/eaops.c14
-rw-r--r--fs/gfs2/eattr.c70
-rw-r--r--fs/gfs2/glock.c102
-rw-r--r--fs/gfs2/glock.h5
-rw-r--r--fs/gfs2/glops.c9
-rw-r--r--fs/gfs2/incore.h48
-rw-r--r--fs/gfs2/inode.c809
-rw-r--r--fs/gfs2/inode.h32
-rw-r--r--fs/gfs2/log.c3
-rw-r--r--fs/gfs2/lops.c30
-rw-r--r--fs/gfs2/main.c2
-rw-r--r--fs/gfs2/meta_io.c12
-rw-r--r--fs/gfs2/ondisk.c17
-rw-r--r--fs/gfs2/ops_address.c31
-rw-r--r--fs/gfs2/ops_dentry.c6
-rw-r--r--fs/gfs2/ops_export.c60
-rw-r--r--fs/gfs2/ops_file.c42
-rw-r--r--fs/gfs2/ops_fstype.c103
-rw-r--r--fs/gfs2/ops_inode.c168
-rw-r--r--fs/gfs2/ops_super.c112
-rw-r--r--fs/gfs2/ops_vm.c12
-rw-r--r--fs/gfs2/page.c64
-rw-r--r--fs/gfs2/quota.c28
-rw-r--r--fs/gfs2/recovery.c23
-rw-r--r--fs/gfs2/rgrp.c118
-rw-r--r--fs/gfs2/rgrp.h1
-rw-r--r--fs/gfs2/super.c45
-rw-r--r--fs/gfs2/sys.c2
-rw-r--r--fs/gfs2/trans.h1
-rw-r--r--fs/gfs2/unlinked.c459
-rw-r--r--fs/gfs2/unlinked.h25
-rw-r--r--fs/gfs2/util.c2
38 files changed, 738 insertions, 1867 deletions
diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile
index 9974201aa16c..0b7977623b80 100644
--- a/fs/gfs2/Makefile
+++ b/fs/gfs2/Makefile
@@ -3,7 +3,7 @@ gfs2-y := acl.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \
3 glops.o inode.o lm.o log.o lops.o locking.o lvb.o main.o meta_io.o \ 3 glops.o inode.o lm.o log.o lops.o locking.o lvb.o main.o meta_io.o \
4 mount.o ondisk.o ops_address.o ops_dentry.o ops_export.o ops_file.o \ 4 mount.o ondisk.o ops_address.o ops_dentry.o ops_export.o ops_file.o \
5 ops_fstype.o ops_inode.o ops_super.o ops_vm.o page.o quota.o \ 5 ops_fstype.o ops_inode.o ops_super.o ops_vm.o page.o quota.o \
6 recovery.o rgrp.o super.o sys.o trans.o unlinked.o util.o 6 recovery.o rgrp.o super.o sys.o trans.o util.o
7 7
8obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += locking/nolock/ 8obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += locking/nolock/
9obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += locking/dlm/ 9obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += locking/dlm/
diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c
index 343dbe3e87bb..9ef4cf2c03db 100644
--- a/fs/gfs2/acl.c
+++ b/fs/gfs2/acl.c
@@ -73,7 +73,7 @@ int gfs2_acl_validate_set(struct gfs2_inode *ip, int access,
73 73
74int gfs2_acl_validate_remove(struct gfs2_inode *ip, int access) 74int gfs2_acl_validate_remove(struct gfs2_inode *ip, int access)
75{ 75{
76 if (!ip->i_sbd->sd_args.ar_posix_acl) 76 if (!GFS2_SB(&ip->i_inode)->sd_args.ar_posix_acl)
77 return -EOPNOTSUPP; 77 return -EOPNOTSUPP;
78 if (current->fsuid != ip->i_di.di_uid && !capable(CAP_FOWNER)) 78 if (current->fsuid != ip->i_di.di_uid && !capable(CAP_FOWNER))
79 return -EPERM; 79 return -EPERM;
@@ -160,7 +160,7 @@ int gfs2_check_acl_locked(struct inode *inode, int mask)
160 struct posix_acl *acl = NULL; 160 struct posix_acl *acl = NULL;
161 int error; 161 int error;
162 162
163 error = acl_get(inode->u.generic_ip, ACL_ACCESS, &acl, NULL, NULL, NULL); 163 error = acl_get(GFS2_I(inode), ACL_ACCESS, &acl, NULL, NULL, NULL);
164 if (error) 164 if (error)
165 return error; 165 return error;
166 166
@@ -175,7 +175,7 @@ int gfs2_check_acl_locked(struct inode *inode, int mask)
175 175
176int gfs2_check_acl(struct inode *inode, int mask) 176int gfs2_check_acl(struct inode *inode, int mask)
177{ 177{
178 struct gfs2_inode *ip = inode->u.generic_ip; 178 struct gfs2_inode *ip = GFS2_I(inode);
179 struct gfs2_holder i_gh; 179 struct gfs2_holder i_gh;
180 int error; 180 int error;
181 181
@@ -192,7 +192,7 @@ int gfs2_check_acl(struct inode *inode, int mask)
192 192
193static int munge_mode(struct gfs2_inode *ip, mode_t mode) 193static int munge_mode(struct gfs2_inode *ip, mode_t mode)
194{ 194{
195 struct gfs2_sbd *sdp = ip->i_sbd; 195 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
196 struct buffer_head *dibh; 196 struct buffer_head *dibh;
197 int error; 197 int error;
198 198
@@ -217,7 +217,7 @@ static int munge_mode(struct gfs2_inode *ip, mode_t mode)
217 217
218int gfs2_acl_create(struct gfs2_inode *dip, struct gfs2_inode *ip) 218int gfs2_acl_create(struct gfs2_inode *dip, struct gfs2_inode *ip)
219{ 219{
220 struct gfs2_sbd *sdp = dip->i_sbd; 220 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
221 struct posix_acl *acl = NULL, *clone; 221 struct posix_acl *acl = NULL, *clone;
222 struct gfs2_ea_request er; 222 struct gfs2_ea_request er;
223 mode_t mode = ip->i_di.di_mode; 223 mode_t mode = ip->i_di.di_mode;
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 41abd3f4fc73..98fa07c2b710 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -136,7 +136,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer,
136 136
137static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size) 137static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size)
138{ 138{
139 struct gfs2_sbd *sdp = ip->i_sbd; 139 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
140 uint64_t *arr; 140 uint64_t *arr;
141 unsigned int max, height; 141 unsigned int max, height;
142 142
@@ -169,7 +169,7 @@ static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size)
169 169
170static int build_height(struct inode *inode, unsigned height) 170static int build_height(struct inode *inode, unsigned height)
171{ 171{
172 struct gfs2_inode *ip = inode->u.generic_ip; 172 struct gfs2_inode *ip = GFS2_I(inode);
173 unsigned new_height = height - ip->i_di.di_height; 173 unsigned new_height = height - ip->i_di.di_height;
174 struct buffer_head *dibh; 174 struct buffer_head *dibh;
175 struct buffer_head *blocks[GFS2_MAX_META_HEIGHT]; 175 struct buffer_head *blocks[GFS2_MAX_META_HEIGHT];
@@ -283,7 +283,7 @@ static int build_height(struct inode *inode, unsigned height)
283static void find_metapath(struct gfs2_inode *ip, uint64_t block, 283static void find_metapath(struct gfs2_inode *ip, uint64_t block,
284 struct metapath *mp) 284 struct metapath *mp)
285{ 285{
286 struct gfs2_sbd *sdp = ip->i_sbd; 286 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
287 uint64_t b = block; 287 uint64_t b = block;
288 unsigned int i; 288 unsigned int i;
289 289
@@ -382,8 +382,8 @@ static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock,
382 int *boundary, 382 int *boundary,
383 struct metapath *mp) 383 struct metapath *mp)
384{ 384{
385 struct gfs2_inode *ip = inode->u.generic_ip; 385 struct gfs2_inode *ip = GFS2_I(inode);
386 struct gfs2_sbd *sdp = ip->i_sbd; 386 struct gfs2_sbd *sdp = GFS2_SB(inode);
387 struct buffer_head *bh; 387 struct buffer_head *bh;
388 int create = *new; 388 int create = *new;
389 unsigned int bsize; 389 unsigned int bsize;
@@ -446,7 +446,7 @@ out:
446 446
447static inline void bmap_lock(struct inode *inode, int create) 447static inline void bmap_lock(struct inode *inode, int create)
448{ 448{
449 struct gfs2_inode *ip = inode->u.generic_ip; 449 struct gfs2_inode *ip = GFS2_I(inode);
450 if (create) 450 if (create)
451 down_write(&ip->i_rw_mutex); 451 down_write(&ip->i_rw_mutex);
452 else 452 else
@@ -455,7 +455,7 @@ static inline void bmap_lock(struct inode *inode, int create)
455 455
456static inline void bmap_unlock(struct inode *inode, int create) 456static inline void bmap_unlock(struct inode *inode, int create)
457{ 457{
458 struct gfs2_inode *ip = inode->u.generic_ip; 458 struct gfs2_inode *ip = GFS2_I(inode);
459 if (create) 459 if (create)
460 up_write(&ip->i_rw_mutex); 460 up_write(&ip->i_rw_mutex);
461 else 461 else
@@ -481,8 +481,8 @@ int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *
481 481
482int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen) 482int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen)
483{ 483{
484 struct gfs2_inode *ip = inode->u.generic_ip; 484 struct gfs2_inode *ip = GFS2_I(inode);
485 struct gfs2_sbd *sdp = ip->i_sbd; 485 struct gfs2_sbd *sdp = GFS2_SB(inode);
486 struct metapath mp; 486 struct metapath mp;
487 struct buffer_head *bh; 487 struct buffer_head *bh;
488 int boundary; 488 int boundary;
@@ -541,7 +541,7 @@ static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh,
541 uint64_t block, int first, block_call_t bc, 541 uint64_t block, int first, block_call_t bc,
542 void *data) 542 void *data)
543{ 543{
544 struct gfs2_sbd *sdp = ip->i_sbd; 544 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
545 struct buffer_head *bh = NULL; 545 struct buffer_head *bh = NULL;
546 uint64_t *top, *bottom; 546 uint64_t *top, *bottom;
547 uint64_t bn; 547 uint64_t bn;
@@ -609,8 +609,8 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
609 struct buffer_head *bh, uint64_t *top, uint64_t *bottom, 609 struct buffer_head *bh, uint64_t *top, uint64_t *bottom,
610 unsigned int height, void *data) 610 unsigned int height, void *data)
611{ 611{
612 struct strip_mine *sm = (struct strip_mine *)data; 612 struct strip_mine *sm = data;
613 struct gfs2_sbd *sdp = ip->i_sbd; 613 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
614 struct gfs2_rgrp_list rlist; 614 struct gfs2_rgrp_list rlist;
615 uint64_t bn, bstart; 615 uint64_t bn, bstart;
616 uint32_t blen; 616 uint32_t blen;
@@ -756,7 +756,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
756 756
757static int do_grow(struct gfs2_inode *ip, uint64_t size) 757static int do_grow(struct gfs2_inode *ip, uint64_t size)
758{ 758{
759 struct gfs2_sbd *sdp = ip->i_sbd; 759 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
760 struct gfs2_alloc *al; 760 struct gfs2_alloc *al;
761 struct buffer_head *dibh; 761 struct buffer_head *dibh;
762 unsigned int h; 762 unsigned int h;
@@ -795,7 +795,7 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size)
795 h = calc_tree_height(ip, size); 795 h = calc_tree_height(ip, size);
796 if (ip->i_di.di_height < h) { 796 if (ip->i_di.di_height < h) {
797 down_write(&ip->i_rw_mutex); 797 down_write(&ip->i_rw_mutex);
798 error = build_height(ip->i_vnode, h); 798 error = build_height(&ip->i_inode, h);
799 up_write(&ip->i_rw_mutex); 799 up_write(&ip->i_rw_mutex);
800 if (error) 800 if (error)
801 goto out_end_trans; 801 goto out_end_trans;
@@ -830,7 +830,7 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size)
830 830
831static int trunc_start(struct gfs2_inode *ip, uint64_t size) 831static int trunc_start(struct gfs2_inode *ip, uint64_t size)
832{ 832{
833 struct gfs2_sbd *sdp = ip->i_sbd; 833 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
834 struct buffer_head *dibh; 834 struct buffer_head *dibh;
835 int journaled = gfs2_is_jdata(ip); 835 int journaled = gfs2_is_jdata(ip);
836 int error; 836 int error;
@@ -854,7 +854,7 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size)
854 854
855 } else { 855 } else {
856 if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1)) 856 if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1))
857 error = gfs2_block_truncate_page(ip->i_vnode->i_mapping); 857 error = gfs2_block_truncate_page(ip->i_inode.i_mapping);
858 858
859 if (!error) { 859 if (!error) {
860 ip->i_di.di_size = size; 860 ip->i_di.di_size = size;
@@ -883,7 +883,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size)
883 if (!size) 883 if (!size)
884 lblock = 0; 884 lblock = 0;
885 else 885 else
886 lblock = (size - 1) >> ip->i_sbd->sd_sb.sb_bsize_shift; 886 lblock = (size - 1) >> GFS2_SB(&ip->i_inode)->sd_sb.sb_bsize_shift;
887 887
888 find_metapath(ip, lblock, &mp); 888 find_metapath(ip, lblock, &mp);
889 gfs2_alloc_get(ip); 889 gfs2_alloc_get(ip);
@@ -911,7 +911,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size)
911 911
912static int trunc_end(struct gfs2_inode *ip) 912static int trunc_end(struct gfs2_inode *ip)
913{ 913{
914 struct gfs2_sbd *sdp = ip->i_sbd; 914 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
915 struct buffer_head *dibh; 915 struct buffer_head *dibh;
916 int error; 916 int error;
917 917
@@ -990,7 +990,7 @@ int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size)
990{ 990{
991 int error; 991 int error;
992 992
993 if (gfs2_assert_warn(ip->i_sbd, S_ISREG(ip->i_di.di_mode))) 993 if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), S_ISREG(ip->i_di.di_mode)))
994 return -EINVAL; 994 return -EINVAL;
995 995
996 if (size > ip->i_di.di_size) 996 if (size > ip->i_di.di_size)
@@ -1027,7 +1027,7 @@ int gfs2_file_dealloc(struct gfs2_inode *ip)
1027void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len, 1027void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len,
1028 unsigned int *data_blocks, unsigned int *ind_blocks) 1028 unsigned int *data_blocks, unsigned int *ind_blocks)
1029{ 1029{
1030 struct gfs2_sbd *sdp = ip->i_sbd; 1030 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1031 unsigned int tmp; 1031 unsigned int tmp;
1032 1032
1033 if (gfs2_is_dir(ip)) { 1033 if (gfs2_is_dir(ip)) {
@@ -1057,7 +1057,7 @@ void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len,
1057int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset, 1057int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset,
1058 unsigned int len, int *alloc_required) 1058 unsigned int len, int *alloc_required)
1059{ 1059{
1060 struct gfs2_sbd *sdp = ip->i_sbd; 1060 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1061 uint64_t lblock, lblock_stop, dblock; 1061 uint64_t lblock, lblock_stop, dblock;
1062 uint32_t extlen; 1062 uint32_t extlen;
1063 int new = 0; 1063 int new = 0;
@@ -1088,7 +1088,7 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset,
1088 } 1088 }
1089 1089
1090 for (; lblock < lblock_stop; lblock += extlen) { 1090 for (; lblock < lblock_stop; lblock += extlen) {
1091 error = gfs2_extent_map(ip->i_vnode, lblock, &new, &dblock, &extlen); 1091 error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen);
1092 if (error) 1092 if (error)
1093 return error; 1093 return error;
1094 1094
diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c
index 9e7b9f296786..1453605c8f32 100644
--- a/fs/gfs2/daemon.c
+++ b/fs/gfs2/daemon.c
@@ -25,7 +25,6 @@
25#include "quota.h" 25#include "quota.h"
26#include "recovery.h" 26#include "recovery.h"
27#include "super.h" 27#include "super.h"
28#include "unlinked.h"
29#include "util.h" 28#include "util.h"
30 29
31/* This uses schedule_timeout() instead of msleep() because it's good for 30/* This uses schedule_timeout() instead of msleep() because it's good for
@@ -195,29 +194,3 @@ int gfs2_quotad(void *data)
195 return 0; 194 return 0;
196} 195}
197 196
198/**
199 * gfs2_inoded - Deallocate unlinked inodes
200 * @sdp: Pointer to GFS2 superblock
201 *
202 */
203
204int gfs2_inoded(void *data)
205{
206 struct gfs2_sbd *sdp = data;
207 unsigned long t;
208 int error;
209
210 while (!kthread_should_stop()) {
211 error = gfs2_unlinked_dealloc(sdp);
212 if (error &&
213 error != -EROFS &&
214 !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
215 fs_err(sdp, "inoded: error = %d\n", error);
216
217 t = gfs2_tune_get(sdp, gt_inoded_secs) * HZ;
218 schedule_timeout_interruptible(t);
219 }
220
221 return 0;
222}
223
diff --git a/fs/gfs2/daemon.h b/fs/gfs2/daemon.h
index aa68e7a1b0b7..aa93eb6f668e 100644
--- a/fs/gfs2/daemon.h
+++ b/fs/gfs2/daemon.h
@@ -15,6 +15,5 @@ int gfs2_glockd(void *data);
15int gfs2_recoverd(void *data); 15int gfs2_recoverd(void *data);
16int gfs2_logd(void *data); 16int gfs2_logd(void *data);
17int gfs2_quotad(void *data); 17int gfs2_quotad(void *data);
18int gfs2_inoded(void *data);
19 18
20#endif /* __DAEMON_DOT_H__ */ 19#endif /* __DAEMON_DOT_H__ */
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 6918a58261e2..b0353884dd7d 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -113,7 +113,7 @@ static int gfs2_dir_get_existing_buffer(struct gfs2_inode *ip, uint64_t block,
113 error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT, &bh); 113 error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT, &bh);
114 if (error) 114 if (error)
115 return error; 115 return error;
116 if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_JD)) { 116 if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_JD)) {
117 brelse(bh); 117 brelse(bh);
118 return -EIO; 118 return -EIO;
119 } 119 }
@@ -158,7 +158,7 @@ static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf,
158static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, 158static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf,
159 uint64_t offset, unsigned int size) 159 uint64_t offset, unsigned int size)
160{ 160{
161 struct gfs2_sbd *sdp = ip->i_sbd; 161 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
162 struct buffer_head *dibh; 162 struct buffer_head *dibh;
163 uint64_t lblock, dblock; 163 uint64_t lblock, dblock;
164 uint32_t extlen = 0; 164 uint32_t extlen = 0;
@@ -197,7 +197,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf,
197 197
198 if (!extlen) { 198 if (!extlen) {
199 new = 1; 199 new = 1;
200 error = gfs2_extent_map(ip->i_vnode, lblock, &new, 200 error = gfs2_extent_map(&ip->i_inode, lblock, &new,
201 &dblock, &extlen); 201 &dblock, &extlen);
202 if (error) 202 if (error)
203 goto fail; 203 goto fail;
@@ -277,7 +277,7 @@ static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf,
277static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, 277static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf,
278 uint64_t offset, unsigned int size) 278 uint64_t offset, unsigned int size)
279{ 279{
280 struct gfs2_sbd *sdp = ip->i_sbd; 280 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
281 uint64_t lblock, dblock; 281 uint64_t lblock, dblock;
282 uint32_t extlen = 0; 282 uint32_t extlen = 0;
283 unsigned int o; 283 unsigned int o;
@@ -314,7 +314,7 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf,
314 314
315 if (!extlen) { 315 if (!extlen) {
316 new = 0; 316 new = 0;
317 error = gfs2_extent_map(ip->i_vnode, lblock, &new, 317 error = gfs2_extent_map(&ip->i_inode, lblock, &new,
318 &dblock, &extlen); 318 &dblock, &extlen);
319 if (error) 319 if (error)
320 goto fail; 320 goto fail;
@@ -534,7 +534,7 @@ static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode,
534 } 534 }
535 535
536consist_inode: 536consist_inode:
537 gfs2_consist_inode(inode->u.generic_ip); 537 gfs2_consist_inode(GFS2_I(inode));
538 return ERR_PTR(-EIO); 538 return ERR_PTR(-EIO);
539} 539}
540 540
@@ -556,13 +556,13 @@ static int dirent_first(struct gfs2_inode *dip, struct buffer_head *bh,
556 struct gfs2_meta_header *h = (struct gfs2_meta_header *)bh->b_data; 556 struct gfs2_meta_header *h = (struct gfs2_meta_header *)bh->b_data;
557 557
558 if (be32_to_cpu(h->mh_type) == GFS2_METATYPE_LF) { 558 if (be32_to_cpu(h->mh_type) == GFS2_METATYPE_LF) {
559 if (gfs2_meta_check(dip->i_sbd, bh)) 559 if (gfs2_meta_check(GFS2_SB(&dip->i_inode), bh))
560 return -EIO; 560 return -EIO;
561 *dent = (struct gfs2_dirent *)(bh->b_data + 561 *dent = (struct gfs2_dirent *)(bh->b_data +
562 sizeof(struct gfs2_leaf)); 562 sizeof(struct gfs2_leaf));
563 return IS_LEAF; 563 return IS_LEAF;
564 } else { 564 } else {
565 if (gfs2_metatype_check(dip->i_sbd, bh, GFS2_METATYPE_DI)) 565 if (gfs2_metatype_check(GFS2_SB(&dip->i_inode), bh, GFS2_METATYPE_DI))
566 return -EIO; 566 return -EIO;
567 *dent = (struct gfs2_dirent *)(bh->b_data + 567 *dent = (struct gfs2_dirent *)(bh->b_data +
568 sizeof(struct gfs2_dinode)); 568 sizeof(struct gfs2_dinode));
@@ -674,7 +674,7 @@ static struct gfs2_dirent *gfs2_init_dirent(struct inode *inode,
674 const struct qstr *name, 674 const struct qstr *name,
675 struct buffer_head *bh) 675 struct buffer_head *bh)
676{ 676{
677 struct gfs2_inode *ip = inode->u.generic_ip; 677 struct gfs2_inode *ip = GFS2_I(inode);
678 struct gfs2_dirent *ndent; 678 struct gfs2_dirent *ndent;
679 unsigned offset = 0, totlen; 679 unsigned offset = 0, totlen;
680 680
@@ -707,8 +707,10 @@ static int get_leaf(struct gfs2_inode *dip, uint64_t leaf_no,
707 int error; 707 int error;
708 708
709 error = gfs2_meta_read(dip->i_gl, leaf_no, DIO_START | DIO_WAIT, bhp); 709 error = gfs2_meta_read(dip->i_gl, leaf_no, DIO_START | DIO_WAIT, bhp);
710 if (!error && gfs2_metatype_check(dip->i_sbd, *bhp, GFS2_METATYPE_LF)) 710 if (!error && gfs2_metatype_check(GFS2_SB(&dip->i_inode), *bhp, GFS2_METATYPE_LF)) {
711 /* printk(KERN_INFO "block num=%llu\n", leaf_no); */
711 error = -EIO; 712 error = -EIO;
713 }
712 714
713 return error; 715 return error;
714} 716}
@@ -759,7 +761,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode,
759{ 761{
760 struct buffer_head *bh; 762 struct buffer_head *bh;
761 struct gfs2_dirent *dent; 763 struct gfs2_dirent *dent;
762 struct gfs2_inode *ip = inode->u.generic_ip; 764 struct gfs2_inode *ip = GFS2_I(inode);
763 int error; 765 int error;
764 766
765 if (ip->i_di.di_flags & GFS2_DIF_EXHASH) { 767 if (ip->i_di.di_flags & GFS2_DIF_EXHASH) {
@@ -771,7 +773,7 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode,
771 gfs2_consist_inode(ip); 773 gfs2_consist_inode(ip);
772 return ERR_PTR(-EIO); 774 return ERR_PTR(-EIO);
773 } 775 }
774 776
775 index = name->hash >> (32 - ip->i_di.di_depth); 777 index = name->hash >> (32 - ip->i_di.di_depth);
776 error = get_first_leaf(ip, index, &bh); 778 error = get_first_leaf(ip, index, &bh);
777 if (error) 779 if (error)
@@ -786,12 +788,14 @@ static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode,
786 brelse(bh); 788 brelse(bh);
787 if (!ln) 789 if (!ln)
788 break; 790 break;
791
789 error = get_leaf(ip, ln, &bh); 792 error = get_leaf(ip, ln, &bh);
790 } while(!error); 793 } while(!error);
791 794
792 return error ? ERR_PTR(error) : NULL; 795 return error ? ERR_PTR(error) : NULL;
793 } 796 }
794 797
798
795 error = gfs2_meta_inode_buffer(ip, &bh); 799 error = gfs2_meta_inode_buffer(ip, &bh);
796 if (error) 800 if (error)
797 return ERR_PTR(error); 801 return ERR_PTR(error);
@@ -807,7 +811,7 @@ got_dent:
807 811
808static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, u16 depth) 812static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, u16 depth)
809{ 813{
810 struct gfs2_inode *ip = inode->u.generic_ip; 814 struct gfs2_inode *ip = GFS2_I(inode);
811 u64 bn = gfs2_alloc_meta(ip); 815 u64 bn = gfs2_alloc_meta(ip);
812 struct buffer_head *bh = gfs2_meta_new(ip->i_gl, bn); 816 struct buffer_head *bh = gfs2_meta_new(ip->i_gl, bn);
813 struct gfs2_leaf *leaf; 817 struct gfs2_leaf *leaf;
@@ -815,6 +819,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
815 struct qstr name = { .name = "", .len = 0, .hash = 0 }; 819 struct qstr name = { .name = "", .len = 0, .hash = 0 };
816 if (!bh) 820 if (!bh)
817 return NULL; 821 return NULL;
822
818 gfs2_trans_add_bh(ip->i_gl, bh, 1); 823 gfs2_trans_add_bh(ip->i_gl, bh, 1);
819 gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); 824 gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF);
820 leaf = (struct gfs2_leaf *)bh->b_data; 825 leaf = (struct gfs2_leaf *)bh->b_data;
@@ -838,8 +843,8 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
838 843
839static int dir_make_exhash(struct inode *inode) 844static int dir_make_exhash(struct inode *inode)
840{ 845{
841 struct gfs2_inode *dip = inode->u.generic_ip; 846 struct gfs2_inode *dip = GFS2_I(inode);
842 struct gfs2_sbd *sdp = dip->i_sbd; 847 struct gfs2_sbd *sdp = GFS2_SB(inode);
843 struct gfs2_dirent *dent; 848 struct gfs2_dirent *dent;
844 struct qstr args; 849 struct qstr args;
845 struct buffer_head *bh, *dibh; 850 struct buffer_head *bh, *dibh;
@@ -874,7 +879,7 @@ static int dir_make_exhash(struct inode *inode)
874 args.len = bh->b_size - sizeof(struct gfs2_dinode) + 879 args.len = bh->b_size - sizeof(struct gfs2_dinode) +
875 sizeof(struct gfs2_leaf); 880 sizeof(struct gfs2_leaf);
876 args.name = bh->b_data; 881 args.name = bh->b_data;
877 dent = gfs2_dirent_scan(dip->i_vnode, bh->b_data, bh->b_size, 882 dent = gfs2_dirent_scan(&dip->i_inode, bh->b_data, bh->b_size,
878 gfs2_dirent_last, &args, NULL); 883 gfs2_dirent_last, &args, NULL);
879 if (!dent) { 884 if (!dent) {
880 brelse(bh); 885 brelse(bh);
@@ -933,7 +938,7 @@ static int dir_make_exhash(struct inode *inode)
933 938
934static int dir_split_leaf(struct inode *inode, const struct qstr *name) 939static int dir_split_leaf(struct inode *inode, const struct qstr *name)
935{ 940{
936 struct gfs2_inode *dip = inode->u.generic_ip; 941 struct gfs2_inode *dip = GFS2_I(inode);
937 struct buffer_head *nbh, *obh, *dibh; 942 struct buffer_head *nbh, *obh, *dibh;
938 struct gfs2_leaf *nleaf, *oleaf; 943 struct gfs2_leaf *nleaf, *oleaf;
939 struct gfs2_dirent *dent, *prev = NULL, *next = NULL, *new; 944 struct gfs2_dirent *dent, *prev = NULL, *next = NULL, *new;
@@ -1044,7 +1049,7 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name)
1044 oleaf->lf_depth = nleaf->lf_depth; 1049 oleaf->lf_depth = nleaf->lf_depth;
1045 1050
1046 error = gfs2_meta_inode_buffer(dip, &dibh); 1051 error = gfs2_meta_inode_buffer(dip, &dibh);
1047 if (!gfs2_assert_withdraw(dip->i_sbd, !error)) { 1052 if (!gfs2_assert_withdraw(GFS2_SB(&dip->i_inode), !error)) {
1048 dip->i_di.di_blocks++; 1053 dip->i_di.di_blocks++;
1049 gfs2_dinode_out(&dip->i_di, dibh->b_data); 1054 gfs2_dinode_out(&dip->i_di, dibh->b_data);
1050 brelse(dibh); 1055 brelse(dibh);
@@ -1073,7 +1078,7 @@ fail_brelse:
1073 1078
1074static int dir_double_exhash(struct gfs2_inode *dip) 1079static int dir_double_exhash(struct gfs2_inode *dip)
1075{ 1080{
1076 struct gfs2_sbd *sdp = dip->i_sbd; 1081 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1077 struct buffer_head *dibh; 1082 struct buffer_head *dibh;
1078 uint32_t hsize; 1083 uint32_t hsize;
1079 uint64_t *buf; 1084 uint64_t *buf;
@@ -1268,7 +1273,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque,
1268 gfs2_filldir_t filldir, int *copied, 1273 gfs2_filldir_t filldir, int *copied,
1269 unsigned *depth, u64 leaf_no) 1274 unsigned *depth, u64 leaf_no)
1270{ 1275{
1271 struct gfs2_inode *ip = inode->u.generic_ip; 1276 struct gfs2_inode *ip = GFS2_I(inode);
1272 struct buffer_head *bh; 1277 struct buffer_head *bh;
1273 struct gfs2_leaf *lf; 1278 struct gfs2_leaf *lf;
1274 unsigned entries = 0; 1279 unsigned entries = 0;
@@ -1348,8 +1353,8 @@ out:
1348static int dir_e_read(struct inode *inode, uint64_t *offset, void *opaque, 1353static int dir_e_read(struct inode *inode, uint64_t *offset, void *opaque,
1349 gfs2_filldir_t filldir) 1354 gfs2_filldir_t filldir)
1350{ 1355{
1351 struct gfs2_inode *dip = inode->u.generic_ip; 1356 struct gfs2_inode *dip = GFS2_I(inode);
1352 struct gfs2_sbd *sdp = dip->i_sbd; 1357 struct gfs2_sbd *sdp = GFS2_SB(inode);
1353 uint32_t hsize, len = 0; 1358 uint32_t hsize, len = 0;
1354 uint32_t ht_offset, lp_offset, ht_offset_cur = -1; 1359 uint32_t ht_offset, lp_offset, ht_offset_cur = -1;
1355 uint32_t hash, index; 1360 uint32_t hash, index;
@@ -1407,7 +1412,7 @@ out:
1407int gfs2_dir_read(struct inode *inode, uint64_t *offset, void *opaque, 1412int gfs2_dir_read(struct inode *inode, uint64_t *offset, void *opaque,
1408 gfs2_filldir_t filldir) 1413 gfs2_filldir_t filldir)
1409{ 1414{
1410 struct gfs2_inode *dip = inode->u.generic_ip; 1415 struct gfs2_inode *dip = GFS2_I(inode);
1411 struct dirent_gather g; 1416 struct dirent_gather g;
1412 const struct gfs2_dirent **darr, *dent; 1417 const struct gfs2_dirent **darr, *dent;
1413 struct buffer_head *dibh; 1418 struct buffer_head *dibh;
@@ -1490,7 +1495,7 @@ int gfs2_dir_search(struct inode *dir, const struct qstr *name,
1490static int dir_new_leaf(struct inode *inode, const struct qstr *name) 1495static int dir_new_leaf(struct inode *inode, const struct qstr *name)
1491{ 1496{
1492 struct buffer_head *bh, *obh; 1497 struct buffer_head *bh, *obh;
1493 struct gfs2_inode *ip = inode->u.generic_ip; 1498 struct gfs2_inode *ip = GFS2_I(inode);
1494 struct gfs2_leaf *leaf, *oleaf; 1499 struct gfs2_leaf *leaf, *oleaf;
1495 int error; 1500 int error;
1496 u32 index; 1501 u32 index;
@@ -1545,7 +1550,7 @@ static int dir_new_leaf(struct inode *inode, const struct qstr *name)
1545int gfs2_dir_add(struct inode *inode, const struct qstr *name, 1550int gfs2_dir_add(struct inode *inode, const struct qstr *name,
1546 const struct gfs2_inum *inum, unsigned type) 1551 const struct gfs2_inum *inum, unsigned type)
1547{ 1552{
1548 struct gfs2_inode *ip = inode->u.generic_ip; 1553 struct gfs2_inode *ip = GFS2_I(inode);
1549 struct buffer_head *bh; 1554 struct buffer_head *bh;
1550 struct gfs2_dirent *dent; 1555 struct gfs2_dirent *dent;
1551 struct gfs2_leaf *leaf; 1556 struct gfs2_leaf *leaf;
@@ -1623,7 +1628,7 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name)
1623 1628
1624 /* Returns _either_ the entry (if its first in block) or the 1629 /* Returns _either_ the entry (if its first in block) or the
1625 previous entry otherwise */ 1630 previous entry otherwise */
1626 dent = gfs2_dirent_search(dip->i_vnode, name, gfs2_dirent_prev, &bh); 1631 dent = gfs2_dirent_search(&dip->i_inode, name, gfs2_dirent_prev, &bh);
1627 if (!dent) { 1632 if (!dent) {
1628 gfs2_consist_inode(dip); 1633 gfs2_consist_inode(dip);
1629 return -EIO; 1634 return -EIO;
@@ -1659,6 +1664,7 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name)
1659 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds(); 1664 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1660 gfs2_dinode_out(&dip->i_di, bh->b_data); 1665 gfs2_dinode_out(&dip->i_di, bh->b_data);
1661 brelse(bh); 1666 brelse(bh);
1667 mark_inode_dirty(&dip->i_inode);
1662 1668
1663 return error; 1669 return error;
1664} 1670}
@@ -1683,7 +1689,7 @@ int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
1683 struct gfs2_dirent *dent; 1689 struct gfs2_dirent *dent;
1684 int error; 1690 int error;
1685 1691
1686 dent = gfs2_dirent_search(dip->i_vnode, filename, gfs2_dirent_find, &bh); 1692 dent = gfs2_dirent_search(&dip->i_inode, filename, gfs2_dirent_find, &bh);
1687 if (!dent) { 1693 if (!dent) {
1688 gfs2_consist_inode(dip); 1694 gfs2_consist_inode(dip);
1689 return -EIO; 1695 return -EIO;
@@ -1720,7 +1726,7 @@ int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
1720 1726
1721static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data) 1727static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data)
1722{ 1728{
1723 struct gfs2_sbd *sdp = dip->i_sbd; 1729 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1724 struct buffer_head *bh; 1730 struct buffer_head *bh;
1725 struct gfs2_leaf *leaf; 1731 struct gfs2_leaf *leaf;
1726 uint32_t hsize, len; 1732 uint32_t hsize, len;
@@ -1800,7 +1806,7 @@ static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data)
1800static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len, 1806static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len,
1801 uint64_t leaf_no, void *data) 1807 uint64_t leaf_no, void *data)
1802{ 1808{
1803 struct gfs2_sbd *sdp = dip->i_sbd; 1809 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1804 struct gfs2_leaf *tmp_leaf; 1810 struct gfs2_leaf *tmp_leaf;
1805 struct gfs2_rgrp_list rlist; 1811 struct gfs2_rgrp_list rlist;
1806 struct buffer_head *bh, *dibh; 1812 struct buffer_head *bh, *dibh;
@@ -1920,7 +1926,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len,
1920 1926
1921int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip) 1927int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip)
1922{ 1928{
1923 struct gfs2_sbd *sdp = dip->i_sbd; 1929 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1924 struct buffer_head *bh; 1930 struct buffer_head *bh;
1925 int error; 1931 int error;
1926 1932
diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c
index 1c5ac3160b3b..b7e6a37cab6e 100644
--- a/fs/gfs2/eaops.c
+++ b/fs/gfs2/eaops.c
@@ -58,7 +58,7 @@ unsigned int gfs2_ea_name2type(const char *name, char **truncated_name)
58 58
59static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) 59static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
60{ 60{
61 struct inode *inode = ip->i_vnode; 61 struct inode *inode = &ip->i_inode;
62 int error = permission(inode, MAY_READ, NULL); 62 int error = permission(inode, MAY_READ, NULL);
63 if (error) 63 if (error)
64 return error; 64 return error;
@@ -68,7 +68,7 @@ static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
68 68
69static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) 69static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
70{ 70{
71 struct inode *inode = ip->i_vnode; 71 struct inode *inode = &ip->i_inode;
72 72
73 if (S_ISREG(inode->i_mode) || 73 if (S_ISREG(inode->i_mode) ||
74 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) { 74 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
@@ -83,7 +83,7 @@ static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
83 83
84static int user_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) 84static int user_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
85{ 85{
86 struct inode *inode = ip->i_vnode; 86 struct inode *inode = &ip->i_inode;
87 87
88 if (S_ISREG(inode->i_mode) || 88 if (S_ISREG(inode->i_mode) ||
89 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) { 89 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
@@ -103,7 +103,7 @@ static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
103 !capable(CAP_SYS_ADMIN)) 103 !capable(CAP_SYS_ADMIN))
104 return -EPERM; 104 return -EPERM;
105 105
106 if (ip->i_sbd->sd_args.ar_posix_acl == 0 && 106 if (GFS2_SB(&ip->i_inode)->sd_args.ar_posix_acl == 0 &&
107 (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) || 107 (GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) ||
108 GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len))) 108 GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)))
109 return -EOPNOTSUPP; 109 return -EOPNOTSUPP;
@@ -172,7 +172,7 @@ static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
172 172
173static int security_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) 173static int security_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
174{ 174{
175 struct inode *inode = ip->i_vnode; 175 struct inode *inode = &ip->i_inode;
176 int error = permission(inode, MAY_READ, NULL); 176 int error = permission(inode, MAY_READ, NULL);
177 if (error) 177 if (error)
178 return error; 178 return error;
@@ -182,7 +182,7 @@ static int security_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
182 182
183static int security_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) 183static int security_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
184{ 184{
185 struct inode *inode = ip->i_vnode; 185 struct inode *inode = &ip->i_inode;
186 int error = permission(inode, MAY_WRITE, NULL); 186 int error = permission(inode, MAY_WRITE, NULL);
187 if (error) 187 if (error)
188 return error; 188 return error;
@@ -192,7 +192,7 @@ static int security_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
192 192
193static int security_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) 193static int security_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
194{ 194{
195 struct inode *inode = ip->i_vnode; 195 struct inode *inode = &ip->i_inode;
196 int error = permission(inode, MAY_WRITE, NULL); 196 int error = permission(inode, MAY_WRITE, NULL);
197 if (error) 197 if (error)
198 return error; 198 return error;
diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c
index 2e114c075707..96736932260f 100644
--- a/fs/gfs2/eattr.c
+++ b/fs/gfs2/eattr.c
@@ -80,7 +80,7 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh,
80 struct gfs2_ea_header *ea, *prev = NULL; 80 struct gfs2_ea_header *ea, *prev = NULL;
81 int error = 0; 81 int error = 0;
82 82
83 if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_EA)) 83 if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_EA))
84 return -EIO; 84 return -EIO;
85 85
86 for (ea = GFS2_EA_BH2FIRST(bh);; prev = ea, ea = GFS2_EA2NEXT(ea)) { 86 for (ea = GFS2_EA_BH2FIRST(bh);; prev = ea, ea = GFS2_EA2NEXT(ea)) {
@@ -128,13 +128,13 @@ static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data)
128 goto out; 128 goto out;
129 } 129 }
130 130
131 if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_IN)) { 131 if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_IN)) {
132 error = -EIO; 132 error = -EIO;
133 goto out; 133 goto out;
134 } 134 }
135 135
136 eablk = (uint64_t *)(bh->b_data + sizeof(struct gfs2_meta_header)); 136 eablk = (uint64_t *)(bh->b_data + sizeof(struct gfs2_meta_header));
137 end = eablk + ip->i_sbd->sd_inptrs; 137 end = eablk + GFS2_SB(&ip->i_inode)->sd_inptrs;
138 138
139 for (; eablk < end; eablk++) { 139 for (; eablk < end; eablk++) {
140 uint64_t bn; 140 uint64_t bn;
@@ -232,7 +232,7 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
232 struct gfs2_ea_header *prev, void *private) 232 struct gfs2_ea_header *prev, void *private)
233{ 233{
234 int *leave = private; 234 int *leave = private;
235 struct gfs2_sbd *sdp = ip->i_sbd; 235 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
236 struct gfs2_rgrpd *rgd; 236 struct gfs2_rgrpd *rgd;
237 struct gfs2_holder rg_gh; 237 struct gfs2_holder rg_gh;
238 struct buffer_head *dibh; 238 struct buffer_head *dibh;
@@ -338,7 +338,7 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
338 if (error) 338 if (error)
339 goto out_alloc; 339 goto out_alloc;
340 340
341 error = gfs2_rindex_hold(ip->i_sbd, &al->al_ri_gh); 341 error = gfs2_rindex_hold(GFS2_SB(&ip->i_inode), &al->al_ri_gh);
342 if (error) 342 if (error)
343 goto out_quota; 343 goto out_quota;
344 344
@@ -459,7 +459,7 @@ int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er)
459static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, 459static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
460 char *data) 460 char *data)
461{ 461{
462 struct gfs2_sbd *sdp = ip->i_sbd; 462 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
463 struct buffer_head **bh; 463 struct buffer_head **bh;
464 unsigned int amount = GFS2_EA_DATA_LEN(ea); 464 unsigned int amount = GFS2_EA_DATA_LEN(ea);
465 unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); 465 unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize);
@@ -604,7 +604,7 @@ int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
604 604
605static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp) 605static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp)
606{ 606{
607 struct gfs2_sbd *sdp = ip->i_sbd; 607 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
608 struct gfs2_ea_header *ea; 608 struct gfs2_ea_header *ea;
609 uint64_t block; 609 uint64_t block;
610 610
@@ -641,7 +641,7 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp)
641static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, 641static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
642 struct gfs2_ea_request *er) 642 struct gfs2_ea_request *er)
643{ 643{
644 struct gfs2_sbd *sdp = ip->i_sbd; 644 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
645 645
646 ea->ea_data_len = cpu_to_be32(er->er_data_len); 646 ea->ea_data_len = cpu_to_be32(er->er_data_len);
647 ea->ea_name_len = er->er_name_len; 647 ea->ea_name_len = er->er_name_len;
@@ -723,7 +723,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
723 if (error) 723 if (error)
724 goto out_gunlock_q; 724 goto out_gunlock_q;
725 725
726 error = gfs2_trans_begin(ip->i_sbd, 726 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode),
727 blks + al->al_rgd->rd_ri.ri_length + 727 blks + al->al_rgd->rd_ri.ri_length +
728 RES_DINODE + RES_STATFS + RES_QUOTA, 0); 728 RES_DINODE + RES_STATFS + RES_QUOTA, 0);
729 if (error) 729 if (error)
@@ -736,7 +736,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
736 error = gfs2_meta_inode_buffer(ip, &dibh); 736 error = gfs2_meta_inode_buffer(ip, &dibh);
737 if (!error) { 737 if (!error) {
738 if (er->er_flags & GFS2_ERF_MODE) { 738 if (er->er_flags & GFS2_ERF_MODE) {
739 gfs2_assert_withdraw(ip->i_sbd, 739 gfs2_assert_withdraw(GFS2_SB(&ip->i_inode),
740 (ip->i_di.di_mode & S_IFMT) == 740 (ip->i_di.di_mode & S_IFMT) ==
741 (er->er_mode & S_IFMT)); 741 (er->er_mode & S_IFMT));
742 ip->i_di.di_mode = er->er_mode; 742 ip->i_di.di_mode = er->er_mode;
@@ -748,7 +748,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
748 } 748 }
749 749
750 out_end_trans: 750 out_end_trans:
751 gfs2_trans_end(ip->i_sbd); 751 gfs2_trans_end(GFS2_SB(&ip->i_inode));
752 752
753 out_ipres: 753 out_ipres:
754 gfs2_inplace_release(ip); 754 gfs2_inplace_release(ip);
@@ -790,7 +790,7 @@ static int ea_init_i(struct gfs2_inode *ip, struct gfs2_ea_request *er,
790 790
791static int ea_init(struct gfs2_inode *ip, struct gfs2_ea_request *er) 791static int ea_init(struct gfs2_inode *ip, struct gfs2_ea_request *er)
792{ 792{
793 unsigned int jbsize = ip->i_sbd->sd_jbsize; 793 unsigned int jbsize = GFS2_SB(&ip->i_inode)->sd_jbsize;
794 unsigned int blks = 1; 794 unsigned int blks = 1;
795 795
796 if (GFS2_EAREQ_SIZE_STUFFED(er) > jbsize) 796 if (GFS2_EAREQ_SIZE_STUFFED(er) > jbsize)
@@ -830,7 +830,7 @@ static void ea_set_remove_stuffed(struct gfs2_inode *ip,
830 return; 830 return;
831 } else if (GFS2_EA2NEXT(prev) != ea) { 831 } else if (GFS2_EA2NEXT(prev) != ea) {
832 prev = GFS2_EA2NEXT(prev); 832 prev = GFS2_EA2NEXT(prev);
833 gfs2_assert_withdraw(ip->i_sbd, GFS2_EA2NEXT(prev) == ea); 833 gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), GFS2_EA2NEXT(prev) == ea);
834 } 834 }
835 835
836 len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea); 836 len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea);
@@ -857,7 +857,7 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh,
857 struct buffer_head *dibh; 857 struct buffer_head *dibh;
858 int error; 858 int error;
859 859
860 error = gfs2_trans_begin(ip->i_sbd, RES_DINODE + 2 * RES_EATTR, 0); 860 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + 2 * RES_EATTR, 0);
861 if (error) 861 if (error)
862 return error; 862 return error;
863 863
@@ -876,7 +876,7 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh,
876 goto out; 876 goto out;
877 877
878 if (er->er_flags & GFS2_ERF_MODE) { 878 if (er->er_flags & GFS2_ERF_MODE) {
879 gfs2_assert_withdraw(ip->i_sbd, 879 gfs2_assert_withdraw(GFS2_SB(&ip->i_inode),
880 (ip->i_di.di_mode & S_IFMT) == (er->er_mode & S_IFMT)); 880 (ip->i_di.di_mode & S_IFMT) == (er->er_mode & S_IFMT));
881 ip->i_di.di_mode = er->er_mode; 881 ip->i_di.di_mode = er->er_mode;
882 } 882 }
@@ -885,7 +885,7 @@ static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh,
885 gfs2_dinode_out(&ip->i_di, dibh->b_data); 885 gfs2_dinode_out(&ip->i_di, dibh->b_data);
886 brelse(dibh); 886 brelse(dibh);
887 out: 887 out:
888 gfs2_trans_end(ip->i_sbd); 888 gfs2_trans_end(GFS2_SB(&ip->i_inode));
889 889
890 return error; 890 return error;
891} 891}
@@ -921,7 +921,7 @@ static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh,
921 int stuffed; 921 int stuffed;
922 int error; 922 int error;
923 923
924 stuffed = ea_calc_size(ip->i_sbd, es->es_er, &size); 924 stuffed = ea_calc_size(GFS2_SB(&ip->i_inode), es->es_er, &size);
925 925
926 if (ea->ea_type == GFS2_EATYPE_UNUSED) { 926 if (ea->ea_type == GFS2_EATYPE_UNUSED) {
927 if (GFS2_EA_REC_LEN(ea) < size) 927 if (GFS2_EA_REC_LEN(ea) < size)
@@ -947,7 +947,7 @@ static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh,
947 es->es_bh = bh; 947 es->es_bh = bh;
948 es->es_ea = ea; 948 es->es_ea = ea;
949 blks = 2 + DIV_ROUND_UP(es->es_er->er_data_len, 949 blks = 2 + DIV_ROUND_UP(es->es_er->er_data_len,
950 ip->i_sbd->sd_jbsize); 950 GFS2_SB(&ip->i_inode)->sd_jbsize);
951 951
952 error = ea_alloc_skeleton(ip, es->es_er, blks, 952 error = ea_alloc_skeleton(ip, es->es_er, blks,
953 ea_set_simple_alloc, es); 953 ea_set_simple_alloc, es);
@@ -961,7 +961,7 @@ static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh,
961static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, 961static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er,
962 void *private) 962 void *private)
963{ 963{
964 struct gfs2_sbd *sdp = ip->i_sbd; 964 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
965 struct buffer_head *indbh, *newbh; 965 struct buffer_head *indbh, *newbh;
966 uint64_t *eablk; 966 uint64_t *eablk;
967 int error; 967 int error;
@@ -1050,8 +1050,8 @@ static int ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er,
1050 1050
1051 if (!(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT)) 1051 if (!(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT))
1052 blks++; 1052 blks++;
1053 if (GFS2_EAREQ_SIZE_STUFFED(er) > ip->i_sbd->sd_jbsize) 1053 if (GFS2_EAREQ_SIZE_STUFFED(er) > GFS2_SB(&ip->i_inode)->sd_jbsize)
1054 blks += DIV_ROUND_UP(er->er_data_len, ip->i_sbd->sd_jbsize); 1054 blks += DIV_ROUND_UP(er->er_data_len, GFS2_SB(&ip->i_inode)->sd_jbsize);
1055 1055
1056 return ea_alloc_skeleton(ip, er, blks, ea_set_block, el); 1056 return ea_alloc_skeleton(ip, er, blks, ea_set_block, el);
1057} 1057}
@@ -1061,7 +1061,7 @@ static int ea_set_remove_unstuffed(struct gfs2_inode *ip,
1061{ 1061{
1062 if (el->el_prev && GFS2_EA2NEXT(el->el_prev) != el->el_ea) { 1062 if (el->el_prev && GFS2_EA2NEXT(el->el_prev) != el->el_ea) {
1063 el->el_prev = GFS2_EA2NEXT(el->el_prev); 1063 el->el_prev = GFS2_EA2NEXT(el->el_prev);
1064 gfs2_assert_withdraw(ip->i_sbd, 1064 gfs2_assert_withdraw(GFS2_SB(&ip->i_inode),
1065 GFS2_EA2NEXT(el->el_prev) == el->el_ea); 1065 GFS2_EA2NEXT(el->el_prev) == el->el_ea);
1066 } 1066 }
1067 1067
@@ -1119,7 +1119,7 @@ int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
1119 er->er_data = NULL; 1119 er->er_data = NULL;
1120 er->er_data_len = 0; 1120 er->er_data_len = 0;
1121 } 1121 }
1122 error = ea_check_size(ip->i_sbd, er); 1122 error = ea_check_size(GFS2_SB(&ip->i_inode), er);
1123 if (error) 1123 if (error)
1124 return error; 1124 return error;
1125 1125
@@ -1127,7 +1127,7 @@ int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
1127 if (error) 1127 if (error)
1128 return error; 1128 return error;
1129 1129
1130 if (IS_IMMUTABLE(ip->i_vnode)) 1130 if (IS_IMMUTABLE(&ip->i_inode))
1131 error = -EPERM; 1131 error = -EPERM;
1132 else 1132 else
1133 error = gfs2_ea_ops[er->er_type]->eo_set(ip, er); 1133 error = gfs2_ea_ops[er->er_type]->eo_set(ip, er);
@@ -1144,7 +1144,7 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el)
1144 struct buffer_head *dibh; 1144 struct buffer_head *dibh;
1145 int error; 1145 int error;
1146 1146
1147 error = gfs2_trans_begin(ip->i_sbd, RES_DINODE + RES_EATTR, 0); 1147 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + RES_EATTR, 0);
1148 if (error) 1148 if (error)
1149 return error; 1149 return error;
1150 1150
@@ -1169,7 +1169,7 @@ static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el)
1169 brelse(dibh); 1169 brelse(dibh);
1170 } 1170 }
1171 1171
1172 gfs2_trans_end(ip->i_sbd); 1172 gfs2_trans_end(GFS2_SB(&ip->i_inode));
1173 1173
1174 return error; 1174 return error;
1175} 1175}
@@ -1219,7 +1219,7 @@ int gfs2_ea_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
1219 if (error) 1219 if (error)
1220 return error; 1220 return error;
1221 1221
1222 if (IS_IMMUTABLE(ip->i_vnode) || IS_APPEND(ip->i_vnode)) 1222 if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
1223 error = -EPERM; 1223 error = -EPERM;
1224 else 1224 else
1225 error = gfs2_ea_ops[er->er_type]->eo_remove(ip, er); 1225 error = gfs2_ea_ops[er->er_type]->eo_remove(ip, er);
@@ -1232,7 +1232,7 @@ int gfs2_ea_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
1232static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, 1232static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip,
1233 struct gfs2_ea_header *ea, char *data) 1233 struct gfs2_ea_header *ea, char *data)
1234{ 1234{
1235 struct gfs2_sbd *sdp = ip->i_sbd; 1235 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1236 struct buffer_head **bh; 1236 struct buffer_head **bh;
1237 unsigned int amount = GFS2_EA_DATA_LEN(ea); 1237 unsigned int amount = GFS2_EA_DATA_LEN(ea);
1238 unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); 1238 unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize);
@@ -1304,7 +1304,7 @@ int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el,
1304 int error; 1304 int error;
1305 1305
1306 if (GFS2_EA_IS_STUFFED(el->el_ea)) { 1306 if (GFS2_EA_IS_STUFFED(el->el_ea)) {
1307 error = gfs2_trans_begin(ip->i_sbd, RES_DINODE + RES_EATTR, 0); 1307 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + RES_EATTR, 0);
1308 if (error) 1308 if (error)
1309 return error; 1309 return error;
1310 1310
@@ -1320,22 +1320,22 @@ int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el,
1320 1320
1321 error = gfs2_meta_inode_buffer(ip, &dibh); 1321 error = gfs2_meta_inode_buffer(ip, &dibh);
1322 if (!error) { 1322 if (!error) {
1323 error = inode_setattr(ip->i_vnode, attr); 1323 error = inode_setattr(&ip->i_inode, attr);
1324 gfs2_assert_warn(ip->i_sbd, !error); 1324 gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error);
1325 gfs2_inode_attr_out(ip); 1325 gfs2_inode_attr_out(ip);
1326 gfs2_trans_add_bh(ip->i_gl, dibh, 1); 1326 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
1327 gfs2_dinode_out(&ip->i_di, dibh->b_data); 1327 gfs2_dinode_out(&ip->i_di, dibh->b_data);
1328 brelse(dibh); 1328 brelse(dibh);
1329 } 1329 }
1330 1330
1331 gfs2_trans_end(ip->i_sbd); 1331 gfs2_trans_end(GFS2_SB(&ip->i_inode));
1332 1332
1333 return error; 1333 return error;
1334} 1334}
1335 1335
1336static int ea_dealloc_indirect(struct gfs2_inode *ip) 1336static int ea_dealloc_indirect(struct gfs2_inode *ip)
1337{ 1337{
1338 struct gfs2_sbd *sdp = ip->i_sbd; 1338 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1339 struct gfs2_rgrp_list rlist; 1339 struct gfs2_rgrp_list rlist;
1340 struct buffer_head *indbh, *dibh; 1340 struct buffer_head *indbh, *dibh;
1341 uint64_t *eablk, *end; 1341 uint64_t *eablk, *end;
@@ -1456,7 +1456,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)
1456 1456
1457static int ea_dealloc_block(struct gfs2_inode *ip) 1457static int ea_dealloc_block(struct gfs2_inode *ip)
1458{ 1458{
1459 struct gfs2_sbd *sdp = ip->i_sbd; 1459 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1460 struct gfs2_alloc *al = &ip->i_alloc; 1460 struct gfs2_alloc *al = &ip->i_alloc;
1461 struct gfs2_rgrpd *rgd; 1461 struct gfs2_rgrpd *rgd;
1462 struct buffer_head *dibh; 1462 struct buffer_head *dibh;
@@ -1518,7 +1518,7 @@ int gfs2_ea_dealloc(struct gfs2_inode *ip)
1518 if (error) 1518 if (error)
1519 goto out_alloc; 1519 goto out_alloc;
1520 1520
1521 error = gfs2_rindex_hold(ip->i_sbd, &al->al_ri_gh); 1521 error = gfs2_rindex_hold(GFS2_SB(&ip->i_inode), &al->al_ri_gh);
1522 if (error) 1522 if (error)
1523 goto out_quota; 1523 goto out_quota;
1524 1524
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 0603a6de52c9..35bac90878a5 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -654,7 +654,7 @@ static void run_queue(struct gfs2_glock *gl)
654 * Gives caller exclusive access to manipulate a glock structure. 654 * Gives caller exclusive access to manipulate a glock structure.
655 */ 655 */
656 656
657void gfs2_glmutex_lock(struct gfs2_glock *gl) 657static void gfs2_glmutex_lock(struct gfs2_glock *gl)
658{ 658{
659 struct gfs2_holder gh; 659 struct gfs2_holder gh;
660 660
@@ -704,7 +704,7 @@ static int gfs2_glmutex_trylock(struct gfs2_glock *gl)
704 * 704 *
705 */ 705 */
706 706
707void gfs2_glmutex_unlock(struct gfs2_glock *gl) 707static void gfs2_glmutex_unlock(struct gfs2_glock *gl)
708{ 708{
709 spin_lock(&gl->gl_spin); 709 spin_lock(&gl->gl_spin);
710 clear_bit(GLF_LOCK, &gl->gl_flags); 710 clear_bit(GLF_LOCK, &gl->gl_flags);
@@ -726,7 +726,7 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state)
726{ 726{
727 struct gfs2_holder *gh, *new_gh = NULL; 727 struct gfs2_holder *gh, *new_gh = NULL;
728 728
729 restart: 729restart:
730 spin_lock(&gl->gl_spin); 730 spin_lock(&gl->gl_spin);
731 731
732 list_for_each_entry(gh, &gl->gl_waiters2, gh_list) { 732 list_for_each_entry(gh, &gl->gl_waiters2, gh_list) {
@@ -752,13 +752,27 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state)
752 goto restart; 752 goto restart;
753 } 753 }
754 754
755 out: 755out:
756 spin_unlock(&gl->gl_spin); 756 spin_unlock(&gl->gl_spin);
757 757
758 if (new_gh) 758 if (new_gh)
759 gfs2_holder_put(new_gh); 759 gfs2_holder_put(new_gh);
760} 760}
761 761
762void gfs2_glock_inode_squish(struct inode *inode)
763{
764 struct gfs2_holder gh;
765 struct gfs2_glock *gl = GFS2_I(inode)->i_gl;
766 gfs2_holder_init(gl, LM_ST_UNLOCKED, 0, &gh);
767 set_bit(HIF_DEMOTE, &gh.gh_iflags);
768 spin_lock(&gl->gl_spin);
769 gfs2_assert(inode->i_sb->s_fs_info, list_empty(&gl->gl_holders));
770 list_add_tail(&gh.gh_list, &gl->gl_waiters2);
771 run_queue(gl);
772 spin_unlock(&gl->gl_spin);
773 gfs2_holder_uninit(&gh);
774}
775
762/** 776/**
763 * state_change - record that the glock is now in a different state 777 * state_change - record that the glock is now in a different state
764 * @gl: the glock 778 * @gl: the glock
@@ -1383,8 +1397,7 @@ int gfs2_glock_be_greedy(struct gfs2_glock *gl, unsigned int time)
1383 struct greedy *gr; 1397 struct greedy *gr;
1384 struct gfs2_holder *gh; 1398 struct gfs2_holder *gh;
1385 1399
1386 if (!time || 1400 if (!time || gl->gl_sbd->sd_args.ar_localcaching ||
1387 gl->gl_sbd->sd_args.ar_localcaching ||
1388 test_and_set_bit(GLF_GREEDY, &gl->gl_flags)) 1401 test_and_set_bit(GLF_GREEDY, &gl->gl_flags))
1389 return 1; 1402 return 1;
1390 1403
@@ -1785,43 +1798,6 @@ void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data)
1785} 1798}
1786 1799
1787/** 1800/**
1788 * gfs2_try_toss_inode - try to remove a particular inode struct from cache
1789 * sdp: the filesystem
1790 * inum: the inode number
1791 *
1792 */
1793
1794void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum)
1795{
1796 struct gfs2_glock *gl;
1797 struct gfs2_inode *ip;
1798 int error;
1799
1800 error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops,
1801 NO_CREATE, &gl);
1802 if (error || !gl)
1803 return;
1804
1805 if (!gfs2_glmutex_trylock(gl))
1806 goto out;
1807
1808 ip = gl->gl_object;
1809 if (!ip)
1810 goto out_unlock;
1811
1812 if (atomic_read(&ip->i_count))
1813 goto out_unlock;
1814
1815 gfs2_inode_destroy(ip, 1);
1816
1817 out_unlock:
1818 gfs2_glmutex_unlock(gl);
1819
1820 out:
1821 gfs2_glock_put(gl);
1822}
1823
1824/**
1825 * gfs2_iopen_go_callback - Try to kick the inode/vnode associated with an 1801 * gfs2_iopen_go_callback - Try to kick the inode/vnode associated with an
1826 * iopen glock from memory 1802 * iopen glock from memory
1827 * @io_gl: the iopen glock 1803 * @io_gl: the iopen glock
@@ -1831,34 +1807,10 @@ void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum)
1831 1807
1832void gfs2_iopen_go_callback(struct gfs2_glock *io_gl, unsigned int state) 1808void gfs2_iopen_go_callback(struct gfs2_glock *io_gl, unsigned int state)
1833{ 1809{
1834 struct gfs2_glock *i_gl;
1835 1810
1836 if (state != LM_ST_UNLOCKED) 1811 if (state != LM_ST_UNLOCKED)
1837 return; 1812 return;
1838 1813 /* FIXME: remove this? */
1839 spin_lock(&io_gl->gl_spin);
1840 i_gl = io_gl->gl_object;
1841 if (i_gl) {
1842 gfs2_glock_hold(i_gl);
1843 spin_unlock(&io_gl->gl_spin);
1844 } else {
1845 spin_unlock(&io_gl->gl_spin);
1846 return;
1847 }
1848
1849 if (gfs2_glmutex_trylock(i_gl)) {
1850 struct gfs2_inode *ip = i_gl->gl_object;
1851 if (ip) {
1852 gfs2_try_toss_vnode(ip);
1853 gfs2_glmutex_unlock(i_gl);
1854 gfs2_glock_schedule_for_reclaim(i_gl);
1855 goto out;
1856 }
1857 gfs2_glmutex_unlock(i_gl);
1858 }
1859
1860 out:
1861 gfs2_glock_put(i_gl);
1862} 1814}
1863 1815
1864/** 1816/**
@@ -1935,11 +1887,6 @@ void gfs2_reclaim_glock(struct gfs2_sbd *sdp)
1935 atomic_inc(&sdp->sd_reclaimed); 1887 atomic_inc(&sdp->sd_reclaimed);
1936 1888
1937 if (gfs2_glmutex_trylock(gl)) { 1889 if (gfs2_glmutex_trylock(gl)) {
1938 if (gl->gl_ops == &gfs2_inode_glops) {
1939 struct gfs2_inode *ip = gl->gl_object;
1940 if (ip && !atomic_read(&ip->i_count))
1941 gfs2_inode_destroy(ip, 1);
1942 }
1943 if (queue_empty(gl, &gl->gl_holders) && 1890 if (queue_empty(gl, &gl->gl_holders) &&
1944 gl->gl_state != LM_ST_UNLOCKED && 1891 gl->gl_state != LM_ST_UNLOCKED &&
1945 demote_ok(gl)) 1892 demote_ok(gl))
@@ -2018,7 +1965,7 @@ static void scan_glock(struct gfs2_glock *gl)
2018 if (gfs2_glmutex_trylock(gl)) { 1965 if (gfs2_glmutex_trylock(gl)) {
2019 if (gl->gl_ops == &gfs2_inode_glops) { 1966 if (gl->gl_ops == &gfs2_inode_glops) {
2020 struct gfs2_inode *ip = gl->gl_object; 1967 struct gfs2_inode *ip = gl->gl_object;
2021 if (ip && !atomic_read(&ip->i_count)) 1968 if (ip)
2022 goto out_schedule; 1969 goto out_schedule;
2023 } 1970 }
2024 if (queue_empty(gl, &gl->gl_holders) && 1971 if (queue_empty(gl, &gl->gl_holders) &&
@@ -2078,11 +2025,6 @@ static void clear_glock(struct gfs2_glock *gl)
2078 } 2025 }
2079 2026
2080 if (gfs2_glmutex_trylock(gl)) { 2027 if (gfs2_glmutex_trylock(gl)) {
2081 if (gl->gl_ops == &gfs2_inode_glops) {
2082 struct gfs2_inode *ip = gl->gl_object;
2083 if (ip && !atomic_read(&ip->i_count))
2084 gfs2_inode_destroy(ip, 1);
2085 }
2086 if (queue_empty(gl, &gl->gl_holders) && 2028 if (queue_empty(gl, &gl->gl_holders) &&
2087 gl->gl_state != LM_ST_UNLOCKED) 2029 gl->gl_state != LM_ST_UNLOCKED)
2088 handle_callback(gl, LM_ST_UNLOCKED); 2030 handle_callback(gl, LM_ST_UNLOCKED);
@@ -2199,13 +2141,11 @@ static int dump_inode(struct gfs2_inode *ip)
2199 (unsigned long long)ip->i_num.no_formal_ino, 2141 (unsigned long long)ip->i_num.no_formal_ino,
2200 (unsigned long long)ip->i_num.no_addr); 2142 (unsigned long long)ip->i_num.no_addr);
2201 printk(KERN_INFO " type = %u\n", IF2DT(ip->i_di.di_mode)); 2143 printk(KERN_INFO " type = %u\n", IF2DT(ip->i_di.di_mode));
2202 printk(KERN_INFO " i_count = %d\n", atomic_read(&ip->i_count));
2203 printk(KERN_INFO " i_flags ="); 2144 printk(KERN_INFO " i_flags =");
2204 for (x = 0; x < 32; x++) 2145 for (x = 0; x < 32; x++)
2205 if (test_bit(x, &ip->i_flags)) 2146 if (test_bit(x, &ip->i_flags))
2206 printk(" %u", x); 2147 printk(" %u", x);
2207 printk(" \n"); 2148 printk(" \n");
2208 printk(KERN_INFO " vnode = %s\n", (ip->i_vnode) ? "yes" : "no");
2209 2149
2210 error = 0; 2150 error = 0;
2211 2151
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index 2e0a2ba92aa0..fdf58db44ae3 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -88,9 +88,6 @@ void gfs2_holder_uninit(struct gfs2_holder *gh);
88void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags); 88void gfs2_glock_xmote_th(struct gfs2_glock *gl, unsigned int state, int flags);
89void gfs2_glock_drop_th(struct gfs2_glock *gl); 89void gfs2_glock_drop_th(struct gfs2_glock *gl);
90 90
91void gfs2_glmutex_lock(struct gfs2_glock *gl);
92void gfs2_glmutex_unlock(struct gfs2_glock *gl);
93
94int gfs2_glock_nq(struct gfs2_holder *gh); 91int gfs2_glock_nq(struct gfs2_holder *gh);
95int gfs2_glock_poll(struct gfs2_holder *gh); 92int gfs2_glock_poll(struct gfs2_holder *gh);
96int gfs2_glock_wait(struct gfs2_holder *gh); 93int gfs2_glock_wait(struct gfs2_holder *gh);
@@ -110,6 +107,7 @@ void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs);
110void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number, 107void gfs2_glock_prefetch_num(struct gfs2_sbd *sdp, uint64_t number,
111 struct gfs2_glock_operations *glops, 108 struct gfs2_glock_operations *glops,
112 unsigned int state, int flags); 109 unsigned int state, int flags);
110void gfs2_glock_inode_squish(struct inode *inode);
113 111
114/** 112/**
115 * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock 113 * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock
@@ -143,7 +141,6 @@ void gfs2_lvb_unhold(struct gfs2_glock *gl);
143 141
144void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data); 142void gfs2_glock_cb(lm_fsdata_t *fsdata, unsigned int type, void *data);
145 143
146void gfs2_try_toss_inode(struct gfs2_sbd *sdp, struct gfs2_inum *inum);
147void gfs2_iopen_go_callback(struct gfs2_glock *gl, unsigned int state); 144void gfs2_iopen_go_callback(struct gfs2_glock *gl, unsigned int state);
148 145
149void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl); 146void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl);
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index e262f22f744e..013bf5f1552f 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -129,6 +129,7 @@ static void inode_go_xmote_bh(struct gfs2_glock *gl)
129 129
130static void inode_go_drop_th(struct gfs2_glock *gl) 130static void inode_go_drop_th(struct gfs2_glock *gl)
131{ 131{
132 printk(KERN_INFO "drop th %p\n", gl->gl_object);
132 gfs2_pte_inval(gl); 133 gfs2_pte_inval(gl);
133 gfs2_glock_drop_th(gl); 134 gfs2_glock_drop_th(gl);
134} 135}
@@ -147,6 +148,7 @@ static void inode_go_sync(struct gfs2_glock *gl, int flags)
147 148
148 if (test_bit(GLF_DIRTY, &gl->gl_flags)) { 149 if (test_bit(GLF_DIRTY, &gl->gl_flags)) {
149 if (meta && data) { 150 if (meta && data) {
151 printk(KERN_INFO "sync all\n");
150 gfs2_page_sync(gl, flags | DIO_START); 152 gfs2_page_sync(gl, flags | DIO_START);
151 gfs2_log_flush(gl->gl_sbd, gl); 153 gfs2_log_flush(gl->gl_sbd, gl);
152 gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT); 154 gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT);
@@ -224,6 +226,7 @@ static int inode_go_lock(struct gfs2_holder *gh)
224 return 0; 226 return 0;
225 227
226 if (ip->i_vn != gl->gl_vn) { 228 if (ip->i_vn != gl->gl_vn) {
229 printk(KERN_INFO "refresh inode %p\n", &ip->i_inode);
227 error = gfs2_inode_refresh(ip); 230 error = gfs2_inode_refresh(ip);
228 if (error) 231 if (error)
229 return error; 232 return error;
@@ -288,7 +291,7 @@ static void inode_greedy(struct gfs2_glock *gl)
288 291
289 spin_unlock(&ip->i_spin); 292 spin_unlock(&ip->i_spin);
290 293
291 gfs2_inode_put(ip); 294 iput(&ip->i_inode);
292} 295}
293 296
294/** 297/**
@@ -361,14 +364,14 @@ static void trans_go_xmote_th(struct gfs2_glock *gl, unsigned int state,
361static void trans_go_xmote_bh(struct gfs2_glock *gl) 364static void trans_go_xmote_bh(struct gfs2_glock *gl)
362{ 365{
363 struct gfs2_sbd *sdp = gl->gl_sbd; 366 struct gfs2_sbd *sdp = gl->gl_sbd;
364 struct gfs2_inode *ip = sdp->sd_jdesc->jd_inode->u.generic_ip; 367 struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
365 struct gfs2_glock *j_gl = ip->i_gl; 368 struct gfs2_glock *j_gl = ip->i_gl;
366 struct gfs2_log_header head; 369 struct gfs2_log_header head;
367 int error; 370 int error;
368 371
369 if (gl->gl_state != LM_ST_UNLOCKED && 372 if (gl->gl_state != LM_ST_UNLOCKED &&
370 test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { 373 test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
371 gfs2_meta_cache_flush(sdp->sd_jdesc->jd_inode->u.generic_ip); 374 gfs2_meta_cache_flush(GFS2_I(sdp->sd_jdesc->jd_inode));
372 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA); 375 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA);
373 376
374 error = gfs2_find_jhead(sdp->sd_jdesc, &head); 377 error = gfs2_find_jhead(sdp->sd_jdesc, &head);
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 8caefec88854..9a67a5954126 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -33,7 +33,6 @@ struct gfs2_inode;
33struct gfs2_file; 33struct gfs2_file;
34struct gfs2_revoke; 34struct gfs2_revoke;
35struct gfs2_revoke_replay; 35struct gfs2_revoke_replay;
36struct gfs2_unlinked;
37struct gfs2_quota_data; 36struct gfs2_quota_data;
38struct gfs2_log_buf; 37struct gfs2_log_buf;
39struct gfs2_trans; 38struct gfs2_trans;
@@ -245,16 +244,12 @@ struct gfs2_inode {
245 struct inode i_inode; 244 struct inode i_inode;
246 struct gfs2_inum i_num; 245 struct gfs2_inum i_num;
247 246
248 atomic_t i_count;
249 unsigned long i_flags; /* GIF_... */ 247 unsigned long i_flags; /* GIF_... */
250 248
251 uint64_t i_vn; 249 uint64_t i_vn;
252 struct gfs2_dinode i_di; 250 struct gfs2_dinode i_di; /* To be replaced by ref to block */
253
254 struct gfs2_glock *i_gl;
255 struct gfs2_sbd *i_sbd;
256 struct inode *i_vnode;
257 251
252 struct gfs2_glock *i_gl; /* Move into i_gh? */
258 struct gfs2_holder i_iopen_gh; 253 struct gfs2_holder i_iopen_gh;
259 struct gfs2_holder i_gh; /* for prepare/commit_write only */ 254 struct gfs2_holder i_gh; /* for prepare/commit_write only */
260 struct gfs2_alloc i_alloc; 255 struct gfs2_alloc i_alloc;
@@ -262,18 +257,27 @@ struct gfs2_inode {
262 257
263 spinlock_t i_spin; 258 spinlock_t i_spin;
264 struct rw_semaphore i_rw_mutex; 259 struct rw_semaphore i_rw_mutex;
265
266 unsigned int i_greedy; 260 unsigned int i_greedy;
267 unsigned long i_last_pfault; 261 unsigned long i_last_pfault;
268 262
269 struct buffer_head *i_cache[GFS2_MAX_META_HEIGHT]; 263 struct buffer_head *i_cache[GFS2_MAX_META_HEIGHT];
270}; 264};
271 265
266/*
267 * Since i_inode is the first element of struct gfs2_inode,
268 * this is effectively a cast.
269 */
272static inline struct gfs2_inode *GFS2_I(struct inode *inode) 270static inline struct gfs2_inode *GFS2_I(struct inode *inode)
273{ 271{
274 return container_of(inode, struct gfs2_inode, i_inode); 272 return container_of(inode, struct gfs2_inode, i_inode);
275} 273}
276 274
275/* To be removed? */
276static inline struct gfs2_sbd *GFS2_SB(struct inode *inode)
277{
278 return inode->i_sb->s_fs_info;
279}
280
277enum { 281enum {
278 GFF_DID_DIRECT_ALLOC = 0, 282 GFF_DID_DIRECT_ALLOC = 0,
279}; 283};
@@ -296,18 +300,6 @@ struct gfs2_revoke_replay {
296}; 300};
297 301
298enum { 302enum {
299 ULF_LOCKED = 0,
300};
301
302struct gfs2_unlinked {
303 struct list_head ul_list;
304 unsigned int ul_count;
305 struct gfs2_unlinked_tag ul_ut;
306 unsigned long ul_flags; /* ULF_... */
307 unsigned int ul_slot;
308};
309
310enum {
311 QDF_USER = 0, 303 QDF_USER = 0,
312 QDF_CHANGE = 1, 304 QDF_CHANGE = 1,
313 QDF_LOCKED = 2, 305 QDF_LOCKED = 2,
@@ -436,7 +428,6 @@ struct gfs2_tune {
436 unsigned int gt_recoverd_secs; 428 unsigned int gt_recoverd_secs;
437 unsigned int gt_logd_secs; 429 unsigned int gt_logd_secs;
438 unsigned int gt_quotad_secs; 430 unsigned int gt_quotad_secs;
439 unsigned int gt_inoded_secs;
440 431
441 unsigned int gt_quota_simul_sync; /* Max quotavals to sync at once */ 432 unsigned int gt_quota_simul_sync; /* Max quotavals to sync at once */
442 unsigned int gt_quota_warn_period; /* Secs between quota warn msgs */ 433 unsigned int gt_quota_warn_period; /* Secs between quota warn msgs */
@@ -495,7 +486,6 @@ struct gfs2_sbd {
495 uint32_t sd_hash_bsize; /* sizeof(exhash block) */ 486 uint32_t sd_hash_bsize; /* sizeof(exhash block) */
496 uint32_t sd_hash_bsize_shift; 487 uint32_t sd_hash_bsize_shift;
497 uint32_t sd_hash_ptrs; /* Number of pointers in a hash block */ 488 uint32_t sd_hash_ptrs; /* Number of pointers in a hash block */
498 uint32_t sd_ut_per_block;
499 uint32_t sd_qc_per_block; 489 uint32_t sd_qc_per_block;
500 uint32_t sd_max_dirres; /* Max blocks needed to add a directory entry */ 490 uint32_t sd_max_dirres; /* Max blocks needed to add a directory entry */
501 uint32_t sd_max_height; /* Max height of a file's metadata tree */ 491 uint32_t sd_max_height; /* Max height of a file's metadata tree */
@@ -527,7 +517,6 @@ struct gfs2_sbd {
527 struct inode *sd_statfs_inode; 517 struct inode *sd_statfs_inode;
528 struct inode *sd_ir_inode; 518 struct inode *sd_ir_inode;
529 struct inode *sd_sc_inode; 519 struct inode *sd_sc_inode;
530 struct inode *sd_ut_inode;
531 struct inode *sd_qc_inode; 520 struct inode *sd_qc_inode;
532 struct inode *sd_rindex; 521 struct inode *sd_rindex;
533 struct inode *sd_quota_inode; 522 struct inode *sd_quota_inode;
@@ -569,7 +558,6 @@ struct gfs2_sbd {
569 558
570 struct gfs2_holder sd_ir_gh; 559 struct gfs2_holder sd_ir_gh;
571 struct gfs2_holder sd_sc_gh; 560 struct gfs2_holder sd_sc_gh;
572 struct gfs2_holder sd_ut_gh;
573 struct gfs2_holder sd_qc_gh; 561 struct gfs2_holder sd_qc_gh;
574 562
575 /* Daemon stuff */ 563 /* Daemon stuff */
@@ -578,21 +566,9 @@ struct gfs2_sbd {
578 struct task_struct *sd_recoverd_process; 566 struct task_struct *sd_recoverd_process;
579 struct task_struct *sd_logd_process; 567 struct task_struct *sd_logd_process;
580 struct task_struct *sd_quotad_process; 568 struct task_struct *sd_quotad_process;
581 struct task_struct *sd_inoded_process;
582 struct task_struct *sd_glockd_process[GFS2_GLOCKD_MAX]; 569 struct task_struct *sd_glockd_process[GFS2_GLOCKD_MAX];
583 unsigned int sd_glockd_num; 570 unsigned int sd_glockd_num;
584 571
585 /* Unlinked inode stuff */
586
587 struct list_head sd_unlinked_list;
588 atomic_t sd_unlinked_count;
589 spinlock_t sd_unlinked_spin;
590 struct mutex sd_unlinked_mutex;
591
592 unsigned int sd_unlinked_slots;
593 unsigned int sd_unlinked_chunks;
594 unsigned char **sd_unlinked_bitmap;
595
596 /* Quota stuff */ 572 /* Quota stuff */
597 573
598 struct list_head sd_quota_list; 574 struct list_head sd_quota_list;
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index c2c7d2b63a57..4e9c42119aed 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -35,7 +35,6 @@
35#include "quota.h" 35#include "quota.h"
36#include "rgrp.h" 36#include "rgrp.h"
37#include "trans.h" 37#include "trans.h"
38#include "unlinked.h"
39#include "util.h" 38#include "util.h"
40 39
41/** 40/**
@@ -72,7 +71,7 @@ static void inode_attr_in(struct gfs2_inode *ip, struct inode *inode)
72 inode->i_ctime.tv_nsec = 0; 71 inode->i_ctime.tv_nsec = 0;
73 inode->i_blksize = PAGE_SIZE; 72 inode->i_blksize = PAGE_SIZE;
74 inode->i_blocks = ip->i_di.di_blocks << 73 inode->i_blocks = ip->i_di.di_blocks <<
75 (ip->i_sbd->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT); 74 (GFS2_SB(inode)->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT);
76 75
77 if (ip->i_di.di_flags & GFS2_DIF_IMMUTABLE) 76 if (ip->i_di.di_flags & GFS2_DIF_IMMUTABLE)
78 inode->i_flags |= S_IMMUTABLE; 77 inode->i_flags |= S_IMMUTABLE;
@@ -93,13 +92,8 @@ static void inode_attr_in(struct gfs2_inode *ip, struct inode *inode)
93 92
94void gfs2_inode_attr_in(struct gfs2_inode *ip) 93void gfs2_inode_attr_in(struct gfs2_inode *ip)
95{ 94{
96 struct inode *inode; 95 struct inode *inode = &ip->i_inode;
97 96 inode_attr_in(ip, inode);
98 inode = gfs2_ip2v_lookup(ip);
99 if (inode) {
100 inode_attr_in(ip, inode);
101 iput(inode);
102 }
103} 97}
104 98
105/** 99/**
@@ -112,9 +106,9 @@ void gfs2_inode_attr_in(struct gfs2_inode *ip)
112 106
113void gfs2_inode_attr_out(struct gfs2_inode *ip) 107void gfs2_inode_attr_out(struct gfs2_inode *ip)
114{ 108{
115 struct inode *inode = ip->i_vnode; 109 struct inode *inode = &ip->i_inode;
116 110
117 gfs2_assert_withdraw(ip->i_sbd, 111 gfs2_assert_withdraw(GFS2_SB(inode),
118 (ip->i_di.di_mode & S_IFMT) == (inode->i_mode & S_IFMT)); 112 (ip->i_di.di_mode & S_IFMT) == (inode->i_mode & S_IFMT));
119 ip->i_di.di_mode = inode->i_mode; 113 ip->i_di.di_mode = inode->i_mode;
120 ip->i_di.di_uid = inode->i_uid; 114 ip->i_di.di_uid = inode->i_uid;
@@ -124,114 +118,100 @@ void gfs2_inode_attr_out(struct gfs2_inode *ip)
124 ip->i_di.di_ctime = inode->i_ctime.tv_sec; 118 ip->i_di.di_ctime = inode->i_ctime.tv_sec;
125} 119}
126 120
127/** 121static int iget_test(struct inode *inode, void *opaque)
128 * gfs2_ip2v_lookup - Get the struct inode for a struct gfs2_inode 122{
129 * @ip: the struct gfs2_inode to get the struct inode for 123 struct gfs2_inode *ip = GFS2_I(inode);
130 * 124 struct gfs2_inum *inum = opaque;
131 * Returns: A VFS inode, or NULL if none 125
132 */ 126 if (ip && ip->i_num.no_addr == inum->no_addr)
127 return 1;
133 128
134struct inode *gfs2_ip2v_lookup(struct gfs2_inode *ip) 129 return 0;
130}
131
132static int iget_set(struct inode *inode, void *opaque)
135{ 133{
136 struct inode *inode = NULL; 134 struct gfs2_inode *ip = GFS2_I(inode);
135 struct gfs2_inum *inum = opaque;
137 136
138 gfs2_assert_warn(ip->i_sbd, test_bit(GIF_MIN_INIT, &ip->i_flags)); 137 ip->i_num = *inum;
138 return 0;
139}
139 140
140 spin_lock(&ip->i_spin); 141struct inode *gfs2_ilookup(struct super_block *sb, struct gfs2_inum *inum)
141 if (ip->i_vnode) 142{
142 inode = igrab(ip->i_vnode); 143 return ilookup5(sb, (unsigned long)inum->no_formal_ino,
143 spin_unlock(&ip->i_spin); 144 iget_test, inum);
145}
144 146
145 return inode; 147static struct inode *gfs2_iget(struct super_block *sb, struct gfs2_inum *inum)
148{
149 return iget5_locked(sb, (unsigned long)inum->no_formal_ino,
150 iget_test, iget_set, inum);
146} 151}
147 152
148/** 153/**
149 * gfs2_ip2v - Get/Create a struct inode for a struct gfs2_inode 154 * gfs2_inode_lookup - Lookup an inode
150 * @ip: the struct gfs2_inode to get the struct inode for 155 * @sb: The super block
156 * @inum: The inode number
157 * @type: The type of the inode
151 * 158 *
152 * Returns: A VFS inode, or NULL if no mem 159 * Returns: A VFS inode, or an error
153 */ 160 */
154 161
155struct inode *gfs2_ip2v(struct gfs2_inode *ip) 162struct inode *gfs2_inode_lookup(struct super_block *sb, struct gfs2_inum *inum, unsigned int type)
156{ 163{
157 struct inode *inode, *tmp; 164 struct inode *inode = gfs2_iget(sb, inum);
158 165 struct gfs2_inode *ip = GFS2_I(inode);
159 inode = gfs2_ip2v_lookup(ip); 166 struct gfs2_glock *io_gl;
160 if (inode) 167 int error;
161 return inode;
162
163 tmp = new_inode(ip->i_sbd->sd_vfs);
164 if (!tmp)
165 return NULL;
166
167 inode_attr_in(ip, tmp);
168
169 if (S_ISREG(ip->i_di.di_mode)) {
170 tmp->i_op = &gfs2_file_iops;
171 tmp->i_fop = &gfs2_file_fops;
172 tmp->i_mapping->a_ops = &gfs2_file_aops;
173 } else if (S_ISDIR(ip->i_di.di_mode)) {
174 tmp->i_op = &gfs2_dir_iops;
175 tmp->i_fop = &gfs2_dir_fops;
176 } else if (S_ISLNK(ip->i_di.di_mode)) {
177 tmp->i_op = &gfs2_symlink_iops;
178 } else {
179 tmp->i_op = &gfs2_dev_iops;
180 init_special_inode(tmp, tmp->i_mode, tmp->i_rdev);
181 }
182
183 tmp->u.generic_ip = NULL;
184
185 for (;;) {
186 spin_lock(&ip->i_spin);
187 if (!ip->i_vnode)
188 break;
189 inode = igrab(ip->i_vnode);
190 spin_unlock(&ip->i_spin);
191 168
192 if (inode) { 169 if (inode->i_state & I_NEW) {
193 iput(tmp); 170 struct gfs2_sbd *sdp = GFS2_SB(inode);
194 return inode; 171 umode_t mode = DT2IF(type);
172 inode->u.generic_ip = ip;
173 inode->i_mode = mode;
174
175 if (S_ISREG(mode)) {
176 inode->i_op = &gfs2_file_iops;
177 inode->i_fop = &gfs2_file_fops;
178 inode->i_mapping->a_ops = &gfs2_file_aops;
179 } else if (S_ISDIR(mode)) {
180 inode->i_op = &gfs2_dir_iops;
181 inode->i_fop = &gfs2_dir_fops;
182 } else if (S_ISLNK(mode)) {
183 inode->i_op = &gfs2_symlink_iops;
184 } else {
185 inode->i_op = &gfs2_dev_iops;
195 } 186 }
196 yield();
197 }
198 187
199 inode = tmp; 188 error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
189 if (unlikely(error))
190 goto fail;
191 ip->i_gl->gl_object = ip;
200 192
201 gfs2_inode_hold(ip); 193 error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
202 ip->i_vnode = inode; 194 if (unlikely(error))
203 inode->u.generic_ip = ip; 195 goto fail_put;
204 196
205 spin_unlock(&ip->i_spin); 197 ip->i_vn = ip->i_gl->gl_vn - 1;
198 error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
199 if (unlikely(error))
200 goto fail_iopen;
206 201
207 insert_inode_hash(inode); 202 gfs2_glock_put(io_gl);
203 unlock_new_inode(inode);
204 }
208 205
209 return inode; 206 return inode;
210} 207fail_iopen:
211 208 gfs2_glock_put(io_gl);
212static int iget_test(struct inode *inode, void *opaque) 209fail_put:
213{ 210 ip->i_gl->gl_object = NULL;
214 struct gfs2_inode *ip = inode->u.generic_ip; 211 gfs2_glock_put(ip->i_gl);
215 struct gfs2_inum *inum = (struct gfs2_inum *)opaque; 212fail:
216 213 iput(inode);
217 if (ip && ip->i_num.no_addr == inum->no_addr) 214 return ERR_PTR(error);
218 return 1;
219
220 return 0;
221}
222
223struct inode *gfs2_iget(struct super_block *sb, struct gfs2_inum *inum)
224{
225 return ilookup5(sb, (unsigned long)inum->no_formal_ino,
226 iget_test, inum);
227}
228
229void gfs2_inode_min_init(struct gfs2_inode *ip, unsigned int type)
230{
231 if (!test_and_set_bit(GIF_MIN_INIT, &ip->i_flags)) {
232 ip->i_di.di_nlink = 1;
233 ip->i_di.di_mode = DT2IF(type);
234 }
235} 215}
236 216
237/** 217/**
@@ -250,7 +230,7 @@ int gfs2_inode_refresh(struct gfs2_inode *ip)
250 if (error) 230 if (error)
251 return error; 231 return error;
252 232
253 if (gfs2_metatype_check(ip->i_sbd, dibh, GFS2_METATYPE_DI)) { 233 if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), dibh, GFS2_METATYPE_DI)) {
254 brelse(dibh); 234 brelse(dibh);
255 return -EIO; 235 return -EIO;
256 } 236 }
@@ -273,151 +253,9 @@ int gfs2_inode_refresh(struct gfs2_inode *ip)
273 return 0; 253 return 0;
274} 254}
275 255
276/** 256int gfs2_dinode_dealloc(struct gfs2_inode *ip)
277 * inode_create - create a struct gfs2_inode
278 * @i_gl: The glock covering the inode
279 * @inum: The inode number
280 * @io_gl: the iopen glock to acquire/hold (using holder in new gfs2_inode)
281 * @io_state: the state the iopen glock should be acquired in
282 * @ipp: pointer to put the returned inode in
283 *
284 * Returns: errno
285 */
286
287static int inode_create(struct gfs2_glock *i_gl, const struct gfs2_inum *inum,
288 struct gfs2_glock *io_gl, unsigned int io_state,
289 struct gfs2_inode **ipp, int need_lock)
290{ 257{
291 struct gfs2_sbd *sdp = i_gl->gl_sbd; 258 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
292 struct gfs2_inode *ip;
293 int error = 0;
294
295 ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
296 if (!ip)
297 return -ENOMEM;
298 memset(ip, 0, sizeof(struct gfs2_inode));
299 ip->i_num = *inum;
300 atomic_set(&ip->i_count, 1);
301 ip->i_vn = i_gl->gl_vn - 1;
302 ip->i_gl = i_gl;
303 ip->i_sbd = sdp;
304 spin_lock_init(&ip->i_spin);
305 init_rwsem(&ip->i_rw_mutex);
306 ip->i_greedy = gfs2_tune_get(sdp, gt_greedy_default);
307
308 if (need_lock) {
309 error = gfs2_glock_nq_init(io_gl,
310 io_state, GL_LOCAL_EXCL | GL_EXACT,
311 &ip->i_iopen_gh);
312 if (error)
313 goto fail;
314
315 spin_lock(&io_gl->gl_spin);
316 gfs2_glock_hold(i_gl);
317 io_gl->gl_object = i_gl;
318 spin_unlock(&io_gl->gl_spin);
319 }
320
321 gfs2_glock_hold(i_gl);
322 i_gl->gl_object = ip;
323 atomic_inc(&sdp->sd_inode_count);
324 *ipp = ip;
325 return 0;
326
327fail:
328 gfs2_meta_cache_flush(ip);
329 kmem_cache_free(gfs2_inode_cachep, ip);
330 *ipp = NULL;
331 return error;
332}
333
334/**
335 * gfs2_inode_get - Create or get a reference on an inode
336 * @i_gl: The glock covering the inode
337 * @inum: The inode number
338 * @create:
339 * @ipp: pointer to put the returned inode in
340 *
341 * Returns: errno
342 */
343
344int gfs2_inode_get(struct gfs2_glock *i_gl, const struct gfs2_inum *inum,
345 int create, struct gfs2_inode **ipp)
346{
347 struct gfs2_sbd *sdp = i_gl->gl_sbd;
348 struct gfs2_glock *io_gl;
349 int error = 0;
350
351 gfs2_glmutex_lock(i_gl);
352
353 *ipp = i_gl->gl_object;
354 if (*ipp) {
355 error = -ESTALE;
356 if ((*ipp)->i_num.no_formal_ino != inum->no_formal_ino)
357 goto out;
358 atomic_inc(&(*ipp)->i_count);
359 error = 0;
360 goto out;
361 }
362
363 if (!create)
364 goto out;
365
366 error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_iopen_glops,
367 CREATE, &io_gl);
368 if (!error) {
369 error = inode_create(i_gl, inum, io_gl, LM_ST_SHARED, ipp, 1);
370 gfs2_glock_put(io_gl);
371 }
372
373 out:
374 gfs2_glmutex_unlock(i_gl);
375
376 return error;
377}
378
379void gfs2_inode_hold(struct gfs2_inode *ip)
380{
381 gfs2_assert(ip->i_sbd, atomic_read(&ip->i_count) > 0);
382 atomic_inc(&ip->i_count);
383}
384
385void gfs2_inode_put(struct gfs2_inode *ip)
386{
387 gfs2_assert(ip->i_sbd, atomic_read(&ip->i_count) > 0);
388 atomic_dec(&ip->i_count);
389}
390
391void gfs2_inode_destroy(struct gfs2_inode *ip, int unlock)
392{
393 struct gfs2_sbd *sdp = ip->i_sbd;
394 struct gfs2_glock *i_gl = ip->i_gl;
395
396 gfs2_assert_warn(sdp, !atomic_read(&ip->i_count));
397 if (unlock) {
398 struct gfs2_glock *io_gl = ip->i_iopen_gh.gh_gl;
399 gfs2_assert(sdp, io_gl->gl_object == i_gl);
400
401 spin_lock(&io_gl->gl_spin);
402 io_gl->gl_object = NULL;
403 spin_unlock(&io_gl->gl_spin);
404 gfs2_glock_put(i_gl);
405
406 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
407 }
408
409 gfs2_meta_cache_flush(ip);
410 kmem_cache_free(gfs2_inode_cachep, ip);
411
412 i_gl->gl_object = NULL;
413 gfs2_glock_put(i_gl);
414
415 atomic_dec(&sdp->sd_inode_count);
416}
417
418static int dinode_dealloc(struct gfs2_inode *ip, struct gfs2_unlinked *ul)
419{
420 struct gfs2_sbd *sdp = ip->i_sbd;
421 struct gfs2_alloc *al; 259 struct gfs2_alloc *al;
422 struct gfs2_rgrpd *rgd; 260 struct gfs2_rgrpd *rgd;
423 int error; 261 int error;
@@ -450,7 +288,7 @@ static int dinode_dealloc(struct gfs2_inode *ip, struct gfs2_unlinked *ul)
450 if (error) 288 if (error)
451 goto out_rindex_relse; 289 goto out_rindex_relse;
452 290
453 error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_UNLINKED + 291 error = gfs2_trans_begin(sdp, RES_RG_BIT +
454 RES_STATFS + RES_QUOTA, 1); 292 RES_STATFS + RES_QUOTA, 1);
455 if (error) 293 if (error)
456 goto out_rg_gunlock; 294 goto out_rg_gunlock;
@@ -459,191 +297,20 @@ static int dinode_dealloc(struct gfs2_inode *ip, struct gfs2_unlinked *ul)
459 297
460 gfs2_free_di(rgd, ip); 298 gfs2_free_di(rgd, ip);
461 299
462 error = gfs2_unlinked_ondisk_rm(sdp, ul);
463
464 gfs2_trans_end(sdp); 300 gfs2_trans_end(sdp);
465 clear_bit(GLF_STICKY, &ip->i_gl->gl_flags); 301 clear_bit(GLF_STICKY, &ip->i_gl->gl_flags);
466 302
467 out_rg_gunlock: 303out_rg_gunlock:
468 gfs2_glock_dq_uninit(&al->al_rgd_gh); 304 gfs2_glock_dq_uninit(&al->al_rgd_gh);
469 305out_rindex_relse:
470 out_rindex_relse:
471 gfs2_glock_dq_uninit(&al->al_ri_gh); 306 gfs2_glock_dq_uninit(&al->al_ri_gh);
472 307out_qs:
473 out_qs:
474 gfs2_quota_unhold(ip); 308 gfs2_quota_unhold(ip);
475
476 out:
477 gfs2_alloc_put(ip);
478
479 return error;
480}
481
482/**
483 * inode_dealloc - Deallocate all on-disk blocks for an inode (dinode)
484 * @sdp: the filesystem
485 * @inum: the inode number to deallocate
486 * @io_gh: a holder for the iopen glock for this inode
487 *
488 * N.B. When we enter this we already hold the iopen glock and getting
489 * the glock for the inode means that we are grabbing the locks in the
490 * "wrong" order so we must only so a try lock operation and fail if we
491 * don't get the lock. Thats ok, since if we fail it means someone else
492 * is using the inode still and thus we shouldn't be deallocating it
493 * anyway.
494 *
495 * Returns: errno
496 */
497
498static int inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul,
499 struct gfs2_holder *io_gh)
500{
501 struct gfs2_inode *ip;
502 struct gfs2_holder i_gh;
503 int error;
504
505 error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr,
506 &gfs2_inode_glops, LM_ST_EXCLUSIVE,
507 LM_FLAG_TRY_1CB|GL_DUMP, &i_gh);
508 switch(error) {
509 case 0:
510 break;
511 case GLR_TRYFAILED:
512 return 1; /* or back off and relock in different order? */
513 default:
514 return error;
515 }
516
517 gfs2_assert_warn(sdp, !i_gh.gh_gl->gl_object);
518 error = inode_create(i_gh.gh_gl, &ul->ul_ut.ut_inum, io_gh->gh_gl,
519 LM_ST_EXCLUSIVE, &ip, 0);
520
521 if (error)
522 goto out;
523
524 error = gfs2_inode_refresh(ip);
525 if (error)
526 goto out_iput;
527
528 if (ip->i_di.di_nlink) {
529 if (gfs2_consist_inode(ip))
530 gfs2_dinode_print(&ip->i_di);
531 error = -EIO;
532 goto out_iput;
533 }
534
535 if (S_ISDIR(ip->i_di.di_mode) &&
536 (ip->i_di.di_flags & GFS2_DIF_EXHASH)) {
537 error = gfs2_dir_exhash_dealloc(ip);
538 if (error)
539 goto out_iput;
540 }
541
542 if (ip->i_di.di_eattr) {
543 error = gfs2_ea_dealloc(ip);
544 if (error)
545 goto out_iput;
546 }
547
548 if (!gfs2_is_stuffed(ip)) {
549 error = gfs2_file_dealloc(ip);
550 if (error)
551 goto out_iput;
552 }
553
554 error = dinode_dealloc(ip, ul);
555 if (error)
556 goto out_iput;
557
558out_iput:
559 gfs2_glmutex_lock(i_gh.gh_gl);
560 gfs2_inode_put(ip);
561 gfs2_inode_destroy(ip, 0);
562 gfs2_glmutex_unlock(i_gh.gh_gl);
563
564out: 309out:
565 gfs2_glock_dq_uninit(&i_gh); 310 gfs2_alloc_put(ip);
566
567 return error;
568}
569
570/**
571 * try_inode_dealloc - Try to deallocate an inode and all its blocks
572 * @sdp: the filesystem
573 *
574 * Returns: 0 on success, -errno on error, 1 on busy (inode open)
575 */
576
577static int try_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul)
578{
579 int error = 0;
580 struct gfs2_holder iogh;
581
582 gfs2_try_toss_inode(sdp, &ul->ul_ut.ut_inum);
583 error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr,
584 &gfs2_iopen_glops, LM_ST_EXCLUSIVE,
585 LM_FLAG_TRY_1CB, &iogh);
586 switch (error) {
587 case 0:
588 break;
589 case GLR_TRYFAILED:
590 return 1;
591 default:
592 return error;
593 }
594
595 error = inode_dealloc(sdp, ul, &iogh);
596 gfs2_glock_dq_uninit(&iogh);
597
598 return error;
599}
600
601static int inode_dealloc_uninit(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul)
602{
603 struct gfs2_rgrpd *rgd;
604 struct gfs2_holder ri_gh, rgd_gh;
605 int error;
606
607 error = gfs2_rindex_hold(sdp, &ri_gh);
608 if (error)
609 return error;
610
611 rgd = gfs2_blk2rgrpd(sdp, ul->ul_ut.ut_inum.no_addr);
612 if (!rgd) {
613 gfs2_consist(sdp);
614 error = -EIO;
615 goto out;
616 }
617
618 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &rgd_gh);
619 if (error)
620 goto out;
621
622 error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_UNLINKED + RES_STATFS, 0);
623 if (error)
624 goto out_gunlock;
625
626 gfs2_free_uninit_di(rgd, ul->ul_ut.ut_inum.no_addr);
627 gfs2_unlinked_ondisk_rm(sdp, ul);
628
629 gfs2_trans_end(sdp);
630
631 out_gunlock:
632 gfs2_glock_dq_uninit(&rgd_gh);
633 out:
634 gfs2_glock_dq_uninit(&ri_gh);
635
636 return error; 311 return error;
637} 312}
638 313
639int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul)
640{
641 if (ul->ul_ut.ut_flags & GFS2_UTF_UNINIT)
642 return inode_dealloc_uninit(sdp, ul);
643 else
644 return try_inode_dealloc(sdp, ul);
645}
646
647/** 314/**
648 * gfs2_change_nlink - Change nlink count on inode 315 * gfs2_change_nlink - Change nlink count on inode
649 * @ip: The GFS2 inode 316 * @ip: The GFS2 inode
@@ -654,6 +321,7 @@ int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul)
654 321
655int gfs2_change_nlink(struct gfs2_inode *ip, int diff) 322int gfs2_change_nlink(struct gfs2_inode *ip, int diff)
656{ 323{
324 struct gfs2_sbd *sdp = ip->i_inode.i_sb->s_fs_info;
657 struct buffer_head *dibh; 325 struct buffer_head *dibh;
658 uint32_t nlink; 326 uint32_t nlink;
659 int error; 327 int error;
@@ -678,8 +346,30 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff)
678 gfs2_trans_add_bh(ip->i_gl, dibh, 1); 346 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
679 gfs2_dinode_out(&ip->i_di, dibh->b_data); 347 gfs2_dinode_out(&ip->i_di, dibh->b_data);
680 brelse(dibh); 348 brelse(dibh);
349 mark_inode_dirty(&ip->i_inode);
681 350
682 return 0; 351 if (ip->i_di.di_nlink == 0) {
352 struct gfs2_rgrpd *rgd;
353 struct gfs2_holder ri_gh, rg_gh;
354
355 error = gfs2_rindex_hold(sdp, &ri_gh);
356 if (error)
357 goto out;
358 error = -EIO;
359 rgd = gfs2_blk2rgrpd(sdp, ip->i_num.no_addr);
360 if (!rgd)
361 goto out_norgrp;
362 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &rg_gh);
363 if (error)
364 goto out_norgrp;
365
366 gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */
367 gfs2_glock_dq_uninit(&rg_gh);
368out_norgrp:
369 gfs2_glock_dq_uninit(&ri_gh);
370 }
371out:
372 return error;
683} 373}
684 374
685struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) 375struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
@@ -703,18 +393,15 @@ struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
703 * Returns: errno 393 * Returns: errno
704 */ 394 */
705 395
706struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, 396struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
707 struct nameidata *nd) 397 int is_root, struct nameidata *nd)
708 398
709{ 399{
710 struct super_block *sb = dir->i_sb; 400 struct super_block *sb = dir->i_sb;
711 struct gfs2_inode *ipp; 401 struct gfs2_inode *dip = GFS2_I(dir);
712 struct gfs2_inode *dip = dir->u.generic_ip;
713 struct gfs2_sbd *sdp = dip->i_sbd;
714 struct gfs2_holder d_gh; 402 struct gfs2_holder d_gh;
715 struct gfs2_inum inum; 403 struct gfs2_inum inum;
716 unsigned int type; 404 unsigned int type;
717 struct gfs2_glock *gl;
718 int error = 0; 405 int error = 0;
719 struct inode *inode = NULL; 406 struct inode *inode = NULL;
720 407
@@ -742,34 +429,18 @@ struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root,
742 if (error) 429 if (error)
743 goto out; 430 goto out;
744 431
745 error = gfs2_glock_get(sdp, inum.no_addr, &gfs2_inode_glops, 432 inode = gfs2_inode_lookup(sb, &inum, type);
746 CREATE, &gl);
747 if (error)
748 goto out;
749
750 error = gfs2_inode_get(gl, &inum, CREATE, &ipp);
751 if (!error)
752 gfs2_inode_min_init(ipp, type);
753
754 gfs2_glock_put(gl);
755 433
756out: 434out:
757 gfs2_glock_dq_uninit(&d_gh); 435 gfs2_glock_dq_uninit(&d_gh);
758 if (error == -ENOENT) 436 if (error == -ENOENT)
759 return NULL; 437 return NULL;
760 if (error == 0) { 438 return inode;
761 inode = gfs2_ip2v(ipp);
762 gfs2_inode_put(ipp);
763 if (!inode)
764 return ERR_PTR(-ENOMEM);
765 return inode;
766 }
767 return ERR_PTR(error);
768} 439}
769 440
770static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino) 441static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino)
771{ 442{
772 struct gfs2_inode *ip = sdp->sd_ir_inode->u.generic_ip; 443 struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode);
773 struct buffer_head *bh; 444 struct buffer_head *bh;
774 struct gfs2_inum_range ir; 445 struct gfs2_inum_range ir;
775 int error; 446 int error;
@@ -810,8 +481,8 @@ static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino)
810 481
811static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino) 482static int pick_formal_ino_2(struct gfs2_sbd *sdp, uint64_t *formal_ino)
812{ 483{
813 struct gfs2_inode *ip = sdp->sd_ir_inode->u.generic_ip; 484 struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode);
814 struct gfs2_inode *m_ip = sdp->sd_inum_inode->u.generic_ip; 485 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_inum_inode);
815 struct gfs2_holder gh; 486 struct gfs2_holder gh;
816 struct buffer_head *bh; 487 struct buffer_head *bh;
817 struct gfs2_inum_range ir; 488 struct gfs2_inum_range ir;
@@ -895,12 +566,12 @@ static int pick_formal_ino(struct gfs2_sbd *sdp, uint64_t *inum)
895 * Returns: errno 566 * Returns: errno
896 */ 567 */
897 568
898static int create_ok(struct gfs2_inode *dip, struct qstr *name, 569static int create_ok(struct gfs2_inode *dip, const struct qstr *name,
899 unsigned int mode) 570 unsigned int mode)
900{ 571{
901 int error; 572 int error;
902 573
903 error = gfs2_repermission(dip->i_vnode, MAY_WRITE | MAY_EXEC, NULL); 574 error = gfs2_repermission(&dip->i_inode, MAY_WRITE | MAY_EXEC, NULL);
904 if (error) 575 if (error)
905 return error; 576 return error;
906 577
@@ -908,7 +579,7 @@ static int create_ok(struct gfs2_inode *dip, struct qstr *name,
908 if (!dip->i_di.di_nlink) 579 if (!dip->i_di.di_nlink)
909 return -EPERM; 580 return -EPERM;
910 581
911 error = gfs2_dir_search(dip->i_vnode, name, NULL, NULL); 582 error = gfs2_dir_search(&dip->i_inode, name, NULL, NULL);
912 switch (error) { 583 switch (error) {
913 case -ENOENT: 584 case -ENOENT:
914 error = 0; 585 error = 0;
@@ -930,7 +601,7 @@ static int create_ok(struct gfs2_inode *dip, struct qstr *name,
930static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, 601static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode,
931 unsigned int *uid, unsigned int *gid) 602 unsigned int *uid, unsigned int *gid)
932{ 603{
933 if (dip->i_sbd->sd_args.ar_suiddir && 604 if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir &&
934 (dip->i_di.di_mode & S_ISUID) && 605 (dip->i_di.di_mode & S_ISUID) &&
935 dip->i_di.di_uid) { 606 dip->i_di.di_uid) {
936 if (S_ISDIR(*mode)) 607 if (S_ISDIR(*mode))
@@ -949,9 +620,9 @@ static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode,
949 *gid = current->fsgid; 620 *gid = current->fsgid;
950} 621}
951 622
952static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_unlinked *ul) 623static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_inum *inum)
953{ 624{
954 struct gfs2_sbd *sdp = dip->i_sbd; 625 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
955 int error; 626 int error;
956 627
957 gfs2_alloc_get(dip); 628 gfs2_alloc_get(dip);
@@ -961,15 +632,11 @@ static int alloc_dinode(struct gfs2_inode *dip, struct gfs2_unlinked *ul)
961 if (error) 632 if (error)
962 goto out; 633 goto out;
963 634
964 error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_UNLINKED + 635 error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS, 0);
965 RES_STATFS, 0);
966 if (error) 636 if (error)
967 goto out_ipreserv; 637 goto out_ipreserv;
968 638
969 ul->ul_ut.ut_inum.no_addr = gfs2_alloc_di(dip); 639 inum->no_addr = gfs2_alloc_di(dip);
970
971 ul->ul_ut.ut_flags = GFS2_UTF_UNINIT;
972 error = gfs2_unlinked_ondisk_add(sdp, ul);
973 640
974 gfs2_trans_end(sdp); 641 gfs2_trans_end(sdp);
975 642
@@ -997,7 +664,7 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
997 struct gfs2_inum *inum, unsigned int mode, 664 struct gfs2_inum *inum, unsigned int mode,
998 unsigned int uid, unsigned int gid) 665 unsigned int uid, unsigned int gid)
999{ 666{
1000 struct gfs2_sbd *sdp = dip->i_sbd; 667 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1001 struct gfs2_dinode *di; 668 struct gfs2_dinode *di;
1002 struct buffer_head *dibh; 669 struct buffer_head *dibh;
1003 670
@@ -1049,9 +716,9 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
1049} 716}
1050 717
1051static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, 718static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
1052 unsigned int mode, struct gfs2_unlinked *ul) 719 unsigned int mode, struct gfs2_inum *inum)
1053{ 720{
1054 struct gfs2_sbd *sdp = dip->i_sbd; 721 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1055 unsigned int uid, gid; 722 unsigned int uid, gid;
1056 int error; 723 int error;
1057 724
@@ -1066,28 +733,25 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
1066 if (error) 733 if (error)
1067 goto out_quota; 734 goto out_quota;
1068 735
1069 error = gfs2_trans_begin(sdp, RES_DINODE + RES_UNLINKED + RES_QUOTA, 0); 736 error = gfs2_trans_begin(sdp, RES_DINODE + RES_QUOTA, 0);
1070 if (error) 737 if (error)
1071 goto out_quota; 738 goto out_quota;
1072 739
1073 ul->ul_ut.ut_flags = 0; 740 init_dinode(dip, gl, inum, mode, uid, gid);
1074 error = gfs2_unlinked_ondisk_munge(sdp, ul);
1075 init_dinode(dip, gl, &ul->ul_ut.ut_inum, mode, uid, gid);
1076 gfs2_quota_change(dip, +1, uid, gid); 741 gfs2_quota_change(dip, +1, uid, gid);
1077 gfs2_trans_end(sdp); 742 gfs2_trans_end(sdp);
1078 743
1079 out_quota: 744out_quota:
1080 gfs2_quota_unlock(dip); 745 gfs2_quota_unlock(dip);
1081 746out:
1082 out:
1083 gfs2_alloc_put(dip); 747 gfs2_alloc_put(dip);
1084 return error; 748 return error;
1085} 749}
1086 750
1087static int link_dinode(struct gfs2_inode *dip, struct qstr *name, 751static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
1088 struct gfs2_inode *ip, struct gfs2_unlinked *ul) 752 struct gfs2_inode *ip)
1089{ 753{
1090 struct gfs2_sbd *sdp = dip->i_sbd; 754 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1091 struct gfs2_alloc *al; 755 struct gfs2_alloc *al;
1092 int alloc_required; 756 int alloc_required;
1093 struct buffer_head *dibh; 757 struct buffer_head *dibh;
@@ -1099,7 +763,7 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name,
1099 if (error) 763 if (error)
1100 goto fail; 764 goto fail;
1101 765
1102 error = alloc_required = gfs2_diradd_alloc_required(dip->i_vnode, name); 766 error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name);
1103 if (alloc_required < 0) 767 if (alloc_required < 0)
1104 goto fail; 768 goto fail;
1105 if (alloc_required) { 769 if (alloc_required) {
@@ -1116,20 +780,17 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name,
1116 780
1117 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + 781 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
1118 al->al_rgd->rd_ri.ri_length + 782 al->al_rgd->rd_ri.ri_length +
1119 2 * RES_DINODE + RES_UNLINKED + 783 2 * RES_DINODE +
1120 RES_STATFS + RES_QUOTA, 0); 784 RES_STATFS + RES_QUOTA, 0);
1121 if (error) 785 if (error)
1122 goto fail_ipreserv; 786 goto fail_ipreserv;
1123 } else { 787 } else {
1124 error = gfs2_trans_begin(sdp, 788 error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0);
1125 RES_LEAF +
1126 2 * RES_DINODE +
1127 RES_UNLINKED, 0);
1128 if (error) 789 if (error)
1129 goto fail_quota_locks; 790 goto fail_quota_locks;
1130 } 791 }
1131 792
1132 error = gfs2_dir_add(dip->i_vnode, name, &ip->i_num, IF2DT(ip->i_di.di_mode)); 793 error = gfs2_dir_add(&dip->i_inode, name, &ip->i_num, IF2DT(ip->i_di.di_mode));
1133 if (error) 794 if (error)
1134 goto fail_end_trans; 795 goto fail_end_trans;
1135 796
@@ -1140,11 +801,6 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name,
1140 gfs2_trans_add_bh(ip->i_gl, dibh, 1); 801 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
1141 gfs2_dinode_out(&ip->i_di, dibh->b_data); 802 gfs2_dinode_out(&ip->i_di, dibh->b_data);
1142 brelse(dibh); 803 brelse(dibh);
1143
1144 error = gfs2_unlinked_ondisk_rm(sdp, ul);
1145 if (error)
1146 goto fail_end_trans;
1147
1148 return 0; 804 return 0;
1149 805
1150fail_end_trans: 806fail_end_trans:
@@ -1178,23 +834,19 @@ fail:
1178 * Returns: An inode 834 * Returns: An inode
1179 */ 835 */
1180 836
1181struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, 837struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
1182 unsigned int mode) 838 unsigned int mode)
1183{ 839{
1184 struct inode *inode; 840 struct inode *inode;
1185 struct gfs2_inode *dip = ghs->gh_gl->gl_object; 841 struct gfs2_inode *dip = ghs->gh_gl->gl_object;
1186 struct gfs2_sbd *sdp = dip->i_sbd; 842 struct inode *dir = &dip->i_inode;
1187 struct gfs2_unlinked *ul; 843 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1188 struct gfs2_inode *ip; 844 struct gfs2_inum inum;
1189 int error; 845 int error;
1190 846
1191 if (!name->len || name->len > GFS2_FNAMESIZE) 847 if (!name->len || name->len > GFS2_FNAMESIZE)
1192 return ERR_PTR(-ENAMETOOLONG); 848 return ERR_PTR(-ENAMETOOLONG);
1193 849
1194 error = gfs2_unlinked_get(sdp, &ul);
1195 if (error)
1196 return ERR_PTR(error);
1197
1198 gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs); 850 gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs);
1199 error = gfs2_glock_nq(ghs); 851 error = gfs2_glock_nq(ghs);
1200 if (error) 852 if (error)
@@ -1204,22 +856,21 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name,
1204 if (error) 856 if (error)
1205 goto fail_gunlock; 857 goto fail_gunlock;
1206 858
1207 error = pick_formal_ino(sdp, &ul->ul_ut.ut_inum.no_formal_ino); 859 error = pick_formal_ino(sdp, &inum.no_formal_ino);
1208 if (error) 860 if (error)
1209 goto fail_gunlock; 861 goto fail_gunlock;
1210 862
1211 error = alloc_dinode(dip, ul); 863 error = alloc_dinode(dip, &inum);
1212 if (error) 864 if (error)
1213 goto fail_gunlock; 865 goto fail_gunlock;
1214 866
1215 if (ul->ul_ut.ut_inum.no_addr < dip->i_num.no_addr) { 867 if (inum.no_addr < dip->i_num.no_addr) {
1216 gfs2_glock_dq(ghs); 868 gfs2_glock_dq(ghs);
1217 869
1218 error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, 870 error = gfs2_glock_nq_num(sdp, inum.no_addr,
1219 &gfs2_inode_glops, LM_ST_EXCLUSIVE, 871 &gfs2_inode_glops, LM_ST_EXCLUSIVE,
1220 GL_SKIP, ghs + 1); 872 GL_SKIP, ghs + 1);
1221 if (error) { 873 if (error) {
1222 gfs2_unlinked_put(sdp, ul);
1223 return ERR_PTR(error); 874 return ERR_PTR(error);
1224 } 875 }
1225 876
@@ -1227,7 +878,6 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name,
1227 error = gfs2_glock_nq(ghs); 878 error = gfs2_glock_nq(ghs);
1228 if (error) { 879 if (error) {
1229 gfs2_glock_dq_uninit(ghs + 1); 880 gfs2_glock_dq_uninit(ghs + 1);
1230 gfs2_unlinked_put(sdp, ul);
1231 return ERR_PTR(error); 881 return ERR_PTR(error);
1232 } 882 }
1233 883
@@ -1235,95 +885,48 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name,
1235 if (error) 885 if (error)
1236 goto fail_gunlock2; 886 goto fail_gunlock2;
1237 } else { 887 } else {
1238 error = gfs2_glock_nq_num(sdp, ul->ul_ut.ut_inum.no_addr, 888 error = gfs2_glock_nq_num(sdp, inum.no_addr,
1239 &gfs2_inode_glops, LM_ST_EXCLUSIVE, 889 &gfs2_inode_glops, LM_ST_EXCLUSIVE,
1240 GL_SKIP, ghs + 1); 890 GL_SKIP, ghs + 1);
1241 if (error) 891 if (error)
1242 goto fail_gunlock; 892 goto fail_gunlock;
1243 } 893 }
1244 894
1245 error = make_dinode(dip, ghs[1].gh_gl, mode, ul); 895 error = make_dinode(dip, ghs[1].gh_gl, mode, &inum);
1246 if (error) 896 if (error)
1247 goto fail_gunlock2; 897 goto fail_gunlock2;
1248 898
1249 error = gfs2_inode_get(ghs[1].gh_gl, &ul->ul_ut.ut_inum, CREATE, &ip); 899 inode = gfs2_inode_lookup(dir->i_sb, &inum, IF2DT(mode));
1250 if (error) 900 if (IS_ERR(inode))
1251 goto fail_gunlock2; 901 goto fail_gunlock2;
1252 902
1253 error = gfs2_inode_refresh(ip); 903 error = gfs2_inode_refresh(GFS2_I(inode));
1254 if (error) 904 if (error)
1255 goto fail_iput; 905 goto fail_iput;
1256 906
1257 error = gfs2_acl_create(dip, ip); 907 error = gfs2_acl_create(dip, GFS2_I(inode));
1258 if (error) 908 if (error)
1259 goto fail_iput; 909 goto fail_iput;
1260 910
1261 error = link_dinode(dip, name, ip, ul); 911 error = link_dinode(dip, name, GFS2_I(inode));
1262 if (error) 912 if (error)
1263 goto fail_iput; 913 goto fail_iput;
1264 914
1265 gfs2_unlinked_put(sdp, ul);
1266
1267 inode = gfs2_ip2v(ip);
1268 gfs2_inode_put(ip);
1269 if (!inode) 915 if (!inode)
1270 return ERR_PTR(-ENOMEM); 916 return ERR_PTR(-ENOMEM);
1271 return inode; 917 return inode;
1272 918
1273fail_iput: 919fail_iput:
1274 gfs2_inode_put(ip); 920 iput(inode);
1275
1276fail_gunlock2: 921fail_gunlock2:
1277 gfs2_glock_dq_uninit(ghs + 1); 922 gfs2_glock_dq_uninit(ghs + 1);
1278
1279fail_gunlock: 923fail_gunlock:
1280 gfs2_glock_dq(ghs); 924 gfs2_glock_dq(ghs);
1281
1282fail: 925fail:
1283 gfs2_unlinked_put(sdp, ul);
1284 return ERR_PTR(error); 926 return ERR_PTR(error);
1285} 927}
1286 928
1287/** 929/**
1288 * gfs2_unlinki - Unlink a file
1289 * @dip: The inode of the directory
1290 * @name: The name of the file to be unlinked
1291 * @ip: The inode of the file to be removed
1292 *
1293 * Assumes Glocks on both dip and ip are held.
1294 *
1295 * Returns: errno
1296 */
1297
1298int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name,
1299 struct gfs2_inode *ip, struct gfs2_unlinked *ul)
1300{
1301 struct gfs2_sbd *sdp = dip->i_sbd;
1302 int error;
1303
1304 error = gfs2_dir_del(dip, name);
1305 if (error)
1306 return error;
1307
1308 error = gfs2_change_nlink(ip, -1);
1309 if (error)
1310 return error;
1311
1312 /* If this inode is being unlinked from the directory structure,
1313 we need to mark that in the log so that it isn't lost during
1314 a crash. */
1315
1316 if (!ip->i_di.di_nlink) {
1317 ul->ul_ut.ut_inum = ip->i_num;
1318 error = gfs2_unlinked_ondisk_add(sdp, ul);
1319 if (!error)
1320 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
1321 }
1322
1323 return error;
1324}
1325
1326/**
1327 * gfs2_rmdiri - Remove a directory 930 * gfs2_rmdiri - Remove a directory
1328 * @dip: The parent directory of the directory to be removed 931 * @dip: The parent directory of the directory to be removed
1329 * @name: The name of the directory to be removed 932 * @name: The name of the directory to be removed
@@ -1334,10 +937,9 @@ int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name,
1334 * Returns: errno 937 * Returns: errno
1335 */ 938 */
1336 939
1337int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, 940int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name,
1338 struct gfs2_inode *ip, struct gfs2_unlinked *ul) 941 struct gfs2_inode *ip)
1339{ 942{
1340 struct gfs2_sbd *sdp = dip->i_sbd;
1341 struct qstr dotname; 943 struct qstr dotname;
1342 int error; 944 int error;
1343 945
@@ -1360,9 +962,7 @@ int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name,
1360 if (error) 962 if (error)
1361 return error; 963 return error;
1362 964
1363 dotname.len = 2; 965 gfs2_str2qstr(&dotname, "..");
1364 dotname.name = "..";
1365 dotname.hash = gfs2_disk_hash(dotname.name, dotname.len);
1366 error = gfs2_dir_del(ip, &dotname); 966 error = gfs2_dir_del(ip, &dotname);
1367 if (error) 967 if (error)
1368 return error; 968 return error;
@@ -1371,15 +971,6 @@ int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name,
1371 if (error) 971 if (error)
1372 return error; 972 return error;
1373 973
1374 /* This inode is being unlinked from the directory structure and
1375 we need to mark that in the log so that it isn't lost during
1376 a crash. */
1377
1378 ul->ul_ut.ut_inum = ip->i_num;
1379 error = gfs2_unlinked_ondisk_add(sdp, ul);
1380 if (!error)
1381 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
1382
1383 return error; 974 return error;
1384} 975}
1385 976
@@ -1394,30 +985,29 @@ int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name,
1394 * Returns: 0 if the parent/child relationship is correct, errno if it isn't 985 * Returns: 0 if the parent/child relationship is correct, errno if it isn't
1395 */ 986 */
1396 987
1397int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name, 988int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
1398 struct gfs2_inode *ip) 989 struct gfs2_inode *ip)
1399{ 990{
1400 struct gfs2_inum inum; 991 struct gfs2_inum inum;
1401 unsigned int type; 992 unsigned int type;
1402 int error; 993 int error;
1403 994
1404 if (IS_IMMUTABLE(ip->i_vnode) || IS_APPEND(ip->i_vnode)) 995 if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
1405 return -EPERM; 996 return -EPERM;
1406 997
1407 if ((dip->i_di.di_mode & S_ISVTX) && 998 if ((dip->i_di.di_mode & S_ISVTX) &&
1408 dip->i_di.di_uid != current->fsuid && 999 dip->i_di.di_uid != current->fsuid &&
1409 ip->i_di.di_uid != current->fsuid && 1000 ip->i_di.di_uid != current->fsuid && !capable(CAP_FOWNER))
1410 !capable(CAP_FOWNER))
1411 return -EPERM; 1001 return -EPERM;
1412 1002
1413 if (IS_APPEND(dip->i_vnode)) 1003 if (IS_APPEND(&dip->i_inode))
1414 return -EPERM; 1004 return -EPERM;
1415 1005
1416 error = gfs2_repermission(dip->i_vnode, MAY_WRITE | MAY_EXEC, NULL); 1006 error = gfs2_repermission(&dip->i_inode, MAY_WRITE | MAY_EXEC, NULL);
1417 if (error) 1007 if (error)
1418 return error; 1008 return error;
1419 1009
1420 error = gfs2_dir_search(dip->i_vnode, name, &inum, &type); 1010 error = gfs2_dir_search(&dip->i_inode, name, &inum, &type);
1421 if (error) 1011 if (error)
1422 return error; 1012 return error;
1423 1013
@@ -1445,7 +1035,7 @@ int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name,
1445 1035
1446int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) 1036int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
1447{ 1037{
1448 struct inode *dir = to->i_vnode; 1038 struct inode *dir = &to->i_inode;
1449 struct super_block *sb = dir->i_sb; 1039 struct super_block *sb = dir->i_sb;
1450 struct inode *tmp; 1040 struct inode *tmp;
1451 struct qstr dotdot; 1041 struct qstr dotdot;
@@ -1456,7 +1046,7 @@ int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
1456 igrab(dir); 1046 igrab(dir);
1457 1047
1458 for (;;) { 1048 for (;;) {
1459 if (dir == this->i_vnode) { 1049 if (dir == &this->i_inode) {
1460 error = -EINVAL; 1050 error = -EINVAL;
1461 break; 1051 break;
1462 } 1052 }
@@ -1528,12 +1118,10 @@ int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len)
1528 memcpy(*buf, dibh->b_data + sizeof(struct gfs2_dinode), x); 1118 memcpy(*buf, dibh->b_data + sizeof(struct gfs2_dinode), x);
1529 *len = x; 1119 *len = x;
1530 1120
1531 out_brelse: 1121out_brelse:
1532 brelse(dibh); 1122 brelse(dibh);
1533 1123out:
1534 out:
1535 gfs2_glock_dq_uninit(&i_gh); 1124 gfs2_glock_dq_uninit(&i_gh);
1536
1537 return error; 1125 return error;
1538} 1126}
1539 1127
@@ -1622,12 +1210,10 @@ int gfs2_glock_nq_atime(struct gfs2_holder *gh)
1622 1210
1623 return 0; 1211 return 0;
1624 1212
1625 fail_end_trans: 1213fail_end_trans:
1626 gfs2_trans_end(sdp); 1214 gfs2_trans_end(sdp);
1627 1215fail:
1628 fail:
1629 gfs2_glock_dq(gh); 1216 gfs2_glock_dq(gh);
1630
1631 return error; 1217 return error;
1632} 1218}
1633 1219
@@ -1722,49 +1308,6 @@ int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs)
1722 return error; 1308 return error;
1723} 1309}
1724 1310
1725/**
1726 * gfs2_try_toss_vnode - See if we can toss a vnode from memory
1727 * @ip: the inode
1728 *
1729 * Returns: 1 if the vnode was tossed
1730 */
1731
1732void gfs2_try_toss_vnode(struct gfs2_inode *ip)
1733{
1734 struct inode *inode;
1735
1736 inode = gfs2_ip2v_lookup(ip);
1737 if (!inode)
1738 return;
1739
1740 d_prune_aliases(inode);
1741
1742 if (S_ISDIR(ip->i_di.di_mode)) {
1743 struct list_head *head = &inode->i_dentry;
1744 struct dentry *d = NULL;
1745
1746 spin_lock(&dcache_lock);
1747 if (list_empty(head))
1748 spin_unlock(&dcache_lock);
1749 else {
1750 d = list_entry(head->next, struct dentry, d_alias);
1751 dget_locked(d);
1752 spin_unlock(&dcache_lock);
1753
1754 if (have_submounts(d))
1755 dput(d);
1756 else {
1757 shrink_dcache_parent(d);
1758 dput(d);
1759 d_prune_aliases(inode);
1760 }
1761 }
1762 }
1763
1764 inode->i_nlink = 0;
1765 iput(inode);
1766}
1767
1768 1311
1769static int 1312static int
1770__gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) 1313__gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
@@ -1774,8 +1317,8 @@ __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
1774 1317
1775 error = gfs2_meta_inode_buffer(ip, &dibh); 1318 error = gfs2_meta_inode_buffer(ip, &dibh);
1776 if (!error) { 1319 if (!error) {
1777 error = inode_setattr(ip->i_vnode, attr); 1320 error = inode_setattr(&ip->i_inode, attr);
1778 gfs2_assert_warn(ip->i_sbd, !error); 1321 gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error);
1779 gfs2_inode_attr_out(ip); 1322 gfs2_inode_attr_out(ip);
1780 1323
1781 gfs2_trans_add_bh(ip->i_gl, dibh, 1); 1324 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
@@ -1802,13 +1345,13 @@ int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
1802 if (current->journal_info) 1345 if (current->journal_info)
1803 return __gfs2_setattr_simple(ip, attr); 1346 return __gfs2_setattr_simple(ip, attr);
1804 1347
1805 error = gfs2_trans_begin(ip->i_sbd, RES_DINODE, 0); 1348 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE, 0);
1806 if (error) 1349 if (error)
1807 return error; 1350 return error;
1808 1351
1809 error = __gfs2_setattr_simple(ip, attr); 1352 error = __gfs2_setattr_simple(ip, attr);
1810 1353
1811 gfs2_trans_end(ip->i_sbd); 1354 gfs2_trans_end(GFS2_SB(&ip->i_inode));
1812 1355
1813 return error; 1356 return error;
1814} 1357}
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index 5ef21317b2f6..30cfcc10beb2 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -27,32 +27,20 @@ static inline int gfs2_is_dir(struct gfs2_inode *ip)
27 27
28void gfs2_inode_attr_in(struct gfs2_inode *ip); 28void gfs2_inode_attr_in(struct gfs2_inode *ip);
29void gfs2_inode_attr_out(struct gfs2_inode *ip); 29void gfs2_inode_attr_out(struct gfs2_inode *ip);
30struct inode *gfs2_ip2v_lookup(struct gfs2_inode *ip); 30struct inode *gfs2_inode_lookup(struct super_block *sb, struct gfs2_inum *inum, unsigned type);
31struct inode *gfs2_ip2v(struct gfs2_inode *ip); 31struct inode *gfs2_ilookup(struct super_block *sb, struct gfs2_inum *inum);
32struct inode *gfs2_iget(struct super_block *sb, struct gfs2_inum *inum);
33 32
34void gfs2_inode_min_init(struct gfs2_inode *ip, unsigned int type);
35int gfs2_inode_refresh(struct gfs2_inode *ip); 33int gfs2_inode_refresh(struct gfs2_inode *ip);
36 34
37int gfs2_inode_get(struct gfs2_glock *i_gl, 35int gfs2_dinode_dealloc(struct gfs2_inode *inode);
38 const struct gfs2_inum *inum, int create,
39 struct gfs2_inode **ipp);
40void gfs2_inode_hold(struct gfs2_inode *ip);
41void gfs2_inode_put(struct gfs2_inode *ip);
42void gfs2_inode_destroy(struct gfs2_inode *ip, int unlock);
43
44int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul);
45
46int gfs2_change_nlink(struct gfs2_inode *ip, int diff); 36int gfs2_change_nlink(struct gfs2_inode *ip, int diff);
47struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root, 37struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
48 struct nameidata *nd); 38 int is_root, struct nameidata *nd);
49struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name, 39struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
50 unsigned int mode); 40 unsigned int mode);
51int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name, 41int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name,
52 struct gfs2_inode *ip, struct gfs2_unlinked *ul); 42 struct gfs2_inode *ip);
53int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name, 43int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
54 struct gfs2_inode *ip, struct gfs2_unlinked *ul);
55int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name,
56 struct gfs2_inode *ip); 44 struct gfs2_inode *ip);
57int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to); 45int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to);
58int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len); 46int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len);
@@ -60,8 +48,6 @@ int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len);
60int gfs2_glock_nq_atime(struct gfs2_holder *gh); 48int gfs2_glock_nq_atime(struct gfs2_holder *gh);
61int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs); 49int gfs2_glock_nq_m_atime(unsigned int num_gh, struct gfs2_holder *ghs);
62 50
63void gfs2_try_toss_vnode(struct gfs2_inode *ip);
64
65int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr); 51int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr);
66 52
67int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd); 53int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd);
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 2a8b4b71dd1f..483d4fa987f6 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -213,6 +213,9 @@ static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn)
213 int bdy; 213 int bdy;
214 214
215 error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, &new, &dbn, &bdy); 215 error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, &new, &dbn, &bdy);
216 if (!(!error && dbn)) {
217 printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, dbn, lbn);
218 }
216 gfs2_assert_withdraw(sdp, !error && dbn); 219 gfs2_assert_withdraw(sdp, !error && dbn);
217 220
218 return dbn; 221 return dbn;
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index e4c75a74df5b..a76f1a778920 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -184,8 +184,7 @@ static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
184static void buf_lo_before_scan(struct gfs2_jdesc *jd, 184static void buf_lo_before_scan(struct gfs2_jdesc *jd,
185 struct gfs2_log_header *head, int pass) 185 struct gfs2_log_header *head, int pass)
186{ 186{
187 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 187 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
188 struct gfs2_sbd *sdp = ip->i_sbd;
189 188
190 if (pass != 0) 189 if (pass != 0)
191 return; 190 return;
@@ -198,8 +197,8 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
198 struct gfs2_log_descriptor *ld, __be64 *ptr, 197 struct gfs2_log_descriptor *ld, __be64 *ptr,
199 int pass) 198 int pass)
200{ 199{
201 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 200 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
202 struct gfs2_sbd *sdp = ip->i_sbd; 201 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
203 struct gfs2_glock *gl = ip->i_gl; 202 struct gfs2_glock *gl = ip->i_gl;
204 unsigned int blks = be32_to_cpu(ld->ld_data1); 203 unsigned int blks = be32_to_cpu(ld->ld_data1);
205 struct buffer_head *bh_log, *bh_ip; 204 struct buffer_head *bh_log, *bh_ip;
@@ -245,8 +244,8 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
245 244
246static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) 245static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
247{ 246{
248 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 247 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
249 struct gfs2_sbd *sdp = ip->i_sbd; 248 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
250 249
251 if (error) { 250 if (error) {
252 gfs2_meta_sync(ip->i_gl, 251 gfs2_meta_sync(ip->i_gl,
@@ -332,8 +331,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp)
332static void revoke_lo_before_scan(struct gfs2_jdesc *jd, 331static void revoke_lo_before_scan(struct gfs2_jdesc *jd,
333 struct gfs2_log_header *head, int pass) 332 struct gfs2_log_header *head, int pass)
334{ 333{
335 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 334 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
336 struct gfs2_sbd *sdp = ip->i_sbd;
337 335
338 if (pass != 0) 336 if (pass != 0)
339 return; 337 return;
@@ -346,8 +344,7 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
346 struct gfs2_log_descriptor *ld, __be64 *ptr, 344 struct gfs2_log_descriptor *ld, __be64 *ptr,
347 int pass) 345 int pass)
348{ 346{
349 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 347 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
350 struct gfs2_sbd *sdp = ip->i_sbd;
351 unsigned int blks = be32_to_cpu(ld->ld_length); 348 unsigned int blks = be32_to_cpu(ld->ld_length);
352 unsigned int revokes = be32_to_cpu(ld->ld_data1); 349 unsigned int revokes = be32_to_cpu(ld->ld_data1);
353 struct buffer_head *bh; 350 struct buffer_head *bh;
@@ -393,8 +390,7 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
393 390
394static void revoke_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) 391static void revoke_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
395{ 392{
396 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 393 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
397 struct gfs2_sbd *sdp = ip->i_sbd;
398 394
399 if (error) { 395 if (error) {
400 gfs2_revoke_clean(sdp); 396 gfs2_revoke_clean(sdp);
@@ -465,7 +461,7 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
465 struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le); 461 struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le);
466 struct gfs2_trans *tr = current->journal_info; 462 struct gfs2_trans *tr = current->journal_info;
467 struct address_space *mapping = bd->bd_bh->b_page->mapping; 463 struct address_space *mapping = bd->bd_bh->b_page->mapping;
468 struct gfs2_inode *ip = mapping->host->u.generic_ip; 464 struct gfs2_inode *ip = GFS2_I(mapping->host);
469 465
470 tr->tr_touched = 1; 466 tr->tr_touched = 1;
471 if (!list_empty(&bd->bd_list_tr) && 467 if (!list_empty(&bd->bd_list_tr) &&
@@ -665,8 +661,8 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
665 struct gfs2_log_descriptor *ld, 661 struct gfs2_log_descriptor *ld,
666 __be64 *ptr, int pass) 662 __be64 *ptr, int pass)
667{ 663{
668 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 664 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
669 struct gfs2_sbd *sdp = ip->i_sbd; 665 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
670 struct gfs2_glock *gl = ip->i_gl; 666 struct gfs2_glock *gl = ip->i_gl;
671 unsigned int blks = be32_to_cpu(ld->ld_data1); 667 unsigned int blks = be32_to_cpu(ld->ld_data1);
672 struct buffer_head *bh_log, *bh_ip; 668 struct buffer_head *bh_log, *bh_ip;
@@ -716,8 +712,8 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
716 712
717static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) 713static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
718{ 714{
719 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 715 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
720 struct gfs2_sbd *sdp = ip->i_sbd; 716 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
721 717
722 if (error) { 718 if (error) {
723 gfs2_meta_sync(ip->i_gl, 719 gfs2_meta_sync(ip->i_gl,
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index b24d0b40d965..c112943ee8c1 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -29,8 +29,6 @@ static void gfs2_init_inode_once(void *foo, kmem_cache_t *cachep, unsigned long
29 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == 29 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
30 SLAB_CTOR_CONSTRUCTOR) { 30 SLAB_CTOR_CONSTRUCTOR) {
31 inode_init_once(&ip->i_inode); 31 inode_init_once(&ip->i_inode);
32 atomic_set(&ip->i_count, 0);
33 ip->i_vnode = &ip->i_inode;
34 spin_lock_init(&ip->i_spin); 32 spin_lock_init(&ip->i_spin);
35 init_rwsem(&ip->i_rw_mutex); 33 init_rwsem(&ip->i_rw_mutex);
36 memset(ip->i_cache, 0, sizeof(ip->i_cache)); 34 memset(ip->i_cache, 0, sizeof(ip->i_cache));
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index c78517225f61..2523d42a02de 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -91,9 +91,6 @@ static void stuck_releasepage(struct buffer_head *bh)
91 fs_warn(sdp, "ip = %llu %llu\n", 91 fs_warn(sdp, "ip = %llu %llu\n",
92 (unsigned long long)ip->i_num.no_formal_ino, 92 (unsigned long long)ip->i_num.no_formal_ino,
93 (unsigned long long)ip->i_num.no_addr); 93 (unsigned long long)ip->i_num.no_addr);
94 fs_warn(sdp, "ip->i_count = %d, ip->i_vnode = %s\n",
95 atomic_read(&ip->i_count),
96 (ip->i_vnode) ? "!NULL" : "NULL");
97 94
98 for (x = 0; x < GFS2_MAX_META_HEIGHT; x++) 95 for (x = 0; x < GFS2_MAX_META_HEIGHT; x++)
99 fs_warn(sdp, "ip->i_cache[%u] = %s\n", 96 fs_warn(sdp, "ip->i_cache[%u] = %s\n",
@@ -567,7 +564,6 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh,
567 564
568 bd = kmem_cache_alloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL), 565 bd = kmem_cache_alloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL),
569 memset(bd, 0, sizeof(struct gfs2_bufdata)); 566 memset(bd, 0, sizeof(struct gfs2_bufdata));
570
571 bd->bd_bh = bh; 567 bd->bd_bh = bh;
572 bd->bd_gl = gl; 568 bd->bd_gl = gl;
573 569
@@ -664,7 +660,7 @@ void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,
664 660
665void gfs2_meta_wipe(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) 661void gfs2_meta_wipe(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen)
666{ 662{
667 struct gfs2_sbd *sdp = ip->i_sbd; 663 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
668 struct inode *aspace = ip->i_gl->gl_aspace; 664 struct inode *aspace = ip->i_gl->gl_aspace;
669 struct buffer_head *bh; 665 struct buffer_head *bh;
670 666
@@ -770,7 +766,7 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num,
770 if (new) 766 if (new)
771 meta_prep_new(bh); 767 meta_prep_new(bh);
772 else { 768 else {
773 error = gfs2_meta_reread(ip->i_sbd, bh, 769 error = gfs2_meta_reread(GFS2_SB(&ip->i_inode), bh,
774 DIO_START | DIO_WAIT); 770 DIO_START | DIO_WAIT);
775 if (error) { 771 if (error) {
776 brelse(bh); 772 brelse(bh);
@@ -797,7 +793,7 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num,
797 } 793 }
798 794
799 if (new) { 795 if (new) {
800 if (gfs2_assert_warn(ip->i_sbd, height)) { 796 if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), height)) {
801 brelse(bh); 797 brelse(bh);
802 return -EIO; 798 return -EIO;
803 } 799 }
@@ -805,7 +801,7 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, uint64_t num,
805 gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); 801 gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN);
806 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); 802 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header));
807 803
808 } else if (gfs2_metatype_check(ip->i_sbd, bh, 804 } else if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh,
809 (height) ? GFS2_METATYPE_IN : GFS2_METATYPE_DI)) { 805 (height) ? GFS2_METATYPE_IN : GFS2_METATYPE_DI)) {
810 brelse(bh); 806 brelse(bh);
811 return -EIO; 807 return -EIO;
diff --git a/fs/gfs2/ondisk.c b/fs/gfs2/ondisk.c
index be5c86e5787e..09154ad7b270 100644
--- a/fs/gfs2/ondisk.c
+++ b/fs/gfs2/ondisk.c
@@ -293,23 +293,6 @@ void gfs2_statfs_change_out(struct gfs2_statfs_change *sc, char *buf)
293 str->sc_dinodes = cpu_to_be64(sc->sc_dinodes); 293 str->sc_dinodes = cpu_to_be64(sc->sc_dinodes);
294} 294}
295 295
296void gfs2_unlinked_tag_in(struct gfs2_unlinked_tag *ut, char *buf)
297{
298 struct gfs2_unlinked_tag *str = (struct gfs2_unlinked_tag *)buf;
299
300 gfs2_inum_in(&ut->ut_inum, buf);
301 ut->ut_flags = be32_to_cpu(str->ut_flags);
302}
303
304void gfs2_unlinked_tag_out(struct gfs2_unlinked_tag *ut, char *buf)
305{
306 struct gfs2_unlinked_tag *str = (struct gfs2_unlinked_tag *)buf;
307
308 gfs2_inum_out(&ut->ut_inum, buf);
309 str->ut_flags = cpu_to_be32(ut->ut_flags);
310 str->__pad = 0;
311}
312
313void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf) 296void gfs2_quota_change_in(struct gfs2_quota_change *qc, char *buf)
314{ 297{
315 struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf; 298 struct gfs2_quota_change *str = (struct gfs2_quota_change *)buf;
diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c
index 16d3ebd32092..207363aed112 100644
--- a/fs/gfs2/ops_address.c
+++ b/fs/gfs2/ops_address.c
@@ -81,7 +81,6 @@ int gfs2_get_block(struct inode *inode, sector_t lblock,
81static int get_block_noalloc(struct inode *inode, sector_t lblock, 81static int get_block_noalloc(struct inode *inode, sector_t lblock,
82 struct buffer_head *bh_result, int create) 82 struct buffer_head *bh_result, int create)
83{ 83{
84 struct gfs2_inode *ip = inode->u.generic_ip;
85 int new = 0; 84 int new = 0;
86 uint64_t dblock; 85 uint64_t dblock;
87 int error; 86 int error;
@@ -93,7 +92,7 @@ static int get_block_noalloc(struct inode *inode, sector_t lblock,
93 92
94 if (dblock) 93 if (dblock)
95 map_bh(bh_result, inode->i_sb, dblock); 94 map_bh(bh_result, inode->i_sb, dblock);
96 else if (gfs2_assert_withdraw(ip->i_sbd, !create)) 95 else if (gfs2_assert_withdraw(GFS2_SB(inode), !create))
97 error = -EIO; 96 error = -EIO;
98 if (boundary) 97 if (boundary)
99 set_buffer_boundary(bh_result); 98 set_buffer_boundary(bh_result);
@@ -114,8 +113,8 @@ static int get_block_noalloc(struct inode *inode, sector_t lblock,
114static int gfs2_writepage(struct page *page, struct writeback_control *wbc) 113static int gfs2_writepage(struct page *page, struct writeback_control *wbc)
115{ 114{
116 struct inode *inode = page->mapping->host; 115 struct inode *inode = page->mapping->host;
117 struct gfs2_inode *ip = page->mapping->host->u.generic_ip; 116 struct gfs2_inode *ip = GFS2_I(page->mapping->host);
118 struct gfs2_sbd *sdp = ip->i_sbd; 117 struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
119 loff_t i_size = i_size_read(inode); 118 loff_t i_size = i_size_read(inode);
120 pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT; 119 pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
121 unsigned offset; 120 unsigned offset;
@@ -216,8 +215,8 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
216 215
217static int gfs2_readpage(struct file *file, struct page *page) 216static int gfs2_readpage(struct file *file, struct page *page)
218{ 217{
219 struct gfs2_inode *ip = page->mapping->host->u.generic_ip; 218 struct gfs2_inode *ip = GFS2_I(page->mapping->host);
220 struct gfs2_sbd *sdp = ip->i_sbd; 219 struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
221 struct gfs2_holder gh; 220 struct gfs2_holder gh;
222 int error; 221 int error;
223 222
@@ -271,8 +270,8 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping,
271 struct list_head *pages, unsigned nr_pages) 270 struct list_head *pages, unsigned nr_pages)
272{ 271{
273 struct inode *inode = mapping->host; 272 struct inode *inode = mapping->host;
274 struct gfs2_inode *ip = inode->u.generic_ip; 273 struct gfs2_inode *ip = GFS2_I(inode);
275 struct gfs2_sbd *sdp = ip->i_sbd; 274 struct gfs2_sbd *sdp = GFS2_SB(inode);
276 struct gfs2_holder gh; 275 struct gfs2_holder gh;
277 unsigned page_idx; 276 unsigned page_idx;
278 int ret; 277 int ret;
@@ -345,8 +344,8 @@ out_unlock:
345static int gfs2_prepare_write(struct file *file, struct page *page, 344static int gfs2_prepare_write(struct file *file, struct page *page,
346 unsigned from, unsigned to) 345 unsigned from, unsigned to)
347{ 346{
348 struct gfs2_inode *ip = page->mapping->host->u.generic_ip; 347 struct gfs2_inode *ip = GFS2_I(page->mapping->host);
349 struct gfs2_sbd *sdp = ip->i_sbd; 348 struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
350 unsigned int data_blocks, ind_blocks, rblocks; 349 unsigned int data_blocks, ind_blocks, rblocks;
351 int alloc_required; 350 int alloc_required;
352 int error = 0; 351 int error = 0;
@@ -440,8 +439,8 @@ static int gfs2_commit_write(struct file *file, struct page *page,
440 unsigned from, unsigned to) 439 unsigned from, unsigned to)
441{ 440{
442 struct inode *inode = page->mapping->host; 441 struct inode *inode = page->mapping->host;
443 struct gfs2_inode *ip = inode->u.generic_ip; 442 struct gfs2_inode *ip = GFS2_I(inode);
444 struct gfs2_sbd *sdp = ip->i_sbd; 443 struct gfs2_sbd *sdp = GFS2_SB(inode);
445 int error = -EOPNOTSUPP; 444 int error = -EOPNOTSUPP;
446 struct buffer_head *dibh; 445 struct buffer_head *dibh;
447 struct gfs2_alloc *al = &ip->i_alloc;; 446 struct gfs2_alloc *al = &ip->i_alloc;;
@@ -520,7 +519,7 @@ fail_nounlock:
520 519
521static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock) 520static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock)
522{ 521{
523 struct gfs2_inode *ip = mapping->host->u.generic_ip; 522 struct gfs2_inode *ip = GFS2_I(mapping->host);
524 struct gfs2_holder i_gh; 523 struct gfs2_holder i_gh;
525 sector_t dblock = 0; 524 sector_t dblock = 0;
526 int error; 525 int error;
@@ -594,7 +593,7 @@ static ssize_t gfs2_direct_IO_write(struct kiocb *iocb, const struct iovec *iov,
594{ 593{
595 struct file *file = iocb->ki_filp; 594 struct file *file = iocb->ki_filp;
596 struct inode *inode = file->f_mapping->host; 595 struct inode *inode = file->f_mapping->host;
597 struct gfs2_inode *ip = inode->u.generic_ip; 596 struct gfs2_inode *ip = GFS2_I(inode);
598 struct gfs2_holder gh; 597 struct gfs2_holder gh;
599 int rv; 598 int rv;
600 599
@@ -641,8 +640,8 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb,
641{ 640{
642 struct file *file = iocb->ki_filp; 641 struct file *file = iocb->ki_filp;
643 struct inode *inode = file->f_mapping->host; 642 struct inode *inode = file->f_mapping->host;
644 struct gfs2_inode *ip = inode->u.generic_ip; 643 struct gfs2_inode *ip = GFS2_I(inode);
645 struct gfs2_sbd *sdp = ip->i_sbd; 644 struct gfs2_sbd *sdp = GFS2_SB(inode);
646 645
647 if (rw == WRITE) 646 if (rw == WRITE)
648 return gfs2_direct_IO_write(iocb, iov, offset, nr_segs); 647 return gfs2_direct_IO_write(iocb, iov, offset, nr_segs);
diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c
index fef415e2068e..fd55979ec428 100644
--- a/fs/gfs2/ops_dentry.c
+++ b/fs/gfs2/ops_dentry.c
@@ -38,8 +38,8 @@
38static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) 38static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
39{ 39{
40 struct dentry *parent = dget_parent(dentry); 40 struct dentry *parent = dget_parent(dentry);
41 struct gfs2_sbd *sdp = parent->d_inode->i_sb->s_fs_info; 41 struct gfs2_sbd *sdp = GFS2_SB(parent->d_inode);
42 struct gfs2_inode *dip = parent->d_inode->u.generic_ip; 42 struct gfs2_inode *dip = GFS2_I(parent->d_inode);
43 struct inode *inode = dentry->d_inode; 43 struct inode *inode = dentry->d_inode;
44 struct gfs2_holder d_gh; 44 struct gfs2_holder d_gh;
45 struct gfs2_inode *ip; 45 struct gfs2_inode *ip;
@@ -71,7 +71,7 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
71 goto fail_gunlock; 71 goto fail_gunlock;
72 } 72 }
73 73
74 ip = inode->u.generic_ip; 74 ip = GFS2_I(inode);
75 75
76 if (!gfs2_inum_equal(&ip->i_num, &inum)) 76 if (!gfs2_inum_equal(&ip->i_num, &inum))
77 goto invalid_gunlock; 77 goto invalid_gunlock;
diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c
index a376ead7d0cd..eacc1c092f91 100644
--- a/fs/gfs2/ops_export.c
+++ b/fs/gfs2/ops_export.c
@@ -66,7 +66,7 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len,
66{ 66{
67 struct inode *inode = dentry->d_inode; 67 struct inode *inode = dentry->d_inode;
68 struct super_block *sb = inode->i_sb; 68 struct super_block *sb = inode->i_sb;
69 struct gfs2_inode *ip = inode->u.generic_ip; 69 struct gfs2_inode *ip = GFS2_I(inode);
70 70
71 if (*len < 4 || (connectable && *len < 8)) 71 if (*len < 4 || (connectable && *len < 8))
72 return 255; 72 return 255;
@@ -86,8 +86,8 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len,
86 86
87 spin_lock(&dentry->d_lock); 87 spin_lock(&dentry->d_lock);
88 inode = dentry->d_parent->d_inode; 88 inode = dentry->d_parent->d_inode;
89 ip = inode->u.generic_ip; 89 ip = GFS2_I(inode);
90 gfs2_inode_hold(ip); 90 igrab(inode);
91 spin_unlock(&dentry->d_lock); 91 spin_unlock(&dentry->d_lock);
92 92
93 fh[4] = ip->i_num.no_formal_ino >> 32; 93 fh[4] = ip->i_num.no_formal_ino >> 32;
@@ -100,7 +100,7 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *fh, int *len,
100 fh[7] = cpu_to_be32(fh[7]); 100 fh[7] = cpu_to_be32(fh[7]);
101 *len = 8; 101 *len = 8;
102 102
103 gfs2_inode_put(ip); 103 iput(inode);
104 104
105 return *len; 105 return *len;
106} 106}
@@ -142,8 +142,8 @@ static int gfs2_get_name(struct dentry *parent, char *name,
142 if (!S_ISDIR(dir->i_mode) || !inode) 142 if (!S_ISDIR(dir->i_mode) || !inode)
143 return -EINVAL; 143 return -EINVAL;
144 144
145 dip = dir->u.generic_ip; 145 dip = GFS2_I(dir);
146 ip = inode->u.generic_ip; 146 ip = GFS2_I(inode);
147 147
148 *name = 0; 148 *name = 0;
149 gnfd.inum = ip->i_num; 149 gnfd.inum = ip->i_num;
@@ -189,39 +189,30 @@ static struct dentry *gfs2_get_parent(struct dentry *child)
189static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p) 189static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p)
190{ 190{
191 struct gfs2_sbd *sdp = sb->s_fs_info; 191 struct gfs2_sbd *sdp = sb->s_fs_info;
192 struct gfs2_inum *inum = (struct gfs2_inum *)inum_p; 192 struct gfs2_inum *inum = inum_p;
193 struct gfs2_holder i_gh, ri_gh, rgd_gh; 193 struct gfs2_holder i_gh, ri_gh, rgd_gh;
194 struct gfs2_rgrpd *rgd; 194 struct gfs2_rgrpd *rgd;
195 struct gfs2_inode *ip;
196 struct inode *inode; 195 struct inode *inode;
197 struct dentry *dentry; 196 struct dentry *dentry;
198 int error; 197 int error;
199 198
200 /* System files? */ 199 /* System files? */
201 200
202 inode = gfs2_iget(sb, inum); 201 inode = gfs2_ilookup(sb, inum);
203 if (inode) { 202 if (inode) {
204 ip = inode->u.generic_ip; 203 if (GFS2_I(inode)->i_num.no_formal_ino != inum->no_formal_ino) {
205 if (ip->i_num.no_formal_ino != inum->no_formal_ino) {
206 iput(inode); 204 iput(inode);
207 return ERR_PTR(-ESTALE); 205 return ERR_PTR(-ESTALE);
208 } 206 }
209 goto out_inode; 207 goto out_inode;
210 } 208 }
211 209
212 error = gfs2_glock_nq_num(sdp, 210 error = gfs2_glock_nq_num(sdp, inum->no_addr, &gfs2_inode_glops,
213 inum->no_addr, &gfs2_inode_glops,
214 LM_ST_SHARED, LM_FLAG_ANY | GL_LOCAL_EXCL, 211 LM_ST_SHARED, LM_FLAG_ANY | GL_LOCAL_EXCL,
215 &i_gh); 212 &i_gh);
216 if (error) 213 if (error)
217 return ERR_PTR(error); 214 return ERR_PTR(error);
218 215
219 error = gfs2_inode_get(i_gh.gh_gl, inum, NO_CREATE, &ip);
220 if (error)
221 goto fail;
222 if (ip)
223 goto out_ip;
224
225 error = gfs2_rindex_hold(sdp, &ri_gh); 216 error = gfs2_rindex_hold(sdp, &ri_gh);
226 if (error) 217 if (error)
227 goto fail; 218 goto fail;
@@ -242,32 +233,29 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p)
242 gfs2_glock_dq_uninit(&rgd_gh); 233 gfs2_glock_dq_uninit(&rgd_gh);
243 gfs2_glock_dq_uninit(&ri_gh); 234 gfs2_glock_dq_uninit(&ri_gh);
244 235
245 error = gfs2_inode_get(i_gh.gh_gl, inum, CREATE, &ip); 236 inode = gfs2_inode_lookup(sb, inum, DT_UNKNOWN);
246 if (error) 237 if (!inode)
238 goto fail;
239 if (IS_ERR(inode)) {
240 error = PTR_ERR(inode);
247 goto fail; 241 goto fail;
242 }
248 243
249 error = gfs2_inode_refresh(ip); 244 error = gfs2_inode_refresh(GFS2_I(inode));
250 if (error) { 245 if (error) {
251 gfs2_inode_put(ip); 246 iput(inode);
252 goto fail; 247 goto fail;
253 } 248 }
254 249
255 out_ip:
256 error = -EIO; 250 error = -EIO;
257 if (ip->i_di.di_flags & GFS2_DIF_SYSTEM) { 251 if (GFS2_I(inode)->i_di.di_flags & GFS2_DIF_SYSTEM) {
258 gfs2_inode_put(ip); 252 iput(inode);
259 goto fail; 253 goto fail;
260 } 254 }
261 255
262 gfs2_glock_dq_uninit(&i_gh); 256 gfs2_glock_dq_uninit(&i_gh);
263 257
264 inode = gfs2_ip2v(ip); 258out_inode:
265 gfs2_inode_put(ip);
266
267 if (!inode)
268 return ERR_PTR(-ENOMEM);
269
270 out_inode:
271 dentry = d_alloc_anon(inode); 259 dentry = d_alloc_anon(inode);
272 if (!dentry) { 260 if (!dentry) {
273 iput(inode); 261 iput(inode);
@@ -276,13 +264,13 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb, void *inum_p)
276 264
277 return dentry; 265 return dentry;
278 266
279 fail_rgd: 267fail_rgd:
280 gfs2_glock_dq_uninit(&rgd_gh); 268 gfs2_glock_dq_uninit(&rgd_gh);
281 269
282 fail_rindex: 270fail_rindex:
283 gfs2_glock_dq_uninit(&ri_gh); 271 gfs2_glock_dq_uninit(&ri_gh);
284 272
285 fail: 273fail:
286 gfs2_glock_dq_uninit(&i_gh); 274 gfs2_glock_dq_uninit(&i_gh);
287 return ERR_PTR(error); 275 return ERR_PTR(error);
288} 276}
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index 1e8f602c1e50..222f3be3e06e 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -105,7 +105,7 @@ static int gfs2_read_actor(read_descriptor_t *desc, struct page *page,
105int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, 105int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state,
106 char *buf, loff_t *pos, unsigned size) 106 char *buf, loff_t *pos, unsigned size)
107{ 107{
108 struct inode *inode = ip->i_vnode; 108 struct inode *inode = &ip->i_inode;
109 read_descriptor_t desc; 109 read_descriptor_t desc;
110 desc.written = 0; 110 desc.written = 0;
111 desc.arg.buf = buf; 111 desc.arg.buf = buf;
@@ -131,7 +131,7 @@ int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state,
131 131
132static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) 132static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin)
133{ 133{
134 struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; 134 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
135 struct gfs2_holder i_gh; 135 struct gfs2_holder i_gh;
136 loff_t error; 136 loff_t error;
137 137
@@ -178,7 +178,7 @@ static ssize_t __gfs2_file_aio_read(struct kiocb *iocb,
178 unsigned long nr_segs, loff_t *ppos) 178 unsigned long nr_segs, loff_t *ppos)
179{ 179{
180 struct file *filp = iocb->ki_filp; 180 struct file *filp = iocb->ki_filp;
181 struct gfs2_inode *ip = filp->f_mapping->host->u.generic_ip; 181 struct gfs2_inode *ip = GFS2_I(filp->f_mapping->host);
182 struct gfs2_holder gh; 182 struct gfs2_holder gh;
183 ssize_t retval; 183 ssize_t retval;
184 unsigned long seg; 184 unsigned long seg;
@@ -361,13 +361,13 @@ static int filldir_reg_func(void *opaque, const char *name, unsigned int length,
361static int readdir_reg(struct file *file, void *dirent, filldir_t filldir) 361static int readdir_reg(struct file *file, void *dirent, filldir_t filldir)
362{ 362{
363 struct inode *dir = file->f_mapping->host; 363 struct inode *dir = file->f_mapping->host;
364 struct gfs2_inode *dip = dir->u.generic_ip; 364 struct gfs2_inode *dip = GFS2_I(dir);
365 struct filldir_reg fdr; 365 struct filldir_reg fdr;
366 struct gfs2_holder d_gh; 366 struct gfs2_holder d_gh;
367 uint64_t offset = file->f_pos; 367 uint64_t offset = file->f_pos;
368 int error; 368 int error;
369 369
370 fdr.fdr_sbd = dip->i_sbd; 370 fdr.fdr_sbd = GFS2_SB(dir);
371 fdr.fdr_prefetch = 1; 371 fdr.fdr_prefetch = 1;
372 fdr.fdr_filldir = filldir; 372 fdr.fdr_filldir = filldir;
373 fdr.fdr_opaque = dirent; 373 fdr.fdr_opaque = dirent;
@@ -451,8 +451,8 @@ static int filldir_bad_func(void *opaque, const char *name, unsigned int length,
451static int readdir_bad(struct file *file, void *dirent, filldir_t filldir) 451static int readdir_bad(struct file *file, void *dirent, filldir_t filldir)
452{ 452{
453 struct inode *dir = file->f_mapping->host; 453 struct inode *dir = file->f_mapping->host;
454 struct gfs2_inode *dip = dir->u.generic_ip; 454 struct gfs2_inode *dip = GFS2_I(dir);
455 struct gfs2_sbd *sdp = dip->i_sbd; 455 struct gfs2_sbd *sdp = GFS2_SB(dir);
456 struct filldir_reg fdr; 456 struct filldir_reg fdr;
457 unsigned int entries, size; 457 unsigned int entries, size;
458 struct filldir_bad *fdb; 458 struct filldir_bad *fdb;
@@ -561,7 +561,7 @@ static const u32 gfs2_to_iflags[32] = {
561static int gfs2_get_flags(struct file *filp, u32 __user *ptr) 561static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
562{ 562{
563 struct inode *inode = filp->f_dentry->d_inode; 563 struct inode *inode = filp->f_dentry->d_inode;
564 struct gfs2_inode *ip = inode->u.generic_ip; 564 struct gfs2_inode *ip = GFS2_I(inode);
565 struct gfs2_holder gh; 565 struct gfs2_holder gh;
566 int error; 566 int error;
567 u32 iflags; 567 u32 iflags;
@@ -601,8 +601,8 @@ static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
601static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) 601static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
602{ 602{
603 struct inode *inode = filp->f_dentry->d_inode; 603 struct inode *inode = filp->f_dentry->d_inode;
604 struct gfs2_inode *ip = inode->u.generic_ip; 604 struct gfs2_inode *ip = GFS2_I(inode);
605 struct gfs2_sbd *sdp = ip->i_sbd; 605 struct gfs2_sbd *sdp = GFS2_SB(inode);
606 struct buffer_head *bh; 606 struct buffer_head *bh;
607 struct gfs2_holder gh; 607 struct gfs2_holder gh;
608 int error; 608 int error;
@@ -693,7 +693,7 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
693 693
694static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) 694static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
695{ 695{
696 struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; 696 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
697 struct gfs2_holder i_gh; 697 struct gfs2_holder i_gh;
698 int error; 698 int error;
699 699
@@ -728,7 +728,7 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
728 728
729static int gfs2_open(struct inode *inode, struct file *file) 729static int gfs2_open(struct inode *inode, struct file *file)
730{ 730{
731 struct gfs2_inode *ip = inode->u.generic_ip; 731 struct gfs2_inode *ip = GFS2_I(inode);
732 struct gfs2_holder i_gh; 732 struct gfs2_holder i_gh;
733 struct gfs2_file *fp; 733 struct gfs2_file *fp;
734 int error; 734 int error;
@@ -739,7 +739,7 @@ static int gfs2_open(struct inode *inode, struct file *file)
739 739
740 mutex_init(&fp->f_fl_mutex); 740 mutex_init(&fp->f_fl_mutex);
741 741
742 gfs2_assert_warn(ip->i_sbd, !file->private_data); 742 gfs2_assert_warn(GFS2_SB(inode), !file->private_data);
743 file->private_data = fp; 743 file->private_data = fp;
744 744
745 if (S_ISREG(ip->i_di.di_mode)) { 745 if (S_ISREG(ip->i_di.di_mode)) {
@@ -808,7 +808,7 @@ static int gfs2_close(struct inode *inode, struct file *file)
808 808
809static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) 809static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync)
810{ 810{
811 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; 811 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
812 812
813 gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); 813 gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl);
814 814
@@ -826,8 +826,8 @@ static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync)
826 826
827static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) 827static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
828{ 828{
829 struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; 829 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
830 struct gfs2_sbd *sdp = ip->i_sbd; 830 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
831 struct lm_lockname name = 831 struct lm_lockname name =
832 { .ln_number = ip->i_num.no_addr, 832 { .ln_number = ip->i_num.no_addr,
833 .ln_type = LM_TYPE_PLOCK }; 833 .ln_type = LM_TYPE_PLOCK };
@@ -881,7 +881,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl)
881{ 881{
882 struct gfs2_file *fp = file->private_data; 882 struct gfs2_file *fp = file->private_data;
883 struct gfs2_holder *fl_gh = &fp->f_fl_gh; 883 struct gfs2_holder *fl_gh = &fp->f_fl_gh;
884 struct gfs2_inode *ip = file->f_dentry->d_inode->u.generic_ip; 884 struct gfs2_inode *ip = GFS2_I(file->f_dentry->d_inode);
885 struct gfs2_glock *gl; 885 struct gfs2_glock *gl;
886 unsigned int state; 886 unsigned int state;
887 int flags; 887 int flags;
@@ -901,7 +901,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl)
901 &(struct file_lock){.fl_type = F_UNLCK}); 901 &(struct file_lock){.fl_type = F_UNLCK});
902 gfs2_glock_dq_uninit(fl_gh); 902 gfs2_glock_dq_uninit(fl_gh);
903 } else { 903 } else {
904 error = gfs2_glock_get(ip->i_sbd, 904 error = gfs2_glock_get(GFS2_SB(&ip->i_inode),
905 ip->i_num.no_addr, &gfs2_flock_glops, 905 ip->i_num.no_addr, &gfs2_flock_glops,
906 CREATE, &gl); 906 CREATE, &gl);
907 if (error) 907 if (error)
@@ -918,7 +918,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl)
918 error = -EAGAIN; 918 error = -EAGAIN;
919 } else { 919 } else {
920 error = flock_lock_file_wait(file, fl); 920 error = flock_lock_file_wait(file, fl);
921 gfs2_assert_warn(ip->i_sbd, !error); 921 gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error);
922 } 922 }
923 923
924 out: 924 out:
@@ -950,8 +950,8 @@ static void do_unflock(struct file *file, struct file_lock *fl)
950 950
951static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) 951static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
952{ 952{
953 struct gfs2_inode *ip = file->f_mapping->host->u.generic_ip; 953 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
954 struct gfs2_sbd *sdp = ip->i_sbd; 954 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
955 955
956 if (!(fl->fl_flags & FL_FLOCK)) 956 if (!(fl->fl_flags & FL_FLOCK))
957 return -ENOLCK; 957 return -ENOLCK;
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index a45982045509..b68eb6b4a4c1 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -32,7 +32,6 @@
32#include "recovery.h" 32#include "recovery.h"
33#include "rgrp.h" 33#include "rgrp.h"
34#include "super.h" 34#include "super.h"
35#include "unlinked.h"
36#include "sys.h" 35#include "sys.h"
37#include "util.h" 36#include "util.h"
38 37
@@ -80,10 +79,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
80 spin_lock_init(&sdp->sd_jindex_spin); 79 spin_lock_init(&sdp->sd_jindex_spin);
81 mutex_init(&sdp->sd_jindex_mutex); 80 mutex_init(&sdp->sd_jindex_mutex);
82 81
83 INIT_LIST_HEAD(&sdp->sd_unlinked_list);
84 spin_lock_init(&sdp->sd_unlinked_spin);
85 mutex_init(&sdp->sd_unlinked_mutex);
86
87 INIT_LIST_HEAD(&sdp->sd_quota_list); 82 INIT_LIST_HEAD(&sdp->sd_quota_list);
88 spin_lock_init(&sdp->sd_quota_spin); 83 spin_lock_init(&sdp->sd_quota_spin);
89 mutex_init(&sdp->sd_quota_mutex); 84 mutex_init(&sdp->sd_quota_mutex);
@@ -248,19 +243,19 @@ static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh,
248 243
249 return 0; 244 return 0;
250 245
251 fail_trans: 246fail_trans:
252 gfs2_glock_put(sdp->sd_trans_gl); 247 gfs2_glock_put(sdp->sd_trans_gl);
253 248
254 fail_rename: 249fail_rename:
255 gfs2_glock_put(sdp->sd_rename_gl); 250 gfs2_glock_put(sdp->sd_rename_gl);
256 251
257 fail_live: 252fail_live:
258 gfs2_glock_dq_uninit(&sdp->sd_live_gh); 253 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
259 254
260 fail_mount: 255fail_mount:
261 gfs2_glock_dq_uninit(mount_gh); 256 gfs2_glock_dq_uninit(mount_gh);
262 257
263 fail: 258fail:
264 while (sdp->sd_glockd_num--) 259 while (sdp->sd_glockd_num--)
265 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); 260 kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
266 261
@@ -269,28 +264,10 @@ static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh,
269 return error; 264 return error;
270} 265}
271 266
272static struct inode *gfs2_lookup_root(struct gfs2_sbd *sdp, 267static struct inode *gfs2_lookup_root(struct super_block *sb,
273 const struct gfs2_inum *inum) 268 struct gfs2_inum *inum)
274{ 269{
275 int error; 270 return gfs2_inode_lookup(sb, inum, DT_DIR);
276 struct gfs2_glock *gl;
277 struct gfs2_inode *ip;
278 struct inode *inode;
279
280 error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops,
281 CREATE, &gl);
282 if (!error) {
283 error = gfs2_inode_get(gl, inum, CREATE, &ip);
284 if (!error) {
285 gfs2_inode_min_init(ip, DT_DIR);
286 inode = gfs2_ip2v(ip);
287 gfs2_inode_put(ip);
288 gfs2_glock_put(gl);
289 return inode;
290 }
291 gfs2_glock_put(gl);
292 }
293 return ERR_PTR(error);
294} 271}
295 272
296static int init_sb(struct gfs2_sbd *sdp, int silent, int undo) 273static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
@@ -305,8 +282,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
305 return 0; 282 return 0;
306 } 283 }
307 284
308 error = gfs2_glock_nq_num(sdp, 285 error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops,
309 GFS2_SB_LOCK, &gfs2_meta_glops,
310 LM_ST_SHARED, 0, &sb_gh); 286 LM_ST_SHARED, 0, &sb_gh);
311 if (error) { 287 if (error) {
312 fs_err(sdp, "can't acquire superblock glock: %d\n", error); 288 fs_err(sdp, "can't acquire superblock glock: %d\n", error);
@@ -345,7 +321,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
345 inum = &sdp->sd_sb.sb_root_dir; 321 inum = &sdp->sd_sb.sb_root_dir;
346 if (sb->s_type == &gfs2meta_fs_type) 322 if (sb->s_type == &gfs2meta_fs_type)
347 inum = &sdp->sd_sb.sb_master_dir; 323 inum = &sdp->sd_sb.sb_master_dir;
348 inode = gfs2_lookup_root(sdp, inum); 324 inode = gfs2_lookup_root(sb, inum);
349 if (IS_ERR(inode)) { 325 if (IS_ERR(inode)) {
350 error = PTR_ERR(inode); 326 error = PTR_ERR(inode);
351 fs_err(sdp, "can't read in root inode: %d\n", error); 327 fs_err(sdp, "can't read in root inode: %d\n", error);
@@ -382,7 +358,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
382 fs_err(sdp, "can't lookup journal index: %d\n", error); 358 fs_err(sdp, "can't lookup journal index: %d\n", error);
383 return PTR_ERR(sdp->sd_jindex); 359 return PTR_ERR(sdp->sd_jindex);
384 } 360 }
385 ip = sdp->sd_jindex->u.generic_ip; 361 ip = GFS2_I(sdp->sd_jindex);
386 set_bit(GLF_STICKY, &ip->i_gl->gl_flags); 362 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
387 363
388 /* Load in the journal index special file */ 364 /* Load in the journal index special file */
@@ -413,8 +389,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
413 } 389 }
414 sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid); 390 sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid);
415 391
416 error = gfs2_glock_nq_num(sdp, 392 error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid,
417 sdp->sd_lockstruct.ls_jid,
418 &gfs2_journal_glops, 393 &gfs2_journal_glops,
419 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP, 394 LM_ST_EXCLUSIVE, LM_FLAG_NOEXP,
420 &sdp->sd_journal_gh); 395 &sdp->sd_journal_gh);
@@ -423,9 +398,8 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
423 goto fail_jindex; 398 goto fail_jindex;
424 } 399 }
425 400
426 ip = sdp->sd_jdesc->jd_inode->u.generic_ip; 401 ip = GFS2_I(sdp->sd_jdesc->jd_inode);
427 error = gfs2_glock_nq_init(ip->i_gl, 402 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
428 LM_ST_SHARED,
429 LM_FLAG_NOEXP | GL_EXACT, 403 LM_FLAG_NOEXP | GL_EXACT,
430 &sdp->sd_jinode_gh); 404 &sdp->sd_jinode_gh);
431 if (error) { 405 if (error) {
@@ -509,7 +483,7 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo)
509 if (undo) 483 if (undo)
510 goto fail_qinode; 484 goto fail_qinode;
511 485
512 inode = gfs2_lookup_root(sdp, &sdp->sd_sb.sb_master_dir); 486 inode = gfs2_lookup_root(sdp->sd_vfs, &sdp->sd_sb.sb_master_dir);
513 if (IS_ERR(inode)) { 487 if (IS_ERR(inode)) {
514 error = PTR_ERR(inode); 488 error = PTR_ERR(inode);
515 fs_err(sdp, "can't read in master directory: %d\n", error); 489 fs_err(sdp, "can't read in master directory: %d\n", error);
@@ -545,7 +519,7 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo)
545 fs_err(sdp, "can't get resource index inode: %d\n", error); 519 fs_err(sdp, "can't get resource index inode: %d\n", error);
546 goto fail_statfs; 520 goto fail_statfs;
547 } 521 }
548 ip = sdp->sd_rindex->u.generic_ip; 522 ip = GFS2_I(sdp->sd_rindex);
549 set_bit(GLF_STICKY, &ip->i_gl->gl_flags); 523 set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
550 sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1; 524 sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1;
551 525
@@ -614,14 +588,6 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo)
614 goto fail_ir_i; 588 goto fail_ir_i;
615 } 589 }
616 590
617 sprintf(buf, "unlinked_tag%u", sdp->sd_jdesc->jd_jid);
618 sdp->sd_ut_inode = gfs2_lookup_simple(pn, buf);
619 if (IS_ERR(sdp->sd_ut_inode)) {
620 error = PTR_ERR(sdp->sd_ut_inode);
621 fs_err(sdp, "can't find local \"ut\" file: %d\n", error);
622 goto fail_sc_i;
623 }
624
625 sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid); 591 sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
626 sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf); 592 sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
627 if (IS_ERR(sdp->sd_qc_inode)) { 593 if (IS_ERR(sdp->sd_qc_inode)) {
@@ -633,7 +599,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo)
633 iput(pn); 599 iput(pn);
634 pn = NULL; 600 pn = NULL;
635 601
636 ip = sdp->sd_ir_inode->u.generic_ip; 602 ip = GFS2_I(sdp->sd_ir_inode);
637 error = gfs2_glock_nq_init(ip->i_gl, 603 error = gfs2_glock_nq_init(ip->i_gl,
638 LM_ST_EXCLUSIVE, 0, 604 LM_ST_EXCLUSIVE, 0,
639 &sdp->sd_ir_gh); 605 &sdp->sd_ir_gh);
@@ -642,7 +608,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo)
642 goto fail_qc_i; 608 goto fail_qc_i;
643 } 609 }
644 610
645 ip = sdp->sd_sc_inode->u.generic_ip; 611 ip = GFS2_I(sdp->sd_sc_inode);
646 error = gfs2_glock_nq_init(ip->i_gl, 612 error = gfs2_glock_nq_init(ip->i_gl,
647 LM_ST_EXCLUSIVE, 0, 613 LM_ST_EXCLUSIVE, 0,
648 &sdp->sd_sc_gh); 614 &sdp->sd_sc_gh);
@@ -651,16 +617,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo)
651 goto fail_ir_gh; 617 goto fail_ir_gh;
652 } 618 }
653 619
654 ip = sdp->sd_ut_inode->u.generic_ip; 620 ip = GFS2_I(sdp->sd_qc_inode);
655 error = gfs2_glock_nq_init(ip->i_gl,
656 LM_ST_EXCLUSIVE, 0,
657 &sdp->sd_ut_gh);
658 if (error) {
659 fs_err(sdp, "can't lock local \"ut\" file: %d\n", error);
660 goto fail_sc_gh;
661 }
662
663 ip = sdp->sd_qc_inode->u.generic_ip;
664 error = gfs2_glock_nq_init(ip->i_gl, 621 error = gfs2_glock_nq_init(ip->i_gl,
665 LM_ST_EXCLUSIVE, 0, 622 LM_ST_EXCLUSIVE, 0,
666 &sdp->sd_qc_gh); 623 &sdp->sd_qc_gh);
@@ -675,9 +632,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo)
675 gfs2_glock_dq_uninit(&sdp->sd_qc_gh); 632 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
676 633
677 fail_ut_gh: 634 fail_ut_gh:
678 gfs2_glock_dq_uninit(&sdp->sd_ut_gh);
679 635
680 fail_sc_gh:
681 gfs2_glock_dq_uninit(&sdp->sd_sc_gh); 636 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
682 637
683 fail_ir_gh: 638 fail_ir_gh:
@@ -687,9 +642,7 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo)
687 iput(sdp->sd_qc_inode); 642 iput(sdp->sd_qc_inode);
688 643
689 fail_ut_i: 644 fail_ut_i:
690 iput(sdp->sd_ut_inode);
691 645
692 fail_sc_i:
693 iput(sdp->sd_sc_inode); 646 iput(sdp->sd_sc_inode);
694 647
695 fail_ir_i: 648 fail_ir_i:
@@ -707,7 +660,7 @@ static int init_threads(struct gfs2_sbd *sdp, int undo)
707 int error = 0; 660 int error = 0;
708 661
709 if (undo) 662 if (undo)
710 goto fail_inoded; 663 goto fail_quotad;
711 664
712 sdp->sd_log_flush_time = jiffies; 665 sdp->sd_log_flush_time = jiffies;
713 sdp->sd_jindex_refresh_time = jiffies; 666 sdp->sd_jindex_refresh_time = jiffies;
@@ -731,25 +684,13 @@ static int init_threads(struct gfs2_sbd *sdp, int undo)
731 } 684 }
732 sdp->sd_quotad_process = p; 685 sdp->sd_quotad_process = p;
733 686
734 p = kthread_run(gfs2_inoded, sdp, "gfs2_inoded");
735 error = IS_ERR(p);
736 if (error) {
737 fs_err(sdp, "can't start inoded thread: %d\n", error);
738 goto fail_quotad;
739 }
740 sdp->sd_inoded_process = p;
741
742 return 0; 687 return 0;
743 688
744 fail_inoded:
745 kthread_stop(sdp->sd_inoded_process);
746 689
747 fail_quotad: 690fail_quotad:
748 kthread_stop(sdp->sd_quotad_process); 691 kthread_stop(sdp->sd_quotad_process);
749 692fail:
750 fail:
751 kthread_stop(sdp->sd_logd_process); 693 kthread_stop(sdp->sd_logd_process);
752
753 return error; 694 return error;
754} 695}
755 696
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index 0c06f92368f2..f678f6b62afd 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -38,7 +38,6 @@
38#include "quota.h" 38#include "quota.h"
39#include "rgrp.h" 39#include "rgrp.h"
40#include "trans.h" 40#include "trans.h"
41#include "unlinked.h"
42#include "util.h" 41#include "util.h"
43 42
44/** 43/**
@@ -53,8 +52,8 @@
53static int gfs2_create(struct inode *dir, struct dentry *dentry, 52static int gfs2_create(struct inode *dir, struct dentry *dentry,
54 int mode, struct nameidata *nd) 53 int mode, struct nameidata *nd)
55{ 54{
56 struct gfs2_inode *dip = dir->u.generic_ip; 55 struct gfs2_inode *dip = GFS2_I(dir);
57 struct gfs2_sbd *sdp = dip->i_sbd; 56 struct gfs2_sbd *sdp = GFS2_SB(dir);
58 struct gfs2_holder ghs[2]; 57 struct gfs2_holder ghs[2];
59 struct inode *inode; 58 struct inode *inode;
60 int new = 1; 59 int new = 1;
@@ -141,10 +140,10 @@ static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
141static int gfs2_link(struct dentry *old_dentry, struct inode *dir, 140static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
142 struct dentry *dentry) 141 struct dentry *dentry)
143{ 142{
144 struct gfs2_inode *dip = dir->u.generic_ip; 143 struct gfs2_inode *dip = GFS2_I(dir);
145 struct gfs2_sbd *sdp = dip->i_sbd; 144 struct gfs2_sbd *sdp = GFS2_SB(dir);
146 struct inode *inode = old_dentry->d_inode; 145 struct inode *inode = old_dentry->d_inode;
147 struct gfs2_inode *ip = inode->u.generic_ip; 146 struct gfs2_inode *ip = GFS2_I(inode);
148 struct gfs2_holder ghs[2]; 147 struct gfs2_holder ghs[2];
149 int alloc_required; 148 int alloc_required;
150 int error; 149 int error;
@@ -231,30 +230,29 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
231 230
232 error = gfs2_change_nlink(ip, +1); 231 error = gfs2_change_nlink(ip, +1);
233 232
234 out_end_trans: 233out_end_trans:
235 gfs2_trans_end(sdp); 234 gfs2_trans_end(sdp);
236 235
237 out_ipres: 236out_ipres:
238 if (alloc_required) 237 if (alloc_required)
239 gfs2_inplace_release(dip); 238 gfs2_inplace_release(dip);
240 239
241 out_gunlock_q: 240out_gunlock_q:
242 if (alloc_required) 241 if (alloc_required)
243 gfs2_quota_unlock(dip); 242 gfs2_quota_unlock(dip);
244 243
245 out_alloc: 244out_alloc:
246 if (alloc_required) 245 if (alloc_required)
247 gfs2_alloc_put(dip); 246 gfs2_alloc_put(dip);
248 247
249 out_gunlock: 248out_gunlock:
250 gfs2_glock_dq_m(2, ghs); 249 gfs2_glock_dq_m(2, ghs);
251 250
252 out: 251out:
253 gfs2_holder_uninit(ghs); 252 gfs2_holder_uninit(ghs);
254 gfs2_holder_uninit(ghs + 1); 253 gfs2_holder_uninit(ghs + 1);
255 254
256 if (!error) { 255 if (!error) {
257 atomic_inc(&inode->i_count);
258 d_instantiate(dentry, inode); 256 d_instantiate(dentry, inode);
259 mark_inode_dirty(inode); 257 mark_inode_dirty(inode);
260 } 258 }
@@ -274,17 +272,12 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
274 272
275static int gfs2_unlink(struct inode *dir, struct dentry *dentry) 273static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
276{ 274{
277 struct gfs2_inode *dip = dir->u.generic_ip; 275 struct gfs2_inode *dip = GFS2_I(dir);
278 struct gfs2_sbd *sdp = dip->i_sbd; 276 struct gfs2_sbd *sdp = GFS2_SB(dir);
279 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; 277 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
280 struct gfs2_unlinked *ul;
281 struct gfs2_holder ghs[2]; 278 struct gfs2_holder ghs[2];
282 int error; 279 int error;
283 280
284 error = gfs2_unlinked_get(sdp, &ul);
285 if (error)
286 return error;
287
288 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 281 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
289 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); 282 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
290 283
@@ -296,24 +289,23 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
296 if (error) 289 if (error)
297 goto out_gunlock; 290 goto out_gunlock;
298 291
299 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF + 292 error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0);
300 RES_UNLINKED, 0);
301 if (error) 293 if (error)
302 goto out_gunlock; 294 goto out_gunlock;
303 295
304 error = gfs2_unlinki(dip, &dentry->d_name, ip, ul); 296 error = gfs2_dir_del(dip, &dentry->d_name);
297 if (error)
298 goto out_end_trans;
305 299
306 gfs2_trans_end(sdp); 300 error = gfs2_change_nlink(ip, -1);
307 301
308 out_gunlock: 302out_end_trans:
303 gfs2_trans_end(sdp);
304out_gunlock:
309 gfs2_glock_dq_m(2, ghs); 305 gfs2_glock_dq_m(2, ghs);
310 306out:
311 out:
312 gfs2_holder_uninit(ghs); 307 gfs2_holder_uninit(ghs);
313 gfs2_holder_uninit(ghs + 1); 308 gfs2_holder_uninit(ghs + 1);
314
315 gfs2_unlinked_put(sdp, ul);
316
317 return error; 309 return error;
318} 310}
319 311
@@ -329,8 +321,8 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
329static int gfs2_symlink(struct inode *dir, struct dentry *dentry, 321static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
330 const char *symname) 322 const char *symname)
331{ 323{
332 struct gfs2_inode *dip = dir->u.generic_ip, *ip; 324 struct gfs2_inode *dip = GFS2_I(dir), *ip;
333 struct gfs2_sbd *sdp = dip->i_sbd; 325 struct gfs2_sbd *sdp = GFS2_SB(dir);
334 struct gfs2_holder ghs[2]; 326 struct gfs2_holder ghs[2];
335 struct inode *inode; 327 struct inode *inode;
336 struct buffer_head *dibh; 328 struct buffer_head *dibh;
@@ -388,8 +380,8 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
388 380
389static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) 381static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
390{ 382{
391 struct gfs2_inode *dip = dir->u.generic_ip, *ip; 383 struct gfs2_inode *dip = GFS2_I(dir), *ip;
392 struct gfs2_sbd *sdp = dip->i_sbd; 384 struct gfs2_sbd *sdp = GFS2_SB(dir);
393 struct gfs2_holder ghs[2]; 385 struct gfs2_holder ghs[2];
394 struct inode *inode; 386 struct inode *inode;
395 struct buffer_head *dibh; 387 struct buffer_head *dibh;
@@ -466,17 +458,12 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
466 458
467static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) 459static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
468{ 460{
469 struct gfs2_inode *dip = dir->u.generic_ip; 461 struct gfs2_inode *dip = GFS2_I(dir);
470 struct gfs2_sbd *sdp = dip->i_sbd; 462 struct gfs2_sbd *sdp = GFS2_SB(dir);
471 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; 463 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
472 struct gfs2_unlinked *ul;
473 struct gfs2_holder ghs[2]; 464 struct gfs2_holder ghs[2];
474 int error; 465 int error;
475 466
476 error = gfs2_unlinked_get(sdp, &ul);
477 if (error)
478 return error;
479
480 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 467 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
481 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); 468 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
482 469
@@ -499,12 +486,11 @@ static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
499 goto out_gunlock; 486 goto out_gunlock;
500 } 487 }
501 488
502 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + 489 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
503 RES_UNLINKED, 0);
504 if (error) 490 if (error)
505 goto out_gunlock; 491 goto out_gunlock;
506 492
507 error = gfs2_rmdiri(dip, &dentry->d_name, ip, ul); 493 error = gfs2_rmdiri(dip, &dentry->d_name, ip);
508 494
509 gfs2_trans_end(sdp); 495 gfs2_trans_end(sdp);
510 496
@@ -515,8 +501,6 @@ static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
515 gfs2_holder_uninit(ghs); 501 gfs2_holder_uninit(ghs);
516 gfs2_holder_uninit(ghs + 1); 502 gfs2_holder_uninit(ghs + 1);
517 503
518 gfs2_unlinked_put(sdp, ul);
519
520 return error; 504 return error;
521} 505}
522 506
@@ -532,8 +516,8 @@ static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
532static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, 516static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
533 dev_t dev) 517 dev_t dev)
534{ 518{
535 struct gfs2_inode *dip = dir->u.generic_ip, *ip; 519 struct gfs2_inode *dip = GFS2_I(dir), *ip;
536 struct gfs2_sbd *sdp = dip->i_sbd; 520 struct gfs2_sbd *sdp = GFS2_SB(dir);
537 struct gfs2_holder ghs[2]; 521 struct gfs2_holder ghs[2];
538 struct inode *inode; 522 struct inode *inode;
539 struct buffer_head *dibh; 523 struct buffer_head *dibh;
@@ -600,12 +584,11 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
600static int gfs2_rename(struct inode *odir, struct dentry *odentry, 584static int gfs2_rename(struct inode *odir, struct dentry *odentry,
601 struct inode *ndir, struct dentry *ndentry) 585 struct inode *ndir, struct dentry *ndentry)
602{ 586{
603 struct gfs2_inode *odip = odir->u.generic_ip; 587 struct gfs2_inode *odip = GFS2_I(odir);
604 struct gfs2_inode *ndip = ndir->u.generic_ip; 588 struct gfs2_inode *ndip = GFS2_I(ndir);
605 struct gfs2_inode *ip = odentry->d_inode->u.generic_ip; 589 struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
606 struct gfs2_inode *nip = NULL; 590 struct gfs2_inode *nip = NULL;
607 struct gfs2_sbd *sdp = odip->i_sbd; 591 struct gfs2_sbd *sdp = GFS2_SB(odir);
608 struct gfs2_unlinked *ul;
609 struct gfs2_holder ghs[4], r_gh; 592 struct gfs2_holder ghs[4], r_gh;
610 unsigned int num_gh; 593 unsigned int num_gh;
611 int dir_rename = 0; 594 int dir_rename = 0;
@@ -614,15 +597,11 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
614 int error; 597 int error;
615 598
616 if (ndentry->d_inode) { 599 if (ndentry->d_inode) {
617 nip = ndentry->d_inode->u.generic_ip; 600 nip = GFS2_I(ndentry->d_inode);
618 if (ip == nip) 601 if (ip == nip)
619 return 0; 602 return 0;
620 } 603 }
621 604
622 error = gfs2_unlinked_get(sdp, &ul);
623 if (error)
624 return error;
625
626 /* Make sure we aren't trying to move a dirctory into it's subdir */ 605 /* Make sure we aren't trying to move a dirctory into it's subdir */
627 606
628 if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) { 607 if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) {
@@ -743,14 +722,12 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
743 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + 722 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
744 al->al_rgd->rd_ri.ri_length + 723 al->al_rgd->rd_ri.ri_length +
745 4 * RES_DINODE + 4 * RES_LEAF + 724 4 * RES_DINODE + 4 * RES_LEAF +
746 RES_UNLINKED + RES_STATFS + 725 RES_STATFS + RES_QUOTA, 0);
747 RES_QUOTA, 0);
748 if (error) 726 if (error)
749 goto out_ipreserv; 727 goto out_ipreserv;
750 } else { 728 } else {
751 error = gfs2_trans_begin(sdp, 4 * RES_DINODE + 729 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
752 5 * RES_LEAF + 730 5 * RES_LEAF, 0);
753 RES_UNLINKED, 0);
754 if (error) 731 if (error)
755 goto out_gunlock; 732 goto out_gunlock;
756 } 733 }
@@ -759,9 +736,13 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
759 736
760 if (nip) { 737 if (nip) {
761 if (S_ISDIR(nip->i_di.di_mode)) 738 if (S_ISDIR(nip->i_di.di_mode))
762 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip, ul); 739 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
763 else 740 else {
764 error = gfs2_unlinki(ndip, &ndentry->d_name, nip, ul); 741 error = gfs2_dir_del(ndip, &ndentry->d_name);
742 if (error)
743 goto out_end_trans;
744 error = gfs2_change_nlink(nip, -1);
745 }
765 if (error) 746 if (error)
766 goto out_end_trans; 747 goto out_end_trans;
767 } 748 }
@@ -800,35 +781,26 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
800 if (error) 781 if (error)
801 goto out_end_trans; 782 goto out_end_trans;
802 783
803 out_end_trans: 784out_end_trans:
804 gfs2_trans_end(sdp); 785 gfs2_trans_end(sdp);
805 786out_ipreserv:
806 out_ipreserv:
807 if (alloc_required) 787 if (alloc_required)
808 gfs2_inplace_release(ndip); 788 gfs2_inplace_release(ndip);
809 789out_gunlock_q:
810 out_gunlock_q:
811 if (alloc_required) 790 if (alloc_required)
812 gfs2_quota_unlock(ndip); 791 gfs2_quota_unlock(ndip);
813 792out_alloc:
814 out_alloc:
815 if (alloc_required) 793 if (alloc_required)
816 gfs2_alloc_put(ndip); 794 gfs2_alloc_put(ndip);
817 795out_gunlock:
818 out_gunlock:
819 gfs2_glock_dq_m(num_gh, ghs); 796 gfs2_glock_dq_m(num_gh, ghs);
820 797out_uninit:
821 out_uninit:
822 for (x = 0; x < num_gh; x++) 798 for (x = 0; x < num_gh; x++)
823 gfs2_holder_uninit(ghs + x); 799 gfs2_holder_uninit(ghs + x);
824 800out_gunlock_r:
825 out_gunlock_r:
826 if (dir_rename) 801 if (dir_rename)
827 gfs2_glock_dq_uninit(&r_gh); 802 gfs2_glock_dq_uninit(&r_gh);
828 803out:
829 out:
830 gfs2_unlinked_put(sdp, ul);
831
832 return error; 804 return error;
833} 805}
834 806
@@ -844,7 +816,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
844static int gfs2_readlink(struct dentry *dentry, char __user *user_buf, 816static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
845 int user_size) 817 int user_size)
846{ 818{
847 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; 819 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
848 char array[GFS2_FAST_NAME_SIZE], *buf = array; 820 char array[GFS2_FAST_NAME_SIZE], *buf = array;
849 unsigned int len = GFS2_FAST_NAME_SIZE; 821 unsigned int len = GFS2_FAST_NAME_SIZE;
850 int error; 822 int error;
@@ -880,7 +852,7 @@ static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
880 852
881static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) 853static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
882{ 854{
883 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; 855 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
884 char array[GFS2_FAST_NAME_SIZE], *buf = array; 856 char array[GFS2_FAST_NAME_SIZE], *buf = array;
885 unsigned int len = GFS2_FAST_NAME_SIZE; 857 unsigned int len = GFS2_FAST_NAME_SIZE;
886 int error; 858 int error;
@@ -906,7 +878,7 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
906 878
907static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd) 879static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
908{ 880{
909 struct gfs2_inode *ip = inode->u.generic_ip; 881 struct gfs2_inode *ip = GFS2_I(inode);
910 struct gfs2_holder i_gh; 882 struct gfs2_holder i_gh;
911 int error; 883 int error;
912 884
@@ -926,7 +898,7 @@ static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
926 898
927static int setattr_size(struct inode *inode, struct iattr *attr) 899static int setattr_size(struct inode *inode, struct iattr *attr)
928{ 900{
929 struct gfs2_inode *ip = inode->u.generic_ip; 901 struct gfs2_inode *ip = GFS2_I(inode);
930 int error; 902 int error;
931 903
932 if (attr->ia_size != ip->i_di.di_size) { 904 if (attr->ia_size != ip->i_di.di_size) {
@@ -944,8 +916,8 @@ static int setattr_size(struct inode *inode, struct iattr *attr)
944 916
945static int setattr_chown(struct inode *inode, struct iattr *attr) 917static int setattr_chown(struct inode *inode, struct iattr *attr)
946{ 918{
947 struct gfs2_inode *ip = inode->u.generic_ip; 919 struct gfs2_inode *ip = GFS2_I(inode);
948 struct gfs2_sbd *sdp = ip->i_sbd; 920 struct gfs2_sbd *sdp = GFS2_SB(inode);
949 struct buffer_head *dibh; 921 struct buffer_head *dibh;
950 uint32_t ouid, ogid, nuid, ngid; 922 uint32_t ouid, ogid, nuid, ngid;
951 int error; 923 int error;
@@ -1021,7 +993,7 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
1021static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) 993static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1022{ 994{
1023 struct inode *inode = dentry->d_inode; 995 struct inode *inode = dentry->d_inode;
1024 struct gfs2_inode *ip = inode->u.generic_ip; 996 struct gfs2_inode *ip = GFS2_I(inode);
1025 struct gfs2_holder i_gh; 997 struct gfs2_holder i_gh;
1026 int error; 998 int error;
1027 999
@@ -1068,7 +1040,7 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1068 struct kstat *stat) 1040 struct kstat *stat)
1069{ 1041{
1070 struct inode *inode = dentry->d_inode; 1042 struct inode *inode = dentry->d_inode;
1071 struct gfs2_inode *ip = inode->u.generic_ip; 1043 struct gfs2_inode *ip = GFS2_I(inode);
1072 struct gfs2_holder gh; 1044 struct gfs2_holder gh;
1073 int error; 1045 int error;
1074 1046
@@ -1084,7 +1056,7 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1084static int gfs2_setxattr(struct dentry *dentry, const char *name, 1056static int gfs2_setxattr(struct dentry *dentry, const char *name,
1085 const void *data, size_t size, int flags) 1057 const void *data, size_t size, int flags)
1086{ 1058{
1087 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip; 1059 struct inode *inode = dentry->d_inode;
1088 struct gfs2_ea_request er; 1060 struct gfs2_ea_request er;
1089 1061
1090 memset(&er, 0, sizeof(struct gfs2_ea_request)); 1062 memset(&er, 0, sizeof(struct gfs2_ea_request));
@@ -1096,9 +1068,9 @@ static int gfs2_setxattr(struct dentry *dentry, const char *name,
1096 er.er_data_len = size; 1068 er.er_data_len = size;
1097 er.er_flags = flags; 1069 er.er_flags = flags;
1098 1070
1099 gfs2_assert_warn(ip->i_sbd, !(er.er_flags & GFS2_ERF_MODE)); 1071 gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE));
1100 1072
1101 return gfs2_ea_set(ip, &er); 1073 return gfs2_ea_set(GFS2_I(inode), &er);
1102} 1074}
1103 1075
1104static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, 1076static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
@@ -1114,7 +1086,7 @@ static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1114 er.er_name_len = strlen(er.er_name); 1086 er.er_name_len = strlen(er.er_name);
1115 er.er_data_len = size; 1087 er.er_data_len = size;
1116 1088
1117 return gfs2_ea_get(dentry->d_inode->u.generic_ip, &er); 1089 return gfs2_ea_get(GFS2_I(dentry->d_inode), &er);
1118} 1090}
1119 1091
1120static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) 1092static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
@@ -1125,7 +1097,7 @@ static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1125 er.er_data = (size) ? buffer : NULL; 1097 er.er_data = (size) ? buffer : NULL;
1126 er.er_data_len = size; 1098 er.er_data_len = size;
1127 1099
1128 return gfs2_ea_list(dentry->d_inode->u.generic_ip, &er); 1100 return gfs2_ea_list(GFS2_I(dentry->d_inode), &er);
1129} 1101}
1130 1102
1131static int gfs2_removexattr(struct dentry *dentry, const char *name) 1103static int gfs2_removexattr(struct dentry *dentry, const char *name)
@@ -1138,7 +1110,7 @@ static int gfs2_removexattr(struct dentry *dentry, const char *name)
1138 return -EOPNOTSUPP; 1110 return -EOPNOTSUPP;
1139 er.er_name_len = strlen(er.er_name); 1111 er.er_name_len = strlen(er.er_name);
1140 1112
1141 return gfs2_ea_remove(dentry->d_inode->u.generic_ip, &er); 1113 return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er);
1142} 1114}
1143 1115
1144struct inode_operations gfs2_file_iops = { 1116struct inode_operations gfs2_file_iops = {
diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c
index 1c17acc946f9..317d497f8f88 100644
--- a/fs/gfs2/ops_super.c
+++ b/fs/gfs2/ops_super.c
@@ -19,6 +19,7 @@
19#include <linux/kthread.h> 19#include <linux/kthread.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/gfs2_ondisk.h> 21#include <linux/gfs2_ondisk.h>
22#include <linux/crc32.h>
22 23
23#include "gfs2.h" 24#include "gfs2.h"
24#include "lm_interface.h" 25#include "lm_interface.h"
@@ -36,6 +37,10 @@
36#include "super.h" 37#include "super.h"
37#include "sys.h" 38#include "sys.h"
38#include "util.h" 39#include "util.h"
40#include "trans.h"
41#include "dir.h"
42#include "eattr.h"
43#include "bmap.h"
39 44
40/** 45/**
41 * gfs2_write_inode - Make sure the inode is stable on the disk 46 * gfs2_write_inode - Make sure the inode is stable on the disk
@@ -47,12 +52,15 @@
47 52
48static int gfs2_write_inode(struct inode *inode, int sync) 53static int gfs2_write_inode(struct inode *inode, int sync)
49{ 54{
50 struct gfs2_inode *ip = inode->u.generic_ip; 55 struct gfs2_inode *ip = GFS2_I(inode);
51 56
52 if (current->flags & PF_MEMALLOC) 57 /* Check this is a "normal" inode */
53 return 0; 58 if (inode->u.generic_ip) {
54 if (ip && sync) 59 if (current->flags & PF_MEMALLOC)
55 gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); 60 return 0;
61 if (sync)
62 gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl);
63 }
56 64
57 return 0; 65 return 0;
58} 66}
@@ -78,7 +86,6 @@ static void gfs2_put_super(struct super_block *sb)
78 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); 86 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
79 mutex_unlock(&sdp->sd_freeze_lock); 87 mutex_unlock(&sdp->sd_freeze_lock);
80 88
81 kthread_stop(sdp->sd_inoded_process);
82 kthread_stop(sdp->sd_quotad_process); 89 kthread_stop(sdp->sd_quotad_process);
83 kthread_stop(sdp->sd_logd_process); 90 kthread_stop(sdp->sd_logd_process);
84 kthread_stop(sdp->sd_recoverd_process); 91 kthread_stop(sdp->sd_recoverd_process);
@@ -110,11 +117,9 @@ static void gfs2_put_super(struct super_block *sb)
110 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); 117 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
111 gfs2_glock_dq_uninit(&sdp->sd_ir_gh); 118 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
112 gfs2_glock_dq_uninit(&sdp->sd_sc_gh); 119 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
113 gfs2_glock_dq_uninit(&sdp->sd_ut_gh);
114 gfs2_glock_dq_uninit(&sdp->sd_qc_gh); 120 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
115 iput(sdp->sd_ir_inode); 121 iput(sdp->sd_ir_inode);
116 iput(sdp->sd_sc_inode); 122 iput(sdp->sd_sc_inode);
117 iput(sdp->sd_ut_inode);
118 iput(sdp->sd_qc_inode); 123 iput(sdp->sd_qc_inode);
119 } 124 }
120 125
@@ -274,16 +279,20 @@ static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
274 279
275static void gfs2_clear_inode(struct inode *inode) 280static void gfs2_clear_inode(struct inode *inode)
276{ 281{
277 struct gfs2_inode *ip = inode->u.generic_ip; 282 /* This tells us its a "real" inode and not one which only
278 283 * serves to contain an address space (see rgrp.c, meta_io.c)
279 if (ip) { 284 * which therefore doesn't have its own glocks.
280 spin_lock(&ip->i_spin); 285 */
281 ip->i_vnode = NULL; 286 if (inode->u.generic_ip) {
282 inode->u.generic_ip = NULL; 287 struct gfs2_inode *ip = GFS2_I(inode);
283 spin_unlock(&ip->i_spin); 288 gfs2_glock_inode_squish(inode);
284 289 gfs2_assert(inode->i_sb->s_fs_info, ip->i_gl->gl_state == LM_ST_UNLOCKED);
290 ip->i_gl->gl_object = NULL;
285 gfs2_glock_schedule_for_reclaim(ip->i_gl); 291 gfs2_glock_schedule_for_reclaim(ip->i_gl);
286 gfs2_inode_put(ip); 292 gfs2_glock_put(ip->i_gl);
293 ip->i_gl = NULL;
294 if (ip->i_iopen_gh.gh_gl)
295 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
287 } 296 }
288} 297}
289 298
@@ -361,6 +370,70 @@ static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
361 return 0; 370 return 0;
362} 371}
363 372
373/*
374 * We have to (at the moment) hold the inodes main lock to cover
375 * the gap between unlocking the shared lock on the iopen lock and
376 * taking the exclusive lock. I'd rather do a shared -> exclusive
377 * conversion on the iopen lock, but we can change that later. This
378 * is safe, just less efficient.
379 */
380static void gfs2_delete_inode(struct inode *inode)
381{
382 struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
383 struct gfs2_inode *ip = GFS2_I(inode);
384 struct gfs2_holder gh;
385 int error;
386
387 if (!inode->u.generic_ip)
388 goto out;
389
390 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &gh);
391 if (unlikely(error)) {
392 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
393 goto out;
394 }
395
396 gfs2_glock_dq(&ip->i_iopen_gh);
397 gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
398 error = gfs2_glock_nq(&ip->i_iopen_gh);
399 if (error)
400 goto out_uninit;
401
402 if (S_ISDIR(ip->i_di.di_mode) &&
403 (ip->i_di.di_flags & GFS2_DIF_EXHASH)) {
404 error = gfs2_dir_exhash_dealloc(ip);
405 if (error)
406 goto out_unlock;
407 }
408
409 if (ip->i_di.di_eattr) {
410 error = gfs2_ea_dealloc(ip);
411 if (error)
412 goto out_unlock;
413 }
414
415 if (!gfs2_is_stuffed(ip)) {
416 error = gfs2_file_dealloc(ip);
417 if (error)
418 goto out_unlock;
419 }
420
421 error = gfs2_dinode_dealloc(ip);
422
423out_unlock:
424 gfs2_glock_dq(&ip->i_iopen_gh);
425out_uninit:
426 gfs2_holder_uninit(&ip->i_iopen_gh);
427 gfs2_glock_dq_uninit(&gh);
428 if (error)
429 fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
430out:
431 truncate_inode_pages(&inode->i_data, 0);
432 clear_inode(inode);
433}
434
435
436
364static struct inode *gfs2_alloc_inode(struct super_block *sb) 437static struct inode *gfs2_alloc_inode(struct super_block *sb)
365{ 438{
366 struct gfs2_sbd *sdp = sb->s_fs_info; 439 struct gfs2_sbd *sdp = sb->s_fs_info;
@@ -370,8 +443,6 @@ static struct inode *gfs2_alloc_inode(struct super_block *sb)
370 if (ip) { 443 if (ip) {
371 ip->i_flags = 0; 444 ip->i_flags = 0;
372 ip->i_gl = NULL; 445 ip->i_gl = NULL;
373 ip->i_sbd = sdp;
374 ip->i_vnode = &ip->i_inode;
375 ip->i_greedy = gfs2_tune_get(sdp, gt_greedy_default); 446 ip->i_greedy = gfs2_tune_get(sdp, gt_greedy_default);
376 ip->i_last_pfault = jiffies; 447 ip->i_last_pfault = jiffies;
377 } 448 }
@@ -387,6 +458,7 @@ struct super_operations gfs2_super_ops = {
387 .alloc_inode = gfs2_alloc_inode, 458 .alloc_inode = gfs2_alloc_inode,
388 .destroy_inode = gfs2_destroy_inode, 459 .destroy_inode = gfs2_destroy_inode,
389 .write_inode = gfs2_write_inode, 460 .write_inode = gfs2_write_inode,
461 .delete_inode = gfs2_delete_inode,
390 .put_super = gfs2_put_super, 462 .put_super = gfs2_put_super,
391 .write_super = gfs2_write_super, 463 .write_super = gfs2_write_super,
392 .write_super_lockfs = gfs2_write_super_lockfs, 464 .write_super_lockfs = gfs2_write_super_lockfs,
diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c
index 263c1fb7bbaf..08709f19ea98 100644
--- a/fs/gfs2/ops_vm.c
+++ b/fs/gfs2/ops_vm.c
@@ -38,15 +38,15 @@ static void pfault_be_greedy(struct gfs2_inode *ip)
38 ip->i_last_pfault = jiffies; 38 ip->i_last_pfault = jiffies;
39 spin_unlock(&ip->i_spin); 39 spin_unlock(&ip->i_spin);
40 40
41 gfs2_inode_hold(ip); 41 igrab(&ip->i_inode);
42 if (gfs2_glock_be_greedy(ip->i_gl, time)) 42 if (gfs2_glock_be_greedy(ip->i_gl, time))
43 gfs2_inode_put(ip); 43 iput(&ip->i_inode);
44} 44}
45 45
46static struct page *gfs2_private_nopage(struct vm_area_struct *area, 46static struct page *gfs2_private_nopage(struct vm_area_struct *area,
47 unsigned long address, int *type) 47 unsigned long address, int *type)
48{ 48{
49 struct gfs2_inode *ip = area->vm_file->f_mapping->host->u.generic_ip; 49 struct gfs2_inode *ip = GFS2_I(area->vm_file->f_mapping->host);
50 struct gfs2_holder i_gh; 50 struct gfs2_holder i_gh;
51 struct page *result; 51 struct page *result;
52 int error; 52 int error;
@@ -69,7 +69,7 @@ static struct page *gfs2_private_nopage(struct vm_area_struct *area,
69 69
70static int alloc_page_backing(struct gfs2_inode *ip, struct page *page) 70static int alloc_page_backing(struct gfs2_inode *ip, struct page *page)
71{ 71{
72 struct gfs2_sbd *sdp = ip->i_sbd; 72 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
73 unsigned long index = page->index; 73 unsigned long index = page->index;
74 uint64_t lblock = index << (PAGE_CACHE_SHIFT - 74 uint64_t lblock = index << (PAGE_CACHE_SHIFT -
75 sdp->sd_sb.sb_bsize_shift); 75 sdp->sd_sb.sb_bsize_shift);
@@ -114,7 +114,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page)
114 unsigned int extlen; 114 unsigned int extlen;
115 int new = 1; 115 int new = 1;
116 116
117 error = gfs2_extent_map(ip->i_vnode, lblock, &new, &dblock, &extlen); 117 error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen);
118 if (error) 118 if (error)
119 goto out_trans; 119 goto out_trans;
120 120
@@ -142,7 +142,7 @@ static int alloc_page_backing(struct gfs2_inode *ip, struct page *page)
142static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area, 142static struct page *gfs2_sharewrite_nopage(struct vm_area_struct *area,
143 unsigned long address, int *type) 143 unsigned long address, int *type)
144{ 144{
145 struct gfs2_inode *ip = area->vm_file->f_mapping->host->u.generic_ip; 145 struct gfs2_inode *ip = GFS2_I(area->vm_file->f_mapping->host);
146 struct gfs2_holder i_gh; 146 struct gfs2_holder i_gh;
147 struct page *result = NULL; 147 struct page *result = NULL;
148 unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) + 148 unsigned long index = ((address - area->vm_start) >> PAGE_CACHE_SHIFT) +
diff --git a/fs/gfs2/page.c b/fs/gfs2/page.c
index cd93644c7d70..a8165a693b56 100644
--- a/fs/gfs2/page.c
+++ b/fs/gfs2/page.c
@@ -38,20 +38,17 @@ void gfs2_pte_inval(struct gfs2_glock *gl)
38 struct inode *inode; 38 struct inode *inode;
39 39
40 ip = gl->gl_object; 40 ip = gl->gl_object;
41 inode = &ip->i_inode;
41 if (!ip || !S_ISREG(ip->i_di.di_mode)) 42 if (!ip || !S_ISREG(ip->i_di.di_mode))
42 return; 43 return;
43 44
44 if (!test_bit(GIF_PAGED, &ip->i_flags)) 45 if (!test_bit(GIF_PAGED, &ip->i_flags))
45 return; 46 return;
46 47
47 inode = gfs2_ip2v_lookup(ip); 48 unmap_shared_mapping_range(inode->i_mapping, 0, 0);
48 if (inode) {
49 unmap_shared_mapping_range(inode->i_mapping, 0, 0);
50 iput(inode);
51 49
52 if (test_bit(GIF_SW_PAGED, &ip->i_flags)) 50 if (test_bit(GIF_SW_PAGED, &ip->i_flags))
53 set_bit(GLF_DIRTY, &gl->gl_flags); 51 set_bit(GLF_DIRTY, &gl->gl_flags);
54 }
55 52
56 clear_bit(GIF_SW_PAGED, &ip->i_flags); 53 clear_bit(GIF_SW_PAGED, &ip->i_flags);
57} 54}
@@ -68,19 +65,12 @@ void gfs2_page_inval(struct gfs2_glock *gl)
68 struct inode *inode; 65 struct inode *inode;
69 66
70 ip = gl->gl_object; 67 ip = gl->gl_object;
68 inode = &ip->i_inode;
71 if (!ip || !S_ISREG(ip->i_di.di_mode)) 69 if (!ip || !S_ISREG(ip->i_di.di_mode))
72 return; 70 return;
73 71
74 inode = gfs2_ip2v_lookup(ip); 72 truncate_inode_pages(inode->i_mapping, 0);
75 if (inode) { 73 gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), !inode->i_mapping->nrpages);
76 struct address_space *mapping = inode->i_mapping;
77
78 truncate_inode_pages(mapping, 0);
79 gfs2_assert_withdraw(ip->i_sbd, !mapping->nrpages);
80
81 iput(inode);
82 }
83
84 clear_bit(GIF_PAGED, &ip->i_flags); 74 clear_bit(GIF_PAGED, &ip->i_flags);
85} 75}
86 76
@@ -97,32 +87,30 @@ void gfs2_page_sync(struct gfs2_glock *gl, int flags)
97{ 87{
98 struct gfs2_inode *ip; 88 struct gfs2_inode *ip;
99 struct inode *inode; 89 struct inode *inode;
90 struct address_space *mapping;
91 int error = 0;
100 92
101 ip = gl->gl_object; 93 ip = gl->gl_object;
94 inode = &ip->i_inode;
102 if (!ip || !S_ISREG(ip->i_di.di_mode)) 95 if (!ip || !S_ISREG(ip->i_di.di_mode))
103 return; 96 return;
104 97
105 inode = gfs2_ip2v_lookup(ip); 98 mapping = inode->i_mapping;
106 if (inode) {
107 struct address_space *mapping = inode->i_mapping;
108 int error = 0;
109 99
110 if (flags & DIO_START) 100 if (flags & DIO_START)
111 filemap_fdatawrite(mapping); 101 filemap_fdatawrite(mapping);
112 if (!error && (flags & DIO_WAIT)) 102 if (!error && (flags & DIO_WAIT))
113 error = filemap_fdatawait(mapping); 103 error = filemap_fdatawait(mapping);
114 104
115 /* Put back any errors cleared by filemap_fdatawait() 105 /* Put back any errors cleared by filemap_fdatawait()
116 so they can be caught by someone who can pass them 106 so they can be caught by someone who can pass them
117 up to user space. */ 107 up to user space. */
118 108
119 if (error == -ENOSPC) 109 if (error == -ENOSPC)
120 set_bit(AS_ENOSPC, &mapping->flags); 110 set_bit(AS_ENOSPC, &mapping->flags);
121 else if (error) 111 else if (error)
122 set_bit(AS_EIO, &mapping->flags); 112 set_bit(AS_EIO, &mapping->flags);
123 113
124 iput(inode);
125 }
126} 114}
127 115
128/** 116/**
@@ -138,8 +126,8 @@ void gfs2_page_sync(struct gfs2_glock *gl, int flags)
138int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, 126int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
139 uint64_t block, void *private) 127 uint64_t block, void *private)
140{ 128{
141 struct gfs2_sbd *sdp = ip->i_sbd; 129 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
142 struct inode *inode = ip->i_vnode; 130 struct inode *inode = &ip->i_inode;
143 struct page *page = (struct page *)private; 131 struct page *page = (struct page *)private;
144 struct buffer_head *bh; 132 struct buffer_head *bh;
145 int release = 0; 133 int release = 0;
@@ -193,8 +181,8 @@ int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
193int gfs2_block_truncate_page(struct address_space *mapping) 181int gfs2_block_truncate_page(struct address_space *mapping)
194{ 182{
195 struct inode *inode = mapping->host; 183 struct inode *inode = mapping->host;
196 struct gfs2_inode *ip = inode->u.generic_ip; 184 struct gfs2_inode *ip = GFS2_I(inode);
197 struct gfs2_sbd *sdp = ip->i_sbd; 185 struct gfs2_sbd *sdp = GFS2_SB(inode);
198 loff_t from = inode->i_size; 186 loff_t from = inode->i_size;
199 unsigned long index = from >> PAGE_CACHE_SHIFT; 187 unsigned long index = from >> PAGE_CACHE_SHIFT;
200 unsigned offset = from & (PAGE_CACHE_SIZE-1); 188 unsigned offset = from & (PAGE_CACHE_SIZE-1);
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index f752b0184690..d3cd5171d7c7 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -248,7 +248,7 @@ static void slot_put(struct gfs2_quota_data *qd)
248static int bh_get(struct gfs2_quota_data *qd) 248static int bh_get(struct gfs2_quota_data *qd)
249{ 249{
250 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 250 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
251 struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip; 251 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
252 unsigned int block, offset; 252 unsigned int block, offset;
253 uint64_t dblock; 253 uint64_t dblock;
254 int new = 0; 254 int new = 0;
@@ -266,7 +266,7 @@ static int bh_get(struct gfs2_quota_data *qd)
266 block = qd->qd_slot / sdp->sd_qc_per_block; 266 block = qd->qd_slot / sdp->sd_qc_per_block;
267 offset = qd->qd_slot % sdp->sd_qc_per_block;; 267 offset = qd->qd_slot % sdp->sd_qc_per_block;;
268 268
269 error = gfs2_block_map(ip->i_vnode, block, &new, &dblock, &boundary); 269 error = gfs2_block_map(&ip->i_inode, block, &new, &dblock, &boundary);
270 if (error) 270 if (error)
271 goto fail; 271 goto fail;
272 error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh); 272 error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh);
@@ -444,7 +444,7 @@ static void qdsb_put(struct gfs2_quota_data *qd)
444 444
445int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) 445int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid)
446{ 446{
447 struct gfs2_sbd *sdp = ip->i_sbd; 447 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
448 struct gfs2_alloc *al = &ip->i_alloc; 448 struct gfs2_alloc *al = &ip->i_alloc;
449 struct gfs2_quota_data **qd = al->al_qd; 449 struct gfs2_quota_data **qd = al->al_qd;
450 int error; 450 int error;
@@ -493,7 +493,7 @@ int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid)
493 493
494void gfs2_quota_unhold(struct gfs2_inode *ip) 494void gfs2_quota_unhold(struct gfs2_inode *ip)
495{ 495{
496 struct gfs2_sbd *sdp = ip->i_sbd; 496 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
497 struct gfs2_alloc *al = &ip->i_alloc; 497 struct gfs2_alloc *al = &ip->i_alloc;
498 unsigned int x; 498 unsigned int x;
499 499
@@ -531,7 +531,7 @@ static int sort_qd(const void *a, const void *b)
531static void do_qc(struct gfs2_quota_data *qd, int64_t change) 531static void do_qc(struct gfs2_quota_data *qd, int64_t change)
532{ 532{
533 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 533 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
534 struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip; 534 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
535 struct gfs2_quota_change *qc = qd->qd_bh_qc; 535 struct gfs2_quota_change *qc = qd->qd_bh_qc;
536 int64_t x; 536 int64_t x;
537 537
@@ -578,7 +578,7 @@ static void do_qc(struct gfs2_quota_data *qd, int64_t change)
578static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, 578static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
579 int64_t change, struct gfs2_quota_data *qd) 579 int64_t change, struct gfs2_quota_data *qd)
580{ 580{
581 struct inode *inode = ip->i_vnode; 581 struct inode *inode = &ip->i_inode;
582 struct address_space *mapping = inode->i_mapping; 582 struct address_space *mapping = inode->i_mapping;
583 unsigned long index = loc >> PAGE_CACHE_SHIFT; 583 unsigned long index = loc >> PAGE_CACHE_SHIFT;
584 unsigned offset = loc & (PAGE_CACHE_SHIFT - 1); 584 unsigned offset = loc & (PAGE_CACHE_SHIFT - 1);
@@ -647,7 +647,7 @@ unlock:
647static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) 647static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
648{ 648{
649 struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd; 649 struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd;
650 struct gfs2_inode *ip = sdp->sd_quota_inode->u.generic_ip; 650 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode);
651 unsigned int data_blocks, ind_blocks; 651 unsigned int data_blocks, ind_blocks;
652 struct file_ra_state ra_state; 652 struct file_ra_state ra_state;
653 struct gfs2_holder *ghs, i_gh; 653 struct gfs2_holder *ghs, i_gh;
@@ -716,7 +716,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
716 goto out_gunlock; 716 goto out_gunlock;
717 } 717 }
718 718
719 file_ra_state_init(&ra_state, ip->i_vnode->i_mapping); 719 file_ra_state_init(&ra_state, ip->i_inode.i_mapping);
720 for (x = 0; x < num_qd; x++) { 720 for (x = 0; x < num_qd; x++) {
721 qd = qda[x]; 721 qd = qda[x];
722 offset = qd2offset(qd); 722 offset = qd2offset(qd);
@@ -758,7 +758,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh,
758 struct gfs2_holder *q_gh) 758 struct gfs2_holder *q_gh)
759{ 759{
760 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 760 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
761 struct gfs2_inode *ip = sdp->sd_quota_inode->u.generic_ip; 761 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode);
762 struct gfs2_holder i_gh; 762 struct gfs2_holder i_gh;
763 struct gfs2_quota q; 763 struct gfs2_quota q;
764 char buf[sizeof(struct gfs2_quota)]; 764 char buf[sizeof(struct gfs2_quota)];
@@ -829,7 +829,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh,
829 829
830int gfs2_quota_lock(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) 830int gfs2_quota_lock(struct gfs2_inode *ip, uint32_t uid, uint32_t gid)
831{ 831{
832 struct gfs2_sbd *sdp = ip->i_sbd; 832 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
833 struct gfs2_alloc *al = &ip->i_alloc; 833 struct gfs2_alloc *al = &ip->i_alloc;
834 unsigned int x; 834 unsigned int x;
835 int error = 0; 835 int error = 0;
@@ -958,7 +958,7 @@ static int print_message(struct gfs2_quota_data *qd, char *type)
958 958
959int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid) 959int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid)
960{ 960{
961 struct gfs2_sbd *sdp = ip->i_sbd; 961 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
962 struct gfs2_alloc *al = &ip->i_alloc; 962 struct gfs2_alloc *al = &ip->i_alloc;
963 struct gfs2_quota_data *qd; 963 struct gfs2_quota_data *qd;
964 int64_t value; 964 int64_t value;
@@ -1008,7 +1008,7 @@ void gfs2_quota_change(struct gfs2_inode *ip, int64_t change,
1008 unsigned int x; 1008 unsigned int x;
1009 unsigned int found = 0; 1009 unsigned int found = 0;
1010 1010
1011 if (gfs2_assert_warn(ip->i_sbd, change)) 1011 if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change))
1012 return; 1012 return;
1013 if (ip->i_di.di_flags & GFS2_DIF_SYSTEM) 1013 if (ip->i_di.di_flags & GFS2_DIF_SYSTEM)
1014 return; 1014 return;
@@ -1126,7 +1126,7 @@ int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id,
1126 1126
1127int gfs2_quota_init(struct gfs2_sbd *sdp) 1127int gfs2_quota_init(struct gfs2_sbd *sdp)
1128{ 1128{
1129 struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip; 1129 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
1130 unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; 1130 unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift;
1131 unsigned int x, slot = 0; 1131 unsigned int x, slot = 0;
1132 unsigned int found = 0; 1132 unsigned int found = 0;
@@ -1162,7 +1162,7 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
1162 1162
1163 if (!extlen) { 1163 if (!extlen) {
1164 int new = 0; 1164 int new = 0;
1165 error = gfs2_extent_map(ip->i_vnode, x, &new, &dblock, &extlen); 1165 error = gfs2_extent_map(&ip->i_inode, x, &new, &dblock, &extlen);
1166 if (error) 1166 if (error)
1167 goto fail; 1167 goto fail;
1168 } 1168 }
diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index c504ac1b831d..7aabc03e4abd 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -32,14 +32,14 @@
32int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, 32int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk,
33 struct buffer_head **bh) 33 struct buffer_head **bh)
34{ 34{
35 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 35 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
36 struct gfs2_glock *gl = ip->i_gl; 36 struct gfs2_glock *gl = ip->i_gl;
37 int new = 0; 37 int new = 0;
38 uint64_t dblock; 38 uint64_t dblock;
39 uint32_t extlen; 39 uint32_t extlen;
40 int error; 40 int error;
41 41
42 error = gfs2_extent_map(ip->i_vnode, blk, &new, &dblock, &extlen); 42 error = gfs2_extent_map(&ip->i_inode, blk, &new, &dblock, &extlen);
43 if (error) 43 if (error)
44 return error; 44 return error;
45 if (!dblock) { 45 if (!dblock) {
@@ -190,7 +190,7 @@ static int find_good_lh(struct gfs2_jdesc *jd, unsigned int *blk,
190 *blk = 0; 190 *blk = 0;
191 191
192 if (*blk == orig_blk) { 192 if (*blk == orig_blk) {
193 gfs2_consist_inode(jd->jd_inode->u.generic_ip); 193 gfs2_consist_inode(GFS2_I(jd->jd_inode));
194 return -EIO; 194 return -EIO;
195 } 195 }
196 } 196 }
@@ -224,7 +224,7 @@ static int jhead_scan(struct gfs2_jdesc *jd, struct gfs2_log_header *head)
224 continue; 224 continue;
225 225
226 if (lh.lh_sequence == head->lh_sequence) { 226 if (lh.lh_sequence == head->lh_sequence) {
227 gfs2_consist_inode(jd->jd_inode->u.generic_ip); 227 gfs2_consist_inode(GFS2_I(jd->jd_inode));
228 return -EIO; 228 return -EIO;
229 } 229 }
230 if (lh.lh_sequence < head->lh_sequence) 230 if (lh.lh_sequence < head->lh_sequence)
@@ -300,8 +300,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header *head)
300static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start, 300static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start,
301 unsigned int end, int pass) 301 unsigned int end, int pass)
302{ 302{
303 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 303 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
304 struct gfs2_sbd *sdp = ip->i_sbd;
305 struct buffer_head *bh; 304 struct buffer_head *bh;
306 struct gfs2_log_descriptor *ld; 305 struct gfs2_log_descriptor *ld;
307 int error = 0; 306 int error = 0;
@@ -330,7 +329,7 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start,
330 continue; 329 continue;
331 } 330 }
332 if (error == 1) { 331 if (error == 1) {
333 gfs2_consist_inode(jd->jd_inode->u.generic_ip); 332 gfs2_consist_inode(GFS2_I(jd->jd_inode));
334 error = -EIO; 333 error = -EIO;
335 } 334 }
336 brelse(bh); 335 brelse(bh);
@@ -367,8 +366,8 @@ static int foreach_descriptor(struct gfs2_jdesc *jd, unsigned int start,
367 366
368static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head) 367static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head)
369{ 368{
370 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 369 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
371 struct gfs2_sbd *sdp = ip->i_sbd; 370 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
372 unsigned int lblock; 371 unsigned int lblock;
373 int new = 0; 372 int new = 0;
374 uint64_t dblock; 373 uint64_t dblock;
@@ -380,7 +379,7 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head)
380 379
381 lblock = head->lh_blkno; 380 lblock = head->lh_blkno;
382 gfs2_replay_incr_blk(sdp, &lblock); 381 gfs2_replay_incr_blk(sdp, &lblock);
383 error = gfs2_block_map(ip->i_vnode, lblock, &new, &dblock, &boundary); 382 error = gfs2_block_map(&ip->i_inode, lblock, &new, &dblock, &boundary);
384 if (error) 383 if (error)
385 return error; 384 return error;
386 if (!dblock) { 385 if (!dblock) {
@@ -426,8 +425,8 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header *head)
426 425
427int gfs2_recover_journal(struct gfs2_jdesc *jd) 426int gfs2_recover_journal(struct gfs2_jdesc *jd)
428{ 427{
429 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 428 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
430 struct gfs2_sbd *sdp = ip->i_sbd; 429 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
431 struct gfs2_log_header head; 430 struct gfs2_log_header head;
432 struct gfs2_holder j_gh, ji_gh, t_gh; 431 struct gfs2_holder j_gh, ji_gh, t_gh;
433 unsigned long t; 432 unsigned long t;
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 691e6f3ce43b..75df79eb50ba 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -34,17 +34,19 @@
34/* 34/*
35 * These routines are used by the resource group routines (rgrp.c) 35 * These routines are used by the resource group routines (rgrp.c)
36 * to keep track of block allocation. Each block is represented by two 36 * to keep track of block allocation. Each block is represented by two
37 * bits. One bit indicates whether or not the block is used. (1=used, 37 * bits. So, each byte represents GFS2_NBBY (i.e. 4) blocks.
38 * 0=free) The other bit indicates whether or not the block contains a 38 *
39 * dinode or not. (1=dinode, 0=not-dinode) So, each byte represents 39 * 0 = Free
40 * GFS2_NBBY (i.e. 4) blocks. 40 * 1 = Used (not metadata)
41 * 2 = Unlinked (still in use) inode
42 * 3 = Used (metadata)
41 */ 43 */
42 44
43static const char valid_change[16] = { 45static const char valid_change[16] = {
44 /* current */ 46 /* current */
45 /* n */ 0, 1, 0, 1, 47 /* n */ 0, 1, 1, 1,
46 /* e */ 1, 0, 0, 0, 48 /* e */ 1, 0, 0, 0,
47 /* w */ 0, 0, 0, 0, 49 /* w */ 0, 0, 0, 1,
48 1, 0, 0, 0 50 1, 0, 0, 0
49}; 51};
50 52
@@ -228,26 +230,27 @@ void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd)
228 tmp = rgd->rd_ri.ri_data - 230 tmp = rgd->rd_ri.ri_data -
229 rgd->rd_rg.rg_free - 231 rgd->rd_rg.rg_free -
230 rgd->rd_rg.rg_dinodes; 232 rgd->rd_rg.rg_dinodes;
231 if (count[1] != tmp) { 233 if (count[1] + count[2] != tmp) {
232 if (gfs2_consist_rgrpd(rgd)) 234 if (gfs2_consist_rgrpd(rgd))
233 fs_err(sdp, "used data mismatch: %u != %u\n", 235 fs_err(sdp, "used data mismatch: %u != %u\n",
234 count[1], tmp); 236 count[1], tmp);
235 return; 237 return;
236 } 238 }
237 239
238 if (count[2]) { 240 if (count[3] != rgd->rd_rg.rg_dinodes) {
239 if (gfs2_consist_rgrpd(rgd)) 241 if (gfs2_consist_rgrpd(rgd))
240 fs_err(sdp, "free metadata mismatch: %u != 0\n", 242 fs_err(sdp, "used metadata mismatch: %u != %u\n",
241 count[2]); 243 count[3], rgd->rd_rg.rg_dinodes);
242 return; 244 return;
243 } 245 }
244 246
245 if (count[3] != rgd->rd_rg.rg_dinodes) { 247 if (count[2] > count[3]) {
246 if (gfs2_consist_rgrpd(rgd)) 248 if (gfs2_consist_rgrpd(rgd))
247 fs_err(sdp, "used metadata mismatch: %u != %u\n", 249 fs_err(sdp, "unlinked inodes > inodes: %u\n",
248 count[3], rgd->rd_rg.rg_dinodes); 250 count[2]);
249 return; 251 return;
250 } 252 }
253
251} 254}
252 255
253static inline int rgrp_contains_block(struct gfs2_rindex *ri, uint64_t block) 256static inline int rgrp_contains_block(struct gfs2_rindex *ri, uint64_t block)
@@ -368,6 +371,9 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd)
368 uint32_t bytes_left, bytes; 371 uint32_t bytes_left, bytes;
369 int x; 372 int x;
370 373
374 if (!length)
375 return -EINVAL;
376
371 rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_KERNEL); 377 rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_KERNEL);
372 if (!rgd->rd_bits) 378 if (!rgd->rd_bits)
373 return -ENOMEM; 379 return -ENOMEM;
@@ -433,14 +439,16 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd)
433 439
434static int gfs2_ri_update(struct gfs2_inode *ip) 440static int gfs2_ri_update(struct gfs2_inode *ip)
435{ 441{
436 struct gfs2_sbd *sdp = ip->i_sbd; 442 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
437 struct inode *inode = ip->i_vnode; 443 struct inode *inode = &ip->i_inode;
438 struct gfs2_rgrpd *rgd; 444 struct gfs2_rgrpd *rgd;
439 char buf[sizeof(struct gfs2_rindex)]; 445 char buf[sizeof(struct gfs2_rindex)];
440 struct file_ra_state ra_state; 446 struct file_ra_state ra_state;
441 uint64_t junk = ip->i_di.di_size; 447 uint64_t junk = ip->i_di.di_size;
442 int error; 448 int error;
443 449
450 printk(KERN_INFO "gfs2_ri_update inode=%p\n", inode);
451
444 if (do_div(junk, sizeof(struct gfs2_rindex))) { 452 if (do_div(junk, sizeof(struct gfs2_rindex))) {
445 gfs2_consist_inode(ip); 453 gfs2_consist_inode(ip);
446 return -EIO; 454 return -EIO;
@@ -448,9 +456,12 @@ static int gfs2_ri_update(struct gfs2_inode *ip)
448 456
449 clear_rgrpdi(sdp); 457 clear_rgrpdi(sdp);
450 458
459 printk(KERN_INFO "rgrps cleared\n");
460
451 file_ra_state_init(&ra_state, inode->i_mapping); 461 file_ra_state_init(&ra_state, inode->i_mapping);
452 for (sdp->sd_rgrps = 0;; sdp->sd_rgrps++) { 462 for (sdp->sd_rgrps = 0;; sdp->sd_rgrps++) {
453 loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex); 463 loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex);
464 printk(KERN_INFO "reading rgrp %d\n", sdp->sd_rgrps);
454 error = gfs2_internal_read(ip, &ra_state, buf, &pos, 465 error = gfs2_internal_read(ip, &ra_state, buf, &pos,
455 sizeof(struct gfs2_rindex)); 466 sizeof(struct gfs2_rindex));
456 if (!error) 467 if (!error)
@@ -474,13 +485,15 @@ static int gfs2_ri_update(struct gfs2_inode *ip)
474 list_add_tail(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list); 485 list_add_tail(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list);
475 486
476 gfs2_rindex_in(&rgd->rd_ri, buf); 487 gfs2_rindex_in(&rgd->rd_ri, buf);
477 488 printk(KERN_INFO "compute bitstructs\n");
478 error = compute_bitstructs(rgd); 489 error = compute_bitstructs(rgd);
479 if (error) 490 if (error)
480 goto fail; 491 goto fail;
481 492
493 printk(KERN_INFO "gfs2_glock_get\n");
482 error = gfs2_glock_get(sdp, rgd->rd_ri.ri_addr, 494 error = gfs2_glock_get(sdp, rgd->rd_ri.ri_addr,
483 &gfs2_rgrp_glops, CREATE, &rgd->rd_gl); 495 &gfs2_rgrp_glops, CREATE, &rgd->rd_gl);
496 printk(KERN_INFO "gfs2_glock_got one\n");
484 if (error) 497 if (error)
485 goto fail; 498 goto fail;
486 499
@@ -488,13 +501,14 @@ static int gfs2_ri_update(struct gfs2_inode *ip)
488 rgd->rd_rg_vn = rgd->rd_gl->gl_vn - 1; 501 rgd->rd_rg_vn = rgd->rd_gl->gl_vn - 1;
489 } 502 }
490 503
504 printk(KERN_INFO "ok, finished\n");
491 sdp->sd_rindex_vn = ip->i_gl->gl_vn; 505 sdp->sd_rindex_vn = ip->i_gl->gl_vn;
492
493 return 0; 506 return 0;
494 507
495 fail: 508fail:
509 printk(KERN_INFO "fail\n");
496 clear_rgrpdi(sdp); 510 clear_rgrpdi(sdp);
497 511 printk(KERN_INFO "cleared rgrps\n");
498 return error; 512 return error;
499} 513}
500 514
@@ -518,7 +532,7 @@ static int gfs2_ri_update(struct gfs2_inode *ip)
518 532
519int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh) 533int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh)
520{ 534{
521 struct gfs2_inode *ip = sdp->sd_rindex->u.generic_ip; 535 struct gfs2_inode *ip = GFS2_I(sdp->sd_rindex);
522 struct gfs2_glock *gl = ip->i_gl; 536 struct gfs2_glock *gl = ip->i_gl;
523 int error; 537 int error;
524 538
@@ -583,8 +597,7 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd)
583 error = gfs2_meta_reread(sdp, bi->bi_bh, DIO_WAIT); 597 error = gfs2_meta_reread(sdp, bi->bi_bh, DIO_WAIT);
584 if (error) 598 if (error)
585 goto fail; 599 goto fail;
586 if (gfs2_metatype_check(sdp, bi->bi_bh, 600 if (gfs2_metatype_check(sdp, bi->bi_bh, y ? GFS2_METATYPE_RB :
587 (y) ? GFS2_METATYPE_RB :
588 GFS2_METATYPE_RG)) { 601 GFS2_METATYPE_RG)) {
589 error = -EIO; 602 error = -EIO;
590 goto fail; 603 goto fail;
@@ -605,7 +618,7 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd)
605 618
606 return 0; 619 return 0;
607 620
608 fail: 621fail:
609 while (x--) { 622 while (x--) {
610 bi = rgd->rd_bits + x; 623 bi = rgd->rd_bits + x;
611 brelse(bi->bi_bh); 624 brelse(bi->bi_bh);
@@ -667,8 +680,7 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd)
667 if (!bi->bi_clone) 680 if (!bi->bi_clone)
668 continue; 681 continue;
669 memcpy(bi->bi_clone + bi->bi_offset, 682 memcpy(bi->bi_clone + bi->bi_offset,
670 bi->bi_bh->b_data + bi->bi_offset, 683 bi->bi_bh->b_data + bi->bi_offset, bi->bi_len);
671 bi->bi_len);
672 } 684 }
673 685
674 spin_lock(&sdp->sd_rindex_spin); 686 spin_lock(&sdp->sd_rindex_spin);
@@ -757,13 +769,11 @@ static struct gfs2_rgrpd *recent_rgrp_first(struct gfs2_sbd *sdp,
757 goto out; 769 goto out;
758 } 770 }
759 771
760 first: 772first:
761 rgd = list_entry(sdp->sd_rindex_recent_list.next, struct gfs2_rgrpd, 773 rgd = list_entry(sdp->sd_rindex_recent_list.next, struct gfs2_rgrpd,
762 rd_recent); 774 rd_recent);
763 775out:
764 out:
765 spin_unlock(&sdp->sd_rindex_spin); 776 spin_unlock(&sdp->sd_rindex_spin);
766
767 return rgd; 777 return rgd;
768} 778}
769 779
@@ -805,9 +815,8 @@ static struct gfs2_rgrpd *recent_rgrp_next(struct gfs2_rgrpd *cur_rgd,
805 if (!list_empty(head)) 815 if (!list_empty(head))
806 rgd = list_entry(head->next, struct gfs2_rgrpd, rd_recent); 816 rgd = list_entry(head->next, struct gfs2_rgrpd, rd_recent);
807 817
808 out: 818out:
809 spin_unlock(&sdp->sd_rindex_spin); 819 spin_unlock(&sdp->sd_rindex_spin);
810
811 return rgd; 820 return rgd;
812} 821}
813 822
@@ -835,7 +844,7 @@ static void recent_rgrp_add(struct gfs2_rgrpd *new_rgd)
835 } 844 }
836 list_add_tail(&new_rgd->rd_recent, &sdp->sd_rindex_recent_list); 845 list_add_tail(&new_rgd->rd_recent, &sdp->sd_rindex_recent_list);
837 846
838 out: 847out:
839 spin_unlock(&sdp->sd_rindex_spin); 848 spin_unlock(&sdp->sd_rindex_spin);
840} 849}
841 850
@@ -898,7 +907,7 @@ static void forward_rgrp_set(struct gfs2_sbd *sdp, struct gfs2_rgrpd *rgd)
898 907
899static int get_local_rgrp(struct gfs2_inode *ip) 908static int get_local_rgrp(struct gfs2_inode *ip)
900{ 909{
901 struct gfs2_sbd *sdp = ip->i_sbd; 910 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
902 struct gfs2_rgrpd *rgd, *begin = NULL; 911 struct gfs2_rgrpd *rgd, *begin = NULL;
903 struct gfs2_alloc *al = &ip->i_alloc; 912 struct gfs2_alloc *al = &ip->i_alloc;
904 int flags = LM_FLAG_TRY; 913 int flags = LM_FLAG_TRY;
@@ -965,7 +974,7 @@ static int get_local_rgrp(struct gfs2_inode *ip)
965 } 974 }
966 } 975 }
967 976
968 out: 977out:
969 ip->i_last_rg_alloc = rgd->rd_ri.ri_addr; 978 ip->i_last_rg_alloc = rgd->rd_ri.ri_addr;
970 979
971 if (begin) { 980 if (begin) {
@@ -988,7 +997,7 @@ static int get_local_rgrp(struct gfs2_inode *ip)
988 997
989int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line) 998int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line)
990{ 999{
991 struct gfs2_sbd *sdp = ip->i_sbd; 1000 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
992 struct gfs2_alloc *al = &ip->i_alloc; 1001 struct gfs2_alloc *al = &ip->i_alloc;
993 int error; 1002 int error;
994 1003
@@ -1020,7 +1029,7 @@ int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line)
1020 1029
1021void gfs2_inplace_release(struct gfs2_inode *ip) 1030void gfs2_inplace_release(struct gfs2_inode *ip)
1022{ 1031{
1023 struct gfs2_sbd *sdp = ip->i_sbd; 1032 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1024 struct gfs2_alloc *al = &ip->i_alloc; 1033 struct gfs2_alloc *al = &ip->i_alloc;
1025 1034
1026 if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1) 1035 if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1)
@@ -1061,8 +1070,7 @@ unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, uint64_t block)
1061 gfs2_assert(rgd->rd_sbd, buf < length); 1070 gfs2_assert(rgd->rd_sbd, buf < length);
1062 buf_block = rgrp_block - bi->bi_start * GFS2_NBBY; 1071 buf_block = rgrp_block - bi->bi_start * GFS2_NBBY;
1063 1072
1064 type = gfs2_testbit(rgd, 1073 type = gfs2_testbit(rgd, bi->bi_bh->b_data + bi->bi_offset,
1065 bi->bi_bh->b_data + bi->bi_offset,
1066 bi->bi_len, buf_block); 1074 bi->bi_len, buf_block);
1067 1075
1068 return type; 1076 return type;
@@ -1210,7 +1218,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, uint64_t bstart,
1210 1218
1211uint64_t gfs2_alloc_data(struct gfs2_inode *ip) 1219uint64_t gfs2_alloc_data(struct gfs2_inode *ip)
1212{ 1220{
1213 struct gfs2_sbd *sdp = ip->i_sbd; 1221 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1214 struct gfs2_alloc *al = &ip->i_alloc; 1222 struct gfs2_alloc *al = &ip->i_alloc;
1215 struct gfs2_rgrpd *rgd = al->al_rgd; 1223 struct gfs2_rgrpd *rgd = al->al_rgd;
1216 uint32_t goal, blk; 1224 uint32_t goal, blk;
@@ -1254,7 +1262,7 @@ uint64_t gfs2_alloc_data(struct gfs2_inode *ip)
1254 1262
1255uint64_t gfs2_alloc_meta(struct gfs2_inode *ip) 1263uint64_t gfs2_alloc_meta(struct gfs2_inode *ip)
1256{ 1264{
1257 struct gfs2_sbd *sdp = ip->i_sbd; 1265 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1258 struct gfs2_alloc *al = &ip->i_alloc; 1266 struct gfs2_alloc *al = &ip->i_alloc;
1259 struct gfs2_rgrpd *rgd = al->al_rgd; 1267 struct gfs2_rgrpd *rgd = al->al_rgd;
1260 uint32_t goal, blk; 1268 uint32_t goal, blk;
@@ -1299,7 +1307,7 @@ uint64_t gfs2_alloc_meta(struct gfs2_inode *ip)
1299 1307
1300uint64_t gfs2_alloc_di(struct gfs2_inode *dip) 1308uint64_t gfs2_alloc_di(struct gfs2_inode *dip)
1301{ 1309{
1302 struct gfs2_sbd *sdp = dip->i_sbd; 1310 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1303 struct gfs2_alloc *al = &dip->i_alloc; 1311 struct gfs2_alloc *al = &dip->i_alloc;
1304 struct gfs2_rgrpd *rgd = al->al_rgd; 1312 struct gfs2_rgrpd *rgd = al->al_rgd;
1305 uint32_t blk; 1313 uint32_t blk;
@@ -1341,7 +1349,7 @@ uint64_t gfs2_alloc_di(struct gfs2_inode *dip)
1341 1349
1342void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) 1350void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen)
1343{ 1351{
1344 struct gfs2_sbd *sdp = ip->i_sbd; 1352 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1345 struct gfs2_rgrpd *rgd; 1353 struct gfs2_rgrpd *rgd;
1346 1354
1347 rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE); 1355 rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE);
@@ -1370,7 +1378,7 @@ void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen)
1370 1378
1371void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen) 1379void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen)
1372{ 1380{
1373 struct gfs2_sbd *sdp = ip->i_sbd; 1381 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1374 struct gfs2_rgrpd *rgd; 1382 struct gfs2_rgrpd *rgd;
1375 1383
1376 rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE); 1384 rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE);
@@ -1385,11 +1393,25 @@ void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen)
1385 gfs2_trans_add_rg(rgd); 1393 gfs2_trans_add_rg(rgd);
1386 1394
1387 gfs2_statfs_change(sdp, 0, +blen, 0); 1395 gfs2_statfs_change(sdp, 0, +blen, 0);
1388 gfs2_quota_change(ip, -(int64_t)blen, 1396 gfs2_quota_change(ip, -(int64_t)blen, ip->i_di.di_uid, ip->i_di.di_gid);
1389 ip->i_di.di_uid, ip->i_di.di_gid);
1390 gfs2_meta_wipe(ip, bstart, blen); 1397 gfs2_meta_wipe(ip, bstart, blen);
1391} 1398}
1392 1399
1400void gfs2_unlink_di(struct inode *inode)
1401{
1402 struct gfs2_inode *ip = GFS2_I(inode);
1403 struct gfs2_sbd *sdp = GFS2_SB(inode);
1404 struct gfs2_rgrpd *rgd;
1405 u64 blkno = ip->i_num.no_addr;
1406
1407 rgd = rgblk_free(sdp, blkno, 1, GFS2_BLKST_UNLINKED);
1408 if (!rgd)
1409 return;
1410 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
1411 gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data);
1412 gfs2_trans_add_rg(rgd);
1413}
1414
1393void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno) 1415void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno)
1394{ 1416{
1395 struct gfs2_sbd *sdp = rgd->rd_sbd; 1417 struct gfs2_sbd *sdp = rgd->rd_sbd;
@@ -1412,12 +1434,6 @@ void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno)
1412 gfs2_trans_add_rg(rgd); 1434 gfs2_trans_add_rg(rgd);
1413} 1435}
1414 1436
1415/**
1416 * gfs2_free_uninit_di - free a dinode block
1417 * @rgd: the resource group that contains the dinode
1418 * @ip: the inode
1419 *
1420 */
1421 1437
1422void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) 1438void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip)
1423{ 1439{
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index d2db3719cc0f..e86a532cc159 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -45,6 +45,7 @@ void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen);
45void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen); 45void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen);
46void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno); 46void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno);
47void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip); 47void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip);
48void gfs2_unlink_di(struct inode *inode);
48 49
49struct gfs2_rgrp_list { 50struct gfs2_rgrp_list {
50 unsigned int rl_rgrps; 51 unsigned int rl_rgrps;
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index a943a505bc5a..f2d287660cc9 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -31,7 +31,6 @@
31#include "rgrp.h" 31#include "rgrp.h"
32#include "super.h" 32#include "super.h"
33#include "trans.h" 33#include "trans.h"
34#include "unlinked.h"
35#include "util.h" 34#include "util.h"
36 35
37/** 36/**
@@ -55,7 +54,6 @@ void gfs2_tune_init(struct gfs2_tune *gt)
55 gt->gt_recoverd_secs = 60; 54 gt->gt_recoverd_secs = 60;
56 gt->gt_logd_secs = 1; 55 gt->gt_logd_secs = 1;
57 gt->gt_quotad_secs = 5; 56 gt->gt_quotad_secs = 5;
58 gt->gt_inoded_secs = 15;
59 gt->gt_quota_simul_sync = 64; 57 gt->gt_quota_simul_sync = 64;
60 gt->gt_quota_warn_period = 10; 58 gt->gt_quota_warn_period = 10;
61 gt->gt_quota_scale_num = 1; 59 gt->gt_quota_scale_num = 1;
@@ -202,9 +200,6 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent)
202 sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2; 200 sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2;
203 sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1; 201 sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1;
204 sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(uint64_t); 202 sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(uint64_t);
205 sdp->sd_ut_per_block = (sdp->sd_sb.sb_bsize -
206 sizeof(struct gfs2_meta_header)) /
207 sizeof(struct gfs2_unlinked_tag);
208 sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize - 203 sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize -
209 sizeof(struct gfs2_meta_header)) / 204 sizeof(struct gfs2_meta_header)) /
210 sizeof(struct gfs2_quota_change); 205 sizeof(struct gfs2_quota_change);
@@ -277,7 +272,7 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent)
277 272
278int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh) 273int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
279{ 274{
280 struct gfs2_inode *dip = sdp->sd_jindex->u.generic_ip; 275 struct gfs2_inode *dip = GFS2_I(sdp->sd_jindex);
281 struct qstr name; 276 struct qstr name;
282 char buf[20]; 277 char buf[20];
283 struct gfs2_jdesc *jd; 278 struct gfs2_jdesc *jd;
@@ -296,8 +291,7 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
296 name.len = sprintf(buf, "journal%u", sdp->sd_journals); 291 name.len = sprintf(buf, "journal%u", sdp->sd_journals);
297 name.hash = gfs2_disk_hash(name.name, name.len); 292 name.hash = gfs2_disk_hash(name.name, name.len);
298 293
299 error = gfs2_dir_search(sdp->sd_jindex, 294 error = gfs2_dir_search(sdp->sd_jindex, &name, NULL, NULL);
300 &name, NULL, NULL);
301 if (error == -ENOENT) { 295 if (error == -ENOENT) {
302 error = 0; 296 error = 0;
303 break; 297 break;
@@ -423,22 +417,19 @@ struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp)
423 417
424int gfs2_jdesc_check(struct gfs2_jdesc *jd) 418int gfs2_jdesc_check(struct gfs2_jdesc *jd)
425{ 419{
426 struct gfs2_inode *ip = jd->jd_inode->u.generic_ip; 420 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
427 struct gfs2_sbd *sdp = ip->i_sbd; 421 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
428 int ar; 422 int ar;
429 int error; 423 int error;
430 424
431 if (ip->i_di.di_size < (8 << 20) || 425 if (ip->i_di.di_size < (8 << 20) || ip->i_di.di_size > (1 << 30) ||
432 ip->i_di.di_size > (1 << 30) ||
433 (ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1))) { 426 (ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1))) {
434 gfs2_consist_inode(ip); 427 gfs2_consist_inode(ip);
435 return -EIO; 428 return -EIO;
436 } 429 }
437 jd->jd_blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; 430 jd->jd_blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift;
438 431
439 error = gfs2_write_alloc_required(ip, 432 error = gfs2_write_alloc_required(ip, 0, ip->i_di.di_size, &ar);
440 0, ip->i_di.di_size,
441 &ar);
442 if (!error && ar) { 433 if (!error && ar) {
443 gfs2_consist_inode(ip); 434 gfs2_consist_inode(ip);
444 error = -EIO; 435 error = -EIO;
@@ -456,7 +447,7 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd)
456 447
457int gfs2_make_fs_rw(struct gfs2_sbd *sdp) 448int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
458{ 449{
459 struct gfs2_inode *ip = sdp->sd_jdesc->jd_inode->u.generic_ip; 450 struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
460 struct gfs2_glock *j_gl = ip->i_gl; 451 struct gfs2_glock *j_gl = ip->i_gl;
461 struct gfs2_holder t_gh; 452 struct gfs2_holder t_gh;
462 struct gfs2_log_header head; 453 struct gfs2_log_header head;
@@ -484,9 +475,6 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
484 sdp->sd_log_sequence = head.lh_sequence + 1; 475 sdp->sd_log_sequence = head.lh_sequence + 1;
485 gfs2_log_pointers_init(sdp, head.lh_blkno); 476 gfs2_log_pointers_init(sdp, head.lh_blkno);
486 477
487 error = gfs2_unlinked_init(sdp);
488 if (error)
489 goto fail;
490 error = gfs2_quota_init(sdp); 478 error = gfs2_quota_init(sdp);
491 if (error) 479 if (error)
492 goto fail_unlinked; 480 goto fail_unlinked;
@@ -498,7 +486,6 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
498 return 0; 486 return 0;
499 487
500 fail_unlinked: 488 fail_unlinked:
501 gfs2_unlinked_cleanup(sdp);
502 489
503 fail: 490 fail:
504 t_gh.gh_flags |= GL_NOCACHE; 491 t_gh.gh_flags |= GL_NOCACHE;
@@ -519,7 +506,6 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
519 struct gfs2_holder t_gh; 506 struct gfs2_holder t_gh;
520 int error; 507 int error;
521 508
522 gfs2_unlinked_dealloc(sdp);
523 gfs2_quota_sync(sdp); 509 gfs2_quota_sync(sdp);
524 gfs2_statfs_sync(sdp); 510 gfs2_statfs_sync(sdp);
525 511
@@ -537,7 +523,6 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
537 if (t_gh.gh_gl) 523 if (t_gh.gh_gl)
538 gfs2_glock_dq_uninit(&t_gh); 524 gfs2_glock_dq_uninit(&t_gh);
539 525
540 gfs2_unlinked_cleanup(sdp);
541 gfs2_quota_cleanup(sdp); 526 gfs2_quota_cleanup(sdp);
542 527
543 return error; 528 return error;
@@ -545,9 +530,9 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
545 530
546int gfs2_statfs_init(struct gfs2_sbd *sdp) 531int gfs2_statfs_init(struct gfs2_sbd *sdp)
547{ 532{
548 struct gfs2_inode *m_ip = sdp->sd_statfs_inode->u.generic_ip; 533 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
549 struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; 534 struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master;
550 struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip; 535 struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
551 struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; 536 struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local;
552 struct buffer_head *m_bh, *l_bh; 537 struct buffer_head *m_bh, *l_bh;
553 struct gfs2_holder gh; 538 struct gfs2_holder gh;
@@ -594,7 +579,7 @@ int gfs2_statfs_init(struct gfs2_sbd *sdp)
594void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free, 579void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free,
595 int64_t dinodes) 580 int64_t dinodes)
596{ 581{
597 struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip; 582 struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
598 struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; 583 struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local;
599 struct buffer_head *l_bh; 584 struct buffer_head *l_bh;
600 int error; 585 int error;
@@ -620,8 +605,8 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free,
620 605
621int gfs2_statfs_sync(struct gfs2_sbd *sdp) 606int gfs2_statfs_sync(struct gfs2_sbd *sdp)
622{ 607{
623 struct gfs2_inode *m_ip = sdp->sd_statfs_inode->u.generic_ip; 608 struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
624 struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip; 609 struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
625 struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master; 610 struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master;
626 struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local; 611 struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local;
627 struct gfs2_holder gh; 612 struct gfs2_holder gh;
@@ -852,10 +837,8 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp,
852 error = -ENOMEM; 837 error = -ENOMEM;
853 goto out; 838 goto out;
854 } 839 }
855 ip = jd->jd_inode->u.generic_ip; 840 ip = GFS2_I(jd->jd_inode);
856 error = gfs2_glock_nq_init(ip->i_gl, 841 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh);
857 LM_ST_SHARED, 0,
858 &lfcc->gh);
859 if (error) { 842 if (error) {
860 kfree(lfcc); 843 kfree(lfcc);
861 goto out; 844 goto out;
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index d32a2c54daee..3c4cb4558905 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -453,7 +453,6 @@ TUNE_ATTR_DAEMON(scand_secs, scand_process);
453TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process); 453TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process);
454TUNE_ATTR_DAEMON(logd_secs, logd_process); 454TUNE_ATTR_DAEMON(logd_secs, logd_process);
455TUNE_ATTR_DAEMON(quotad_secs, quotad_process); 455TUNE_ATTR_DAEMON(quotad_secs, quotad_process);
456TUNE_ATTR_DAEMON(inoded_secs, inoded_process);
457TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); 456TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store);
458 457
459static struct attribute *tune_attrs[] = { 458static struct attribute *tune_attrs[] = {
@@ -485,7 +484,6 @@ static struct attribute *tune_attrs[] = {
485 &tune_attr_recoverd_secs.attr, 484 &tune_attr_recoverd_secs.attr,
486 &tune_attr_logd_secs.attr, 485 &tune_attr_logd_secs.attr,
487 &tune_attr_quotad_secs.attr, 486 &tune_attr_quotad_secs.attr,
488 &tune_attr_inoded_secs.attr,
489 &tune_attr_quota_scale.attr, 487 &tune_attr_quota_scale.attr,
490 &tune_attr_new_files_jdata.attr, 488 &tune_attr_new_files_jdata.attr,
491 &tune_attr_new_files_directio.attr, 489 &tune_attr_new_files_directio.attr,
diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h
index 60ef163dd9bb..fbef3f5a99e3 100644
--- a/fs/gfs2/trans.h
+++ b/fs/gfs2/trans.h
@@ -17,7 +17,6 @@
17#define RES_LEAF 1 17#define RES_LEAF 1
18#define RES_RG_BIT 2 18#define RES_RG_BIT 2
19#define RES_EATTR 1 19#define RES_EATTR 1
20#define RES_UNLINKED 1
21#define RES_STATFS 1 20#define RES_STATFS 1
22#define RES_QUOTA 2 21#define RES_QUOTA 2
23 22
diff --git a/fs/gfs2/unlinked.c b/fs/gfs2/unlinked.c
deleted file mode 100644
index b92d73002055..000000000000
--- a/fs/gfs2/unlinked.c
+++ /dev/null
@@ -1,459 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License v.2.
8 */
9
10#include <linux/sched.h>
11#include <linux/slab.h>
12#include <linux/spinlock.h>
13#include <linux/completion.h>
14#include <linux/buffer_head.h>
15#include <linux/kthread.h>
16#include <linux/gfs2_ondisk.h>
17
18#include "gfs2.h"
19#include "lm_interface.h"
20#include "incore.h"
21#include "bmap.h"
22#include "inode.h"
23#include "meta_io.h"
24#include "trans.h"
25#include "unlinked.h"
26#include "util.h"
27
28static int munge_ondisk(struct gfs2_sbd *sdp, unsigned int slot,
29 struct gfs2_unlinked_tag *ut)
30{
31 struct gfs2_inode *ip = sdp->sd_ut_inode->u.generic_ip;
32 unsigned int block, offset;
33 uint64_t dblock;
34 int new = 0;
35 struct buffer_head *bh;
36 int error;
37 int boundary;
38
39 block = slot / sdp->sd_ut_per_block;
40 offset = slot % sdp->sd_ut_per_block;
41
42 error = gfs2_block_map(ip->i_vnode, block, &new, &dblock, &boundary);
43 if (error)
44 return error;
45 error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh);
46 if (error)
47 return error;
48 if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_UT)) {
49 error = -EIO;
50 goto out;
51 }
52
53 mutex_lock(&sdp->sd_unlinked_mutex);
54 gfs2_trans_add_bh(ip->i_gl, bh, 1);
55 gfs2_unlinked_tag_out(ut, bh->b_data +
56 sizeof(struct gfs2_meta_header) +
57 offset * sizeof(struct gfs2_unlinked_tag));
58 mutex_unlock(&sdp->sd_unlinked_mutex);
59
60 out:
61 brelse(bh);
62
63 return error;
64}
65
66static void ul_hash(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul)
67{
68 spin_lock(&sdp->sd_unlinked_spin);
69 list_add(&ul->ul_list, &sdp->sd_unlinked_list);
70 gfs2_assert(sdp, ul->ul_count);
71 ul->ul_count++;
72 atomic_inc(&sdp->sd_unlinked_count);
73 spin_unlock(&sdp->sd_unlinked_spin);
74}
75
76static void ul_unhash(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul)
77{
78 spin_lock(&sdp->sd_unlinked_spin);
79 list_del_init(&ul->ul_list);
80 gfs2_assert(sdp, ul->ul_count > 1);
81 ul->ul_count--;
82 gfs2_assert_warn(sdp, atomic_read(&sdp->sd_unlinked_count) > 0);
83 atomic_dec(&sdp->sd_unlinked_count);
84 spin_unlock(&sdp->sd_unlinked_spin);
85}
86
87static struct gfs2_unlinked *ul_fish(struct gfs2_sbd *sdp)
88{
89 struct list_head *head;
90 struct gfs2_unlinked *ul;
91 int found = 0;
92
93 if (sdp->sd_vfs->s_flags & MS_RDONLY)
94 return NULL;
95
96 spin_lock(&sdp->sd_unlinked_spin);
97
98 head = &sdp->sd_unlinked_list;
99
100 list_for_each_entry(ul, head, ul_list) {
101 if (test_bit(ULF_LOCKED, &ul->ul_flags))
102 continue;
103
104 list_move_tail(&ul->ul_list, head);
105 ul->ul_count++;
106 set_bit(ULF_LOCKED, &ul->ul_flags);
107 found = 1;
108
109 break;
110 }
111
112 if (!found)
113 ul = NULL;
114
115 spin_unlock(&sdp->sd_unlinked_spin);
116
117 return ul;
118}
119
120/**
121 * enforce_limit - limit the number of inodes waiting to be deallocated
122 * @sdp: the filesystem
123 *
124 * Returns: errno
125 */
126
127static void enforce_limit(struct gfs2_sbd *sdp)
128{
129 unsigned int tries = 0, min = 0;
130 int error;
131
132 if (atomic_read(&sdp->sd_unlinked_count) <
133 gfs2_tune_get(sdp, gt_ilimit))
134 return;
135
136 tries = gfs2_tune_get(sdp, gt_ilimit_tries);
137 min = gfs2_tune_get(sdp, gt_ilimit_min);
138
139 while (tries--) {
140 struct gfs2_unlinked *ul = ul_fish(sdp);
141 if (!ul)
142 break;
143 error = gfs2_inode_dealloc(sdp, ul);
144 gfs2_unlinked_put(sdp, ul);
145
146 if (!error) {
147 if (!--min)
148 break;
149 } else if (error != 1)
150 break;
151 }
152}
153
154static struct gfs2_unlinked *ul_alloc(struct gfs2_sbd *sdp)
155{
156 struct gfs2_unlinked *ul;
157
158 ul = kzalloc(sizeof(struct gfs2_unlinked), GFP_KERNEL);
159 if (ul) {
160 INIT_LIST_HEAD(&ul->ul_list);
161 ul->ul_count = 1;
162 set_bit(ULF_LOCKED, &ul->ul_flags);
163 }
164
165 return ul;
166}
167
168int gfs2_unlinked_get(struct gfs2_sbd *sdp, struct gfs2_unlinked **ul)
169{
170 unsigned int c, o = 0, b;
171 unsigned char byte = 0;
172
173 enforce_limit(sdp);
174
175 *ul = ul_alloc(sdp);
176 if (!*ul)
177 return -ENOMEM;
178
179 spin_lock(&sdp->sd_unlinked_spin);
180
181 for (c = 0; c < sdp->sd_unlinked_chunks; c++)
182 for (o = 0; o < PAGE_SIZE; o++) {
183 byte = sdp->sd_unlinked_bitmap[c][o];
184 if (byte != 0xFF)
185 goto found;
186 }
187
188 goto fail;
189
190found:
191 for (b = 0; b < 8; b++)
192 if (!(byte & (1 << b)))
193 break;
194 (*ul)->ul_slot = c * (8 * PAGE_SIZE) + o * 8 + b;
195
196 if ((*ul)->ul_slot >= sdp->sd_unlinked_slots)
197 goto fail;
198
199 sdp->sd_unlinked_bitmap[c][o] |= 1 << b;
200
201 spin_unlock(&sdp->sd_unlinked_spin);
202
203 return 0;
204
205fail:
206 spin_unlock(&sdp->sd_unlinked_spin);
207 kfree(*ul);
208 return -ENOSPC;
209}
210
211void gfs2_unlinked_put(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul)
212{
213 gfs2_assert_warn(sdp, test_and_clear_bit(ULF_LOCKED, &ul->ul_flags));
214
215 spin_lock(&sdp->sd_unlinked_spin);
216 gfs2_assert(sdp, ul->ul_count);
217 ul->ul_count--;
218 if (!ul->ul_count) {
219 gfs2_icbit_munge(sdp, sdp->sd_unlinked_bitmap, ul->ul_slot, 0);
220 spin_unlock(&sdp->sd_unlinked_spin);
221 kfree(ul);
222 } else
223 spin_unlock(&sdp->sd_unlinked_spin);
224}
225
226int gfs2_unlinked_ondisk_add(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul)
227{
228 int error;
229
230 gfs2_assert_warn(sdp, test_bit(ULF_LOCKED, &ul->ul_flags));
231 gfs2_assert_warn(sdp, list_empty(&ul->ul_list));
232
233 error = munge_ondisk(sdp, ul->ul_slot, &ul->ul_ut);
234 if (!error)
235 ul_hash(sdp, ul);
236
237 return error;
238}
239
240int gfs2_unlinked_ondisk_munge(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul)
241{
242 int error;
243
244 gfs2_assert_warn(sdp, test_bit(ULF_LOCKED, &ul->ul_flags));
245 gfs2_assert_warn(sdp, !list_empty(&ul->ul_list));
246
247 error = munge_ondisk(sdp, ul->ul_slot, &ul->ul_ut);
248
249 return error;
250}
251
252int gfs2_unlinked_ondisk_rm(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul)
253{
254 struct gfs2_unlinked_tag ut;
255 int error;
256
257 gfs2_assert_warn(sdp, test_bit(ULF_LOCKED, &ul->ul_flags));
258 gfs2_assert_warn(sdp, !list_empty(&ul->ul_list));
259
260 memset(&ut, 0, sizeof(struct gfs2_unlinked_tag));
261
262 error = munge_ondisk(sdp, ul->ul_slot, &ut);
263 if (error)
264 return error;
265
266 ul_unhash(sdp, ul);
267
268 return 0;
269}
270
271/**
272 * gfs2_unlinked_dealloc - Go through the list of inodes to be deallocated
273 * @sdp: the filesystem
274 *
275 * Returns: errno
276 */
277
278int gfs2_unlinked_dealloc(struct gfs2_sbd *sdp)
279{
280 unsigned int hits, strikes;
281 int error;
282
283 for (;;) {
284 hits = 0;
285 strikes = 0;
286
287 for (;;) {
288 struct gfs2_unlinked *ul = ul_fish(sdp);
289 if (!ul)
290 return 0;
291 error = gfs2_inode_dealloc(sdp, ul);
292 gfs2_unlinked_put(sdp, ul);
293
294 if (!error) {
295 hits++;
296 if (strikes)
297 strikes--;
298 } else if (error == 1) {
299 strikes++;
300 if (strikes >=
301 atomic_read(&sdp->sd_unlinked_count)) {
302 error = 0;
303 break;
304 }
305 } else
306 return error;
307 }
308
309 if (!hits || kthread_should_stop())
310 break;
311
312 cond_resched();
313 }
314
315 return 0;
316}
317
318int gfs2_unlinked_init(struct gfs2_sbd *sdp)
319{
320 struct gfs2_inode *ip = sdp->sd_ut_inode->u.generic_ip;
321 unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift;
322 unsigned int x, slot = 0;
323 unsigned int found = 0;
324 uint64_t dblock;
325 uint32_t extlen = 0;
326 int error;
327
328 if (!ip->i_di.di_size ||
329 ip->i_di.di_size > (64 << 20) ||
330 ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1)) {
331 gfs2_consist_inode(ip);
332 return -EIO;
333 }
334 sdp->sd_unlinked_slots = blocks * sdp->sd_ut_per_block;
335 sdp->sd_unlinked_chunks = DIV_ROUND_UP(sdp->sd_unlinked_slots,
336 8 * PAGE_SIZE);
337
338 error = -ENOMEM;
339
340 sdp->sd_unlinked_bitmap = kcalloc(sdp->sd_unlinked_chunks,
341 sizeof(unsigned char *),
342 GFP_KERNEL);
343 if (!sdp->sd_unlinked_bitmap)
344 return error;
345
346 for (x = 0; x < sdp->sd_unlinked_chunks; x++) {
347 sdp->sd_unlinked_bitmap[x] = kzalloc(PAGE_SIZE, GFP_KERNEL);
348 if (!sdp->sd_unlinked_bitmap[x])
349 goto fail;
350 }
351
352 for (x = 0; x < blocks; x++) {
353 struct buffer_head *bh;
354 unsigned int y;
355
356 if (!extlen) {
357 int new = 0;
358 error = gfs2_extent_map(ip->i_vnode, x, &new, &dblock, &extlen);
359 if (error)
360 goto fail;
361 }
362 gfs2_meta_ra(ip->i_gl, dblock, extlen);
363 error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT,
364 &bh);
365 if (error)
366 goto fail;
367 error = -EIO;
368 if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_UT)) {
369 brelse(bh);
370 goto fail;
371 }
372
373 for (y = 0;
374 y < sdp->sd_ut_per_block && slot < sdp->sd_unlinked_slots;
375 y++, slot++) {
376 struct gfs2_unlinked_tag ut;
377 struct gfs2_unlinked *ul;
378
379 gfs2_unlinked_tag_in(&ut, bh->b_data +
380 sizeof(struct gfs2_meta_header) +
381 y * sizeof(struct gfs2_unlinked_tag));
382 if (!ut.ut_inum.no_addr)
383 continue;
384
385 error = -ENOMEM;
386 ul = ul_alloc(sdp);
387 if (!ul) {
388 brelse(bh);
389 goto fail;
390 }
391 ul->ul_ut = ut;
392 ul->ul_slot = slot;
393
394 spin_lock(&sdp->sd_unlinked_spin);
395 gfs2_icbit_munge(sdp, sdp->sd_unlinked_bitmap, slot, 1);
396 spin_unlock(&sdp->sd_unlinked_spin);
397 ul_hash(sdp, ul);
398
399 gfs2_unlinked_put(sdp, ul);
400 found++;
401 }
402
403 brelse(bh);
404 dblock++;
405 extlen--;
406 }
407
408 if (found)
409 fs_info(sdp, "found %u unlinked inodes\n", found);
410
411 return 0;
412
413fail:
414 gfs2_unlinked_cleanup(sdp);
415 return error;
416}
417
418/**
419 * gfs2_unlinked_cleanup - get rid of any extra struct gfs2_unlinked structures
420 * @sdp: the filesystem
421 *
422 */
423
424void gfs2_unlinked_cleanup(struct gfs2_sbd *sdp)
425{
426 struct list_head *head = &sdp->sd_unlinked_list;
427 struct gfs2_unlinked *ul;
428 unsigned int x;
429
430 spin_lock(&sdp->sd_unlinked_spin);
431 while (!list_empty(head)) {
432 ul = list_entry(head->next, struct gfs2_unlinked, ul_list);
433
434 if (ul->ul_count > 1) {
435 list_move_tail(&ul->ul_list, head);
436 spin_unlock(&sdp->sd_unlinked_spin);
437 schedule();
438 spin_lock(&sdp->sd_unlinked_spin);
439 continue;
440 }
441
442 list_del_init(&ul->ul_list);
443 atomic_dec(&sdp->sd_unlinked_count);
444
445 gfs2_assert_warn(sdp, ul->ul_count == 1);
446 gfs2_assert_warn(sdp, !test_bit(ULF_LOCKED, &ul->ul_flags));
447 kfree(ul);
448 }
449 spin_unlock(&sdp->sd_unlinked_spin);
450
451 gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_unlinked_count));
452
453 if (sdp->sd_unlinked_bitmap) {
454 for (x = 0; x < sdp->sd_unlinked_chunks; x++)
455 kfree(sdp->sd_unlinked_bitmap[x]);
456 kfree(sdp->sd_unlinked_bitmap);
457 }
458}
459
diff --git a/fs/gfs2/unlinked.h b/fs/gfs2/unlinked.h
deleted file mode 100644
index 159cf5ffe47e..000000000000
--- a/fs/gfs2/unlinked.h
+++ /dev/null
@@ -1,25 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License v.2.
8 */
9
10#ifndef __UNLINKED_DOT_H__
11#define __UNLINKED_DOT_H__
12
13int gfs2_unlinked_get(struct gfs2_sbd *sdp, struct gfs2_unlinked **ul);
14void gfs2_unlinked_put(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul);
15
16int gfs2_unlinked_ondisk_add(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul);
17int gfs2_unlinked_ondisk_munge(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul);
18int gfs2_unlinked_ondisk_rm(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul);
19
20int gfs2_unlinked_dealloc(struct gfs2_sbd *sdp);
21
22int gfs2_unlinked_init(struct gfs2_sbd *sdp);
23void gfs2_unlinked_cleanup(struct gfs2_sbd *sdp);
24
25#endif /* __UNLINKED_DOT_H__ */
diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
index 88974e9824f7..39e67b1ec70a 100644
--- a/fs/gfs2/util.c
+++ b/fs/gfs2/util.c
@@ -109,7 +109,7 @@ int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function,
109int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, 109int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
110 const char *function, char *file, unsigned int line) 110 const char *function, char *file, unsigned int line)
111{ 111{
112 struct gfs2_sbd *sdp = ip->i_sbd; 112 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
113 int rv; 113 int rv;
114 rv = gfs2_lm_withdraw(sdp, 114 rv = gfs2_lm_withdraw(sdp,
115 "GFS2: fsid=%s: fatal: filesystem consistency error\n" 115 "GFS2: fsid=%s: fatal: filesystem consistency error\n"