aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/log.c
diff options
context:
space:
mode:
authorBenjamin Marzinski <bmarzins@redhat.com>2013-04-05 21:31:46 -0400
committerSteven Whitehouse <swhiteho@redhat.com>2013-04-08 03:46:22 -0400
commit16ca9412d8018188bddda29c3fee88471b94e3cb (patch)
tree4fdd7fdd2ab7ea216e5120c5f484a24bcea01d83 /fs/gfs2/log.c
parent20095218fb882139527c0e04b8e63869fa057b14 (diff)
GFS2: replace gfs2_ail structure with gfs2_trans
In order to allow transactions and log flushes to happen at the same time, gfs2 needs to move the transaction accounting and active items list code into the gfs2_trans structure. As a first step toward this, this patch removes the gfs2_ail structure, and handles the active items list in the gfs_trans structure. This keeps gfs2 from allocating an ail structure on log flushes, and gives us a struture that can later be used to store the transaction accounting outside of the gfs2 superblock structure. With this patch, at the end of a transaction, gfs2 will add the gfs2_trans structure to the superblock if there is not one already. This structure now has the active items fields that were previously in gfs2_ail. This is not necessary in the case where the transaction was simply used to add revokes, since these are never written outside of the journal, and thus, don't need an active items list. Also, in order to make sure that the transaction structure is not removed while it's still in use by gfs2_trans_end, unlocking the sd_log_flush_lock has to happen slightly later in ending the transaction. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/log.c')
-rw-r--r--fs/gfs2/log.c104
1 files changed, 57 insertions, 47 deletions
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)) >