David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 4 | * |
| 5 | * This copyrighted material is made available to anyone wishing to use, |
| 6 | * modify, copy, or redistribute it subject to the terms and conditions |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/completion.h> |
| 14 | #include <linux/buffer_head.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 15 | #include <linux/gfs2_ondisk.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 16 | #include <linux/lm_interface.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 17 | |
| 18 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 19 | #include "incore.h" |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame] | 20 | #include "inode.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 21 | #include "glock.h" |
| 22 | #include "log.h" |
| 23 | #include "lops.h" |
| 24 | #include "meta_io.h" |
| 25 | #include "recovery.h" |
| 26 | #include "rgrp.h" |
| 27 | #include "trans.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 28 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 29 | |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 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 | */ |
| 37 | static 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 | |
| 65 | static 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 | |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 94 | |
| 95 | static inline struct gfs2_log_descriptor *bh_log_desc(struct buffer_head *bh) |
| 96 | { |
| 97 | return (struct gfs2_log_descriptor *)bh->b_data; |
| 98 | } |
| 99 | |
| 100 | static inline __be64 *bh_log_ptr(struct buffer_head *bh) |
| 101 | { |
| 102 | struct gfs2_log_descriptor *ld = bh_log_desc(bh); |
| 103 | return (__force __be64 *)(ld + 1); |
| 104 | } |
| 105 | |
| 106 | static inline __be64 *bh_ptr_end(struct buffer_head *bh) |
| 107 | { |
| 108 | return (__force __be64 *)(bh->b_data + bh->b_size); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | static struct buffer_head *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type) |
| 113 | { |
| 114 | struct buffer_head *bh = gfs2_log_get_buf(sdp); |
| 115 | struct gfs2_log_descriptor *ld = bh_log_desc(bh); |
| 116 | ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC); |
| 117 | ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD); |
| 118 | ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD); |
| 119 | ld->ld_type = cpu_to_be32(ld_type); |
| 120 | ld->ld_length = 0; |
| 121 | ld->ld_data1 = 0; |
| 122 | ld->ld_data2 = 0; |
| 123 | memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved)); |
| 124 | return bh; |
| 125 | } |
| 126 | |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 127 | static void __glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 128 | { |
| 129 | struct gfs2_glock *gl; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 130 | struct gfs2_trans *tr = current->journal_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 131 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 132 | tr->tr_touched = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 133 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 134 | gl = container_of(le, struct gfs2_glock, gl_le); |
| 135 | if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(gl))) |
| 136 | return; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 137 | |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 138 | if (!list_empty(&le->le_list)) |
Benjamin Marzinski | 6883562 | 2007-03-23 09:05:12 +0000 | [diff] [blame] | 139 | return; |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 140 | |
Benjamin Marzinski | 6883562 | 2007-03-23 09:05:12 +0000 | [diff] [blame] | 141 | gfs2_glock_hold(gl); |
| 142 | set_bit(GLF_DIRTY, &gl->gl_flags); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 143 | sdp->sd_log_num_gl++; |
| 144 | list_add(&le->le_list, &sdp->sd_log_le_gl); |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static void glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) |
| 148 | { |
| 149 | gfs2_log_lock(sdp); |
| 150 | __glock_lo_add(sdp, le); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 151 | gfs2_log_unlock(sdp); |
| 152 | } |
| 153 | |
| 154 | static void glock_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) |
| 155 | { |
| 156 | struct list_head *head = &sdp->sd_log_le_gl; |
| 157 | struct gfs2_glock *gl; |
| 158 | |
| 159 | while (!list_empty(head)) { |
| 160 | gl = list_entry(head->next, struct gfs2_glock, gl_le.le_list); |
| 161 | list_del_init(&gl->gl_le.le_list); |
| 162 | sdp->sd_log_num_gl--; |
| 163 | |
| 164 | gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(gl)); |
| 165 | gfs2_glock_put(gl); |
| 166 | } |
| 167 | gfs2_assert_warn(sdp, !sdp->sd_log_num_gl); |
| 168 | } |
| 169 | |
| 170 | static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) |
| 171 | { |
| 172 | struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le); |
| 173 | struct gfs2_trans *tr; |
| 174 | |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 175 | lock_buffer(bd->bd_bh); |
Steven Whitehouse | 8bd9572 | 2007-01-25 10:04:20 +0000 | [diff] [blame] | 176 | gfs2_log_lock(sdp); |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 177 | if (!list_empty(&bd->bd_list_tr)) |
| 178 | goto out; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 179 | tr = current->journal_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 180 | tr->tr_touched = 1; |
| 181 | tr->tr_num_buf++; |
| 182 | list_add(&bd->bd_list_tr, &tr->tr_list_buf); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 183 | if (!list_empty(&le->le_list)) |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 184 | goto out; |
| 185 | __glock_lo_add(sdp, &bd->bd_gl->gl_le); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 186 | gfs2_meta_check(sdp, bd->bd_bh); |
Steven Whitehouse | a98ab22 | 2006-01-18 13:38:44 +0000 | [diff] [blame] | 187 | gfs2_pin(sdp, bd->bd_bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 188 | sdp->sd_log_num_buf++; |
| 189 | list_add(&le->le_list, &sdp->sd_log_le_buf); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 190 | tr->tr_num_buf_new++; |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 191 | out: |
| 192 | gfs2_log_unlock(sdp); |
| 193 | unlock_buffer(bd->bd_bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static void buf_lo_incore_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) |
| 197 | { |
| 198 | struct list_head *head = &tr->tr_list_buf; |
| 199 | struct gfs2_bufdata *bd; |
| 200 | |
Steven Whitehouse | 8bd9572 | 2007-01-25 10:04:20 +0000 | [diff] [blame] | 201 | gfs2_log_lock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 202 | while (!list_empty(head)) { |
| 203 | bd = list_entry(head->next, struct gfs2_bufdata, bd_list_tr); |
| 204 | list_del_init(&bd->bd_list_tr); |
| 205 | tr->tr_num_buf--; |
| 206 | } |
Steven Whitehouse | 8bd9572 | 2007-01-25 10:04:20 +0000 | [diff] [blame] | 207 | gfs2_log_unlock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 208 | gfs2_assert_warn(sdp, !tr->tr_num_buf); |
| 209 | } |
| 210 | |
| 211 | static void buf_lo_before_commit(struct gfs2_sbd *sdp) |
| 212 | { |
| 213 | struct buffer_head *bh; |
| 214 | struct gfs2_log_descriptor *ld; |
| 215 | struct gfs2_bufdata *bd1 = NULL, *bd2; |
Bob Peterson | 905d2ae | 2007-07-24 14:05:31 -0500 | [diff] [blame] | 216 | unsigned int total; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 217 | unsigned int limit; |
| 218 | unsigned int num; |
| 219 | unsigned n; |
| 220 | __be64 *ptr; |
| 221 | |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame] | 222 | limit = buf_limit(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 223 | /* for 4k blocks, limit = 503 */ |
| 224 | |
Bob Peterson | 905d2ae | 2007-07-24 14:05:31 -0500 | [diff] [blame] | 225 | gfs2_log_lock(sdp); |
| 226 | total = sdp->sd_log_num_buf; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 227 | bd1 = bd2 = list_prepare_entry(bd1, &sdp->sd_log_le_buf, bd_le.le_list); |
| 228 | while(total) { |
| 229 | num = total; |
| 230 | if (total > limit) |
| 231 | num = limit; |
Bob Peterson | 905d2ae | 2007-07-24 14:05:31 -0500 | [diff] [blame] | 232 | gfs2_log_unlock(sdp); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 233 | bh = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_METADATA); |
Bob Peterson | 905d2ae | 2007-07-24 14:05:31 -0500 | [diff] [blame] | 234 | gfs2_log_lock(sdp); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 235 | ld = bh_log_desc(bh); |
| 236 | ptr = bh_log_ptr(bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 237 | ld->ld_length = cpu_to_be32(num + 1); |
| 238 | ld->ld_data1 = cpu_to_be32(num); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 239 | |
| 240 | n = 0; |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 241 | list_for_each_entry_continue(bd1, &sdp->sd_log_le_buf, |
| 242 | bd_le.le_list) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 243 | *ptr++ = cpu_to_be64(bd1->bd_bh->b_blocknr); |
| 244 | if (++n >= num) |
| 245 | break; |
| 246 | } |
| 247 | |
Bob Peterson | 905d2ae | 2007-07-24 14:05:31 -0500 | [diff] [blame] | 248 | gfs2_log_unlock(sdp); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 249 | submit_bh(WRITE, bh); |
Bob Peterson | 905d2ae | 2007-07-24 14:05:31 -0500 | [diff] [blame] | 250 | gfs2_log_lock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 251 | |
| 252 | n = 0; |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 253 | list_for_each_entry_continue(bd2, &sdp->sd_log_le_buf, |
| 254 | bd_le.le_list) { |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 255 | get_bh(bd2->bd_bh); |
Bob Peterson | 905d2ae | 2007-07-24 14:05:31 -0500 | [diff] [blame] | 256 | gfs2_log_unlock(sdp); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 257 | lock_buffer(bd2->bd_bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 258 | bh = gfs2_log_fake_buf(sdp, bd2->bd_bh); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 259 | submit_bh(WRITE, bh); |
Bob Peterson | 905d2ae | 2007-07-24 14:05:31 -0500 | [diff] [blame] | 260 | gfs2_log_lock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 261 | if (++n >= num) |
| 262 | break; |
| 263 | } |
| 264 | |
Bob Peterson | 905d2ae | 2007-07-24 14:05:31 -0500 | [diff] [blame] | 265 | BUG_ON(total < num); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 266 | total -= num; |
| 267 | } |
Bob Peterson | 905d2ae | 2007-07-24 14:05:31 -0500 | [diff] [blame] | 268 | gfs2_log_unlock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) |
| 272 | { |
| 273 | struct list_head *head = &sdp->sd_log_le_buf; |
| 274 | struct gfs2_bufdata *bd; |
| 275 | |
| 276 | while (!list_empty(head)) { |
| 277 | bd = list_entry(head->next, struct gfs2_bufdata, bd_le.le_list); |
| 278 | list_del_init(&bd->bd_le.le_list); |
| 279 | sdp->sd_log_num_buf--; |
| 280 | |
Steven Whitehouse | a98ab22 | 2006-01-18 13:38:44 +0000 | [diff] [blame] | 281 | gfs2_unpin(sdp, bd->bd_bh, ai); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 282 | } |
| 283 | gfs2_assert_warn(sdp, !sdp->sd_log_num_buf); |
| 284 | } |
| 285 | |
| 286 | static void buf_lo_before_scan(struct gfs2_jdesc *jd, |
Al Viro | 5516762 | 2006-10-13 21:47:13 -0400 | [diff] [blame] | 287 | struct gfs2_log_header_host *head, int pass) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 288 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 289 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 290 | |
| 291 | if (pass != 0) |
| 292 | return; |
| 293 | |
| 294 | sdp->sd_found_blocks = 0; |
| 295 | sdp->sd_replayed_blocks = 0; |
| 296 | } |
| 297 | |
| 298 | static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, |
| 299 | struct gfs2_log_descriptor *ld, __be64 *ptr, |
| 300 | int pass) |
| 301 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 302 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); |
| 303 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 304 | struct gfs2_glock *gl = ip->i_gl; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 305 | unsigned int blks = be32_to_cpu(ld->ld_data1); |
| 306 | struct buffer_head *bh_log, *bh_ip; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 307 | u64 blkno; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 308 | int error = 0; |
| 309 | |
| 310 | if (pass != 1 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_METADATA) |
| 311 | return 0; |
| 312 | |
| 313 | gfs2_replay_incr_blk(sdp, &start); |
| 314 | |
| 315 | for (; blks; gfs2_replay_incr_blk(sdp, &start), blks--) { |
| 316 | blkno = be64_to_cpu(*ptr++); |
| 317 | |
| 318 | sdp->sd_found_blocks++; |
| 319 | |
| 320 | if (gfs2_revoke_check(sdp, blkno, start)) |
| 321 | continue; |
| 322 | |
| 323 | error = gfs2_replay_read_block(jd, start, &bh_log); |
Steven Whitehouse | 82ffa51 | 2006-09-04 14:47:06 -0400 | [diff] [blame] | 324 | if (error) |
| 325 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 326 | |
| 327 | bh_ip = gfs2_meta_new(gl, blkno); |
| 328 | memcpy(bh_ip->b_data, bh_log->b_data, bh_log->b_size); |
| 329 | |
| 330 | if (gfs2_meta_check(sdp, bh_ip)) |
| 331 | error = -EIO; |
| 332 | else |
| 333 | mark_buffer_dirty(bh_ip); |
| 334 | |
| 335 | brelse(bh_log); |
| 336 | brelse(bh_ip); |
| 337 | |
| 338 | if (error) |
| 339 | break; |
| 340 | |
| 341 | sdp->sd_replayed_blocks++; |
| 342 | } |
| 343 | |
| 344 | return error; |
| 345 | } |
| 346 | |
| 347 | static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) |
| 348 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 349 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); |
| 350 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 351 | |
| 352 | if (error) { |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 353 | gfs2_meta_sync(ip->i_gl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 354 | return; |
| 355 | } |
| 356 | if (pass != 1) |
| 357 | return; |
| 358 | |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 359 | gfs2_meta_sync(ip->i_gl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 360 | |
| 361 | fs_info(sdp, "jid=%u: Replayed %u of %u blocks\n", |
| 362 | jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); |
| 363 | } |
| 364 | |
| 365 | static void revoke_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) |
| 366 | { |
| 367 | struct gfs2_trans *tr; |
| 368 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 369 | tr = current->journal_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 370 | tr->tr_touched = 1; |
| 371 | tr->tr_num_revoke++; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 372 | sdp->sd_log_num_revoke++; |
| 373 | list_add(&le->le_list, &sdp->sd_log_le_revoke); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | static void revoke_lo_before_commit(struct gfs2_sbd *sdp) |
| 377 | { |
| 378 | struct gfs2_log_descriptor *ld; |
| 379 | struct gfs2_meta_header *mh; |
| 380 | struct buffer_head *bh; |
| 381 | unsigned int offset; |
| 382 | struct list_head *head = &sdp->sd_log_le_revoke; |
Steven Whitehouse | 82e8608 | 2007-09-02 15:39:43 +0100 | [diff] [blame] | 383 | struct gfs2_bufdata *bd; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 384 | |
| 385 | if (!sdp->sd_log_num_revoke) |
| 386 | return; |
| 387 | |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 388 | bh = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_REVOKE); |
| 389 | ld = bh_log_desc(bh); |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 390 | ld->ld_length = cpu_to_be32(gfs2_struct2blk(sdp, sdp->sd_log_num_revoke, |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 391 | sizeof(u64))); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 392 | ld->ld_data1 = cpu_to_be32(sdp->sd_log_num_revoke); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 393 | offset = sizeof(struct gfs2_log_descriptor); |
| 394 | |
| 395 | while (!list_empty(head)) { |
Steven Whitehouse | 82e8608 | 2007-09-02 15:39:43 +0100 | [diff] [blame] | 396 | bd = list_entry(head->next, struct gfs2_bufdata, bd_le.le_list); |
| 397 | list_del_init(&bd->bd_le.le_list); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 398 | sdp->sd_log_num_revoke--; |
| 399 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 400 | if (offset + sizeof(u64) > sdp->sd_sb.sb_bsize) { |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 401 | submit_bh(WRITE, bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 402 | |
| 403 | bh = gfs2_log_get_buf(sdp); |
| 404 | mh = (struct gfs2_meta_header *)bh->b_data; |
| 405 | mh->mh_magic = cpu_to_be32(GFS2_MAGIC); |
Steven Whitehouse | e3167de | 2006-03-30 15:46:23 -0500 | [diff] [blame] | 406 | mh->mh_type = cpu_to_be32(GFS2_METATYPE_LB); |
| 407 | mh->mh_format = cpu_to_be32(GFS2_FORMAT_LB); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 408 | offset = sizeof(struct gfs2_meta_header); |
| 409 | } |
| 410 | |
Steven Whitehouse | 82e8608 | 2007-09-02 15:39:43 +0100 | [diff] [blame] | 411 | *(__be64 *)(bh->b_data + offset) = cpu_to_be64(bd->bd_blkno); |
Steven Whitehouse | 0820ab5 | 2007-09-02 16:47:38 +0100 | [diff] [blame] | 412 | kmem_cache_free(gfs2_bufdata_cachep, bd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 413 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 414 | offset += sizeof(u64); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 415 | } |
| 416 | gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); |
| 417 | |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 418 | submit_bh(WRITE, bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | static void revoke_lo_before_scan(struct gfs2_jdesc *jd, |
Al Viro | 5516762 | 2006-10-13 21:47:13 -0400 | [diff] [blame] | 422 | struct gfs2_log_header_host *head, int pass) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 423 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 424 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 425 | |
| 426 | if (pass != 0) |
| 427 | return; |
| 428 | |
| 429 | sdp->sd_found_revokes = 0; |
| 430 | sdp->sd_replay_tail = head->lh_tail; |
| 431 | } |
| 432 | |
| 433 | static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, |
| 434 | struct gfs2_log_descriptor *ld, __be64 *ptr, |
| 435 | int pass) |
| 436 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 437 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 438 | unsigned int blks = be32_to_cpu(ld->ld_length); |
| 439 | unsigned int revokes = be32_to_cpu(ld->ld_data1); |
| 440 | struct buffer_head *bh; |
| 441 | unsigned int offset; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 442 | u64 blkno; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 443 | int first = 1; |
| 444 | int error; |
| 445 | |
| 446 | if (pass != 0 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_REVOKE) |
| 447 | return 0; |
| 448 | |
| 449 | offset = sizeof(struct gfs2_log_descriptor); |
| 450 | |
| 451 | for (; blks; gfs2_replay_incr_blk(sdp, &start), blks--) { |
| 452 | error = gfs2_replay_read_block(jd, start, &bh); |
| 453 | if (error) |
| 454 | return error; |
| 455 | |
| 456 | if (!first) |
| 457 | gfs2_metatype_check(sdp, bh, GFS2_METATYPE_LB); |
| 458 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 459 | while (offset + sizeof(u64) <= sdp->sd_sb.sb_bsize) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 460 | blkno = be64_to_cpu(*(__be64 *)(bh->b_data + offset)); |
| 461 | |
| 462 | error = gfs2_revoke_add(sdp, blkno, start); |
| 463 | if (error < 0) |
| 464 | return error; |
| 465 | else if (error) |
| 466 | sdp->sd_found_revokes++; |
| 467 | |
| 468 | if (!--revokes) |
| 469 | break; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 470 | offset += sizeof(u64); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | brelse(bh); |
| 474 | offset = sizeof(struct gfs2_meta_header); |
| 475 | first = 0; |
| 476 | } |
| 477 | |
| 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | static void revoke_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) |
| 482 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 483 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 484 | |
| 485 | if (error) { |
| 486 | gfs2_revoke_clean(sdp); |
| 487 | return; |
| 488 | } |
| 489 | if (pass != 1) |
| 490 | return; |
| 491 | |
| 492 | fs_info(sdp, "jid=%u: Found %u revoke tags\n", |
| 493 | jd->jd_jid, sdp->sd_found_revokes); |
| 494 | |
| 495 | gfs2_revoke_clean(sdp); |
| 496 | } |
| 497 | |
| 498 | static void rg_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) |
| 499 | { |
| 500 | struct gfs2_rgrpd *rgd; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 501 | struct gfs2_trans *tr = current->journal_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 502 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 503 | tr->tr_touched = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 504 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 505 | rgd = container_of(le, struct gfs2_rgrpd, rd_le); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 506 | |
| 507 | gfs2_log_lock(sdp); |
Benjamin Marzinski | 6883562 | 2007-03-23 09:05:12 +0000 | [diff] [blame] | 508 | if (!list_empty(&le->le_list)){ |
| 509 | gfs2_log_unlock(sdp); |
| 510 | return; |
| 511 | } |
| 512 | gfs2_rgrp_bh_hold(rgd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 513 | sdp->sd_log_num_rg++; |
| 514 | list_add(&le->le_list, &sdp->sd_log_le_rg); |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 515 | gfs2_log_unlock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static void rg_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) |
| 519 | { |
| 520 | struct list_head *head = &sdp->sd_log_le_rg; |
| 521 | struct gfs2_rgrpd *rgd; |
| 522 | |
| 523 | while (!list_empty(head)) { |
| 524 | rgd = list_entry(head->next, struct gfs2_rgrpd, rd_le.le_list); |
| 525 | list_del_init(&rgd->rd_le.le_list); |
| 526 | sdp->sd_log_num_rg--; |
| 527 | |
| 528 | gfs2_rgrp_repolish_clones(rgd); |
| 529 | gfs2_rgrp_bh_put(rgd); |
| 530 | } |
| 531 | gfs2_assert_warn(sdp, !sdp->sd_log_num_rg); |
| 532 | } |
| 533 | |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 534 | /** |
| 535 | * databuf_lo_add - Add a databuf to the transaction. |
| 536 | * |
| 537 | * This is used in two distinct cases: |
| 538 | * i) In ordered write mode |
| 539 | * We put the data buffer on a list so that we can ensure that its |
| 540 | * synced to disk at the right time |
| 541 | * ii) In journaled data mode |
| 542 | * We need to journal the data block in the same way as metadata in |
| 543 | * the functions above. The difference is that here we have a tag |
| 544 | * which is two __be64's being the block number (as per meta data) |
| 545 | * and a flag which says whether the data block needs escaping or |
| 546 | * not. This means we need a new log entry for each 251 or so data |
| 547 | * blocks, which isn't an enormous overhead but twice as much as |
| 548 | * for normal metadata blocks. |
| 549 | */ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 550 | static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) |
| 551 | { |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 552 | struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 553 | struct gfs2_trans *tr = current->journal_info; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 554 | struct address_space *mapping = bd->bd_bh->b_page->mapping; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 555 | struct gfs2_inode *ip = GFS2_I(mapping->host); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 556 | |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 557 | lock_buffer(bd->bd_bh); |
Steven Whitehouse | 8bd9572 | 2007-01-25 10:04:20 +0000 | [diff] [blame] | 558 | gfs2_log_lock(sdp); |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 559 | if (!list_empty(&bd->bd_list_tr)) |
| 560 | goto out; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 561 | tr->tr_touched = 1; |
Robert Peterson | 773ed1a | 2007-06-20 08:34:06 -0500 | [diff] [blame] | 562 | if (gfs2_is_jdata(ip)) { |
| 563 | tr->tr_num_buf++; |
| 564 | list_add(&bd->bd_list_tr, &tr->tr_list_buf); |
| 565 | } |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame] | 566 | if (!list_empty(&le->le_list)) |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 567 | goto out; |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame] | 568 | |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 569 | __glock_lo_add(sdp, &bd->bd_gl->gl_le); |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame] | 570 | if (gfs2_is_jdata(ip)) { |
Robert Peterson | 2332c44 | 2007-06-18 14:50:20 -0500 | [diff] [blame] | 571 | gfs2_pin(sdp, bd->bd_bh); |
| 572 | tr->tr_num_databuf_new++; |
Steven Whitehouse | d7b616e | 2007-09-02 10:48:13 +0100 | [diff] [blame] | 573 | sdp->sd_log_num_databuf++; |
| 574 | list_add(&le->le_list, &sdp->sd_log_le_databuf); |
| 575 | } else { |
| 576 | list_add(&le->le_list, &sdp->sd_log_le_ordered); |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 577 | } |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 578 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 579 | gfs2_log_unlock(sdp); |
Steven Whitehouse | 9b9107a | 2007-08-27 13:54:05 +0100 | [diff] [blame] | 580 | unlock_buffer(bd->bd_bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 583 | static void gfs2_check_magic(struct buffer_head *bh) |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 584 | { |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 585 | void *kaddr; |
| 586 | __be32 *ptr; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 587 | |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 588 | clear_buffer_escaped(bh); |
| 589 | kaddr = kmap_atomic(bh->b_page, KM_USER0); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 590 | ptr = kaddr + bh_offset(bh); |
| 591 | if (*ptr == cpu_to_be32(GFS2_MAGIC)) |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 592 | set_buffer_escaped(bh); |
Russell Cattelan | c312c4f | 2006-10-12 09:23:41 -0400 | [diff] [blame] | 593 | kunmap_atomic(kaddr, KM_USER0); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 594 | } |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 595 | |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 596 | static void gfs2_write_blocks(struct gfs2_sbd *sdp, struct buffer_head *bh, |
| 597 | struct list_head *list, struct list_head *done, |
| 598 | unsigned int n) |
| 599 | { |
| 600 | struct buffer_head *bh1; |
| 601 | struct gfs2_log_descriptor *ld; |
| 602 | struct gfs2_bufdata *bd; |
| 603 | __be64 *ptr; |
| 604 | |
| 605 | if (!bh) |
| 606 | return; |
| 607 | |
| 608 | ld = bh_log_desc(bh); |
| 609 | ld->ld_length = cpu_to_be32(n + 1); |
| 610 | ld->ld_data1 = cpu_to_be32(n); |
| 611 | |
| 612 | ptr = bh_log_ptr(bh); |
| 613 | |
| 614 | get_bh(bh); |
| 615 | submit_bh(WRITE, bh); |
| 616 | gfs2_log_lock(sdp); |
| 617 | while(!list_empty(list)) { |
| 618 | bd = list_entry(list->next, struct gfs2_bufdata, bd_le.le_list); |
| 619 | list_move_tail(&bd->bd_le.le_list, done); |
| 620 | get_bh(bd->bd_bh); |
| 621 | while (be64_to_cpu(*ptr) != bd->bd_bh->b_blocknr) { |
| 622 | gfs2_log_incr_head(sdp); |
| 623 | ptr += 2; |
| 624 | } |
| 625 | gfs2_log_unlock(sdp); |
| 626 | lock_buffer(bd->bd_bh); |
| 627 | if (buffer_escaped(bd->bd_bh)) { |
| 628 | void *kaddr; |
| 629 | bh1 = gfs2_log_get_buf(sdp); |
| 630 | kaddr = kmap_atomic(bd->bd_bh->b_page, KM_USER0); |
| 631 | memcpy(bh1->b_data, kaddr + bh_offset(bd->bd_bh), |
| 632 | bh1->b_size); |
| 633 | kunmap_atomic(kaddr, KM_USER0); |
| 634 | *(__be32 *)bh1->b_data = 0; |
| 635 | clear_buffer_escaped(bd->bd_bh); |
| 636 | unlock_buffer(bd->bd_bh); |
| 637 | brelse(bd->bd_bh); |
| 638 | } else { |
| 639 | bh1 = gfs2_log_fake_buf(sdp, bd->bd_bh); |
| 640 | } |
| 641 | submit_bh(WRITE, bh1); |
| 642 | gfs2_log_lock(sdp); |
| 643 | ptr += 2; |
| 644 | } |
| 645 | gfs2_log_unlock(sdp); |
| 646 | brelse(bh); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /** |
| 650 | * databuf_lo_before_commit - Scan the data buffers, writing as we go |
| 651 | * |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 652 | */ |
Steven Whitehouse | d7b616e | 2007-09-02 10:48:13 +0100 | [diff] [blame] | 653 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 654 | static void databuf_lo_before_commit(struct gfs2_sbd *sdp) |
| 655 | { |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 656 | struct gfs2_bufdata *bd = NULL; |
| 657 | struct buffer_head *bh = NULL; |
| 658 | unsigned int n = 0; |
| 659 | __be64 *ptr = NULL, *end = NULL; |
| 660 | LIST_HEAD(processed); |
| 661 | LIST_HEAD(in_progress); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 662 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 663 | gfs2_log_lock(sdp); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 664 | while (!list_empty(&sdp->sd_log_le_databuf)) { |
| 665 | if (ptr == end) { |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 666 | gfs2_log_unlock(sdp); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 667 | gfs2_write_blocks(sdp, bh, &in_progress, &processed, n); |
| 668 | n = 0; |
| 669 | bh = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_JDATA); |
| 670 | ptr = bh_log_ptr(bh); |
| 671 | end = bh_ptr_end(bh) - 1; |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 672 | gfs2_log_lock(sdp); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 673 | continue; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 674 | } |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 675 | bd = list_entry(sdp->sd_log_le_databuf.next, struct gfs2_bufdata, bd_le.le_list); |
| 676 | list_move_tail(&bd->bd_le.le_list, &in_progress); |
| 677 | gfs2_check_magic(bd->bd_bh); |
| 678 | *ptr++ = cpu_to_be64(bd->bd_bh->b_blocknr); |
| 679 | *ptr++ = cpu_to_be64(buffer_escaped(bh) ? 1 : 0); |
| 680 | n++; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 681 | } |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 682 | gfs2_log_unlock(sdp); |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 683 | gfs2_write_blocks(sdp, bh, &in_progress, &processed, n); |
| 684 | gfs2_log_lock(sdp); |
| 685 | list_splice(&processed, &sdp->sd_log_le_databuf); |
| 686 | gfs2_log_unlock(sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 689 | static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start, |
| 690 | struct gfs2_log_descriptor *ld, |
| 691 | __be64 *ptr, int pass) |
| 692 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 693 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); |
| 694 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 695 | struct gfs2_glock *gl = ip->i_gl; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 696 | unsigned int blks = be32_to_cpu(ld->ld_data1); |
| 697 | struct buffer_head *bh_log, *bh_ip; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 698 | u64 blkno; |
| 699 | u64 esc; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 700 | int error = 0; |
| 701 | |
| 702 | if (pass != 1 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_JDATA) |
| 703 | return 0; |
| 704 | |
| 705 | gfs2_replay_incr_blk(sdp, &start); |
| 706 | for (; blks; gfs2_replay_incr_blk(sdp, &start), blks--) { |
| 707 | blkno = be64_to_cpu(*ptr++); |
| 708 | esc = be64_to_cpu(*ptr++); |
| 709 | |
| 710 | sdp->sd_found_blocks++; |
| 711 | |
| 712 | if (gfs2_revoke_check(sdp, blkno, start)) |
| 713 | continue; |
| 714 | |
| 715 | error = gfs2_replay_read_block(jd, start, &bh_log); |
| 716 | if (error) |
| 717 | return error; |
| 718 | |
| 719 | bh_ip = gfs2_meta_new(gl, blkno); |
| 720 | memcpy(bh_ip->b_data, bh_log->b_data, bh_log->b_size); |
| 721 | |
| 722 | /* Unescape */ |
| 723 | if (esc) { |
| 724 | __be32 *eptr = (__be32 *)bh_ip->b_data; |
| 725 | *eptr = cpu_to_be32(GFS2_MAGIC); |
| 726 | } |
| 727 | mark_buffer_dirty(bh_ip); |
| 728 | |
| 729 | brelse(bh_log); |
| 730 | brelse(bh_ip); |
| 731 | if (error) |
| 732 | break; |
| 733 | |
| 734 | sdp->sd_replayed_blocks++; |
| 735 | } |
| 736 | |
| 737 | return error; |
| 738 | } |
| 739 | |
| 740 | /* FIXME: sort out accounting for log blocks etc. */ |
| 741 | |
| 742 | static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass) |
| 743 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 744 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); |
| 745 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 746 | |
| 747 | if (error) { |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 748 | gfs2_meta_sync(ip->i_gl); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 749 | return; |
| 750 | } |
| 751 | if (pass != 1) |
| 752 | return; |
| 753 | |
| 754 | /* data sync? */ |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 755 | gfs2_meta_sync(ip->i_gl); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 756 | |
| 757 | fs_info(sdp, "jid=%u: Replayed %u of %u data blocks\n", |
| 758 | jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks); |
| 759 | } |
| 760 | |
| 761 | static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai) |
| 762 | { |
| 763 | struct list_head *head = &sdp->sd_log_le_databuf; |
| 764 | struct gfs2_bufdata *bd; |
| 765 | |
| 766 | while (!list_empty(head)) { |
| 767 | bd = list_entry(head->next, struct gfs2_bufdata, bd_le.le_list); |
Steven Whitehouse | b8e1aab | 2006-08-22 16:25:50 -0400 | [diff] [blame] | 768 | list_del_init(&bd->bd_le.le_list); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 769 | sdp->sd_log_num_databuf--; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 770 | gfs2_unpin(sdp, bd->bd_bh, ai); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 771 | } |
| 772 | gfs2_assert_warn(sdp, !sdp->sd_log_num_databuf); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 776 | const struct gfs2_log_operations gfs2_glock_lops = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 777 | .lo_add = glock_lo_add, |
| 778 | .lo_after_commit = glock_lo_after_commit, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 779 | .lo_name = "glock", |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 780 | }; |
| 781 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 782 | const struct gfs2_log_operations gfs2_buf_lops = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 783 | .lo_add = buf_lo_add, |
| 784 | .lo_incore_commit = buf_lo_incore_commit, |
| 785 | .lo_before_commit = buf_lo_before_commit, |
| 786 | .lo_after_commit = buf_lo_after_commit, |
| 787 | .lo_before_scan = buf_lo_before_scan, |
| 788 | .lo_scan_elements = buf_lo_scan_elements, |
| 789 | .lo_after_scan = buf_lo_after_scan, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 790 | .lo_name = "buf", |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 791 | }; |
| 792 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 793 | const struct gfs2_log_operations gfs2_revoke_lops = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 794 | .lo_add = revoke_lo_add, |
| 795 | .lo_before_commit = revoke_lo_before_commit, |
| 796 | .lo_before_scan = revoke_lo_before_scan, |
| 797 | .lo_scan_elements = revoke_lo_scan_elements, |
| 798 | .lo_after_scan = revoke_lo_after_scan, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 799 | .lo_name = "revoke", |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 800 | }; |
| 801 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 802 | const struct gfs2_log_operations gfs2_rg_lops = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 803 | .lo_add = rg_lo_add, |
| 804 | .lo_after_commit = rg_lo_after_commit, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 805 | .lo_name = "rg", |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 806 | }; |
| 807 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 808 | const struct gfs2_log_operations gfs2_databuf_lops = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 809 | .lo_add = databuf_lo_add, |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 810 | .lo_incore_commit = buf_lo_incore_commit, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 811 | .lo_before_commit = databuf_lo_before_commit, |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 812 | .lo_after_commit = databuf_lo_after_commit, |
| 813 | .lo_scan_elements = databuf_lo_scan_elements, |
| 814 | .lo_after_scan = databuf_lo_after_scan, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 815 | .lo_name = "databuf", |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 816 | }; |
| 817 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 818 | const struct gfs2_log_operations *gfs2_log_ops[] = { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 819 | &gfs2_glock_lops, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 820 | &gfs2_databuf_lops, |
Steven Whitehouse | 16615be | 2007-09-17 10:59:52 +0100 | [diff] [blame] | 821 | &gfs2_buf_lops, |
| 822 | &gfs2_rg_lops, |
| 823 | &gfs2_revoke_lops, |
Steven Whitehouse | ea67eed | 2006-09-05 10:53:09 -0400 | [diff] [blame] | 824 | NULL, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 825 | }; |
| 826 | |