10 #include <linux/sched.h>
11 #include <linux/slab.h>
40 static void gfs2_pin(
struct gfs2_sbd *sdp,
struct buffer_head *bh)
46 clear_buffer_dirty(bh);
47 if (test_set_buffer_pinned(bh))
49 if (!buffer_uptodate(bh))
61 trace_gfs2_pin(bd, 1);
64 static bool buffer_is_rgrp(
const struct gfs2_bufdata *bd)
96 static void gfs2_unpin(
struct gfs2_sbd *sdp,
struct buffer_head *bh,
101 BUG_ON(!buffer_uptodate(bh));
102 BUG_ON(!buffer_pinned(bh));
106 clear_buffer_pinned(bh);
108 if (buffer_is_rgrp(bd))
109 maybe_release_space(bd);
125 trace_gfs2_pin(bd, 0);
130 static void gfs2_log_incr_head(
struct gfs2_sbd *sdp)
150 gfs2_log_incr_head(sdp);
170 static void gfs2_end_log_write_bh(
struct gfs2_sbd *sdp,
struct bio_vec *bvec,
173 struct buffer_head *bh, *
next;
177 bh = page_buffers(page);
179 while (bh_offset(bh) < bvec->bv_offset)
180 bh = bh->b_this_page;
183 set_buffer_write_io_error(bh);
185 next = bh->b_this_page;
203 static void gfs2_end_log_write(
struct bio *bio,
int error)
205 struct gfs2_sbd *sdp = bio->bi_private;
206 struct bio_vec *bvec;
212 fs_err(sdp,
"Error %d writing to log\n", error);
215 bio_for_each_segment(bvec, bio, i) {
216 page = bvec->bv_page;
217 if (page_has_buffers(page))
218 gfs2_end_log_write_bh(sdp, bvec, error);
259 static struct bio *gfs2_log_alloc_bio(
struct gfs2_sbd *sdp,
u64 blkno)
271 nrvecs =
max(nrvecs/2, 1
U);
275 bio->bi_bdev = sb->
s_bdev;
276 bio->bi_end_io = gfs2_end_log_write;
277 bio->bi_private = sdp;
297 static struct bio *gfs2_log_get_bio(
struct gfs2_sbd *sdp,
u64 blkno)
303 nblk = bio->bi_sector + bio_sectors(bio);
310 return gfs2_log_alloc_bio(sdp, blkno);
326 static void gfs2_log_write(
struct gfs2_sbd *sdp,
struct page *page,
327 unsigned size,
unsigned offset)
329 u64 blkno = gfs2_log_bmap(sdp);
333 bio = gfs2_log_get_bio(sdp, blkno);
337 bio = gfs2_log_alloc_bio(sdp, blkno);
353 static void gfs2_log_write_bh(
struct gfs2_sbd *sdp,
struct buffer_head *bh)
355 gfs2_log_write(sdp, bh->b_page, bh->b_size, bh_offset(bh));
375 static struct page *gfs2_get_log_desc(
struct gfs2_sbd *sdp,
u32 ld_type,
376 u32 ld_length,
u32 ld_data1)
405 "Attempting to add uninitialised block to journal (inplace block=%lld)\n",
406 (
unsigned long long)bd->
bd_bh->b_blocknr);
409 gfs2_pin(sdp, bd->
bd_bh);
417 static void gfs2_check_magic(
struct buffer_head *bh)
422 clear_buffer_escaped(bh);
424 ptr = kaddr + bh_offset(bh);
426 set_buffer_escaped(bh);
430 static void gfs2_before_commit(
struct gfs2_sbd *sdp,
unsigned int limit,
431 unsigned int total,
struct list_head *blist,
447 gfs2_log_unlock(sdp);
457 gfs2_check_magic(bd1->
bd_bh);
464 gfs2_log_unlock(sdp);
471 gfs2_log_unlock(sdp);
472 lock_buffer(bd2->bd_bh);
474 if (buffer_escaped(bd2->bd_bh)) {
479 memcpy(ptr, kaddr + bh_offset(bd2->bd_bh),
483 clear_buffer_escaped(bd2->bd_bh);
488 gfs2_log_write_bh(sdp, bd2->bd_bh);
498 gfs2_log_unlock(sdp);
501 static void buf_lo_before_commit(
struct gfs2_sbd *sdp)
514 while (!list_empty(head)) {
519 gfs2_unpin(sdp, bd->
bd_bh, ai);
524 static void buf_lo_before_scan(
struct gfs2_jdesc *jd,
536 static int buf_lo_scan_elements(
struct gfs2_jdesc *jd,
unsigned int start,
544 struct buffer_head *bh_log, *bh_ip;
551 gfs2_replay_incr_blk(sdp, &start);
553 for (; blks; gfs2_replay_incr_blk(sdp, &start), blks--) {
566 memcpy(bh_ip->b_data, bh_log->b_data, bh_log->b_size);
568 if (gfs2_meta_check(sdp, bh_ip))
585 static void buf_lo_after_scan(
struct gfs2_jdesc *jd,
int error,
int pass)
599 fs_info(sdp,
"jid=%u: Replayed %u of %u blocks\n",
617 static void revoke_lo_before_commit(
struct gfs2_sbd *sdp)
636 if (offset +
sizeof(
u64) > sdp->
sd_sb.sb_bsize) {
649 offset +=
sizeof(
u64);
656 static void revoke_lo_after_commit(
struct gfs2_sbd *sdp,
struct gfs2_ail *ai)
662 while (!list_empty(head)) {
672 static void revoke_lo_before_scan(
struct gfs2_jdesc *jd,
684 static int revoke_lo_scan_elements(
struct gfs2_jdesc *jd,
unsigned int start,
691 struct buffer_head *bh;
702 for (; blks; gfs2_replay_incr_blk(sdp, &start), blks--) {
710 while (offset +
sizeof(
u64) <= sdp->
sd_sb.sb_bsize) {
723 offset +=
sizeof(
u64);
734 static void revoke_lo_after_scan(
struct gfs2_jdesc *jd,
int error,
int pass)
745 fs_info(sdp,
"jid=%u: Found %u revoke tags\n",
779 if (gfs2_is_jdata(ip)) {
780 gfs2_pin(sdp, bd->
bd_bh);
794 static void databuf_lo_before_commit(
struct gfs2_sbd *sdp)
802 static int databuf_lo_scan_elements(
struct gfs2_jdesc *jd,
unsigned int start,
810 struct buffer_head *bh_log, *bh_ip;
818 gfs2_replay_incr_blk(sdp, &start);
819 for (; blks; gfs2_replay_incr_blk(sdp, &start), blks--) {
833 memcpy(bh_ip->b_data, bh_log->b_data, bh_log->b_size);
853 static void databuf_lo_after_scan(
struct gfs2_jdesc *jd,
int error,
int pass)
868 fs_info(sdp,
"jid=%u: Replayed %u of %u data blocks\n",
872 static void databuf_lo_after_commit(
struct gfs2_sbd *sdp,
struct gfs2_ail *ai)
877 while (!list_empty(head)) {
881 gfs2_unpin(sdp, bd->
bd_bh, ai);
888 .lo_add = buf_lo_add,
889 .lo_before_commit = buf_lo_before_commit,
890 .lo_after_commit = buf_lo_after_commit,
891 .lo_before_scan = buf_lo_before_scan,
892 .lo_scan_elements = buf_lo_scan_elements,
893 .lo_after_scan = buf_lo_after_scan,
898 .lo_add = revoke_lo_add,
899 .lo_before_commit = revoke_lo_before_commit,
900 .lo_after_commit = revoke_lo_after_commit,
901 .lo_before_scan = revoke_lo_before_scan,
902 .lo_scan_elements = revoke_lo_scan_elements,
903 .lo_after_scan = revoke_lo_after_scan,
912 .lo_add = databuf_lo_add,
913 .lo_before_commit = databuf_lo_before_commit,
914 .lo_after_commit = databuf_lo_after_commit,
915 .lo_scan_elements = databuf_lo_scan_elements,
916 .lo_after_scan = databuf_lo_after_scan,
917 .lo_name =
"databuf",