2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
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 version 2.
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>
15 #include <linux/mempool.h>
16 #include <linux/gfs2_ondisk.h>
17 #include <linux/bio.h>
31 #include "trace_gfs2.h"
34 * gfs2_pin - Pin a buffer in memory
35 * @sdp: The superblock
36 * @bh: The buffer to be pinned
38 * The log lock must be held when calling this function
40 static void gfs2_pin(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
)
42 struct gfs2_bufdata
*bd
;
44 BUG_ON(!current
->journal_info
);
46 clear_buffer_dirty(bh
);
47 if (test_set_buffer_pinned(bh
))
48 gfs2_assert_withdraw(sdp
, 0);
49 if (!buffer_uptodate(bh
))
50 gfs2_io_error_bh(sdp
, bh
);
52 /* If this buffer is in the AIL and it has already been written
53 * to in-place disk block, remove it from the AIL.
55 spin_lock(&sdp
->sd_ail_lock
);
57 list_move(&bd
->bd_ail_st_list
, &bd
->bd_ail
->ai_ail2_list
);
58 spin_unlock(&sdp
->sd_ail_lock
);
60 atomic_inc(&sdp
->sd_log_pinned
);
61 trace_gfs2_pin(bd
, 1);
64 static bool buffer_is_rgrp(const struct gfs2_bufdata
*bd
)
66 return bd
->bd_gl
->gl_name
.ln_type
== LM_TYPE_RGRP
;
69 static void maybe_release_space(struct gfs2_bufdata
*bd
)
71 struct gfs2_glock
*gl
= bd
->bd_gl
;
72 struct gfs2_sbd
*sdp
= gl
->gl_sbd
;
73 struct gfs2_rgrpd
*rgd
= gl
->gl_object
;
74 unsigned int index
= bd
->bd_bh
->b_blocknr
- gl
->gl_name
.ln_number
;
75 struct gfs2_bitmap
*bi
= rgd
->rd_bits
+ index
;
77 if (bi
->bi_clone
== 0)
79 if (sdp
->sd_args
.ar_discard
)
80 gfs2_rgrp_send_discards(sdp
, rgd
->rd_data0
, bd
->bd_bh
, bi
, 1, NULL
);
81 memcpy(bi
->bi_clone
+ bi
->bi_offset
,
82 bd
->bd_bh
->b_data
+ bi
->bi_offset
, bi
->bi_len
);
83 clear_bit(GBF_FULL
, &bi
->bi_flags
);
84 rgd
->rd_free_clone
= rgd
->rd_free
;
88 * gfs2_unpin - Unpin a buffer
89 * @sdp: the filesystem the buffer belongs to
90 * @bh: The buffer to unpin
92 * @flags: The inode dirty flags
96 static void gfs2_unpin(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
99 struct gfs2_bufdata
*bd
= bh
->b_private
;
101 BUG_ON(!buffer_uptodate(bh
));
102 BUG_ON(!buffer_pinned(bh
));
105 mark_buffer_dirty(bh
);
106 clear_buffer_pinned(bh
);
108 if (buffer_is_rgrp(bd
))
109 maybe_release_space(bd
);
111 spin_lock(&sdp
->sd_ail_lock
);
113 list_del(&bd
->bd_ail_st_list
);
116 struct gfs2_glock
*gl
= bd
->bd_gl
;
117 list_add(&bd
->bd_ail_gl_list
, &gl
->gl_ail_list
);
118 atomic_inc(&gl
->gl_ail_count
);
121 list_add(&bd
->bd_ail_st_list
, &ai
->ai_ail1_list
);
122 spin_unlock(&sdp
->sd_ail_lock
);
124 clear_bit(GLF_LFLUSH
, &bd
->bd_gl
->gl_flags
);
125 trace_gfs2_pin(bd
, 0);
127 atomic_dec(&sdp
->sd_log_pinned
);
131 static inline struct gfs2_log_descriptor
*bh_log_desc(struct buffer_head
*bh
)
133 return (struct gfs2_log_descriptor
*)bh
->b_data
;
136 static inline __be64
*bh_log_ptr(struct buffer_head
*bh
)
138 struct gfs2_log_descriptor
*ld
= bh_log_desc(bh
);
139 return (__force __be64
*)(ld
+ 1);
142 static inline __be64
*bh_ptr_end(struct buffer_head
*bh
)
144 return (__force __be64
*)(bh
->b_data
+ bh
->b_size
);
148 * gfs2_log_write_endio - End of I/O for a log buffer
149 * @bh: The buffer head
150 * @uptodate: I/O Status
154 static void gfs2_log_write_endio(struct buffer_head
*bh
, int uptodate
)
156 struct gfs2_sbd
*sdp
= bh
->b_private
;
157 bh
->b_private
= NULL
;
159 end_buffer_write_sync(bh
, uptodate
);
160 if (atomic_dec_and_test(&sdp
->sd_log_in_flight
))
161 wake_up(&sdp
->sd_log_flush_wait
);
165 * gfs2_log_get_buf - Get and initialize a buffer to use for log control data
166 * @sdp: The GFS2 superblock
168 * tReturns: the buffer_head
171 static struct buffer_head
*gfs2_log_get_buf(struct gfs2_sbd
*sdp
)
173 u64 blkno
= gfs2_log_bmap(sdp
, sdp
->sd_log_flush_head
);
174 struct buffer_head
*bh
;
176 bh
= sb_getblk(sdp
->sd_vfs
, blkno
);
178 memset(bh
->b_data
, 0, bh
->b_size
);
179 set_buffer_uptodate(bh
);
180 clear_buffer_dirty(bh
);
181 gfs2_log_incr_head(sdp
);
182 atomic_inc(&sdp
->sd_log_in_flight
);
184 bh
->b_end_io
= gfs2_log_write_endio
;
190 * gfs2_fake_write_endio -
191 * @bh: The buffer head
192 * @uptodate: The I/O Status
196 static void gfs2_fake_write_endio(struct buffer_head
*bh
, int uptodate
)
198 struct buffer_head
*real_bh
= bh
->b_private
;
199 struct gfs2_bufdata
*bd
= real_bh
->b_private
;
200 struct gfs2_sbd
*sdp
= bd
->bd_gl
->gl_sbd
;
202 end_buffer_write_sync(bh
, uptodate
);
203 mempool_free(bh
, gfs2_bh_pool
);
204 unlock_buffer(real_bh
);
206 if (atomic_dec_and_test(&sdp
->sd_log_in_flight
))
207 wake_up(&sdp
->sd_log_flush_wait
);
211 * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log
212 * @sdp: the filesystem
213 * @data: the data the buffer_head should point to
215 * Returns: the log buffer descriptor
218 static struct buffer_head
*gfs2_log_fake_buf(struct gfs2_sbd
*sdp
,
219 struct buffer_head
*real
)
221 u64 blkno
= gfs2_log_bmap(sdp
, sdp
->sd_log_flush_head
);
222 struct buffer_head
*bh
;
224 bh
= mempool_alloc(gfs2_bh_pool
, GFP_NOFS
);
225 atomic_set(&bh
->b_count
, 1);
226 bh
->b_state
= (1 << BH_Mapped
) | (1 << BH_Uptodate
) | (1 << BH_Lock
);
227 set_bh_page(bh
, real
->b_page
, bh_offset(real
));
228 bh
->b_blocknr
= blkno
;
229 bh
->b_size
= sdp
->sd_sb
.sb_bsize
;
230 bh
->b_bdev
= sdp
->sd_vfs
->s_bdev
;
231 bh
->b_private
= real
;
232 bh
->b_end_io
= gfs2_fake_write_endio
;
234 gfs2_log_incr_head(sdp
);
235 atomic_inc(&sdp
->sd_log_in_flight
);
240 static struct buffer_head
*gfs2_get_log_desc(struct gfs2_sbd
*sdp
, u32 ld_type
)
242 struct buffer_head
*bh
= gfs2_log_get_buf(sdp
);
243 struct gfs2_log_descriptor
*ld
= bh_log_desc(bh
);
244 ld
->ld_header
.mh_magic
= cpu_to_be32(GFS2_MAGIC
);
245 ld
->ld_header
.mh_type
= cpu_to_be32(GFS2_METATYPE_LD
);
246 ld
->ld_header
.mh_format
= cpu_to_be32(GFS2_FORMAT_LD
);
247 ld
->ld_type
= cpu_to_be32(ld_type
);
251 memset(ld
->ld_reserved
, 0, sizeof(ld
->ld_reserved
));
255 static void buf_lo_add(struct gfs2_sbd
*sdp
, struct gfs2_log_element
*le
)
257 struct gfs2_bufdata
*bd
= container_of(le
, struct gfs2_bufdata
, bd_le
);
258 struct gfs2_meta_header
*mh
;
259 struct gfs2_trans
*tr
;
261 lock_buffer(bd
->bd_bh
);
263 if (!list_empty(&bd
->bd_list_tr
))
265 tr
= current
->journal_info
;
268 list_add(&bd
->bd_list_tr
, &tr
->tr_list_buf
);
269 if (!list_empty(&le
->le_list
))
271 set_bit(GLF_LFLUSH
, &bd
->bd_gl
->gl_flags
);
272 set_bit(GLF_DIRTY
, &bd
->bd_gl
->gl_flags
);
273 gfs2_meta_check(sdp
, bd
->bd_bh
);
274 gfs2_pin(sdp
, bd
->bd_bh
);
275 mh
= (struct gfs2_meta_header
*)bd
->bd_bh
->b_data
;
276 mh
->__pad0
= cpu_to_be64(0);
277 mh
->mh_jid
= cpu_to_be32(sdp
->sd_jdesc
->jd_jid
);
278 sdp
->sd_log_num_buf
++;
279 list_add(&le
->le_list
, &sdp
->sd_log_le_buf
);
280 tr
->tr_num_buf_new
++;
282 gfs2_log_unlock(sdp
);
283 unlock_buffer(bd
->bd_bh
);
286 static void buf_lo_before_commit(struct gfs2_sbd
*sdp
)
288 struct buffer_head
*bh
;
289 struct gfs2_log_descriptor
*ld
;
290 struct gfs2_bufdata
*bd1
= NULL
, *bd2
;
297 limit
= buf_limit(sdp
);
298 /* for 4k blocks, limit = 503 */
301 total
= sdp
->sd_log_num_buf
;
302 bd1
= bd2
= list_prepare_entry(bd1
, &sdp
->sd_log_le_buf
, bd_le
.le_list
);
307 gfs2_log_unlock(sdp
);
308 bh
= gfs2_get_log_desc(sdp
, GFS2_LOG_DESC_METADATA
);
310 ld
= bh_log_desc(bh
);
311 ptr
= bh_log_ptr(bh
);
312 ld
->ld_length
= cpu_to_be32(num
+ 1);
313 ld
->ld_data1
= cpu_to_be32(num
);
316 list_for_each_entry_continue(bd1
, &sdp
->sd_log_le_buf
,
318 *ptr
++ = cpu_to_be64(bd1
->bd_bh
->b_blocknr
);
323 gfs2_log_unlock(sdp
);
324 submit_bh(WRITE_SYNC
, bh
);
328 list_for_each_entry_continue(bd2
, &sdp
->sd_log_le_buf
,
331 gfs2_log_unlock(sdp
);
332 lock_buffer(bd2
->bd_bh
);
333 bh
= gfs2_log_fake_buf(sdp
, bd2
->bd_bh
);
334 submit_bh(WRITE_SYNC
, bh
);
343 gfs2_log_unlock(sdp
);
346 static void buf_lo_after_commit(struct gfs2_sbd
*sdp
, struct gfs2_ail
*ai
)
348 struct list_head
*head
= &sdp
->sd_log_le_buf
;
349 struct gfs2_bufdata
*bd
;
351 while (!list_empty(head
)) {
352 bd
= list_entry(head
->next
, struct gfs2_bufdata
, bd_le
.le_list
);
353 list_del_init(&bd
->bd_le
.le_list
);
354 sdp
->sd_log_num_buf
--;
356 gfs2_unpin(sdp
, bd
->bd_bh
, ai
);
358 gfs2_assert_warn(sdp
, !sdp
->sd_log_num_buf
);
361 static void buf_lo_before_scan(struct gfs2_jdesc
*jd
,
362 struct gfs2_log_header_host
*head
, int pass
)
364 struct gfs2_sbd
*sdp
= GFS2_SB(jd
->jd_inode
);
369 sdp
->sd_found_blocks
= 0;
370 sdp
->sd_replayed_blocks
= 0;
373 static int buf_lo_scan_elements(struct gfs2_jdesc
*jd
, unsigned int start
,
374 struct gfs2_log_descriptor
*ld
, __be64
*ptr
,
377 struct gfs2_inode
*ip
= GFS2_I(jd
->jd_inode
);
378 struct gfs2_sbd
*sdp
= GFS2_SB(jd
->jd_inode
);
379 struct gfs2_glock
*gl
= ip
->i_gl
;
380 unsigned int blks
= be32_to_cpu(ld
->ld_data1
);
381 struct buffer_head
*bh_log
, *bh_ip
;
385 if (pass
!= 1 || be32_to_cpu(ld
->ld_type
) != GFS2_LOG_DESC_METADATA
)
388 gfs2_replay_incr_blk(sdp
, &start
);
390 for (; blks
; gfs2_replay_incr_blk(sdp
, &start
), blks
--) {
391 blkno
= be64_to_cpu(*ptr
++);
393 sdp
->sd_found_blocks
++;
395 if (gfs2_revoke_check(sdp
, blkno
, start
))
398 error
= gfs2_replay_read_block(jd
, start
, &bh_log
);
402 bh_ip
= gfs2_meta_new(gl
, blkno
);
403 memcpy(bh_ip
->b_data
, bh_log
->b_data
, bh_log
->b_size
);
405 if (gfs2_meta_check(sdp
, bh_ip
))
408 mark_buffer_dirty(bh_ip
);
416 sdp
->sd_replayed_blocks
++;
422 static void buf_lo_after_scan(struct gfs2_jdesc
*jd
, int error
, int pass
)
424 struct gfs2_inode
*ip
= GFS2_I(jd
->jd_inode
);
425 struct gfs2_sbd
*sdp
= GFS2_SB(jd
->jd_inode
);
428 gfs2_meta_sync(ip
->i_gl
);
434 gfs2_meta_sync(ip
->i_gl
);
436 fs_info(sdp
, "jid=%u: Replayed %u of %u blocks\n",
437 jd
->jd_jid
, sdp
->sd_replayed_blocks
, sdp
->sd_found_blocks
);
440 static void revoke_lo_add(struct gfs2_sbd
*sdp
, struct gfs2_log_element
*le
)
442 struct gfs2_bufdata
*bd
= container_of(le
, struct gfs2_bufdata
, bd_le
);
443 struct gfs2_glock
*gl
= bd
->bd_gl
;
444 struct gfs2_trans
*tr
;
446 tr
= current
->journal_info
;
449 sdp
->sd_log_num_revoke
++;
450 atomic_inc(&gl
->gl_revokes
);
451 set_bit(GLF_LFLUSH
, &gl
->gl_flags
);
452 list_add(&le
->le_list
, &sdp
->sd_log_le_revoke
);
455 static void revoke_lo_before_commit(struct gfs2_sbd
*sdp
)
457 struct gfs2_log_descriptor
*ld
;
458 struct gfs2_meta_header
*mh
;
459 struct buffer_head
*bh
;
461 struct list_head
*head
= &sdp
->sd_log_le_revoke
;
462 struct gfs2_bufdata
*bd
;
464 if (!sdp
->sd_log_num_revoke
)
467 bh
= gfs2_get_log_desc(sdp
, GFS2_LOG_DESC_REVOKE
);
468 ld
= bh_log_desc(bh
);
469 ld
->ld_length
= cpu_to_be32(gfs2_struct2blk(sdp
, sdp
->sd_log_num_revoke
,
471 ld
->ld_data1
= cpu_to_be32(sdp
->sd_log_num_revoke
);
472 offset
= sizeof(struct gfs2_log_descriptor
);
474 list_for_each_entry(bd
, head
, bd_le
.le_list
) {
475 sdp
->sd_log_num_revoke
--;
477 if (offset
+ sizeof(u64
) > sdp
->sd_sb
.sb_bsize
) {
478 submit_bh(WRITE_SYNC
, bh
);
480 bh
= gfs2_log_get_buf(sdp
);
481 mh
= (struct gfs2_meta_header
*)bh
->b_data
;
482 mh
->mh_magic
= cpu_to_be32(GFS2_MAGIC
);
483 mh
->mh_type
= cpu_to_be32(GFS2_METATYPE_LB
);
484 mh
->mh_format
= cpu_to_be32(GFS2_FORMAT_LB
);
485 offset
= sizeof(struct gfs2_meta_header
);
488 *(__be64
*)(bh
->b_data
+ offset
) = cpu_to_be64(bd
->bd_blkno
);
489 offset
+= sizeof(u64
);
491 gfs2_assert_withdraw(sdp
, !sdp
->sd_log_num_revoke
);
493 submit_bh(WRITE_SYNC
, bh
);
496 static void revoke_lo_after_commit(struct gfs2_sbd
*sdp
, struct gfs2_ail
*ai
)
498 struct list_head
*head
= &sdp
->sd_log_le_revoke
;
499 struct gfs2_bufdata
*bd
;
500 struct gfs2_glock
*gl
;
502 while (!list_empty(head
)) {
503 bd
= list_entry(head
->next
, struct gfs2_bufdata
, bd_le
.le_list
);
504 list_del_init(&bd
->bd_le
.le_list
);
506 atomic_dec(&gl
->gl_revokes
);
507 clear_bit(GLF_LFLUSH
, &gl
->gl_flags
);
508 kmem_cache_free(gfs2_bufdata_cachep
, bd
);
512 static void revoke_lo_before_scan(struct gfs2_jdesc
*jd
,
513 struct gfs2_log_header_host
*head
, int pass
)
515 struct gfs2_sbd
*sdp
= GFS2_SB(jd
->jd_inode
);
520 sdp
->sd_found_revokes
= 0;
521 sdp
->sd_replay_tail
= head
->lh_tail
;
524 static int revoke_lo_scan_elements(struct gfs2_jdesc
*jd
, unsigned int start
,
525 struct gfs2_log_descriptor
*ld
, __be64
*ptr
,
528 struct gfs2_sbd
*sdp
= GFS2_SB(jd
->jd_inode
);
529 unsigned int blks
= be32_to_cpu(ld
->ld_length
);
530 unsigned int revokes
= be32_to_cpu(ld
->ld_data1
);
531 struct buffer_head
*bh
;
537 if (pass
!= 0 || be32_to_cpu(ld
->ld_type
) != GFS2_LOG_DESC_REVOKE
)
540 offset
= sizeof(struct gfs2_log_descriptor
);
542 for (; blks
; gfs2_replay_incr_blk(sdp
, &start
), blks
--) {
543 error
= gfs2_replay_read_block(jd
, start
, &bh
);
548 gfs2_metatype_check(sdp
, bh
, GFS2_METATYPE_LB
);
550 while (offset
+ sizeof(u64
) <= sdp
->sd_sb
.sb_bsize
) {
551 blkno
= be64_to_cpu(*(__be64
*)(bh
->b_data
+ offset
));
553 error
= gfs2_revoke_add(sdp
, blkno
, start
);
559 sdp
->sd_found_revokes
++;
563 offset
+= sizeof(u64
);
567 offset
= sizeof(struct gfs2_meta_header
);
574 static void revoke_lo_after_scan(struct gfs2_jdesc
*jd
, int error
, int pass
)
576 struct gfs2_sbd
*sdp
= GFS2_SB(jd
->jd_inode
);
579 gfs2_revoke_clean(sdp
);
585 fs_info(sdp
, "jid=%u: Found %u revoke tags\n",
586 jd
->jd_jid
, sdp
->sd_found_revokes
);
588 gfs2_revoke_clean(sdp
);
592 * databuf_lo_add - Add a databuf to the transaction.
594 * This is used in two distinct cases:
595 * i) In ordered write mode
596 * We put the data buffer on a list so that we can ensure that its
597 * synced to disk at the right time
598 * ii) In journaled data mode
599 * We need to journal the data block in the same way as metadata in
600 * the functions above. The difference is that here we have a tag
601 * which is two __be64's being the block number (as per meta data)
602 * and a flag which says whether the data block needs escaping or
603 * not. This means we need a new log entry for each 251 or so data
604 * blocks, which isn't an enormous overhead but twice as much as
605 * for normal metadata blocks.
607 static void databuf_lo_add(struct gfs2_sbd
*sdp
, struct gfs2_log_element
*le
)
609 struct gfs2_bufdata
*bd
= container_of(le
, struct gfs2_bufdata
, bd_le
);
610 struct gfs2_trans
*tr
= current
->journal_info
;
611 struct address_space
*mapping
= bd
->bd_bh
->b_page
->mapping
;
612 struct gfs2_inode
*ip
= GFS2_I(mapping
->host
);
614 lock_buffer(bd
->bd_bh
);
617 if (!list_empty(&bd
->bd_list_tr
))
620 if (gfs2_is_jdata(ip
)) {
622 list_add(&bd
->bd_list_tr
, &tr
->tr_list_buf
);
625 if (!list_empty(&le
->le_list
))
628 set_bit(GLF_LFLUSH
, &bd
->bd_gl
->gl_flags
);
629 set_bit(GLF_DIRTY
, &bd
->bd_gl
->gl_flags
);
630 if (gfs2_is_jdata(ip
)) {
631 gfs2_pin(sdp
, bd
->bd_bh
);
632 tr
->tr_num_databuf_new
++;
633 sdp
->sd_log_num_databuf
++;
634 list_add_tail(&le
->le_list
, &sdp
->sd_log_le_databuf
);
636 list_add_tail(&le
->le_list
, &sdp
->sd_log_le_ordered
);
639 gfs2_log_unlock(sdp
);
640 unlock_buffer(bd
->bd_bh
);
643 static void gfs2_check_magic(struct buffer_head
*bh
)
648 clear_buffer_escaped(bh
);
649 kaddr
= kmap_atomic(bh
->b_page
);
650 ptr
= kaddr
+ bh_offset(bh
);
651 if (*ptr
== cpu_to_be32(GFS2_MAGIC
))
652 set_buffer_escaped(bh
);
653 kunmap_atomic(kaddr
);
656 static void gfs2_write_blocks(struct gfs2_sbd
*sdp
, struct buffer_head
*bh
,
657 struct list_head
*list
, struct list_head
*done
,
660 struct buffer_head
*bh1
;
661 struct gfs2_log_descriptor
*ld
;
662 struct gfs2_bufdata
*bd
;
668 ld
= bh_log_desc(bh
);
669 ld
->ld_length
= cpu_to_be32(n
+ 1);
670 ld
->ld_data1
= cpu_to_be32(n
);
672 ptr
= bh_log_ptr(bh
);
675 submit_bh(WRITE_SYNC
, bh
);
677 while(!list_empty(list
)) {
678 bd
= list_entry(list
->next
, struct gfs2_bufdata
, bd_le
.le_list
);
679 list_move_tail(&bd
->bd_le
.le_list
, done
);
681 while (be64_to_cpu(*ptr
) != bd
->bd_bh
->b_blocknr
) {
682 gfs2_log_incr_head(sdp
);
685 gfs2_log_unlock(sdp
);
686 lock_buffer(bd
->bd_bh
);
687 if (buffer_escaped(bd
->bd_bh
)) {
689 bh1
= gfs2_log_get_buf(sdp
);
690 kaddr
= kmap_atomic(bd
->bd_bh
->b_page
);
691 memcpy(bh1
->b_data
, kaddr
+ bh_offset(bd
->bd_bh
),
693 kunmap_atomic(kaddr
);
694 *(__be32
*)bh1
->b_data
= 0;
695 clear_buffer_escaped(bd
->bd_bh
);
696 unlock_buffer(bd
->bd_bh
);
699 bh1
= gfs2_log_fake_buf(sdp
, bd
->bd_bh
);
701 submit_bh(WRITE_SYNC
, bh1
);
705 gfs2_log_unlock(sdp
);
710 * databuf_lo_before_commit - Scan the data buffers, writing as we go
714 static void databuf_lo_before_commit(struct gfs2_sbd
*sdp
)
716 struct gfs2_bufdata
*bd
= NULL
;
717 struct buffer_head
*bh
= NULL
;
719 __be64
*ptr
= NULL
, *end
= NULL
;
720 LIST_HEAD(processed
);
721 LIST_HEAD(in_progress
);
724 while (!list_empty(&sdp
->sd_log_le_databuf
)) {
726 gfs2_log_unlock(sdp
);
727 gfs2_write_blocks(sdp
, bh
, &in_progress
, &processed
, n
);
729 bh
= gfs2_get_log_desc(sdp
, GFS2_LOG_DESC_JDATA
);
730 ptr
= bh_log_ptr(bh
);
731 end
= bh_ptr_end(bh
) - 1;
735 bd
= list_entry(sdp
->sd_log_le_databuf
.next
, struct gfs2_bufdata
, bd_le
.le_list
);
736 list_move_tail(&bd
->bd_le
.le_list
, &in_progress
);
737 gfs2_check_magic(bd
->bd_bh
);
738 *ptr
++ = cpu_to_be64(bd
->bd_bh
->b_blocknr
);
739 *ptr
++ = cpu_to_be64(buffer_escaped(bh
) ? 1 : 0);
742 gfs2_log_unlock(sdp
);
743 gfs2_write_blocks(sdp
, bh
, &in_progress
, &processed
, n
);
745 list_splice(&processed
, &sdp
->sd_log_le_databuf
);
746 gfs2_log_unlock(sdp
);
749 static int databuf_lo_scan_elements(struct gfs2_jdesc
*jd
, unsigned int start
,
750 struct gfs2_log_descriptor
*ld
,
751 __be64
*ptr
, int pass
)
753 struct gfs2_inode
*ip
= GFS2_I(jd
->jd_inode
);
754 struct gfs2_sbd
*sdp
= GFS2_SB(jd
->jd_inode
);
755 struct gfs2_glock
*gl
= ip
->i_gl
;
756 unsigned int blks
= be32_to_cpu(ld
->ld_data1
);
757 struct buffer_head
*bh_log
, *bh_ip
;
762 if (pass
!= 1 || be32_to_cpu(ld
->ld_type
) != GFS2_LOG_DESC_JDATA
)
765 gfs2_replay_incr_blk(sdp
, &start
);
766 for (; blks
; gfs2_replay_incr_blk(sdp
, &start
), blks
--) {
767 blkno
= be64_to_cpu(*ptr
++);
768 esc
= be64_to_cpu(*ptr
++);
770 sdp
->sd_found_blocks
++;
772 if (gfs2_revoke_check(sdp
, blkno
, start
))
775 error
= gfs2_replay_read_block(jd
, start
, &bh_log
);
779 bh_ip
= gfs2_meta_new(gl
, blkno
);
780 memcpy(bh_ip
->b_data
, bh_log
->b_data
, bh_log
->b_size
);
784 __be32
*eptr
= (__be32
*)bh_ip
->b_data
;
785 *eptr
= cpu_to_be32(GFS2_MAGIC
);
787 mark_buffer_dirty(bh_ip
);
792 sdp
->sd_replayed_blocks
++;
798 /* FIXME: sort out accounting for log blocks etc. */
800 static void databuf_lo_after_scan(struct gfs2_jdesc
*jd
, int error
, int pass
)
802 struct gfs2_inode
*ip
= GFS2_I(jd
->jd_inode
);
803 struct gfs2_sbd
*sdp
= GFS2_SB(jd
->jd_inode
);
806 gfs2_meta_sync(ip
->i_gl
);
813 gfs2_meta_sync(ip
->i_gl
);
815 fs_info(sdp
, "jid=%u: Replayed %u of %u data blocks\n",
816 jd
->jd_jid
, sdp
->sd_replayed_blocks
, sdp
->sd_found_blocks
);
819 static void databuf_lo_after_commit(struct gfs2_sbd
*sdp
, struct gfs2_ail
*ai
)
821 struct list_head
*head
= &sdp
->sd_log_le_databuf
;
822 struct gfs2_bufdata
*bd
;
824 while (!list_empty(head
)) {
825 bd
= list_entry(head
->next
, struct gfs2_bufdata
, bd_le
.le_list
);
826 list_del_init(&bd
->bd_le
.le_list
);
827 sdp
->sd_log_num_databuf
--;
828 gfs2_unpin(sdp
, bd
->bd_bh
, ai
);
830 gfs2_assert_warn(sdp
, !sdp
->sd_log_num_databuf
);
834 const struct gfs2_log_operations gfs2_buf_lops
= {
835 .lo_add
= buf_lo_add
,
836 .lo_before_commit
= buf_lo_before_commit
,
837 .lo_after_commit
= buf_lo_after_commit
,
838 .lo_before_scan
= buf_lo_before_scan
,
839 .lo_scan_elements
= buf_lo_scan_elements
,
840 .lo_after_scan
= buf_lo_after_scan
,
844 const struct gfs2_log_operations gfs2_revoke_lops
= {
845 .lo_add
= revoke_lo_add
,
846 .lo_before_commit
= revoke_lo_before_commit
,
847 .lo_after_commit
= revoke_lo_after_commit
,
848 .lo_before_scan
= revoke_lo_before_scan
,
849 .lo_scan_elements
= revoke_lo_scan_elements
,
850 .lo_after_scan
= revoke_lo_after_scan
,
854 const struct gfs2_log_operations gfs2_rg_lops
= {
858 const struct gfs2_log_operations gfs2_databuf_lops
= {
859 .lo_add
= databuf_lo_add
,
860 .lo_before_commit
= databuf_lo_before_commit
,
861 .lo_after_commit
= databuf_lo_after_commit
,
862 .lo_scan_elements
= databuf_lo_scan_elements
,
863 .lo_after_scan
= databuf_lo_after_scan
,
864 .lo_name
= "databuf",
867 const struct gfs2_log_operations
*gfs2_log_ops
[] = {