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