Lines Matching refs:sdp

35 static void gfs2_log_shutdown(struct gfs2_sbd *sdp);
48 unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct) in gfs2_struct2blk() argument
55 first = sdp->sd_ldptrs; in gfs2_struct2blk()
59 second = sdp->sd_inptrs; in gfs2_struct2blk()
91 static int gfs2_ail1_start_one(struct gfs2_sbd *sdp, in gfs2_ail1_start_one() argument
94 __releases(&sdp->sd_ail_lock) in gfs2_ail1_start_one()
95 __acquires(&sdp->sd_ail_lock) in gfs2_ail1_start_one()
106 gfs2_assert(sdp, bd->bd_tr == tr); in gfs2_ail1_start_one()
114 if (!cmpxchg(&sdp->sd_log_error, 0, -EIO)) { in gfs2_ail1_start_one()
115 gfs2_io_error_bh(sdp, bh); in gfs2_ail1_start_one()
116 gfs2_withdraw_delayed(sdp); in gfs2_ail1_start_one()
120 if (gfs2_withdrawn(sdp)) { in gfs2_ail1_start_one()
133 spin_unlock(&sdp->sd_ail_lock); in gfs2_ail1_start_one()
140 spin_lock(&sdp->sd_ail_lock); in gfs2_ail1_start_one()
151 static void dump_ail_list(struct gfs2_sbd *sdp) in dump_ail_list() argument
157 list_for_each_entry_reverse(tr, &sdp->sd_ail1_list, tr_list) { in dump_ail_list()
161 fs_err(sdp, "bd %p: blk:0x%llx bh=%p ", bd, in dump_ail_list()
164 fs_err(sdp, "\n"); in dump_ail_list()
167 fs_err(sdp, "0x%llx up2:%d dirt:%d lkd:%d req:%d " in dump_ail_list()
192 void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc) in gfs2_ail1_flush() argument
194 struct list_head *head = &sdp->sd_ail1_list; in gfs2_ail1_flush()
200 trace_gfs2_ail_flush(sdp, wbc, 1); in gfs2_ail1_flush()
202 spin_lock(&sdp->sd_ail_lock); in gfs2_ail1_flush()
206 fs_err(sdp, "Error: In %s for ten minutes! t=%d\n", in gfs2_ail1_flush()
208 dump_ail_list(sdp); in gfs2_ail1_flush()
214 ret = gfs2_ail1_start_one(sdp, wbc, tr, &plug); in gfs2_ail1_flush()
222 spin_unlock(&sdp->sd_ail_lock); in gfs2_ail1_flush()
225 gfs2_lm(sdp, "gfs2_ail1_start_one returned: %d\n", ret); in gfs2_ail1_flush()
226 gfs2_withdraw(sdp); in gfs2_ail1_flush()
228 trace_gfs2_ail_flush(sdp, wbc, 0); in gfs2_ail1_flush()
236 static void gfs2_ail1_start(struct gfs2_sbd *sdp) in gfs2_ail1_start() argument
245 return gfs2_ail1_flush(sdp, &wbc); in gfs2_ail1_start()
248 static void gfs2_log_update_flush_tail(struct gfs2_sbd *sdp) in gfs2_log_update_flush_tail() argument
250 unsigned int new_flush_tail = sdp->sd_log_head; in gfs2_log_update_flush_tail()
253 if (!list_empty(&sdp->sd_ail1_list)) { in gfs2_log_update_flush_tail()
254 tr = list_last_entry(&sdp->sd_ail1_list, in gfs2_log_update_flush_tail()
258 sdp->sd_log_flush_tail = new_flush_tail; in gfs2_log_update_flush_tail()
261 static void gfs2_log_update_head(struct gfs2_sbd *sdp) in gfs2_log_update_head() argument
263 unsigned int new_head = sdp->sd_log_flush_head; in gfs2_log_update_head()
265 if (sdp->sd_log_flush_tail == sdp->sd_log_head) in gfs2_log_update_head()
266 sdp->sd_log_flush_tail = new_head; in gfs2_log_update_head()
267 sdp->sd_log_head = new_head; in gfs2_log_update_head()
274 static void gfs2_ail_empty_tr(struct gfs2_sbd *sdp, struct gfs2_trans *tr, in gfs2_ail_empty_tr() argument
282 gfs2_assert(sdp, bd->bd_tr == tr); in gfs2_ail_empty_tr()
296 static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr, in gfs2_ail1_empty_one() argument
306 gfs2_assert(sdp, bd->bd_tr == tr); in gfs2_ail1_empty_one()
316 if (!sdp->sd_log_error && buffer_busy(bh)) { in gfs2_ail1_empty_one()
321 !cmpxchg(&sdp->sd_log_error, 0, -EIO)) { in gfs2_ail1_empty_one()
322 gfs2_io_error_bh(sdp, bh); in gfs2_ail1_empty_one()
323 gfs2_withdraw_delayed(sdp); in gfs2_ail1_empty_one()
332 gfs2_add_revoke(sdp, bd); in gfs2_ail1_empty_one()
349 static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int max_revokes) in gfs2_ail1_empty() argument
355 spin_lock(&sdp->sd_ail_lock); in gfs2_ail1_empty()
356 list_for_each_entry_safe_reverse(tr, s, &sdp->sd_ail1_list, tr_list) { in gfs2_ail1_empty()
357 if (!gfs2_ail1_empty_one(sdp, tr, &max_revokes) && oldest_tr) in gfs2_ail1_empty()
358 list_move(&tr->tr_list, &sdp->sd_ail2_list); in gfs2_ail1_empty()
362 gfs2_log_update_flush_tail(sdp); in gfs2_ail1_empty()
363 ret = list_empty(&sdp->sd_ail1_list); in gfs2_ail1_empty()
364 spin_unlock(&sdp->sd_ail_lock); in gfs2_ail1_empty()
366 if (test_bit(SDF_WITHDRAWING, &sdp->sd_flags)) { in gfs2_ail1_empty()
367 gfs2_lm(sdp, "fatal: I/O error(s)\n"); in gfs2_ail1_empty()
368 gfs2_withdraw(sdp); in gfs2_ail1_empty()
374 static void gfs2_ail1_wait(struct gfs2_sbd *sdp) in gfs2_ail1_wait() argument
380 spin_lock(&sdp->sd_ail_lock); in gfs2_ail1_wait()
381 list_for_each_entry_reverse(tr, &sdp->sd_ail1_list, tr_list) { in gfs2_ail1_wait()
387 spin_unlock(&sdp->sd_ail_lock); in gfs2_ail1_wait()
393 spin_unlock(&sdp->sd_ail_lock); in gfs2_ail1_wait()
396 static void __ail2_empty(struct gfs2_sbd *sdp, struct gfs2_trans *tr) in __ail2_empty() argument
398 gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail2_list); in __ail2_empty()
400 gfs2_assert_warn(sdp, list_empty(&tr->tr_ail1_list)); in __ail2_empty()
401 gfs2_assert_warn(sdp, list_empty(&tr->tr_ail2_list)); in __ail2_empty()
402 gfs2_trans_free(sdp, tr); in __ail2_empty()
405 static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) in ail2_empty() argument
407 struct list_head *ail2_list = &sdp->sd_ail2_list; in ail2_empty()
408 unsigned int old_tail = sdp->sd_log_tail; in ail2_empty()
411 spin_lock(&sdp->sd_ail_lock); in ail2_empty()
415 __ail2_empty(sdp, tr); in ail2_empty()
420 __ail2_empty(sdp, tr); in ail2_empty()
423 spin_unlock(&sdp->sd_ail_lock); in ail2_empty()
431 bool gfs2_log_is_empty(struct gfs2_sbd *sdp) { in gfs2_log_is_empty() argument
432 return atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks; in gfs2_log_is_empty()
435 static bool __gfs2_log_try_reserve_revokes(struct gfs2_sbd *sdp, unsigned int revokes) in __gfs2_log_try_reserve_revokes() argument
439 available = atomic_read(&sdp->sd_log_revokes_available); in __gfs2_log_try_reserve_revokes()
441 if (atomic_try_cmpxchg(&sdp->sd_log_revokes_available, in __gfs2_log_try_reserve_revokes()
455 void gfs2_log_release_revokes(struct gfs2_sbd *sdp, unsigned int revokes) in gfs2_log_release_revokes() argument
458 atomic_add(revokes, &sdp->sd_log_revokes_available); in gfs2_log_release_revokes()
468 void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) in gfs2_log_release() argument
470 atomic_add(blks, &sdp->sd_log_blks_free); in gfs2_log_release()
471 trace_gfs2_log_blocks(sdp, blks); in gfs2_log_release()
472 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= in gfs2_log_release()
473 sdp->sd_jdesc->jd_blocks); in gfs2_log_release()
474 if (atomic_read(&sdp->sd_log_blks_needed)) in gfs2_log_release()
475 wake_up(&sdp->sd_log_waitq); in gfs2_log_release()
487 static bool __gfs2_log_try_reserve(struct gfs2_sbd *sdp, unsigned int blks, in __gfs2_log_try_reserve() argument
493 free_blocks = atomic_read(&sdp->sd_log_blks_free); in __gfs2_log_try_reserve()
495 if (atomic_try_cmpxchg(&sdp->sd_log_blks_free, &free_blocks, in __gfs2_log_try_reserve()
497 trace_gfs2_log_blocks(sdp, -blks); in __gfs2_log_try_reserve()
523 static void __gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks, in __gfs2_log_reserve() argument
529 atomic_add(blks, &sdp->sd_log_blks_needed); in __gfs2_log_reserve()
531 if (current != sdp->sd_logd_process) in __gfs2_log_reserve()
532 wake_up(&sdp->sd_logd_waitq); in __gfs2_log_reserve()
533 io_wait_event(sdp->sd_log_waitq, in __gfs2_log_reserve()
534 (free_blocks = atomic_read(&sdp->sd_log_blks_free), in __gfs2_log_reserve()
537 if (atomic_try_cmpxchg(&sdp->sd_log_blks_free, in __gfs2_log_reserve()
545 trace_gfs2_log_blocks(sdp, -blks); in __gfs2_log_reserve()
546 if (atomic_sub_return(blks, &sdp->sd_log_blks_needed)) in __gfs2_log_reserve()
547 wake_up(&sdp->sd_log_waitq); in __gfs2_log_reserve()
560 bool gfs2_log_try_reserve(struct gfs2_sbd *sdp, struct gfs2_trans *tr, in gfs2_log_try_reserve() argument
568 if (revokes && !__gfs2_log_try_reserve_revokes(sdp, revokes)) { in gfs2_log_try_reserve()
569 revoke_blks = DIV_ROUND_UP(revokes, sdp->sd_inptrs); in gfs2_log_try_reserve()
570 *extra_revokes = revoke_blks * sdp->sd_inptrs - revokes; in gfs2_log_try_reserve()
575 if (__gfs2_log_try_reserve(sdp, blks, GFS2_LOG_FLUSH_MIN_BLOCKS)) in gfs2_log_try_reserve()
578 gfs2_log_release_revokes(sdp, revokes); in gfs2_log_try_reserve()
591 void gfs2_log_reserve(struct gfs2_sbd *sdp, struct gfs2_trans *tr, in gfs2_log_reserve() argument
600 revoke_blks = DIV_ROUND_UP(revokes, sdp->sd_inptrs); in gfs2_log_reserve()
601 *extra_revokes = revoke_blks * sdp->sd_inptrs - revokes; in gfs2_log_reserve()
604 __gfs2_log_reserve(sdp, blks, GFS2_LOG_FLUSH_MIN_BLOCKS); in gfs2_log_reserve()
619 static inline unsigned int log_distance(struct gfs2_sbd *sdp, unsigned int newer, in log_distance() argument
626 dist += sdp->sd_jdesc->jd_blocks; in log_distance()
652 static unsigned int calc_reserved(struct gfs2_sbd *sdp) in calc_reserved() argument
656 struct gfs2_trans *tr = sdp->sd_log_tr; in calc_reserved()
660 reserved += blocks + DIV_ROUND_UP(blocks, buf_limit(sdp)); in calc_reserved()
662 reserved += blocks + DIV_ROUND_UP(blocks, databuf_limit(sdp)); in calc_reserved()
667 static void log_pull_tail(struct gfs2_sbd *sdp) in log_pull_tail() argument
669 unsigned int new_tail = sdp->sd_log_flush_tail; in log_pull_tail()
672 if (new_tail == sdp->sd_log_tail) in log_pull_tail()
674 dist = log_distance(sdp, new_tail, sdp->sd_log_tail); in log_pull_tail()
675 ail2_empty(sdp, new_tail); in log_pull_tail()
676 gfs2_log_release(sdp, dist); in log_pull_tail()
677 sdp->sd_log_tail = new_tail; in log_pull_tail()
681 void log_flush_wait(struct gfs2_sbd *sdp) in log_flush_wait() argument
685 if (atomic_read(&sdp->sd_log_in_flight)) { in log_flush_wait()
687 prepare_to_wait(&sdp->sd_log_flush_wait, &wait, in log_flush_wait()
689 if (atomic_read(&sdp->sd_log_in_flight)) in log_flush_wait()
691 } while(atomic_read(&sdp->sd_log_in_flight)); in log_flush_wait()
692 finish_wait(&sdp->sd_log_flush_wait, &wait); in log_flush_wait()
716 static void gfs2_ordered_write(struct gfs2_sbd *sdp) in gfs2_ordered_write() argument
721 spin_lock(&sdp->sd_ordered_lock); in gfs2_ordered_write()
722 list_sort(NULL, &sdp->sd_log_ordered, &ip_cmp); in gfs2_ordered_write()
723 while (!list_empty(&sdp->sd_log_ordered)) { in gfs2_ordered_write()
724 ip = list_first_entry(&sdp->sd_log_ordered, struct gfs2_inode, i_ordered); in gfs2_ordered_write()
730 spin_unlock(&sdp->sd_ordered_lock); in gfs2_ordered_write()
732 spin_lock(&sdp->sd_ordered_lock); in gfs2_ordered_write()
734 list_splice(&written, &sdp->sd_log_ordered); in gfs2_ordered_write()
735 spin_unlock(&sdp->sd_ordered_lock); in gfs2_ordered_write()
738 static void gfs2_ordered_wait(struct gfs2_sbd *sdp) in gfs2_ordered_wait() argument
742 spin_lock(&sdp->sd_ordered_lock); in gfs2_ordered_wait()
743 while (!list_empty(&sdp->sd_log_ordered)) { in gfs2_ordered_wait()
744 ip = list_first_entry(&sdp->sd_log_ordered, struct gfs2_inode, i_ordered); in gfs2_ordered_wait()
748 spin_unlock(&sdp->sd_ordered_lock); in gfs2_ordered_wait()
750 spin_lock(&sdp->sd_ordered_lock); in gfs2_ordered_wait()
752 spin_unlock(&sdp->sd_ordered_lock); in gfs2_ordered_wait()
757 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_ordered_del_inode() local
759 spin_lock(&sdp->sd_ordered_lock); in gfs2_ordered_del_inode()
761 spin_unlock(&sdp->sd_ordered_lock); in gfs2_ordered_del_inode()
764 void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd) in gfs2_add_revoke() argument
769 sdp->sd_log_num_revoke++; in gfs2_add_revoke()
777 list_add(&bd->bd_list, &sdp->sd_log_revokes); in gfs2_add_revoke()
800 void gfs2_flush_revokes(struct gfs2_sbd *sdp) in gfs2_flush_revokes() argument
803 unsigned int max_revokes = atomic_read(&sdp->sd_log_revokes_available); in gfs2_flush_revokes()
805 gfs2_log_lock(sdp); in gfs2_flush_revokes()
806 gfs2_ail1_empty(sdp, max_revokes); in gfs2_flush_revokes()
807 gfs2_log_unlock(sdp); in gfs2_flush_revokes()
823 void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, in gfs2_write_log_header() argument
830 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; in gfs2_write_log_header()
832 struct super_block *sb = sdp->sd_vfs; in gfs2_write_log_header()
835 if (gfs2_withdrawn(sdp)) in gfs2_write_log_header()
846 lh->lh_header.mh_jid = cpu_to_be32(sdp->sd_jdesc->jd_jid); in gfs2_write_log_header()
865 if (gfs2_assert_withdraw(sdp, ret == 0)) in gfs2_write_log_header()
876 cpu_to_be64(GFS2_I(sdp->sd_sc_inode)->i_no_addr); in gfs2_write_log_header()
878 cpu_to_be64(GFS2_I(sdp->sd_qc_inode)->i_no_addr); in gfs2_write_log_header()
880 spin_lock(&sdp->sd_statfs_spin); in gfs2_write_log_header()
884 spin_unlock(&sdp->sd_statfs_spin); in gfs2_write_log_header()
893 gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock); in gfs2_write_log_header()
905 static void log_write_header(struct gfs2_sbd *sdp, u32 flags) in log_write_header() argument
908 enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state); in log_write_header()
910 gfs2_assert_withdraw(sdp, (state != SFS_FROZEN)); in log_write_header()
912 if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) { in log_write_header()
913 gfs2_ordered_wait(sdp); in log_write_header()
914 log_flush_wait(sdp); in log_write_header()
917 sdp->sd_log_idle = (sdp->sd_log_flush_tail == sdp->sd_log_flush_head); in log_write_header()
918 gfs2_write_log_header(sdp, sdp->sd_jdesc, sdp->sd_log_sequence++, in log_write_header()
919 sdp->sd_log_flush_tail, sdp->sd_log_flush_head, in log_write_header()
921 gfs2_log_incr_head(sdp); in log_write_header()
922 log_flush_wait(sdp); in log_write_header()
923 log_pull_tail(sdp); in log_write_header()
924 gfs2_log_update_head(sdp); in log_write_header()
931 void gfs2_ail_drain(struct gfs2_sbd *sdp) in gfs2_ail_drain() argument
935 spin_lock(&sdp->sd_ail_lock); in gfs2_ail_drain()
943 while (!list_empty(&sdp->sd_ail1_list)) { in gfs2_ail_drain()
944 tr = list_first_entry(&sdp->sd_ail1_list, struct gfs2_trans, in gfs2_ail_drain()
946 gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail1_list); in gfs2_ail_drain()
947 gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail2_list); in gfs2_ail_drain()
949 gfs2_trans_free(sdp, tr); in gfs2_ail_drain()
951 while (!list_empty(&sdp->sd_ail2_list)) { in gfs2_ail_drain()
952 tr = list_first_entry(&sdp->sd_ail2_list, struct gfs2_trans, in gfs2_ail_drain()
954 gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail2_list); in gfs2_ail_drain()
956 gfs2_trans_free(sdp, tr); in gfs2_ail_drain()
958 gfs2_drain_revokes(sdp); in gfs2_ail_drain()
959 spin_unlock(&sdp->sd_ail_lock); in gfs2_ail_drain()
966 static void empty_ail1_list(struct gfs2_sbd *sdp) in empty_ail1_list() argument
972 fs_err(sdp, "Error: In %s for 10 minutes! t=%d\n", in empty_ail1_list()
974 dump_ail_list(sdp); in empty_ail1_list()
977 gfs2_ail1_start(sdp); in empty_ail1_list()
978 gfs2_ail1_wait(sdp); in empty_ail1_list()
979 if (gfs2_ail1_empty(sdp, 0)) in empty_ail1_list()
1026 void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags) in gfs2_log_flush() argument
1030 enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state); in gfs2_log_flush()
1034 down_write(&sdp->sd_log_flush_lock); in gfs2_log_flush()
1035 trace_gfs2_log_flush(sdp, 1, flags); in gfs2_log_flush()
1042 if (gfs2_withdrawn(sdp) || !test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) in gfs2_log_flush()
1049 first_log_head = sdp->sd_log_head; in gfs2_log_flush()
1050 sdp->sd_log_flush_head = first_log_head; in gfs2_log_flush()
1052 tr = sdp->sd_log_tr; in gfs2_log_flush()
1053 if (tr || sdp->sd_log_num_revoke) { in gfs2_log_flush()
1055 gfs2_log_release(sdp, reserved_blocks); in gfs2_log_flush()
1056 reserved_blocks = sdp->sd_log_blks_reserved; in gfs2_log_flush()
1057 reserved_revokes = sdp->sd_log_num_revoke; in gfs2_log_flush()
1059 sdp->sd_log_tr = NULL; in gfs2_log_flush()
1062 if (gfs2_assert_withdraw_delayed(sdp, in gfs2_log_flush()
1071 if (current == sdp->sd_logd_process) in gfs2_log_flush()
1074 if (!__gfs2_log_try_reserve(sdp, reserved_blocks, taboo_blocks)) { in gfs2_log_flush()
1075 up_write(&sdp->sd_log_flush_lock); in gfs2_log_flush()
1076 __gfs2_log_reserve(sdp, reserved_blocks, taboo_blocks); in gfs2_log_flush()
1077 down_write(&sdp->sd_log_flush_lock); in gfs2_log_flush()
1080 BUG_ON(sdp->sd_log_num_revoke); in gfs2_log_flush()
1084 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); in gfs2_log_flush()
1087 if (gfs2_assert_withdraw_delayed(sdp, !reserved_revokes)) in gfs2_log_flush()
1090 gfs2_ordered_write(sdp); in gfs2_log_flush()
1091 if (gfs2_withdrawn(sdp)) in gfs2_log_flush()
1093 lops_before_commit(sdp, tr); in gfs2_log_flush()
1094 if (gfs2_withdrawn(sdp)) in gfs2_log_flush()
1096 gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE); in gfs2_log_flush()
1097 if (gfs2_withdrawn(sdp)) in gfs2_log_flush()
1100 if (sdp->sd_log_head != sdp->sd_log_flush_head) { in gfs2_log_flush()
1101 log_write_header(sdp, flags); in gfs2_log_flush()
1102 } else if (sdp->sd_log_tail != sdp->sd_log_flush_tail && !sdp->sd_log_idle) { in gfs2_log_flush()
1103 log_write_header(sdp, flags); in gfs2_log_flush()
1105 if (gfs2_withdrawn(sdp)) in gfs2_log_flush()
1107 lops_after_commit(sdp, tr); in gfs2_log_flush()
1109 gfs2_log_lock(sdp); in gfs2_log_flush()
1110 sdp->sd_log_blks_reserved = 0; in gfs2_log_flush()
1112 spin_lock(&sdp->sd_ail_lock); in gfs2_log_flush()
1114 list_add(&tr->tr_list, &sdp->sd_ail1_list); in gfs2_log_flush()
1117 spin_unlock(&sdp->sd_ail_lock); in gfs2_log_flush()
1118 gfs2_log_unlock(sdp); in gfs2_log_flush()
1121 if (!sdp->sd_log_idle) { in gfs2_log_flush()
1122 empty_ail1_list(sdp); in gfs2_log_flush()
1123 if (gfs2_withdrawn(sdp)) in gfs2_log_flush()
1125 log_write_header(sdp, flags); in gfs2_log_flush()
1129 gfs2_log_shutdown(sdp); in gfs2_log_flush()
1131 atomic_set(&sdp->sd_freeze_state, SFS_FROZEN); in gfs2_log_flush()
1135 used_blocks = log_distance(sdp, sdp->sd_log_flush_head, first_log_head); in gfs2_log_flush()
1136 reserved_revokes += atomic_read(&sdp->sd_log_revokes_available); in gfs2_log_flush()
1137 atomic_set(&sdp->sd_log_revokes_available, sdp->sd_ldptrs); in gfs2_log_flush()
1138 gfs2_assert_withdraw(sdp, reserved_revokes % sdp->sd_inptrs == sdp->sd_ldptrs); in gfs2_log_flush()
1139 if (reserved_revokes > sdp->sd_ldptrs) in gfs2_log_flush()
1140 reserved_blocks += (reserved_revokes - sdp->sd_ldptrs) / sdp->sd_inptrs; in gfs2_log_flush()
1143 gfs2_assert_withdraw_delayed(sdp, used_blocks < reserved_blocks); in gfs2_log_flush()
1144 gfs2_log_release(sdp, reserved_blocks - used_blocks); in gfs2_log_flush()
1146 up_write(&sdp->sd_log_flush_lock); in gfs2_log_flush()
1147 gfs2_trans_free(sdp, tr); in gfs2_log_flush()
1148 if (gfs2_withdrawing(sdp)) in gfs2_log_flush()
1149 gfs2_withdraw(sdp); in gfs2_log_flush()
1150 trace_gfs2_log_flush(sdp, 0, flags); in gfs2_log_flush()
1161 spin_lock(&sdp->sd_ail_lock); in gfs2_log_flush()
1163 list_add(&tr->tr_list, &sdp->sd_ail1_list); in gfs2_log_flush()
1164 spin_unlock(&sdp->sd_ail_lock); in gfs2_log_flush()
1175 static void gfs2_merge_trans(struct gfs2_sbd *sdp, struct gfs2_trans *new) in gfs2_merge_trans() argument
1177 struct gfs2_trans *old = sdp->sd_log_tr; in gfs2_merge_trans()
1191 spin_lock(&sdp->sd_ail_lock); in gfs2_merge_trans()
1194 spin_unlock(&sdp->sd_ail_lock); in gfs2_merge_trans()
1197 static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) in log_refund() argument
1203 gfs2_log_lock(sdp); in log_refund()
1205 if (sdp->sd_log_tr) { in log_refund()
1206 gfs2_merge_trans(sdp, tr); in log_refund()
1208 gfs2_assert_withdraw(sdp, !test_bit(TR_ONSTACK, &tr->tr_flags)); in log_refund()
1209 sdp->sd_log_tr = tr; in log_refund()
1213 reserved = calc_reserved(sdp); in log_refund()
1214 maxres = sdp->sd_log_blks_reserved + tr->tr_reserved; in log_refund()
1215 gfs2_assert_withdraw(sdp, maxres >= reserved); in log_refund()
1218 gfs2_log_release(sdp, unused); in log_refund()
1219 sdp->sd_log_blks_reserved = reserved; in log_refund()
1221 gfs2_log_unlock(sdp); in log_refund()
1239 void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) in gfs2_log_commit() argument
1241 log_refund(sdp, tr); in gfs2_log_commit()
1243 if (atomic_read(&sdp->sd_log_pinned) > atomic_read(&sdp->sd_log_thresh1) || in gfs2_log_commit()
1244 ((sdp->sd_jdesc->jd_blocks - atomic_read(&sdp->sd_log_blks_free)) > in gfs2_log_commit()
1245 atomic_read(&sdp->sd_log_thresh2))) in gfs2_log_commit()
1246 wake_up(&sdp->sd_logd_waitq); in gfs2_log_commit()
1255 static void gfs2_log_shutdown(struct gfs2_sbd *sdp) in gfs2_log_shutdown() argument
1257 gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); in gfs2_log_shutdown()
1258 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); in gfs2_log_shutdown()
1259 gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list)); in gfs2_log_shutdown()
1261 log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT | GFS2_LFC_SHUTDOWN); in gfs2_log_shutdown()
1262 log_pull_tail(sdp); in gfs2_log_shutdown()
1264 gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail); in gfs2_log_shutdown()
1265 gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list)); in gfs2_log_shutdown()
1268 static inline int gfs2_jrnl_flush_reqd(struct gfs2_sbd *sdp) in gfs2_jrnl_flush_reqd() argument
1270 return (atomic_read(&sdp->sd_log_pinned) + in gfs2_jrnl_flush_reqd()
1271 atomic_read(&sdp->sd_log_blks_needed) >= in gfs2_jrnl_flush_reqd()
1272 atomic_read(&sdp->sd_log_thresh1)); in gfs2_jrnl_flush_reqd()
1275 static inline int gfs2_ail_flush_reqd(struct gfs2_sbd *sdp) in gfs2_ail_flush_reqd() argument
1277 unsigned int used_blocks = sdp->sd_jdesc->jd_blocks - atomic_read(&sdp->sd_log_blks_free); in gfs2_ail_flush_reqd()
1279 if (test_and_clear_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags)) in gfs2_ail_flush_reqd()
1282 return used_blocks + atomic_read(&sdp->sd_log_blks_needed) >= in gfs2_ail_flush_reqd()
1283 atomic_read(&sdp->sd_log_thresh2); in gfs2_ail_flush_reqd()
1296 struct gfs2_sbd *sdp = data; in gfs2_logd() local
1302 if (gfs2_withdrawn(sdp)) { in gfs2_logd()
1307 if (sdp->sd_log_error) { in gfs2_logd()
1308 gfs2_lm(sdp, in gfs2_logd()
1312 sdp->sd_fsname, sdp->sd_log_error); in gfs2_logd()
1313 gfs2_withdraw(sdp); in gfs2_logd()
1317 if (gfs2_jrnl_flush_reqd(sdp) || t == 0) { in gfs2_logd()
1318 gfs2_ail1_empty(sdp, 0); in gfs2_logd()
1319 gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL | in gfs2_logd()
1323 if (gfs2_ail_flush_reqd(sdp)) { in gfs2_logd()
1324 gfs2_ail1_start(sdp); in gfs2_logd()
1325 gfs2_ail1_wait(sdp); in gfs2_logd()
1326 gfs2_ail1_empty(sdp, 0); in gfs2_logd()
1327 gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL | in gfs2_logd()
1331 t = gfs2_tune_get(sdp, gt_logd_secs) * HZ; in gfs2_logd()
1336 prepare_to_wait(&sdp->sd_logd_waitq, &wait, in gfs2_logd()
1338 if (!gfs2_ail_flush_reqd(sdp) && in gfs2_logd()
1339 !gfs2_jrnl_flush_reqd(sdp) && in gfs2_logd()
1342 } while(t && !gfs2_ail_flush_reqd(sdp) && in gfs2_logd()
1343 !gfs2_jrnl_flush_reqd(sdp) && in gfs2_logd()
1345 finish_wait(&sdp->sd_logd_waitq, &wait); in gfs2_logd()