aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/lops.c
diff options
context:
space:
mode:
authorSteven Whitehouse <swhiteho@redhat.com>2007-08-27 08:54:05 -0400
committerSteven Whitehouse <swhiteho@redhat.com>2007-10-10 03:56:00 -0400
commit9b9107a5a8b190e6cf09bbdf893869c6a9c482cc (patch)
tree77016dd5476f6ba72605ac0cdcbccec3ce794057 /fs/gfs2/lops.c
parenteaf965270ffff3086ef929e660ace45e862cfd2d (diff)
[GFS2] Move pin/unpin into lops.c, clean up locking
gfs2_pin and gfs2_unpin are only used in lops.c, despite being defined in meta_io.c, so this patch moves them into lops.c and makes them static. At the same time, its possible to clean up the locking in the buf and databuf _lo_add() functions so that we only need to grab the spinlock once. Also we have to move lock_buffer() around the _lo_add() functions since we can't do that in gfs2_pin() any more since we hold the spinlock for the duration of that function. As a result, the code shrinks by 12 lines and we do far fewer operations when adding buffers to the log. It also makes the code somewhat easier to read & understand. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/lops.c')
-rw-r--r--fs/gfs2/lops.c117
1 files changed, 89 insertions, 28 deletions
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 7ef335623373..3ec587135d46 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -27,7 +27,71 @@
27#include "trans.h" 27#include "trans.h"
28#include "util.h" 28#include "util.h"
29 29
30static void glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) 30/**
31 * gfs2_pin - Pin a buffer in memory
32 * @sdp: The superblock
33 * @bh: The buffer to be pinned
34 *
35 * The log lock must be held when calling this function
36 */
37static void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh)
38{
39 struct gfs2_bufdata *bd;
40
41 gfs2_assert_withdraw(sdp, test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags));
42
43 clear_buffer_dirty(bh);
44 if (test_set_buffer_pinned(bh))
45 gfs2_assert_withdraw(sdp, 0);
46 if (!buffer_uptodate(bh))
47 gfs2_io_error_bh(sdp, bh);
48 bd = bh->b_private;
49 /* If this buffer is in the AIL and it has already been written
50 * to in-place disk block, remove it from the AIL.
51 */
52 if (bd->bd_ail)
53 list_move(&bd->bd_ail_st_list, &bd->bd_ail->ai_ail2_list);
54 get_bh(bh);
55}
56
57/**
58 * gfs2_unpin - Unpin a buffer
59 * @sdp: the filesystem the buffer belongs to
60 * @bh: The buffer to unpin
61 * @ai:
62 *
63 */
64
65static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,
66 struct gfs2_ail *ai)
67{
68 struct gfs2_bufdata *bd = bh->b_private;
69
70 gfs2_assert_withdraw(sdp, buffer_uptodate(bh));
71
72 if (!buffer_pinned(bh))
73 gfs2_assert_withdraw(sdp, 0);
74
75 lock_buffer(bh);
76 mark_buffer_dirty(bh);
77 clear_buffer_pinned(bh);
78
79 gfs2_log_lock(sdp);
80 if (bd->bd_ail) {
81 list_del(&bd->bd_ail_st_list);
82 brelse(bh);
83 } else {
84 struct gfs2_glock *gl = bd->bd_gl;
85 list_add(&bd->bd_ail_gl_list, &gl->gl_ail_list);
86 atomic_inc(&gl->gl_ail_count);
87 }
88 bd->bd_ail = ai;
89 list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list);
90 gfs2_log_unlock(sdp);
91 unlock_buffer(bh);
92}
93
94static void __glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
31{ 95{
32 struct gfs2_glock *gl; 96 struct gfs2_glock *gl;
33 struct gfs2_trans *tr = current->journal_info; 97 struct gfs2_trans *tr = current->journal_info;
@@ -38,15 +102,19 @@ static void glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
38 if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(gl))) 102 if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(gl)))
39 return; 103 return;
40 104
41 gfs2_log_lock(sdp); 105 if (!list_empty(&le->le_list))
42 if (!list_empty(&le->le_list)){
43 gfs2_log_unlock(sdp);
44 return; 106 return;
45 } 107
46 gfs2_glock_hold(gl); 108 gfs2_glock_hold(gl);
47 set_bit(GLF_DIRTY, &gl->gl_flags); 109 set_bit(GLF_DIRTY, &gl->gl_flags);
48 sdp->sd_log_num_gl++; 110 sdp->sd_log_num_gl++;
49 list_add(&le->le_list, &sdp->sd_log_le_gl); 111 list_add(&le->le_list, &sdp->sd_log_le_gl);
112}
113
114static void glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
115{
116 gfs2_log_lock(sdp);
117 __glock_lo_add(sdp, le);
50 gfs2_log_unlock(sdp); 118 gfs2_log_unlock(sdp);
51} 119}
52 120
@@ -71,30 +139,25 @@ static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
71 struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le); 139 struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le);
72 struct gfs2_trans *tr; 140 struct gfs2_trans *tr;
73 141
142 lock_buffer(bd->bd_bh);
74 gfs2_log_lock(sdp); 143 gfs2_log_lock(sdp);
75 if (!list_empty(&bd->bd_list_tr)) { 144 if (!list_empty(&bd->bd_list_tr))
76 gfs2_log_unlock(sdp); 145 goto out;
77 return;
78 }
79 tr = current->journal_info; 146 tr = current->journal_info;
80 tr->tr_touched = 1; 147 tr->tr_touched = 1;
81 tr->tr_num_buf++; 148 tr->tr_num_buf++;
82 list_add(&bd->bd_list_tr, &tr->tr_list_buf); 149 list_add(&bd->bd_list_tr, &tr->tr_list_buf);
83 gfs2_log_unlock(sdp);
84
85 if (!list_empty(&le->le_list)) 150 if (!list_empty(&le->le_list))
86 return; 151 goto out;
87 152 __glock_lo_add(sdp, &bd->bd_gl->gl_le);
88 gfs2_trans_add_gl(bd->bd_gl);
89
90 gfs2_meta_check(sdp, bd->bd_bh); 153 gfs2_meta_check(sdp, bd->bd_bh);
91 gfs2_pin(sdp, bd->bd_bh); 154 gfs2_pin(sdp, bd->bd_bh);
92 gfs2_log_lock(sdp);
93 sdp->sd_log_num_buf++; 155 sdp->sd_log_num_buf++;
94 list_add(&le->le_list, &sdp->sd_log_le_buf); 156 list_add(&le->le_list, &sdp->sd_log_le_buf);
95 gfs2_log_unlock(sdp);
96
97 tr->tr_num_buf_new++; 157 tr->tr_num_buf_new++;
158out:
159 gfs2_log_unlock(sdp);
160 unlock_buffer(bd->bd_bh);
98} 161}
99 162
100static void buf_lo_incore_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 163static void buf_lo_incore_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
@@ -476,31 +539,29 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
476 struct address_space *mapping = bd->bd_bh->b_page->mapping; 539 struct address_space *mapping = bd->bd_bh->b_page->mapping;
477 struct gfs2_inode *ip = GFS2_I(mapping->host); 540 struct gfs2_inode *ip = GFS2_I(mapping->host);
478 541
542 lock_buffer(bd->bd_bh);
479 gfs2_log_lock(sdp); 543 gfs2_log_lock(sdp);
480 if (!list_empty(&bd->bd_list_tr)) { 544 if (!list_empty(&bd->bd_list_tr))
481 gfs2_log_unlock(sdp); 545 goto out;
482 return;
483 }
484 tr->tr_touched = 1; 546 tr->tr_touched = 1;
485 if (gfs2_is_jdata(ip)) { 547 if (gfs2_is_jdata(ip)) {
486 tr->tr_num_buf++; 548 tr->tr_num_buf++;
487 list_add(&bd->bd_list_tr, &tr->tr_list_buf); 549 list_add(&bd->bd_list_tr, &tr->tr_list_buf);
488 } 550 }
489 gfs2_log_unlock(sdp);
490 if (!list_empty(&le->le_list)) 551 if (!list_empty(&le->le_list))
491 return; 552 goto out;
492 553
493 gfs2_trans_add_gl(bd->bd_gl); 554 __glock_lo_add(sdp, &bd->bd_gl->gl_le);
494 if (gfs2_is_jdata(ip)) { 555 if (gfs2_is_jdata(ip)) {
495 gfs2_pin(sdp, bd->bd_bh); 556 gfs2_pin(sdp, bd->bd_bh);
496 tr->tr_num_databuf_new++; 557 tr->tr_num_databuf_new++;
497 }
498 gfs2_log_lock(sdp);
499 if (gfs2_is_jdata(ip))
500 sdp->sd_log_num_jdata++; 558 sdp->sd_log_num_jdata++;
559 }
501 sdp->sd_log_num_databuf++; 560 sdp->sd_log_num_databuf++;
502 list_add(&le->le_list, &sdp->sd_log_le_databuf); 561 list_add(&le->le_list, &sdp->sd_log_le_databuf);
562out:
503 gfs2_log_unlock(sdp); 563 gfs2_log_unlock(sdp);
564 unlock_buffer(bd->bd_bh);
504} 565}
505 566
506static int gfs2_check_magic(struct buffer_head *bh) 567static int gfs2_check_magic(struct buffer_head *bh)