aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-04-30 14:27:14 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-30 14:27:14 -0400
commite72859b87f57826f41e07a87bbaed65ed1133f85 (patch)
treee4f60e36346d67638302b888a69c416766d015f9 /fs/gfs2
parentc9ef713993ba168b38d1a97ea0ab00874f1da022 (diff)
parent222cb538f5f18741466dc27cc6cf4375bccf1f89 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw
Pull GFS2 updates from Steven Whitehouse: "There is not a whole lot of change this time - there are some further changes which are in the works, but those will be held over until next time. Here there are some clean ups to inode creation, the addition of an origin (local or remote) indicator to glock demote requests, removal of one of the remaining GFP_NOFAIL allocations during log flushes, one minor clean up, and a one liner bug fix." * git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw: GFS2: Flush work queue before clearing glock hash tables GFS2: Add origin indicator to glock demote tracing GFS2: Add origin indicator to glock callbacks GFS2: replace gfs2_ail structure with gfs2_trans GFS2: Remove vestigial parameter ip from function rs_deltree GFS2: Use gfs2_dinode_out() in the inode create path GFS2: Remove gfs2_refresh_inode from inode creation path GFS2: Clean up inode creation path
Diffstat (limited to 'fs/gfs2')
-rw-r--r--fs/gfs2/aops.c2
-rw-r--r--fs/gfs2/bmap.c2
-rw-r--r--fs/gfs2/glock.c28
-rw-r--r--fs/gfs2/glock.h1
-rw-r--r--fs/gfs2/glops.c4
-rw-r--r--fs/gfs2/incore.h19
-rw-r--r--fs/gfs2/inode.c188
-rw-r--r--fs/gfs2/log.c104
-rw-r--r--fs/gfs2/lops.c32
-rw-r--r--fs/gfs2/lops.h5
-rw-r--r--fs/gfs2/meta_io.c2
-rw-r--r--fs/gfs2/rgrp.c24
-rw-r--r--fs/gfs2/rgrp.h2
-rw-r--r--fs/gfs2/super.c2
-rw-r--r--fs/gfs2/trace_gfs2.h11
-rw-r--r--fs/gfs2/trans.c4
16 files changed, 188 insertions, 242 deletions
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index 24f414f0ce61..9883694f1e7c 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -1055,7 +1055,7 @@ int gfs2_releasepage(struct page *page, gfp_t gfp_mask)
1055 if (atomic_read(&bh->b_count)) 1055 if (atomic_read(&bh->b_count))
1056 goto cannot_release; 1056 goto cannot_release;
1057 bd = bh->b_private; 1057 bd = bh->b_private;
1058 if (bd && bd->bd_ail) 1058 if (bd && bd->bd_tr)
1059 goto cannot_release; 1059 goto cannot_release;
1060 if (buffer_pinned(bh) || buffer_dirty(bh)) 1060 if (buffer_pinned(bh) || buffer_dirty(bh))
1061 goto not_possible; 1061 goto not_possible;
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 5e83657f046e..1dc9a13ce6bb 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -787,7 +787,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
787 goto out_rlist; 787 goto out_rlist;
788 788
789 if (gfs2_rs_active(ip->i_res)) /* needs to be done with the rgrp glock held */ 789 if (gfs2_rs_active(ip->i_res)) /* needs to be done with the rgrp glock held */
790 gfs2_rs_deltree(ip, ip->i_res); 790 gfs2_rs_deltree(ip->i_res);
791 791
792 error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + 792 error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE +
793 RES_INDIRECT + RES_STATFS + RES_QUOTA, 793 RES_INDIRECT + RES_STATFS + RES_QUOTA,
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index bd8223595495..9435384562a2 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -912,7 +912,7 @@ int gfs2_glock_wait(struct gfs2_holder *gh)
912 */ 912 */
913 913
914static void handle_callback(struct gfs2_glock *gl, unsigned int state, 914static void handle_callback(struct gfs2_glock *gl, unsigned int state,
915 unsigned long delay) 915 unsigned long delay, bool remote)
916{ 916{
917 int bit = delay ? GLF_PENDING_DEMOTE : GLF_DEMOTE; 917 int bit = delay ? GLF_PENDING_DEMOTE : GLF_DEMOTE;
918 918
@@ -925,8 +925,8 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state,
925 gl->gl_demote_state = LM_ST_UNLOCKED; 925 gl->gl_demote_state = LM_ST_UNLOCKED;
926 } 926 }
927 if (gl->gl_ops->go_callback) 927 if (gl->gl_ops->go_callback)
928 gl->gl_ops->go_callback(gl); 928 gl->gl_ops->go_callback(gl, remote);
929 trace_gfs2_demote_rq(gl); 929 trace_gfs2_demote_rq(gl, remote);
930} 930}
931 931
932void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...) 932void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...)
@@ -1091,7 +1091,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
1091 1091
1092 spin_lock(&gl->gl_spin); 1092 spin_lock(&gl->gl_spin);
1093 if (gh->gh_flags & GL_NOCACHE) 1093 if (gh->gh_flags & GL_NOCACHE)
1094 handle_callback(gl, LM_ST_UNLOCKED, 0); 1094 handle_callback(gl, LM_ST_UNLOCKED, 0, false);
1095 1095
1096 list_del_init(&gh->gh_list); 1096 list_del_init(&gh->gh_list);
1097 if (find_first_holder(gl) == NULL) { 1097 if (find_first_holder(gl) == NULL) {
@@ -1279,19 +1279,6 @@ void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs)
1279 gfs2_glock_dq(&ghs[num_gh]); 1279 gfs2_glock_dq(&ghs[num_gh]);
1280} 1280}
1281 1281
1282/**
1283 * gfs2_glock_dq_uninit_m - release multiple glocks
1284 * @num_gh: the number of structures
1285 * @ghs: an array of struct gfs2_holder structures
1286 *
1287 */
1288
1289void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs)
1290{
1291 while (num_gh--)
1292 gfs2_glock_dq_uninit(&ghs[num_gh]);
1293}
1294
1295void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state) 1282void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
1296{ 1283{
1297 unsigned long delay = 0; 1284 unsigned long delay = 0;
@@ -1309,7 +1296,7 @@ void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
1309 } 1296 }
1310 1297
1311 spin_lock(&gl->gl_spin); 1298 spin_lock(&gl->gl_spin);
1312 handle_callback(gl, state, delay); 1299 handle_callback(gl, state, delay, true);
1313 spin_unlock(&gl->gl_spin); 1300 spin_unlock(&gl->gl_spin);
1314 if (queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0) 1301 if (queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0)
1315 gfs2_glock_put(gl); 1302 gfs2_glock_put(gl);
@@ -1422,7 +1409,7 @@ __acquires(&lru_lock)
1422 spin_unlock(&lru_lock); 1409 spin_unlock(&lru_lock);
1423 spin_lock(&gl->gl_spin); 1410 spin_lock(&gl->gl_spin);
1424 if (demote_ok(gl)) 1411 if (demote_ok(gl))
1425 handle_callback(gl, LM_ST_UNLOCKED, 0); 1412 handle_callback(gl, LM_ST_UNLOCKED, 0, false);
1426 WARN_ON(!test_and_clear_bit(GLF_LOCK, &gl->gl_flags)); 1413 WARN_ON(!test_and_clear_bit(GLF_LOCK, &gl->gl_flags));
1427 smp_mb__after_clear_bit(); 1414 smp_mb__after_clear_bit();
1428 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0) 1415 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
@@ -1547,7 +1534,7 @@ static void clear_glock(struct gfs2_glock *gl)
1547 1534
1548 spin_lock(&gl->gl_spin); 1535 spin_lock(&gl->gl_spin);
1549 if (gl->gl_state != LM_ST_UNLOCKED) 1536 if (gl->gl_state != LM_ST_UNLOCKED)
1550 handle_callback(gl, LM_ST_UNLOCKED, 0); 1537 handle_callback(gl, LM_ST_UNLOCKED, 0, false);
1551 spin_unlock(&gl->gl_spin); 1538 spin_unlock(&gl->gl_spin);
1552 gfs2_glock_hold(gl); 1539 gfs2_glock_hold(gl);
1553 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0) 1540 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
@@ -1590,6 +1577,7 @@ static void dump_glock_func(struct gfs2_glock *gl)
1590void gfs2_gl_hash_clear(struct gfs2_sbd *sdp) 1577void gfs2_gl_hash_clear(struct gfs2_sbd *sdp)
1591{ 1578{
1592 set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags); 1579 set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags);
1580 flush_workqueue(glock_workqueue);
1593 glock_hash_walk(clear_glock, sdp); 1581 glock_hash_walk(clear_glock, sdp);
1594 flush_workqueue(glock_workqueue); 1582 flush_workqueue(glock_workqueue);
1595 wait_event(sdp->sd_glock_wait, atomic_read(&sdp->sd_glock_disposal) == 0); 1583 wait_event(sdp->sd_glock_wait, atomic_read(&sdp->sd_glock_disposal) == 0);
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index fd580b7861d5..69f66e3d22bf 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -201,7 +201,6 @@ extern int gfs2_glock_nq_num(struct gfs2_sbd *sdp, u64 number,
201 struct gfs2_holder *gh); 201 struct gfs2_holder *gh);
202extern int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs); 202extern int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs);
203extern void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs); 203extern void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs);
204extern void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs);
205extern int gfs2_dump_glock(struct seq_file *seq, const struct gfs2_glock *gl); 204extern int gfs2_dump_glock(struct seq_file *seq, const struct gfs2_glock *gl);
206#define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) { gfs2_dump_glock(NULL, gl); BUG(); } } while(0) 205#define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) { gfs2_dump_glock(NULL, gl); BUG(); } } while(0)
207extern __printf(2, 3) 206extern __printf(2, 3)
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 444b6503ebc4..c66e99c97571 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -515,12 +515,12 @@ static int trans_go_demote_ok(const struct gfs2_glock *gl)
515 * 515 *
516 * gl_spin lock is held while calling this 516 * gl_spin lock is held while calling this
517 */ 517 */
518static void iopen_go_callback(struct gfs2_glock *gl) 518static void iopen_go_callback(struct gfs2_glock *gl, bool remote)
519{ 519{
520 struct gfs2_inode *ip = (struct gfs2_inode *)gl->gl_object; 520 struct gfs2_inode *ip = (struct gfs2_inode *)gl->gl_object;
521 struct gfs2_sbd *sdp = gl->gl_sbd; 521 struct gfs2_sbd *sdp = gl->gl_sbd;
522 522
523 if (sdp->sd_vfs->s_flags & MS_RDONLY) 523 if (!remote || (sdp->sd_vfs->s_flags & MS_RDONLY))
524 return; 524 return;
525 525
526 if (gl->gl_demote_state == LM_ST_UNLOCKED && 526 if (gl->gl_demote_state == LM_ST_UNLOCKED &&
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 5c29216e9cc1..26aabd7caba7 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -31,7 +31,6 @@ struct gfs2_holder;
31struct gfs2_glock; 31struct gfs2_glock;
32struct gfs2_quota_data; 32struct gfs2_quota_data;
33struct gfs2_trans; 33struct gfs2_trans;
34struct gfs2_ail;
35struct gfs2_jdesc; 34struct gfs2_jdesc;
36struct gfs2_sbd; 35struct gfs2_sbd;
37struct lm_lockops; 36struct lm_lockops;
@@ -53,7 +52,7 @@ struct gfs2_log_header_host {
53 52
54struct gfs2_log_operations { 53struct gfs2_log_operations {
55 void (*lo_before_commit) (struct gfs2_sbd *sdp); 54 void (*lo_before_commit) (struct gfs2_sbd *sdp);
56 void (*lo_after_commit) (struct gfs2_sbd *sdp, struct gfs2_ail *ai); 55 void (*lo_after_commit) (struct gfs2_sbd *sdp, struct gfs2_trans *tr);
57 void (*lo_before_scan) (struct gfs2_jdesc *jd, 56 void (*lo_before_scan) (struct gfs2_jdesc *jd,
58 struct gfs2_log_header_host *head, int pass); 57 struct gfs2_log_header_host *head, int pass);
59 int (*lo_scan_elements) (struct gfs2_jdesc *jd, unsigned int start, 58 int (*lo_scan_elements) (struct gfs2_jdesc *jd, unsigned int start,
@@ -139,7 +138,7 @@ struct gfs2_bufdata {
139 struct list_head bd_list; 138 struct list_head bd_list;
140 const struct gfs2_log_operations *bd_ops; 139 const struct gfs2_log_operations *bd_ops;
141 140
142 struct gfs2_ail *bd_ail; 141 struct gfs2_trans *bd_tr;
143 struct list_head bd_ail_st_list; 142 struct list_head bd_ail_st_list;
144 struct list_head bd_ail_gl_list; 143 struct list_head bd_ail_gl_list;
145}; 144};
@@ -211,7 +210,7 @@ struct gfs2_glock_operations {
211 int (*go_lock) (struct gfs2_holder *gh); 210 int (*go_lock) (struct gfs2_holder *gh);
212 void (*go_unlock) (struct gfs2_holder *gh); 211 void (*go_unlock) (struct gfs2_holder *gh);
213 int (*go_dump)(struct seq_file *seq, const struct gfs2_glock *gl); 212 int (*go_dump)(struct seq_file *seq, const struct gfs2_glock *gl);
214 void (*go_callback) (struct gfs2_glock *gl); 213 void (*go_callback)(struct gfs2_glock *gl, bool remote);
215 const int go_type; 214 const int go_type;
216 const unsigned long go_flags; 215 const unsigned long go_flags;
217#define GLOF_ASPACE 1 216#define GLOF_ASPACE 1
@@ -433,6 +432,7 @@ struct gfs2_trans {
433 struct gfs2_holder tr_t_gh; 432 struct gfs2_holder tr_t_gh;
434 433
435 int tr_touched; 434 int tr_touched;
435 int tr_attached;
436 436
437 unsigned int tr_num_buf_new; 437 unsigned int tr_num_buf_new;
438 unsigned int tr_num_databuf_new; 438 unsigned int tr_num_databuf_new;
@@ -440,14 +440,12 @@ struct gfs2_trans {
440 unsigned int tr_num_databuf_rm; 440 unsigned int tr_num_databuf_rm;
441 unsigned int tr_num_revoke; 441 unsigned int tr_num_revoke;
442 unsigned int tr_num_revoke_rm; 442 unsigned int tr_num_revoke_rm;
443};
444 443
445struct gfs2_ail { 444 struct list_head tr_list;
446 struct list_head ai_list;
447 445
448 unsigned int ai_first; 446 unsigned int tr_first;
449 struct list_head ai_ail1_list; 447 struct list_head tr_ail1_list;
450 struct list_head ai_ail2_list; 448 struct list_head tr_ail2_list;
451}; 449};
452 450
453struct gfs2_journal_extent { 451struct gfs2_journal_extent {
@@ -710,6 +708,7 @@ struct gfs2_sbd {
710 708
711 spinlock_t sd_log_lock; 709 spinlock_t sd_log_lock;
712 710
711 struct gfs2_trans *sd_log_tr;
713 unsigned int sd_log_blks_reserved; 712 unsigned int sd_log_blks_reserved;
714 unsigned int sd_log_commited_buf; 713 unsigned int sd_log_commited_buf;
715 unsigned int sd_log_commited_databuf; 714 unsigned int sd_log_commited_databuf;
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index cc00bd1d1f87..8833a4f264e3 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -392,11 +392,15 @@ static int alloc_dinode(struct gfs2_inode *ip, u32 flags)
392 int error; 392 int error;
393 int dblocks = 1; 393 int dblocks = 1;
394 394
395 error = gfs2_inplace_reserve(ip, RES_DINODE, flags); 395 error = gfs2_quota_lock_check(ip);
396 if (error) 396 if (error)
397 goto out; 397 goto out;
398 398
399 error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS, 0); 399 error = gfs2_inplace_reserve(ip, RES_DINODE, flags);
400 if (error)
401 goto out_quota;
402
403 error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 0);
400 if (error) 404 if (error)
401 goto out_ipreserv; 405 goto out_ipreserv;
402 406
@@ -409,6 +413,8 @@ static int alloc_dinode(struct gfs2_inode *ip, u32 flags)
409 413
410out_ipreserv: 414out_ipreserv:
411 gfs2_inplace_release(ip); 415 gfs2_inplace_release(ip);
416out_quota:
417 gfs2_quota_unlock(ip);
412out: 418out:
413 return error; 419 return error;
414} 420}
@@ -440,59 +446,27 @@ static void gfs2_init_dir(struct buffer_head *dibh,
440 */ 446 */
441 447
442static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip, 448static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,
443 const char *symname, struct buffer_head **bhp) 449 const char *symname)
444{ 450{
445 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
446 struct gfs2_dinode *di; 451 struct gfs2_dinode *di;
447 struct buffer_head *dibh; 452 struct buffer_head *dibh;
448 struct timespec tv = CURRENT_TIME;
449 453
450 dibh = gfs2_meta_new(ip->i_gl, ip->i_no_addr); 454 dibh = gfs2_meta_new(ip->i_gl, ip->i_no_addr);
451 gfs2_trans_add_meta(ip->i_gl, dibh); 455 gfs2_trans_add_meta(ip->i_gl, dibh);
452 gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI);
453 gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
454 di = (struct gfs2_dinode *)dibh->b_data; 456 di = (struct gfs2_dinode *)dibh->b_data;
457 gfs2_dinode_out(ip, di);
455 458
456 di->di_num.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino);
457 di->di_num.no_addr = cpu_to_be64(ip->i_no_addr);
458 di->di_mode = cpu_to_be32(ip->i_inode.i_mode);
459 di->di_uid = cpu_to_be32(i_uid_read(&ip->i_inode));
460 di->di_gid = cpu_to_be32(i_gid_read(&ip->i_inode));
461 di->di_nlink = 0;
462 di->di_size = cpu_to_be64(ip->i_inode.i_size);
463 di->di_blocks = cpu_to_be64(1);
464 di->di_atime = di->di_mtime = di->di_ctime = cpu_to_be64(tv.tv_sec);
465 di->di_major = cpu_to_be32(MAJOR(ip->i_inode.i_rdev)); 459 di->di_major = cpu_to_be32(MAJOR(ip->i_inode.i_rdev));
466 di->di_minor = cpu_to_be32(MINOR(ip->i_inode.i_rdev)); 460 di->di_minor = cpu_to_be32(MINOR(ip->i_inode.i_rdev));
467 di->di_goal_meta = di->di_goal_data = cpu_to_be64(ip->i_no_addr);
468 di->di_generation = cpu_to_be64(ip->i_generation);
469 di->di_flags = 0;
470 di->__pad1 = 0; 461 di->__pad1 = 0;
471 di->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) ? GFS2_FORMAT_DE : 0);
472 di->di_height = 0;
473 di->__pad2 = 0; 462 di->__pad2 = 0;
474 di->__pad3 = 0; 463 di->__pad3 = 0;
475 di->di_depth = 0;
476 di->di_entries = 0;
477 memset(&di->__pad4, 0, sizeof(di->__pad4)); 464 memset(&di->__pad4, 0, sizeof(di->__pad4));
478 di->di_eattr = 0;
479 di->di_atime_nsec = cpu_to_be32(tv.tv_nsec);
480 di->di_mtime_nsec = cpu_to_be32(tv.tv_nsec);
481 di->di_ctime_nsec = cpu_to_be32(tv.tv_nsec);
482 memset(&di->di_reserved, 0, sizeof(di->di_reserved)); 465 memset(&di->di_reserved, 0, sizeof(di->di_reserved));
466 gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
483 467
484 switch(ip->i_inode.i_mode & S_IFMT) { 468 switch(ip->i_inode.i_mode & S_IFMT) {
485 case S_IFREG:
486 if ((dip->i_diskflags & GFS2_DIF_INHERIT_JDATA) ||
487 gfs2_tune_get(sdp, gt_new_files_jdata))
488 di->di_flags |= cpu_to_be32(GFS2_DIF_JDATA);
489 break;
490 case S_IFDIR: 469 case S_IFDIR:
491 di->di_flags |= cpu_to_be32(dip->i_diskflags &
492 GFS2_DIF_INHERIT_JDATA);
493 di->di_flags |= cpu_to_be32(GFS2_DIF_JDATA);
494 di->di_size = cpu_to_be64(sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode));
495 di->di_entries = cpu_to_be32(2);
496 gfs2_init_dir(dibh, dip); 470 gfs2_init_dir(dibh, dip);
497 break; 471 break;
498 case S_IFLNK: 472 case S_IFLNK:
@@ -501,63 +475,17 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,
501 } 475 }
502 476
503 set_buffer_uptodate(dibh); 477 set_buffer_uptodate(dibh);
504 478 brelse(dibh);
505 *bhp = dibh;
506}
507
508static int make_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,
509 const char *symname, struct buffer_head **bhp)
510{
511 struct inode *inode = &ip->i_inode;
512 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
513 int error;
514
515 error = gfs2_rindex_update(sdp);
516 if (error)
517 return error;
518
519 error = gfs2_quota_lock(dip, inode->i_uid, inode->i_gid);
520 if (error)
521 return error;
522
523 error = gfs2_quota_check(dip, inode->i_uid, inode->i_gid);
524 if (error)
525 goto out_quota;
526
527 error = gfs2_trans_begin(sdp, RES_DINODE + RES_QUOTA, 0);
528 if (error)
529 goto out_quota;
530
531 init_dinode(dip, ip, symname, bhp);
532 gfs2_quota_change(dip, +1, inode->i_uid, inode->i_gid);
533 gfs2_trans_end(sdp);
534
535out_quota:
536 gfs2_quota_unlock(dip);
537 return error;
538} 479}
539 480
540static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, 481static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
541 struct gfs2_inode *ip) 482 struct gfs2_inode *ip, int arq)
542{ 483{
543 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 484 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
544 int alloc_required;
545 struct buffer_head *dibh;
546 int error; 485 int error;
547 486
548 error = gfs2_rindex_update(sdp); 487 if (arq) {
549 if (error) 488 error = gfs2_quota_lock_check(dip);
550 return error;
551
552 error = gfs2_quota_lock(dip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE);
553 if (error)
554 goto fail;
555
556 error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name);
557 if (alloc_required < 0)
558 goto fail_quota_locks;
559 if (alloc_required) {
560 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid);
561 if (error) 489 if (error)
562 goto fail_quota_locks; 490 goto fail_quota_locks;
563 491
@@ -581,26 +509,12 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
581 if (error) 509 if (error)
582 goto fail_end_trans; 510 goto fail_end_trans;
583 511
584 error = gfs2_meta_inode_buffer(ip, &dibh);
585 if (error)
586 goto fail_end_trans;
587 set_nlink(&ip->i_inode, S_ISDIR(ip->i_inode.i_mode) ? 2 : 1);
588 gfs2_trans_add_meta(ip->i_gl, dibh);
589 gfs2_dinode_out(ip, dibh->b_data);
590 brelse(dibh);
591 return 0;
592
593fail_end_trans: 512fail_end_trans:
594 gfs2_trans_end(sdp); 513 gfs2_trans_end(sdp);
595
596fail_ipreserv: 514fail_ipreserv:
597 if (alloc_required) 515 gfs2_inplace_release(dip);
598 gfs2_inplace_release(dip);
599
600fail_quota_locks: 516fail_quota_locks:
601 gfs2_quota_unlock(dip); 517 gfs2_quota_unlock(dip);
602
603fail:
604 return error; 518 return error;
605} 519}
606 520
@@ -650,8 +564,8 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
650 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 564 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
651 struct gfs2_glock *io_gl; 565 struct gfs2_glock *io_gl;
652 int error; 566 int error;
653 struct buffer_head *bh = NULL;
654 u32 aflags = 0; 567 u32 aflags = 0;
568 int arq;
655 569
656 if (!name->len || name->len > GFS2_FNAMESIZE) 570 if (!name->len || name->len > GFS2_FNAMESIZE)
657 return -ENAMETOOLONG; 571 return -ENAMETOOLONG;
@@ -660,6 +574,10 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
660 if (error) 574 if (error)
661 return error; 575 return error;
662 576
577 error = gfs2_rindex_update(sdp);
578 if (error)
579 return error;
580
663 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 581 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
664 if (error) 582 if (error)
665 goto fail; 583 goto fail;
@@ -674,22 +592,48 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
674 if (error) 592 if (error)
675 goto fail_gunlock; 593 goto fail_gunlock;
676 594
595 arq = error = gfs2_diradd_alloc_required(dir, name);
596 if (error < 0)
597 goto fail_gunlock;
598
677 inode = new_inode(sdp->sd_vfs); 599 inode = new_inode(sdp->sd_vfs);
678 if (!inode) { 600 error = -ENOMEM;
679 gfs2_glock_dq_uninit(ghs); 601 if (!inode)
680 return -ENOMEM; 602 goto fail_gunlock;
681 } 603
682 ip = GFS2_I(inode); 604 ip = GFS2_I(inode);
683 error = gfs2_rs_alloc(ip); 605 error = gfs2_rs_alloc(ip);
684 if (error) 606 if (error)
685 goto fail_free_inode; 607 goto fail_free_inode;
686 608
687 set_bit(GIF_INVALID, &ip->i_flags);
688 inode->i_mode = mode; 609 inode->i_mode = mode;
610 set_nlink(inode, S_ISDIR(mode) ? 2 : 1);
689 inode->i_rdev = dev; 611 inode->i_rdev = dev;
690 inode->i_size = size; 612 inode->i_size = size;
613 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
614 gfs2_set_inode_blocks(inode, 1);
691 munge_mode_uid_gid(dip, inode); 615 munge_mode_uid_gid(dip, inode);
692 ip->i_goal = dip->i_goal; 616 ip->i_goal = dip->i_goal;
617 ip->i_diskflags = 0;
618 ip->i_eattr = 0;
619 ip->i_height = 0;
620 ip->i_depth = 0;
621 ip->i_entries = 0;
622
623 switch(mode & S_IFMT) {
624 case S_IFREG:
625 if ((dip->i_diskflags & GFS2_DIF_INHERIT_JDATA) ||
626 gfs2_tune_get(sdp, gt_new_files_jdata))
627 ip->i_diskflags |= GFS2_DIF_JDATA;
628 gfs2_set_aops(inode);
629 break;
630 case S_IFDIR:
631 ip->i_diskflags |= (dip->i_diskflags & GFS2_DIF_INHERIT_JDATA);
632 ip->i_diskflags |= GFS2_DIF_JDATA;
633 ip->i_entries = 2;
634 break;
635 }
636 gfs2_set_inode_flags(inode);
693 637
694 if ((GFS2_I(sdp->sd_root_dir->d_inode) == dip) || 638 if ((GFS2_I(sdp->sd_root_dir->d_inode) == dip) ||
695 (dip->i_diskflags & GFS2_DIF_TOPDIR)) 639 (dip->i_diskflags & GFS2_DIF_TOPDIR))
@@ -708,10 +652,13 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
708 if (error) 652 if (error)
709 goto fail_free_inode; 653 goto fail_free_inode;
710 654
711 error = make_dinode(dip, ip, symname, &bh); 655 error = gfs2_trans_begin(sdp, RES_DINODE, 0);
712 if (error) 656 if (error)
713 goto fail_gunlock2; 657 goto fail_gunlock2;
714 658
659 init_dinode(dip, ip, symname);
660 gfs2_trans_end(sdp);
661
715 error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl); 662 error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
716 if (error) 663 if (error)
717 goto fail_gunlock2; 664 goto fail_gunlock2;
@@ -725,10 +672,6 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
725 gfs2_set_iop(inode); 672 gfs2_set_iop(inode);
726 insert_inode_hash(inode); 673 insert_inode_hash(inode);
727 674
728 error = gfs2_inode_refresh(ip);
729 if (error)
730 goto fail_gunlock3;
731
732 error = gfs2_acl_create(dip, inode); 675 error = gfs2_acl_create(dip, inode);
733 if (error) 676 if (error)
734 goto fail_gunlock3; 677 goto fail_gunlock3;
@@ -737,18 +680,13 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
737 if (error) 680 if (error)
738 goto fail_gunlock3; 681 goto fail_gunlock3;
739 682
740 error = link_dinode(dip, name, ip); 683 error = link_dinode(dip, name, ip, arq);
741 if (error) 684 if (error)
742 goto fail_gunlock3; 685 goto fail_gunlock3;
743 686
744 if (bh)
745 brelse(bh);
746
747 gfs2_trans_end(sdp);
748 gfs2_inplace_release(dip);
749 gfs2_quota_unlock(dip);
750 mark_inode_dirty(inode); 687 mark_inode_dirty(inode);
751 gfs2_glock_dq_uninit_m(2, ghs); 688 gfs2_glock_dq_uninit(ghs);
689 gfs2_glock_dq_uninit(ghs + 1);
752 d_instantiate(dentry, inode); 690 d_instantiate(dentry, inode);
753 return 0; 691 return 0;
754 692
@@ -769,12 +707,12 @@ fail_free_inode:
769fail_gunlock: 707fail_gunlock:
770 gfs2_glock_dq_uninit(ghs); 708 gfs2_glock_dq_uninit(ghs);
771 if (inode && !IS_ERR(inode)) { 709 if (inode && !IS_ERR(inode)) {
710 clear_nlink(inode);
711 mark_inode_dirty(inode);
772 set_bit(GIF_ALLOC_FAILED, &GFS2_I(inode)->i_flags); 712 set_bit(GIF_ALLOC_FAILED, &GFS2_I(inode)->i_flags);
773 iput(inode); 713 iput(inode);
774 } 714 }
775fail: 715fail:
776 if (bh)
777 brelse(bh);
778 return error; 716 return error;
779} 717}
780 718
@@ -1151,7 +1089,9 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
1151 1089
1152static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 1090static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
1153{ 1091{
1154 return gfs2_create_inode(dir, dentry, S_IFDIR | mode, 0, NULL, 0, 0); 1092 struct gfs2_sbd *sdp = GFS2_SB(dir);
1093 unsigned dsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
1094 return gfs2_create_inode(dir, dentry, S_IFDIR | mode, 0, NULL, dsize, 0);
1155} 1095}
1156 1096
1157/** 1097/**
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 9a2ca8be7647..b404f4853034 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -73,7 +73,7 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
73 73
74void gfs2_remove_from_ail(struct gfs2_bufdata *bd) 74void gfs2_remove_from_ail(struct gfs2_bufdata *bd)
75{ 75{
76 bd->bd_ail = NULL; 76 bd->bd_tr = NULL;
77 list_del_init(&bd->bd_ail_st_list); 77 list_del_init(&bd->bd_ail_st_list);
78 list_del_init(&bd->bd_ail_gl_list); 78 list_del_init(&bd->bd_ail_gl_list);
79 atomic_dec(&bd->bd_gl->gl_ail_count); 79 atomic_dec(&bd->bd_gl->gl_ail_count);
@@ -90,7 +90,7 @@ void gfs2_remove_from_ail(struct gfs2_bufdata *bd)
90 90
91static int gfs2_ail1_start_one(struct gfs2_sbd *sdp, 91static int gfs2_ail1_start_one(struct gfs2_sbd *sdp,
92 struct writeback_control *wbc, 92 struct writeback_control *wbc,
93 struct gfs2_ail *ai) 93 struct gfs2_trans *tr)
94__releases(&sdp->sd_ail_lock) 94__releases(&sdp->sd_ail_lock)
95__acquires(&sdp->sd_ail_lock) 95__acquires(&sdp->sd_ail_lock)
96{ 96{
@@ -99,15 +99,15 @@ __acquires(&sdp->sd_ail_lock)
99 struct gfs2_bufdata *bd, *s; 99 struct gfs2_bufdata *bd, *s;
100 struct buffer_head *bh; 100 struct buffer_head *bh;
101 101
102 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, bd_ail_st_list) { 102 list_for_each_entry_safe_reverse(bd, s, &tr->tr_ail1_list, bd_ail_st_list) {
103 bh = bd->bd_bh; 103 bh = bd->bd_bh;
104 104
105 gfs2_assert(sdp, bd->bd_ail == ai); 105 gfs2_assert(sdp, bd->bd_tr == tr);
106 106
107 if (!buffer_busy(bh)) { 107 if (!buffer_busy(bh)) {
108 if (!buffer_uptodate(bh)) 108 if (!buffer_uptodate(bh))
109 gfs2_io_error_bh(sdp, bh); 109 gfs2_io_error_bh(sdp, bh);
110 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); 110 list_move(&bd->bd_ail_st_list, &tr->tr_ail2_list);
111 continue; 111 continue;
112 } 112 }
113 113
@@ -116,7 +116,7 @@ __acquires(&sdp->sd_ail_lock)
116 if (gl == bd->bd_gl) 116 if (gl == bd->bd_gl)
117 continue; 117 continue;
118 gl = bd->bd_gl; 118 gl = bd->bd_gl;
119 list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list); 119 list_move(&bd->bd_ail_st_list, &tr->tr_ail1_list);
120 mapping = bh->b_page->mapping; 120 mapping = bh->b_page->mapping;
121 if (!mapping) 121 if (!mapping)
122 continue; 122 continue;
@@ -144,15 +144,15 @@ __acquires(&sdp->sd_ail_lock)
144void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc) 144void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)
145{ 145{
146 struct list_head *head = &sdp->sd_ail1_list; 146 struct list_head *head = &sdp->sd_ail1_list;
147 struct gfs2_ail *ai; 147 struct gfs2_trans *tr;
148 148
149 trace_gfs2_ail_flush(sdp, wbc, 1); 149 trace_gfs2_ail_flush(sdp, wbc, 1);
150 spin_lock(&sdp->sd_ail_lock); 150 spin_lock(&sdp->sd_ail_lock);
151restart: 151restart:
152 list_for_each_entry_reverse(ai, head, ai_list) { 152 list_for_each_entry_reverse(tr, head, tr_list) {
153 if (wbc->nr_to_write <= 0) 153 if (wbc->nr_to_write <= 0)
154 break; 154 break;
155 if (gfs2_ail1_start_one(sdp, wbc, ai)) 155 if (gfs2_ail1_start_one(sdp, wbc, tr))
156 goto restart; 156 goto restart;
157 } 157 }
158 spin_unlock(&sdp->sd_ail_lock); 158 spin_unlock(&sdp->sd_ail_lock);
@@ -183,20 +183,20 @@ static void gfs2_ail1_start(struct gfs2_sbd *sdp)
183 * 183 *
184 */ 184 */
185 185
186static void gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) 186static void gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
187{ 187{
188 struct gfs2_bufdata *bd, *s; 188 struct gfs2_bufdata *bd, *s;
189 struct buffer_head *bh; 189 struct buffer_head *bh;
190 190
191 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list, 191 list_for_each_entry_safe_reverse(bd, s, &tr->tr_ail1_list,
192 bd_ail_st_list) { 192 bd_ail_st_list) {
193 bh = bd->bd_bh; 193 bh = bd->bd_bh;
194 gfs2_assert(sdp, bd->bd_ail == ai); 194 gfs2_assert(sdp, bd->bd_tr == tr);
195 if (buffer_busy(bh)) 195 if (buffer_busy(bh))
196 continue; 196 continue;
197 if (!buffer_uptodate(bh)) 197 if (!buffer_uptodate(bh))
198 gfs2_io_error_bh(sdp, bh); 198 gfs2_io_error_bh(sdp, bh);
199 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list); 199 list_move(&bd->bd_ail_st_list, &tr->tr_ail2_list);
200 } 200 }
201 201
202} 202}
@@ -210,14 +210,14 @@ static void gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
210 210
211static int gfs2_ail1_empty(struct gfs2_sbd *sdp) 211static int gfs2_ail1_empty(struct gfs2_sbd *sdp)
212{ 212{
213 struct gfs2_ail *ai, *s; 213 struct gfs2_trans *tr, *s;
214 int ret; 214 int ret;
215 215
216 spin_lock(&sdp->sd_ail_lock); 216 spin_lock(&sdp->sd_ail_lock);
217 list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) { 217 list_for_each_entry_safe_reverse(tr, s, &sdp->sd_ail1_list, tr_list) {
218 gfs2_ail1_empty_one(sdp, ai); 218 gfs2_ail1_empty_one(sdp, tr);
219 if (list_empty(&ai->ai_ail1_list)) 219 if (list_empty(&tr->tr_ail1_list))
220 list_move(&ai->ai_list, &sdp->sd_ail2_list); 220 list_move(&tr->tr_list, &sdp->sd_ail2_list);
221 else 221 else
222 break; 222 break;
223 } 223 }
@@ -229,13 +229,13 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp)
229 229
230static void gfs2_ail1_wait(struct gfs2_sbd *sdp) 230static void gfs2_ail1_wait(struct gfs2_sbd *sdp)
231{ 231{
232 struct gfs2_ail *ai; 232 struct gfs2_trans *tr;
233 struct gfs2_bufdata *bd; 233 struct gfs2_bufdata *bd;
234 struct buffer_head *bh; 234 struct buffer_head *bh;
235 235
236 spin_lock(&sdp->sd_ail_lock); 236 spin_lock(&sdp->sd_ail_lock);
237 list_for_each_entry_reverse(ai, &sdp->sd_ail1_list, ai_list) { 237 list_for_each_entry_reverse(tr, &sdp->sd_ail1_list, tr_list) {
238 list_for_each_entry(bd, &ai->ai_ail1_list, bd_ail_st_list) { 238 list_for_each_entry(bd, &tr->tr_ail1_list, bd_ail_st_list) {
239 bh = bd->bd_bh; 239 bh = bd->bd_bh;
240 if (!buffer_locked(bh)) 240 if (!buffer_locked(bh))
241 continue; 241 continue;
@@ -256,40 +256,40 @@ static void gfs2_ail1_wait(struct gfs2_sbd *sdp)
256 * 256 *
257 */ 257 */
258 258
259static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) 259static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
260{ 260{
261 struct list_head *head = &ai->ai_ail2_list; 261 struct list_head *head = &tr->tr_ail2_list;
262 struct gfs2_bufdata *bd; 262 struct gfs2_bufdata *bd;
263 263
264 while (!list_empty(head)) { 264 while (!list_empty(head)) {
265 bd = list_entry(head->prev, struct gfs2_bufdata, 265 bd = list_entry(head->prev, struct gfs2_bufdata,
266 bd_ail_st_list); 266 bd_ail_st_list);
267 gfs2_assert(sdp, bd->bd_ail == ai); 267 gfs2_assert(sdp, bd->bd_tr == tr);
268 gfs2_remove_from_ail(bd); 268 gfs2_remove_from_ail(bd);
269 } 269 }
270} 270}
271 271
272static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) 272static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
273{ 273{
274 struct gfs2_ail *ai, *safe; 274 struct gfs2_trans *tr, *safe;
275 unsigned int old_tail = sdp->sd_log_tail; 275 unsigned int old_tail = sdp->sd_log_tail;
276 int wrap = (new_tail < old_tail); 276 int wrap = (new_tail < old_tail);
277 int a, b, rm; 277 int a, b, rm;
278 278
279 spin_lock(&sdp->sd_ail_lock); 279 spin_lock(&sdp->sd_ail_lock);
280 280
281 list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) { 281 list_for_each_entry_safe(tr, safe, &sdp->sd_ail2_list, tr_list) {
282 a = (old_tail <= ai->ai_first); 282 a = (old_tail <= tr->tr_first);
283 b = (ai->ai_first < new_tail); 283 b = (tr->tr_first < new_tail);
284 rm = (wrap) ? (a || b) : (a && b); 284 rm = (wrap) ? (a || b) : (a && b);
285 if (!rm) 285 if (!rm)
286 continue; 286 continue;
287 287
288 gfs2_ail2_empty_one(sdp, ai); 288 gfs2_ail2_empty_one(sdp, tr);
289 list_del(&ai->ai_list); 289 list_del(&tr->tr_list);
290 gfs2_assert_warn(sdp, list_empty(&ai->ai_ail1_list)); 290 gfs2_assert_warn(sdp, list_empty(&tr->tr_ail1_list));
291 gfs2_assert_warn(sdp, list_empty(&ai->ai_ail2_list)); 291 gfs2_assert_warn(sdp, list_empty(&tr->tr_ail2_list));
292 kfree(ai); 292 kfree(tr);
293 } 293 }
294 294
295 spin_unlock(&sdp->sd_ail_lock); 295 spin_unlock(&sdp->sd_ail_lock);
@@ -435,7 +435,7 @@ static unsigned int calc_reserved(struct gfs2_sbd *sdp)
435 435
436static unsigned int current_tail(struct gfs2_sbd *sdp) 436static unsigned int current_tail(struct gfs2_sbd *sdp)
437{ 437{
438 struct gfs2_ail *ai; 438 struct gfs2_trans *tr;
439 unsigned int tail; 439 unsigned int tail;
440 440
441 spin_lock(&sdp->sd_ail_lock); 441 spin_lock(&sdp->sd_ail_lock);
@@ -443,8 +443,9 @@ static unsigned int current_tail(struct gfs2_sbd *sdp)
443 if (list_empty(&sdp->sd_ail1_list)) { 443 if (list_empty(&sdp->sd_ail1_list)) {
444 tail = sdp->sd_log_head; 444 tail = sdp->sd_log_head;
445 } else { 445 } else {
446 ai = list_entry(sdp->sd_ail1_list.prev, struct gfs2_ail, ai_list); 446 tr = list_entry(sdp->sd_ail1_list.prev, struct gfs2_trans,
447 tail = ai->ai_first; 447 tr_list);
448 tail = tr->tr_first;
448 } 449 }
449 450
450 spin_unlock(&sdp->sd_ail_lock); 451 spin_unlock(&sdp->sd_ail_lock);
@@ -600,7 +601,7 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
600 601
601void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) 602void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
602{ 603{
603 struct gfs2_ail *ai; 604 struct gfs2_trans *tr;
604 605
605 down_write(&sdp->sd_log_flush_lock); 606 down_write(&sdp->sd_log_flush_lock);
606 607
@@ -611,9 +612,12 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
611 } 612 }
612 trace_gfs2_log_flush(sdp, 1); 613 trace_gfs2_log_flush(sdp, 1);
613 614
614 ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); 615 tr = sdp->sd_log_tr;
615 INIT_LIST_HEAD(&ai->ai_ail1_list); 616 if (tr) {
616 INIT_LIST_HEAD(&ai->ai_ail2_list); 617 sdp->sd_log_tr = NULL;
618 INIT_LIST_HEAD(&tr->tr_ail1_list);
619 INIT_LIST_HEAD(&tr->tr_ail2_list);
620 }
617 621
618 if (sdp->sd_log_num_buf != sdp->sd_log_commited_buf) { 622 if (sdp->sd_log_num_buf != sdp->sd_log_commited_buf) {
619 printk(KERN_INFO "GFS2: log buf %u %u\n", sdp->sd_log_num_buf, 623 printk(KERN_INFO "GFS2: log buf %u %u\n", sdp->sd_log_num_buf,
@@ -630,7 +634,8 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
630 634
631 sdp->sd_log_flush_head = sdp->sd_log_head; 635 sdp->sd_log_flush_head = sdp->sd_log_head;
632 sdp->sd_log_flush_wrapped = 0; 636 sdp->sd_log_flush_wrapped = 0;
633 ai->ai_first = sdp->sd_log_flush_head; 637 if (tr)
638 tr->tr_first = sdp->sd_log_flush_head;
634 639
635 gfs2_ordered_write(sdp); 640 gfs2_ordered_write(sdp);
636 lops_before_commit(sdp); 641 lops_before_commit(sdp);
@@ -643,7 +648,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
643 trace_gfs2_log_blocks(sdp, -1); 648 trace_gfs2_log_blocks(sdp, -1);
644 log_write_header(sdp, 0); 649 log_write_header(sdp, 0);
645 } 650 }
646 lops_after_commit(sdp, ai); 651 lops_after_commit(sdp, tr);
647 652
648 gfs2_log_lock(sdp); 653 gfs2_log_lock(sdp);
649 sdp->sd_log_head = sdp->sd_log_flush_head; 654 sdp->sd_log_head = sdp->sd_log_flush_head;
@@ -653,16 +658,16 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
653 sdp->sd_log_commited_revoke = 0; 658 sdp->sd_log_commited_revoke = 0;
654 659
655 spin_lock(&sdp->sd_ail_lock); 660 spin_lock(&sdp->sd_ail_lock);
656 if (!list_empty(&ai->ai_ail1_list)) { 661 if (tr && !list_empty(&tr->tr_ail1_list)) {
657 list_add(&ai->ai_list, &sdp->sd_ail1_list); 662 list_add(&tr->tr_list, &sdp->sd_ail1_list);
658 ai = NULL; 663 tr = NULL;
659 } 664 }
660 spin_unlock(&sdp->sd_ail_lock); 665 spin_unlock(&sdp->sd_ail_lock);
661 gfs2_log_unlock(sdp); 666 gfs2_log_unlock(sdp);
662 trace_gfs2_log_flush(sdp, 0); 667 trace_gfs2_log_flush(sdp, 0);
663 up_write(&sdp->sd_log_flush_lock); 668 up_write(&sdp->sd_log_flush_lock);
664 669
665 kfree(ai); 670 kfree(tr);
666} 671}
667 672
668static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 673static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
@@ -687,6 +692,12 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
687 sdp->sd_jdesc->jd_blocks); 692 sdp->sd_jdesc->jd_blocks);
688 sdp->sd_log_blks_reserved = reserved; 693 sdp->sd_log_blks_reserved = reserved;
689 694
695 if (sdp->sd_log_tr == NULL &&
696 (tr->tr_num_buf_new || tr->tr_num_databuf_new)) {
697 gfs2_assert_withdraw(sdp, tr->tr_t_gh.gh_gl);
698 sdp->sd_log_tr = tr;
699 tr->tr_attached = 1;
700 }
690 gfs2_log_unlock(sdp); 701 gfs2_log_unlock(sdp);
691} 702}
692 703
@@ -708,7 +719,6 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
708void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 719void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
709{ 720{
710 log_refund(sdp, tr); 721 log_refund(sdp, tr);
711 up_read(&sdp->sd_log_flush_lock);
712 722
713 if (atomic_read(&sdp->sd_log_pinned) > atomic_read(&sdp->sd_log_thresh1) || 723 if (atomic_read(&sdp->sd_log_pinned) > atomic_read(&sdp->sd_log_thresh1) ||
714 ((sdp->sd_jdesc->jd_blocks - atomic_read(&sdp->sd_log_blks_free)) > 724 ((sdp->sd_jdesc->jd_blocks - atomic_read(&sdp->sd_log_blks_free)) >
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index a5055977a214..7318abf9d0fb 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -53,8 +53,8 @@ void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh)
53 * to in-place disk block, remove it from the AIL. 53 * to in-place disk block, remove it from the AIL.
54 */ 54 */
55 spin_lock(&sdp->sd_ail_lock); 55 spin_lock(&sdp->sd_ail_lock);
56 if (bd->bd_ail) 56 if (bd->bd_tr)
57 list_move(&bd->bd_ail_st_list, &bd->bd_ail->ai_ail2_list); 57 list_move(&bd->bd_ail_st_list, &bd->bd_tr->tr_ail2_list);
58 spin_unlock(&sdp->sd_ail_lock); 58 spin_unlock(&sdp->sd_ail_lock);
59 get_bh(bh); 59 get_bh(bh);
60 atomic_inc(&sdp->sd_log_pinned); 60 atomic_inc(&sdp->sd_log_pinned);
@@ -94,7 +94,7 @@ static void maybe_release_space(struct gfs2_bufdata *bd)
94 */ 94 */
95 95
96static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, 96static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,
97 struct gfs2_ail *ai) 97 struct gfs2_trans *tr)
98{ 98{
99 struct gfs2_bufdata *bd = bh->b_private; 99 struct gfs2_bufdata *bd = bh->b_private;
100 100
@@ -109,7 +109,7 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,
109 maybe_release_space(bd); 109 maybe_release_space(bd);
110 110
111 spin_lock(&sdp->sd_ail_lock); 111 spin_lock(&sdp->sd_ail_lock);
112 if (bd->bd_ail) { 112 if (bd->bd_tr) {
113 list_del(&bd->bd_ail_st_list); 113 list_del(&bd->bd_ail_st_list);
114 brelse(bh); 114 brelse(bh);
115 } else { 115 } else {
@@ -117,8 +117,8 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,
117 list_add(&bd->bd_ail_gl_list, &gl->gl_ail_list); 117 list_add(&bd->bd_ail_gl_list, &gl->gl_ail_list);
118 atomic_inc(&gl->gl_ail_count); 118 atomic_inc(&gl->gl_ail_count);
119 } 119 }
120 bd->bd_ail = ai; 120 bd->bd_tr = tr;
121 list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list); 121 list_add(&bd->bd_ail_st_list, &tr->tr_ail1_list);
122 spin_unlock(&sdp->sd_ail_lock); 122 spin_unlock(&sdp->sd_ail_lock);
123 123
124 clear_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags); 124 clear_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags);
@@ -480,17 +480,22 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp)
480 &sdp->sd_log_le_buf, 0); 480 &sdp->sd_log_le_buf, 0);
481} 481}
482 482
483static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) 483static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
484{ 484{
485 struct list_head *head = &sdp->sd_log_le_buf; 485 struct list_head *head = &sdp->sd_log_le_buf;
486 struct gfs2_bufdata *bd; 486 struct gfs2_bufdata *bd;
487 487
488 if (tr == NULL) {
489 gfs2_assert(sdp, list_empty(head));
490 return;
491 }
492
488 while (!list_empty(head)) { 493 while (!list_empty(head)) {
489 bd = list_entry(head->next, struct gfs2_bufdata, bd_list); 494 bd = list_entry(head->next, struct gfs2_bufdata, bd_list);
490 list_del_init(&bd->bd_list); 495 list_del_init(&bd->bd_list);
491 sdp->sd_log_num_buf--; 496 sdp->sd_log_num_buf--;
492 497
493 gfs2_unpin(sdp, bd->bd_bh, ai); 498 gfs2_unpin(sdp, bd->bd_bh, tr);
494 } 499 }
495 gfs2_assert_warn(sdp, !sdp->sd_log_num_buf); 500 gfs2_assert_warn(sdp, !sdp->sd_log_num_buf);
496} 501}
@@ -613,7 +618,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp)
613 gfs2_log_write_page(sdp, page); 618 gfs2_log_write_page(sdp, page);
614} 619}
615 620
616static void revoke_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) 621static void revoke_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
617{ 622{
618 struct list_head *head = &sdp->sd_log_le_revoke; 623 struct list_head *head = &sdp->sd_log_le_revoke;
619 struct gfs2_bufdata *bd; 624 struct gfs2_bufdata *bd;
@@ -791,16 +796,21 @@ static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
791 jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); 796 jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks);
792} 797}
793 798
794static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) 799static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
795{ 800{
796 struct list_head *head = &sdp->sd_log_le_databuf; 801 struct list_head *head = &sdp->sd_log_le_databuf;
797 struct gfs2_bufdata *bd; 802 struct gfs2_bufdata *bd;
798 803
804 if (tr == NULL) {
805 gfs2_assert(sdp, list_empty(head));
806 return;
807 }
808
799 while (!list_empty(head)) { 809 while (!list_empty(head)) {
800 bd = list_entry(head->next, struct gfs2_bufdata, bd_list); 810 bd = list_entry(head->next, struct gfs2_bufdata, bd_list);
801 list_del_init(&bd->bd_list); 811 list_del_init(&bd->bd_list);
802 sdp->sd_log_num_databuf--; 812 sdp->sd_log_num_databuf--;
803 gfs2_unpin(sdp, bd->bd_bh, ai); 813 gfs2_unpin(sdp, bd->bd_bh, tr);
804 } 814 }
805 gfs2_assert_warn(sdp, !sdp->sd_log_num_databuf); 815 gfs2_assert_warn(sdp, !sdp->sd_log_num_databuf);
806} 816}
diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h
index ba77b7da8325..87e062e05c92 100644
--- a/fs/gfs2/lops.h
+++ b/fs/gfs2/lops.h
@@ -55,12 +55,13 @@ static inline void lops_before_commit(struct gfs2_sbd *sdp)
55 gfs2_log_ops[x]->lo_before_commit(sdp); 55 gfs2_log_ops[x]->lo_before_commit(sdp);
56} 56}
57 57
58static inline void lops_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) 58static inline void lops_after_commit(struct gfs2_sbd *sdp,
59 struct gfs2_trans *tr)
59{ 60{
60 int x; 61 int x;
61 for (x = 0; gfs2_log_ops[x]; x++) 62 for (x = 0; gfs2_log_ops[x]; x++)
62 if (gfs2_log_ops[x]->lo_after_commit) 63 if (gfs2_log_ops[x]->lo_after_commit)
63 gfs2_log_ops[x]->lo_after_commit(sdp, ai); 64 gfs2_log_ops[x]->lo_after_commit(sdp, tr);
64} 65}
65 66
66static inline void lops_before_scan(struct gfs2_jdesc *jd, 67static inline void lops_before_scan(struct gfs2_jdesc *jd,
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index b059bbb5059e..1a89afb68472 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -295,7 +295,7 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int
295 } 295 }
296 if (bd) { 296 if (bd) {
297 spin_lock(&sdp->sd_ail_lock); 297 spin_lock(&sdp->sd_ail_lock);
298 if (bd->bd_ail) { 298 if (bd->bd_tr) {
299 gfs2_remove_from_ail(bd); 299 gfs2_remove_from_ail(bd);
300 bh->b_private = NULL; 300 bh->b_private = NULL;
301 bd->bd_bh = NULL; 301 bd->bd_bh = NULL;
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 5a51265a4341..0c5a575b513e 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -592,7 +592,7 @@ static void dump_rs(struct seq_file *seq, const struct gfs2_blkreserv *rs)
592 * @rs: The reservation to remove 592 * @rs: The reservation to remove
593 * 593 *
594 */ 594 */
595static void __rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs) 595static void __rs_deltree(struct gfs2_blkreserv *rs)
596{ 596{
597 struct gfs2_rgrpd *rgd; 597 struct gfs2_rgrpd *rgd;
598 598
@@ -605,7 +605,7 @@ static void __rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs)
605 RB_CLEAR_NODE(&rs->rs_node); 605 RB_CLEAR_NODE(&rs->rs_node);
606 606
607 if (rs->rs_free) { 607 if (rs->rs_free) {
608 /* return reserved blocks to the rgrp and the ip */ 608 /* return reserved blocks to the rgrp */
609 BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free); 609 BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free);
610 rs->rs_rbm.rgd->rd_reserved -= rs->rs_free; 610 rs->rs_rbm.rgd->rd_reserved -= rs->rs_free;
611 rs->rs_free = 0; 611 rs->rs_free = 0;
@@ -619,14 +619,14 @@ static void __rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs)
619 * @rs: The reservation to remove 619 * @rs: The reservation to remove
620 * 620 *
621 */ 621 */
622void gfs2_rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs) 622void gfs2_rs_deltree(struct gfs2_blkreserv *rs)
623{ 623{
624 struct gfs2_rgrpd *rgd; 624 struct gfs2_rgrpd *rgd;
625 625
626 rgd = rs->rs_rbm.rgd; 626 rgd = rs->rs_rbm.rgd;
627 if (rgd) { 627 if (rgd) {
628 spin_lock(&rgd->rd_rsspin); 628 spin_lock(&rgd->rd_rsspin);
629 __rs_deltree(ip, rs); 629 __rs_deltree(rs);
630 spin_unlock(&rgd->rd_rsspin); 630 spin_unlock(&rgd->rd_rsspin);
631 } 631 }
632} 632}
@@ -640,7 +640,7 @@ void gfs2_rs_delete(struct gfs2_inode *ip)
640{ 640{
641 down_write(&ip->i_rw_mutex); 641 down_write(&ip->i_rw_mutex);
642 if (ip->i_res) { 642 if (ip->i_res) {
643 gfs2_rs_deltree(ip, ip->i_res); 643 gfs2_rs_deltree(ip->i_res);
644 BUG_ON(ip->i_res->rs_free); 644 BUG_ON(ip->i_res->rs_free);
645 kmem_cache_free(gfs2_rsrv_cachep, ip->i_res); 645 kmem_cache_free(gfs2_rsrv_cachep, ip->i_res);
646 ip->i_res = NULL; 646 ip->i_res = NULL;
@@ -664,7 +664,7 @@ static void return_all_reservations(struct gfs2_rgrpd *rgd)
664 spin_lock(&rgd->rd_rsspin); 664 spin_lock(&rgd->rd_rsspin);
665 while ((n = rb_first(&rgd->rd_rstree))) { 665 while ((n = rb_first(&rgd->rd_rstree))) {
666 rs = rb_entry(n, struct gfs2_blkreserv, rs_node); 666 rs = rb_entry(n, struct gfs2_blkreserv, rs_node);
667 __rs_deltree(NULL, rs); 667 __rs_deltree(rs);
668 } 668 }
669 spin_unlock(&rgd->rd_rsspin); 669 spin_unlock(&rgd->rd_rsspin);
670} 670}
@@ -1874,7 +1874,7 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested, u32 aflags)
1874 1874
1875 /* Drop reservation, if we couldn't use reserved rgrp */ 1875 /* Drop reservation, if we couldn't use reserved rgrp */
1876 if (gfs2_rs_active(rs)) 1876 if (gfs2_rs_active(rs))
1877 gfs2_rs_deltree(ip, rs); 1877 gfs2_rs_deltree(rs);
1878check_rgrp: 1878check_rgrp:
1879 /* Check for unlinked inodes which can be reclaimed */ 1879 /* Check for unlinked inodes which can be reclaimed */
1880 if (rs->rs_rbm.rgd->rd_flags & GFS2_RDF_CHECK) 1880 if (rs->rs_rbm.rgd->rd_flags & GFS2_RDF_CHECK)
@@ -2087,7 +2087,7 @@ static void gfs2_adjust_reservation(struct gfs2_inode *ip,
2087 if (rs->rs_free && !ret) 2087 if (rs->rs_free && !ret)
2088 goto out; 2088 goto out;
2089 } 2089 }
2090 __rs_deltree(ip, rs); 2090 __rs_deltree(rs);
2091 } 2091 }
2092out: 2092out:
2093 spin_unlock(&rgd->rd_rsspin); 2093 spin_unlock(&rgd->rd_rsspin);
@@ -2180,13 +2180,7 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
2180 if (dinode) 2180 if (dinode)
2181 gfs2_trans_add_unrevoke(sdp, block, 1); 2181 gfs2_trans_add_unrevoke(sdp, block, 1);
2182 2182
2183 /* 2183 gfs2_quota_change(ip, *nblocks, ip->i_inode.i_uid, ip->i_inode.i_gid);
2184 * This needs reviewing to see why we cannot do the quota change
2185 * at this point in the dinode case.
2186 */
2187 if (ndata)
2188 gfs2_quota_change(ip, ndata, ip->i_inode.i_uid,
2189 ip->i_inode.i_gid);
2190 2184
2191 rbm.rgd->rd_free_clone -= *nblocks; 2185 rbm.rgd->rd_free_clone -= *nblocks;
2192 trace_gfs2_block_alloc(ip, rbm.rgd, block, *nblocks, 2186 trace_gfs2_block_alloc(ip, rbm.rgd, block, *nblocks,
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index 842185853f6b..5b3f4a896e6c 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -47,7 +47,7 @@ extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
47 bool dinode, u64 *generation); 47 bool dinode, u64 *generation);
48 48
49extern int gfs2_rs_alloc(struct gfs2_inode *ip); 49extern int gfs2_rs_alloc(struct gfs2_inode *ip);
50extern void gfs2_rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs); 50extern void gfs2_rs_deltree(struct gfs2_blkreserv *rs);
51extern void gfs2_rs_delete(struct gfs2_inode *ip); 51extern void gfs2_rs_delete(struct gfs2_inode *ip);
52extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta); 52extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta);
53extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen); 53extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen);
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index cab77b8ba84f..917c8e1eb4ae 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1512,7 +1512,7 @@ out_truncate:
1512out_unlock: 1512out_unlock:
1513 /* Error path for case 1 */ 1513 /* Error path for case 1 */
1514 if (gfs2_rs_active(ip->i_res)) 1514 if (gfs2_rs_active(ip->i_res))
1515 gfs2_rs_deltree(ip, ip->i_res); 1515 gfs2_rs_deltree(ip->i_res);
1516 1516
1517 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) 1517 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
1518 gfs2_glock_dq(&ip->i_iopen_gh); 1518 gfs2_glock_dq(&ip->i_iopen_gh);
diff --git a/fs/gfs2/trace_gfs2.h b/fs/gfs2/trace_gfs2.h
index 2ee13e841e9f..20c007d747ab 100644
--- a/fs/gfs2/trace_gfs2.h
+++ b/fs/gfs2/trace_gfs2.h
@@ -159,9 +159,9 @@ TRACE_EVENT(gfs2_glock_put,
159/* Callback (local or remote) requesting lock demotion */ 159/* Callback (local or remote) requesting lock demotion */
160TRACE_EVENT(gfs2_demote_rq, 160TRACE_EVENT(gfs2_demote_rq,
161 161
162 TP_PROTO(const struct gfs2_glock *gl), 162 TP_PROTO(const struct gfs2_glock *gl, bool remote),
163 163
164 TP_ARGS(gl), 164 TP_ARGS(gl, remote),
165 165
166 TP_STRUCT__entry( 166 TP_STRUCT__entry(
167 __field( dev_t, dev ) 167 __field( dev_t, dev )
@@ -170,6 +170,7 @@ TRACE_EVENT(gfs2_demote_rq,
170 __field( u8, cur_state ) 170 __field( u8, cur_state )
171 __field( u8, dmt_state ) 171 __field( u8, dmt_state )
172 __field( unsigned long, flags ) 172 __field( unsigned long, flags )
173 __field( bool, remote )
173 ), 174 ),
174 175
175 TP_fast_assign( 176 TP_fast_assign(
@@ -179,14 +180,16 @@ TRACE_EVENT(gfs2_demote_rq,
179 __entry->cur_state = glock_trace_state(gl->gl_state); 180 __entry->cur_state = glock_trace_state(gl->gl_state);
180 __entry->dmt_state = glock_trace_state(gl->gl_demote_state); 181 __entry->dmt_state = glock_trace_state(gl->gl_demote_state);
181 __entry->flags = gl->gl_flags | (gl->gl_object ? (1UL<<GLF_OBJECT) : 0); 182 __entry->flags = gl->gl_flags | (gl->gl_object ? (1UL<<GLF_OBJECT) : 0);
183 __entry->remote = remote;
182 ), 184 ),
183 185
184 TP_printk("%u,%u glock %d:%lld demote %s to %s flags:%s", 186 TP_printk("%u,%u glock %d:%lld demote %s to %s flags:%s %s",
185 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->gltype, 187 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->gltype,
186 (unsigned long long)__entry->glnum, 188 (unsigned long long)__entry->glnum,
187 glock_trace_name(__entry->cur_state), 189 glock_trace_name(__entry->cur_state),
188 glock_trace_name(__entry->dmt_state), 190 glock_trace_name(__entry->dmt_state),
189 show_glock_flags(__entry->flags)) 191 show_glock_flags(__entry->flags),
192 __entry->remote ? "remote" : "local")
190 193
191); 194);
192 195
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index 5bc023ea38ac..7374907742a8 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -136,8 +136,10 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
136 if (tr->tr_t_gh.gh_gl) { 136 if (tr->tr_t_gh.gh_gl) {
137 gfs2_glock_dq(&tr->tr_t_gh); 137 gfs2_glock_dq(&tr->tr_t_gh);
138 gfs2_holder_uninit(&tr->tr_t_gh); 138 gfs2_holder_uninit(&tr->tr_t_gh);
139 kfree(tr); 139 if (!tr->tr_attached)
140 kfree(tr);
140 } 141 }
142 up_read(&sdp->sd_log_flush_lock);
141 143
142 if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS) 144 if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS)
143 gfs2_log_flush(sdp, NULL); 145 gfs2_log_flush(sdp, NULL);