10 #include <linux/sched.h>
11 #include <linux/slab.h>
56 if (nstruct > first) {
57 second = (sdp->
sd_sb.sb_bsize -
91 static int gfs2_ail1_start_one(
struct gfs2_sbd *sdp,
100 struct buffer_head *bh;
108 if (!buffer_uptodate(bh))
114 if (!buffer_dirty(bh))
120 mapping = bh->b_page->mapping;
123 spin_unlock(&sdp->sd_ail_lock);
125 spin_lock(&sdp->sd_ail_lock);
126 if (wbc->nr_to_write <= 0)
149 trace_gfs2_ail_flush(sdp, wbc, 1);
155 if (gfs2_ail1_start_one(sdp, wbc, ai))
159 trace_gfs2_ail_flush(sdp, wbc, 0);
167 static void gfs2_ail1_start(
struct gfs2_sbd *sdp)
189 struct buffer_head *bh;
197 if (!buffer_uptodate(bh))
211 static int gfs2_ail1_empty(
struct gfs2_sbd *sdp)
218 gfs2_ail1_empty_one(sdp, ai);
230 static void gfs2_ail1_wait(
struct gfs2_sbd *sdp)
234 struct buffer_head *bh;
240 if (!buffer_locked(bh))
264 while (!list_empty(head)) {
272 static void ail2_empty(
struct gfs2_sbd *sdp,
unsigned int new_tail)
276 int wrap = (new_tail < old_tail);
284 rm = (
wrap) ? (a || b) : (a &&
b);
288 gfs2_ail2_empty_one(sdp, ai);
320 unsigned reserved_blks = 6 * (4096 / sdp->
sd_vfs->s_blocksize);
321 unsigned wanted = blks + reserved_blks;
324 unsigned int free_blocks;
331 if (
unlikely(free_blocks <= wanted)) {
340 }
while(free_blocks <= wanted);
344 free_blocks - blks) != free_blocks)
346 trace_gfs2_log_blocks(sdp, -blks);
372 static inline unsigned int log_distance(
struct gfs2_sbd *sdp,
unsigned int newer,
377 dist = newer - older;
409 static unsigned int calc_reserved(
struct gfs2_sbd *sdp)
412 unsigned int mbuf_limit, metabufhdrs_needed;
413 unsigned int dbuf_limit, databufhdrs_needed;
414 unsigned int revokes = 0;
418 (mbuf_limit - 1)) / mbuf_limit;
419 dbuf_limit = databuf_limit(sdp);
421 (dbuf_limit - 1)) / dbuf_limit;
436 static unsigned int current_tail(
struct gfs2_sbd *sdp)
455 static void log_pull_tail(
struct gfs2_sbd *sdp,
unsigned int new_tail)
457 unsigned int dist = log_distance(sdp, new_tail, sdp->
sd_log_tail);
459 ail2_empty(sdp, new_tail);
462 trace_gfs2_log_blocks(sdp, dist);
470 static void log_flush_wait(
struct gfs2_sbd *sdp)
492 if (bda->
bd_bh->b_blocknr < bdb->
bd_bh->b_blocknr)
494 if (bda->
bd_bh->b_blocknr > bdb->
bd_bh->b_blocknr)
499 static void gfs2_ordered_write(
struct gfs2_sbd *sdp)
502 struct buffer_head *bh;
509 list_move(&bd->
bd_list, &written);
511 if (!buffer_dirty(bh))
514 gfs2_log_unlock(sdp);
516 if (buffer_mapped(bh) && test_clear_buffer_dirty(bh)) {
526 gfs2_log_unlock(sdp);
529 static void gfs2_ordered_wait(
struct gfs2_sbd *sdp)
532 struct buffer_head *bh;
538 if (buffer_locked(bh)) {
540 gfs2_log_unlock(sdp);
548 gfs2_log_unlock(sdp);
568 gfs2_ail1_empty(sdp);
569 tail = current_tail(sdp);
584 gfs2_ordered_wait(sdp);
595 log_pull_tail(sdp, tail);
616 trace_gfs2_log_flush(sdp, 1);
639 gfs2_ordered_write(sdp);
640 lops_before_commit(sdp);
644 log_write_header(sdp, 0);
647 trace_gfs2_log_blocks(sdp, -1);
648 log_write_header(sdp, 0);
650 lops_after_commit(sdp, ai);
665 gfs2_log_unlock(sdp);
666 trace_gfs2_log_flush(sdp, 0);
685 reserved = calc_reserved(sdp);
689 trace_gfs2_log_blocks(sdp, unused);
694 gfs2_log_unlock(sdp);
766 gfs2_ail1_start(sdp);
768 if (gfs2_ail1_empty(sdp))
774 static inline int gfs2_jrnl_flush_reqd(
struct gfs2_sbd *sdp)
779 static inline int gfs2_ail_flush_reqd(
struct gfs2_sbd *sdp)
801 if (gfs2_jrnl_flush_reqd(sdp) || t == 0) {
802 gfs2_ail1_empty(sdp);
806 if (gfs2_ail_flush_reqd(sdp)) {
807 gfs2_ail1_start(sdp);
809 gfs2_ail1_empty(sdp);
813 if (!gfs2_ail_flush_reqd(sdp))
823 if (!gfs2_ail_flush_reqd(sdp) &&
824 !gfs2_jrnl_flush_reqd(sdp) &&
827 }
while(t && !gfs2_ail_flush_reqd(sdp) &&
828 !gfs2_jrnl_flush_reqd(sdp) &&