aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/gfs2/inode.c')
-rw-r--r--fs/gfs2/inode.c809
1 files changed, 176 insertions, 633 deletions
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}