Lines Matching +full:ip +full:- +full:blocks

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
4 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
38 * gfs2_struct2blk - compute stuff
42 * Compute the number of log descriptor blocks needed to hold a certain number
45 * Returns: the number of blocks needed (minimum is always 1)
55 first = sdp->sd_ldptrs; in gfs2_struct2blk()
58 /* Subsequent struct gfs2_meta_header blocks */ in gfs2_struct2blk()
59 second = sdp->sd_inptrs; in gfs2_struct2blk()
60 blks += DIV_ROUND_UP(nstruct - first, second); in gfs2_struct2blk()
67 * gfs2_remove_from_ail - Remove an entry from the ail lists, updating counters
76 bd->bd_tr = NULL; in gfs2_remove_from_ail()
77 list_del_init(&bd->bd_ail_st_list); in gfs2_remove_from_ail()
78 list_del_init(&bd->bd_ail_gl_list); in gfs2_remove_from_ail()
79 atomic_dec(&bd->bd_gl->gl_ail_count); in gfs2_remove_from_ail()
80 brelse(bd->bd_bh); in gfs2_remove_from_ail()
84 * gfs2_ail1_start_one - Start I/O on a transaction
94 __releases(&sdp->sd_ail_lock) in gfs2_ail1_start_one()
95 __acquires(&sdp->sd_ail_lock) in gfs2_ail1_start_one()
103 list_for_each_entry_safe_reverse(bd, s, &tr->tr_ail1_list, bd_ail_st_list) { in gfs2_ail1_start_one()
104 bh = bd->bd_bh; in gfs2_ail1_start_one()
106 gfs2_assert(sdp, bd->bd_tr == tr); in gfs2_ail1_start_one()
110 list_move(&bd->bd_ail_st_list, in gfs2_ail1_start_one()
111 &tr->tr_ail2_list); in gfs2_ail1_start_one()
114 if (!cmpxchg(&sdp->sd_log_error, 0, -EIO)) { in gfs2_ail1_start_one()
126 if (gl == bd->bd_gl) in gfs2_ail1_start_one()
128 gl = bd->bd_gl; in gfs2_ail1_start_one()
129 list_move(&bd->bd_ail_st_list, &tr->tr_ail1_list); in gfs2_ail1_start_one()
130 mapping = bh->b_page->mapping; 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()
141 if (ret == -ENODATA) /* if a jdata write into a new hole */ in gfs2_ail1_start_one()
143 if (ret || wbc->nr_to_write <= 0) in gfs2_ail1_start_one()
145 return -EBUSY; in gfs2_ail1_start_one()
157 list_for_each_entry_reverse(tr, &sdp->sd_ail1_list, tr_list) { in dump_ail_list()
158 list_for_each_entry_reverse(bd, &tr->tr_ail1_list, in dump_ail_list()
160 bh = bd->bd_bh; in dump_ail_list()
162 (unsigned long long)bd->bd_blkno, bh); in dump_ail_list()
170 (unsigned long long)bh->b_blocknr, in dump_ail_list()
184 * gfs2_ail1_flush - start writeback of some ail1 entries
194 struct list_head *head = &sdp->sd_ail1_list; in gfs2_ail1_flush()
202 spin_lock(&sdp->sd_ail_lock); in gfs2_ail1_flush()
207 __func__, current->journal_info ? 1 : 0); in gfs2_ail1_flush()
212 if (wbc->nr_to_write <= 0) in gfs2_ail1_flush()
216 if (ret == -EBUSY) in gfs2_ail1_flush()
222 spin_unlock(&sdp->sd_ail_lock); in gfs2_ail1_flush()
232 * gfs2_ail1_start - start writeback of all ail1 entries
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()
256 new_flush_tail = tr->tr_first; in gfs2_log_update_flush_tail()
258 sdp->sd_log_flush_tail = new_flush_tail; in gfs2_log_update_flush_tail()
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()
271 * gfs2_ail_empty_tr - empty one of the ail lists of a transaction
282 gfs2_assert(sdp, bd->bd_tr == tr); in gfs2_ail_empty_tr()
288 * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced
303 list_for_each_entry_safe_reverse(bd, s, &tr->tr_ail1_list, in gfs2_ail1_empty_one()
305 bh = bd->bd_bh; in gfs2_ail1_empty_one()
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()
331 if (*max_revokes && list_empty(&bd->bd_list)) { in gfs2_ail1_empty_one()
333 (*max_revokes)--; in gfs2_ail1_empty_one()
336 list_move(&bd->bd_ail_st_list, &tr->tr_ail2_list); in gfs2_ail1_empty_one()
342 * gfs2_ail1_empty - Try to empty the ail1 lists
344 * @max_revokes: If non-zero, add revokes where appropriate
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()
358 list_move(&tr->tr_list, &sdp->sd_ail2_list); 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()
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()
382 list_for_each_entry(bd, &tr->tr_ail1_list, bd_ail_st_list) { in gfs2_ail1_wait()
383 bh = bd->bd_bh; 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()
398 gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail2_list); in __ail2_empty()
399 list_del(&tr->tr_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()
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()
414 if (old_tail <= tr->tr_first && tr->tr_first < new_tail) in ail2_empty()
419 if (old_tail <= tr->tr_first || tr->tr_first < new_tail) in ail2_empty()
423 spin_unlock(&sdp->sd_ail_lock); in ail2_empty()
427 * gfs2_log_is_empty - Check if the log is empty
432 return atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks; in gfs2_log_is_empty()
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()
442 &available, available - revokes)) in __gfs2_log_try_reserve_revokes()
449 * gfs2_log_release_revokes - Release a given number of revokes
453 * sdp->sd_log_flush_lock must be held.
458 atomic_add(revokes, &sdp->sd_log_revokes_available); in gfs2_log_release_revokes()
462 * gfs2_log_release - Release a given number of log blocks
464 * @blks: The number of blocks
470 atomic_add(blks, &sdp->sd_log_blks_free); 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()
479 * __gfs2_log_try_reserve - Try to make a log reservation
481 * @blks: The number of blocks to reserve
482 * @taboo_blks: The number of blocks to leave free
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()
496 free_blocks - blks)) { in __gfs2_log_try_reserve()
497 trace_gfs2_log_blocks(sdp, -blks); in __gfs2_log_try_reserve()
505 * __gfs2_log_reserve - Make a log reservation
507 * @blks: The number of blocks to reserve
508 * @taboo_blks: The number of blocks to leave free
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()
539 free_blocks - blks)) 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()
551 * gfs2_log_try_reserve - Try to make a log reservation
556 * This is similar to gfs2_log_reserve, but sdp->sd_log_flush_lock must be
563 unsigned int blks = tr->tr_reserved; in gfs2_log_try_reserve()
564 unsigned int revokes = tr->tr_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()
583 * gfs2_log_reserve - Make a log reservation
588 * sdp->sd_log_flush_lock must not be held.
594 unsigned int blks = tr->tr_reserved; in gfs2_log_reserve()
595 unsigned int revokes = tr->tr_revokes; in gfs2_log_reserve()
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()
608 * log_distance - Compute distance between two journal blocks
614 * blocks in the journal
616 * Returns: the distance in blocks
624 dist = newer - older; in log_distance()
626 dist += sdp->sd_jdesc->jd_blocks; in log_distance()
632 * calc_reserved - Calculate the number of blocks to keep reserved
636 * metadata blocks (e.g. normal file I/O rewriting file time stamps) and
637 * all our journaled data blocks for journaled files (e.g. files in the
641 * We can have metadata blocks and jdata blocks in the same journal. Each
644 * in cases where we have more blocks than will fit in a log descriptor.
647 * Also, we need to reserve blocks for revoke journal entries and one for an
650 * Returns: the number of blocks reserved
655 unsigned int blocks; in calc_reserved() local
656 struct gfs2_trans *tr = sdp->sd_log_tr; in calc_reserved()
659 blocks = tr->tr_num_buf_new - tr->tr_num_buf_rm; in calc_reserved()
660 reserved += blocks + DIV_ROUND_UP(blocks, buf_limit(sdp)); in calc_reserved()
661 blocks = tr->tr_num_databuf_new - tr->tr_num_databuf_rm; in calc_reserved()
662 reserved += blocks + DIV_ROUND_UP(blocks, databuf_limit(sdp)); in calc_reserved()
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()
677 sdp->sd_log_tail = new_tail; in log_pull_tail()
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()
703 if (ipa->i_no_addr < ipb->i_no_addr) in ip_cmp()
704 return -1; in ip_cmp()
705 if (ipa->i_no_addr > ipb->i_no_addr) in ip_cmp()
710 static void __ordered_del_inode(struct gfs2_inode *ip) in __ordered_del_inode() argument
712 if (!list_empty(&ip->i_ordered)) in __ordered_del_inode()
713 list_del_init(&ip->i_ordered); in __ordered_del_inode()
718 struct gfs2_inode *ip; in gfs2_ordered_write() local
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()
725 if (ip->i_inode.i_mapping->nrpages == 0) { in gfs2_ordered_write()
726 __ordered_del_inode(ip); in gfs2_ordered_write()
729 list_move(&ip->i_ordered, &written); in gfs2_ordered_write()
730 spin_unlock(&sdp->sd_ordered_lock); in gfs2_ordered_write()
731 filemap_fdatawrite(ip->i_inode.i_mapping); 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()
740 struct gfs2_inode *ip; in gfs2_ordered_wait() local
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()
745 __ordered_del_inode(ip); in gfs2_ordered_wait()
746 if (ip->i_inode.i_mapping->nrpages == 0) in gfs2_ordered_wait()
748 spin_unlock(&sdp->sd_ordered_lock); in gfs2_ordered_wait()
749 filemap_fdatawait(ip->i_inode.i_mapping); 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()
755 void gfs2_ordered_del_inode(struct gfs2_inode *ip) in gfs2_ordered_del_inode() argument
757 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_ordered_del_inode()
759 spin_lock(&sdp->sd_ordered_lock); in gfs2_ordered_del_inode()
760 __ordered_del_inode(ip); in gfs2_ordered_del_inode()
761 spin_unlock(&sdp->sd_ordered_lock); in gfs2_ordered_del_inode()
766 struct buffer_head *bh = bd->bd_bh; in gfs2_add_revoke()
767 struct gfs2_glock *gl = bd->bd_gl; in gfs2_add_revoke()
769 sdp->sd_log_num_revoke++; in gfs2_add_revoke()
770 if (atomic_inc_return(&gl->gl_revokes) == 1) in gfs2_add_revoke()
772 bh->b_private = NULL; in gfs2_add_revoke()
773 bd->bd_blkno = bh->b_blocknr; in gfs2_add_revoke()
775 bd->bd_bh = NULL; in gfs2_add_revoke()
776 set_bit(GLF_LFLUSH, &gl->gl_flags); in gfs2_add_revoke()
777 list_add(&bd->bd_list, &sdp->sd_log_revokes); in gfs2_add_revoke()
782 if (atomic_dec_return(&gl->gl_revokes) == 0) { in gfs2_glock_remove_revoke()
783 clear_bit(GLF_LFLUSH, &gl->gl_flags); in gfs2_glock_remove_revoke()
789 * gfs2_flush_revokes - Add as many revokes to the system transaction as we can
795 * likely be some left-over space in the last revoke block of that transaction.
796 * We can fill that space with additional revokes for blocks that have already
798 * us from having to keep track of those blocks on the AIL2 list later.
803 unsigned int max_revokes = atomic_read(&sdp->sd_log_revokes_available); in gfs2_flush_revokes()
811 * gfs2_write_log_header - Write a journal log header buffer at lblock
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()
842 lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); in gfs2_write_log_header()
843 lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH); in gfs2_write_log_header()
844 lh->lh_header.__pad0 = cpu_to_be64(0); in gfs2_write_log_header()
845 lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH); in gfs2_write_log_header()
846 lh->lh_header.mh_jid = cpu_to_be32(sdp->sd_jdesc->jd_jid); in gfs2_write_log_header()
847 lh->lh_sequence = cpu_to_be64(seq); in gfs2_write_log_header()
848 lh->lh_flags = cpu_to_be32(flags); in gfs2_write_log_header()
849 lh->lh_tail = cpu_to_be32(tail); in gfs2_write_log_header()
850 lh->lh_blkno = cpu_to_be32(lblock); in gfs2_write_log_header()
852 lh->lh_hash = cpu_to_be32(hash); in gfs2_write_log_header()
855 lh->lh_nsec = cpu_to_be32(tv.tv_nsec); in gfs2_write_log_header()
856 lh->lh_sec = cpu_to_be64(tv.tv_sec); in gfs2_write_log_header()
857 if (!list_empty(&jd->extent_list)) in gfs2_write_log_header()
864 ret = gfs2_get_extent(jd->jd_inode, lblock, &dblock, &extlen); in gfs2_write_log_header()
868 lh->lh_addr = cpu_to_be64(dblock); in gfs2_write_log_header()
869 lh->lh_jinode = cpu_to_be64(GFS2_I(jd->jd_inode)->i_no_addr); in gfs2_write_log_header()
875 lh->lh_statfs_addr = in gfs2_write_log_header()
876 cpu_to_be64(GFS2_I(sdp->sd_sc_inode)->i_no_addr); in gfs2_write_log_header()
877 lh->lh_quota_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()
881 lh->lh_local_total = cpu_to_be64(l_sc->sc_total); in gfs2_write_log_header()
882 lh->lh_local_free = cpu_to_be64(l_sc->sc_free); in gfs2_write_log_header()
883 lh->lh_local_dinodes = cpu_to_be64(l_sc->sc_dinodes); in gfs2_write_log_header()
884 spin_unlock(&sdp->sd_statfs_spin); in gfs2_write_log_header()
890 sb->s_blocksize - LH_V1_SIZE - 4); in gfs2_write_log_header()
891 lh->lh_crc = cpu_to_be32(crc); in gfs2_write_log_header()
893 gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock); in gfs2_write_log_header()
894 gfs2_log_submit_bio(&jd->jd_log_bio, REQ_OP_WRITE | op_flags); in gfs2_write_log_header()
898 * log_write_header - Get and initialize a journal header buffer
908 enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state); in log_write_header()
912 if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) { 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()
928 * gfs2_ail_drain - drain the ail lists after a withdraw
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()
948 list_del(&tr->tr_list); 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()
955 list_del(&tr->tr_list); in gfs2_ail_drain()
959 spin_unlock(&sdp->sd_ail_lock); in gfs2_ail_drain()
963 * empty_ail1_list - try to start IO and empty the ail1 list
973 __func__, current->journal_info ? 1 : 0); in empty_ail1_list()
985 * trans_drain - drain the buf and databuf queue for a failed transaction
1000 head = &tr->tr_buf; in trans_drain()
1003 list_del_init(&bd->bd_list); in trans_drain()
1004 if (!list_empty(&bd->bd_ail_st_list)) in trans_drain()
1008 head = &tr->tr_databuf; in trans_drain()
1011 list_del_init(&bd->bd_list); in trans_drain()
1012 if (!list_empty(&bd->bd_ail_st_list)) in trans_drain()
1019 * gfs2_log_flush - flush incore transaction(s)
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()
1042 if (gfs2_withdrawn(sdp) || !test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) in gfs2_log_flush()
1046 if (gl && !test_bit(GLF_LFLUSH, &gl->gl_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()
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()
1060 tr->tr_first = first_log_head; in gfs2_log_flush()
1063 !tr->tr_num_buf_new && !tr->tr_num_databuf_new)) in gfs2_log_flush()
1071 if (current == sdp->sd_logd_process) in gfs2_log_flush()
1075 up_write(&sdp->sd_log_flush_lock); 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()
1096 gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE); in gfs2_log_flush()
1100 if (sdp->sd_log_head != sdp->sd_log_flush_head) { in gfs2_log_flush()
1102 } else if (sdp->sd_log_tail != sdp->sd_log_flush_tail && !sdp->sd_log_idle) { 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()
1113 if (tr && !list_empty(&tr->tr_ail1_list)) { 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()
1121 if (!sdp->sd_log_idle) { 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()
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()
1161 spin_lock(&sdp->sd_ail_lock); in gfs2_log_flush()
1162 if (tr && list_empty(&tr->tr_list)) 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()
1170 * gfs2_merge_trans - Merge a new transaction into a cached transaction
1177 struct gfs2_trans *old = sdp->sd_log_tr; in gfs2_merge_trans()
1179 WARN_ON_ONCE(!test_bit(TR_ATTACHED, &old->tr_flags)); in gfs2_merge_trans()
1181 old->tr_num_buf_new += new->tr_num_buf_new; in gfs2_merge_trans()
1182 old->tr_num_databuf_new += new->tr_num_databuf_new; in gfs2_merge_trans()
1183 old->tr_num_buf_rm += new->tr_num_buf_rm; in gfs2_merge_trans()
1184 old->tr_num_databuf_rm += new->tr_num_databuf_rm; in gfs2_merge_trans()
1185 old->tr_revokes += new->tr_revokes; in gfs2_merge_trans()
1186 old->tr_num_revoke += new->tr_num_revoke; in gfs2_merge_trans()
1188 list_splice_tail_init(&new->tr_databuf, &old->tr_databuf); in gfs2_merge_trans()
1189 list_splice_tail_init(&new->tr_buf, &old->tr_buf); in gfs2_merge_trans()
1191 spin_lock(&sdp->sd_ail_lock); in gfs2_merge_trans()
1192 list_splice_tail_init(&new->tr_ail1_list, &old->tr_ail1_list); in gfs2_merge_trans()
1193 list_splice_tail_init(&new->tr_ail2_list, &old->tr_ail2_list); in gfs2_merge_trans()
1194 spin_unlock(&sdp->sd_ail_lock); in gfs2_merge_trans()
1205 if (sdp->sd_log_tr) { in log_refund()
1207 } else if (tr->tr_num_buf_new || tr->tr_num_databuf_new) { 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()
1210 set_bit(TR_ATTACHED, &tr->tr_flags); in log_refund()
1214 maxres = sdp->sd_log_blks_reserved + tr->tr_reserved; in log_refund()
1216 unused = maxres - reserved; in log_refund()
1219 sdp->sd_log_blks_reserved = reserved; in log_refund()
1225 * gfs2_log_commit - Commit a transaction to the log
1229 * We wake up gfs2_logd if the number of pinned blocks exceed thresh1
1230 * or the total number of used blocks (pinned blocks plus AIL blocks)
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()
1250 * gfs2_log_shutdown - write a shutdown header into a journal
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()
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()
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()
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()
1287 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
1307 if (sdp->sd_log_error) { in gfs2_logd()
1312 sdp->sd_fsname, sdp->sd_log_error); in gfs2_logd()
1336 prepare_to_wait(&sdp->sd_logd_waitq, &wait, in gfs2_logd()
1345 finish_wait(&sdp->sd_logd_waitq, &wait); in gfs2_logd()