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