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