2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2007 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/gfs2_ondisk.h>
16 #include <linux/crc32.h>
17 #include <linux/lm_interface.h>
18 #include <linux/delay.h>
19 #include <linux/kthread.h>
20 #include <linux/freezer.h>
35 * gfs2_struct2blk - compute stuff
36 * @sdp: the filesystem
37 * @nstruct: the number of structures
38 * @ssize: the size of the structures
40 * Compute the number of log descriptor blocks needed to hold a certain number
41 * of structures of a certain size.
43 * Returns: the number of blocks needed (minimum is always 1)
46 unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
50 unsigned int first, second;
53 first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / ssize;
55 if (nstruct > first) {
56 second = (sdp->sd_sb.sb_bsize -
57 sizeof(struct gfs2_meta_header)) / ssize;
58 blks += DIV_ROUND_UP(nstruct - first, second);
65 * gfs2_remove_from_ail - Remove an entry from the ail lists, updating counters
66 * @mapping: The associated mapping (maybe NULL)
67 * @bd: The gfs2_bufdata to remove
69 * The log lock _must_ be held when calling this function
73 void gfs2_remove_from_ail(struct gfs2_bufdata *bd)
76 list_del_init(&bd->bd_ail_st_list);
77 list_del_init(&bd->bd_ail_gl_list);
78 atomic_dec(&bd->bd_gl->gl_ail_count);
83 * gfs2_ail1_start_one - Start I/O on a part of the AIL
84 * @sdp: the filesystem
85 * @tr: the part of the AIL
89 static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
91 struct gfs2_bufdata *bd, *s;
92 struct buffer_head *bh;
98 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
102 gfs2_assert(sdp, bd->bd_ail == ai);
104 if (!buffer_busy(bh)) {
105 if (!buffer_uptodate(bh))
106 gfs2_io_error_bh(sdp, bh);
107 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
111 if (!buffer_dirty(bh))
114 list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list);
117 gfs2_log_unlock(sdp);
119 if (test_clear_buffer_dirty(bh)) {
120 bh->b_end_io = end_buffer_write_sync;
121 submit_bh(WRITE, bh);
135 * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced
136 * @sdp: the filesystem
141 static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags)
143 struct gfs2_bufdata *bd, *s;
144 struct buffer_head *bh;
146 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
150 gfs2_assert(sdp, bd->bd_ail == ai);
152 if (buffer_busy(bh)) {
159 if (!buffer_uptodate(bh))
160 gfs2_io_error_bh(sdp, bh);
162 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
165 return list_empty(&ai->ai_ail1_list);
168 static void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags)
170 struct list_head *head;
172 struct list_head *first;
173 struct gfs2_ail *first_ai, *ai, *tmp;
177 head = &sdp->sd_ail1_list;
178 if (list_empty(head)) {
179 gfs2_log_unlock(sdp);
182 sync_gen = sdp->sd_ail_sync_gen++;
185 first_ai = list_entry(first, struct gfs2_ail, ai_list);
186 first_ai->ai_sync_gen = sync_gen;
187 gfs2_ail1_start_one(sdp, first_ai); /* This may drop log lock */
193 if (first && (head->prev != first ||
194 gfs2_ail1_empty_one(sdp, first_ai, 0)))
198 list_for_each_entry_safe_reverse(ai, tmp, head, ai_list) {
199 if (ai->ai_sync_gen >= sync_gen)
201 ai->ai_sync_gen = sync_gen;
202 gfs2_ail1_start_one(sdp, ai); /* This may drop log lock */
208 gfs2_log_unlock(sdp);
211 static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
213 struct gfs2_ail *ai, *s;
218 list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) {
219 if (gfs2_ail1_empty_one(sdp, ai, flags))
220 list_move(&ai->ai_list, &sdp->sd_ail2_list);
221 else if (!(flags & DIO_ALL))
225 ret = list_empty(&sdp->sd_ail1_list);
227 gfs2_log_unlock(sdp);
234 * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced
235 * @sdp: the filesystem
240 static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
242 struct list_head *head = &ai->ai_ail2_list;
243 struct gfs2_bufdata *bd;
245 while (!list_empty(head)) {
246 bd = list_entry(head->prev, struct gfs2_bufdata,
248 gfs2_assert(sdp, bd->bd_ail == ai);
249 gfs2_remove_from_ail(bd);
253 static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
255 struct gfs2_ail *ai, *safe;
256 unsigned int old_tail = sdp->sd_log_tail;
257 int wrap = (new_tail < old_tail);
262 list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) {
263 a = (old_tail <= ai->ai_first);
264 b = (ai->ai_first < new_tail);
265 rm = (wrap) ? (a || b) : (a && b);
269 gfs2_ail2_empty_one(sdp, ai);
270 list_del(&ai->ai_list);
271 gfs2_assert_warn(sdp, list_empty(&ai->ai_ail1_list));
272 gfs2_assert_warn(sdp, list_empty(&ai->ai_ail2_list));
276 gfs2_log_unlock(sdp);
280 * gfs2_log_reserve - Make a log reservation
281 * @sdp: The GFS2 superblock
282 * @blks: The number of blocks to reserve
284 * Note that we never give out the last few blocks of the journal. Thats
285 * due to the fact that there is a small number of header blocks
286 * associated with each log flush. The exact number can't be known until
287 * flush time, so we ensure that we have just enough free blocks at all
288 * times to avoid running out during a log flush.
293 int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
295 unsigned int try = 0;
296 unsigned reserved_blks = 6 * (4096 / sdp->sd_vfs->s_blocksize);
298 if (gfs2_assert_warn(sdp, blks) ||
299 gfs2_assert_warn(sdp, blks <= sdp->sd_jdesc->jd_blocks))
302 mutex_lock(&sdp->sd_log_reserve_mutex);
304 while(atomic_read(&sdp->sd_log_blks_free) <= (blks + reserved_blks)) {
305 gfs2_log_unlock(sdp);
306 gfs2_ail1_empty(sdp, 0);
307 gfs2_log_flush(sdp, NULL);
310 gfs2_ail1_start(sdp, 0);
313 atomic_sub(blks, &sdp->sd_log_blks_free);
314 gfs2_log_unlock(sdp);
315 mutex_unlock(&sdp->sd_log_reserve_mutex);
317 down_read(&sdp->sd_log_flush_lock);
323 * gfs2_log_release - Release a given number of log blocks
324 * @sdp: The GFS2 superblock
325 * @blks: The number of blocks
329 void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
333 atomic_add(blks, &sdp->sd_log_blks_free);
334 gfs2_assert_withdraw(sdp,
335 atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks);
336 gfs2_log_unlock(sdp);
337 up_read(&sdp->sd_log_flush_lock);
340 static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn)
342 struct gfs2_journal_extent *je;
344 list_for_each_entry(je, &sdp->sd_jdesc->extent_list, extent_list) {
345 if (lbn >= je->lblock && lbn < je->lblock + je->blocks)
346 return je->dblock + lbn - je->lblock;
353 * log_distance - Compute distance between two journal blocks
354 * @sdp: The GFS2 superblock
355 * @newer: The most recent journal block of the pair
356 * @older: The older journal block of the pair
358 * Compute the distance (in the journal direction) between two
359 * blocks in the journal
361 * Returns: the distance in blocks
364 static inline unsigned int log_distance(struct gfs2_sbd *sdp, unsigned int newer,
369 dist = newer - older;
371 dist += sdp->sd_jdesc->jd_blocks;
377 * calc_reserved - Calculate the number of blocks to reserve when
378 * refunding a transaction's unused buffers.
379 * @sdp: The GFS2 superblock
381 * This is complex. We need to reserve room for all our currently used
382 * metadata buffers (e.g. normal file I/O rewriting file time stamps) and
383 * all our journaled data buffers for journaled files (e.g. files in the
384 * meta_fs like rindex, or files for which chattr +j was done.)
385 * If we don't reserve enough space, gfs2_log_refund and gfs2_log_flush
386 * will count it as free space (sd_log_blks_free) and corruption will follow.
388 * We can have metadata bufs and jdata bufs in the same journal. So each
389 * type gets its own log header, for which we need to reserve a block.
390 * In fact, each type has the potential for needing more than one header
391 * in cases where we have more buffers than will fit on a journal page.
392 * Metadata journal entries take up half the space of journaled buffer entries.
393 * Thus, metadata entries have buf_limit (502) and journaled buffers have
394 * databuf_limit (251) before they cause a wrap around.
396 * Also, we need to reserve blocks for revoke journal entries and one for an
397 * overall header for the lot.
399 * Returns: the number of blocks reserved
401 static unsigned int calc_reserved(struct gfs2_sbd *sdp)
403 unsigned int reserved = 0;
404 unsigned int mbuf_limit, metabufhdrs_needed;
405 unsigned int dbuf_limit, databufhdrs_needed;
406 unsigned int revokes = 0;
408 mbuf_limit = buf_limit(sdp);
409 metabufhdrs_needed = (sdp->sd_log_commited_buf +
410 (mbuf_limit - 1)) / mbuf_limit;
411 dbuf_limit = databuf_limit(sdp);
412 databufhdrs_needed = (sdp->sd_log_commited_databuf +
413 (dbuf_limit - 1)) / dbuf_limit;
415 if (sdp->sd_log_commited_revoke)
416 revokes = gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke,
419 reserved = sdp->sd_log_commited_buf + metabufhdrs_needed +
420 sdp->sd_log_commited_databuf + databufhdrs_needed +
422 /* One for the overall header */
428 static unsigned int current_tail(struct gfs2_sbd *sdp)
435 if (list_empty(&sdp->sd_ail1_list)) {
436 tail = sdp->sd_log_head;
438 ai = list_entry(sdp->sd_ail1_list.prev, struct gfs2_ail, ai_list);
442 gfs2_log_unlock(sdp);
447 void gfs2_log_incr_head(struct gfs2_sbd *sdp)
449 if (sdp->sd_log_flush_head == sdp->sd_log_tail)
450 BUG_ON(sdp->sd_log_flush_head != sdp->sd_log_head);
452 if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) {
453 sdp->sd_log_flush_head = 0;
454 sdp->sd_log_flush_wrapped = 1;
459 * gfs2_log_write_endio - End of I/O for a log buffer
460 * @bh: The buffer head
461 * @uptodate: I/O Status
465 static void gfs2_log_write_endio(struct buffer_head *bh, int uptodate)
467 struct gfs2_sbd *sdp = bh->b_private;
468 bh->b_private = NULL;
470 end_buffer_write_sync(bh, uptodate);
471 if (atomic_dec_and_test(&sdp->sd_log_in_flight))
472 wake_up(&sdp->sd_log_flush_wait);
476 * gfs2_log_get_buf - Get and initialize a buffer to use for log control data
477 * @sdp: The GFS2 superblock
479 * Returns: the buffer_head
482 struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp)
484 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
485 struct buffer_head *bh;
487 bh = sb_getblk(sdp->sd_vfs, blkno);
489 memset(bh->b_data, 0, bh->b_size);
490 set_buffer_uptodate(bh);
491 clear_buffer_dirty(bh);
492 gfs2_log_incr_head(sdp);
493 atomic_inc(&sdp->sd_log_in_flight);
495 bh->b_end_io = gfs2_log_write_endio;
501 * gfs2_fake_write_endio -
502 * @bh: The buffer head
503 * @uptodate: The I/O Status
507 static void gfs2_fake_write_endio(struct buffer_head *bh, int uptodate)
509 struct buffer_head *real_bh = bh->b_private;
510 struct gfs2_bufdata *bd = real_bh->b_private;
511 struct gfs2_sbd *sdp = bd->bd_gl->gl_sbd;
513 end_buffer_write_sync(bh, uptodate);
514 free_buffer_head(bh);
515 unlock_buffer(real_bh);
517 if (atomic_dec_and_test(&sdp->sd_log_in_flight))
518 wake_up(&sdp->sd_log_flush_wait);
522 * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log
523 * @sdp: the filesystem
524 * @data: the data the buffer_head should point to
526 * Returns: the log buffer descriptor
529 struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp,
530 struct buffer_head *real)
532 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
533 struct buffer_head *bh;
535 bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL);
536 atomic_set(&bh->b_count, 1);
537 bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate) | (1 << BH_Lock);
538 set_bh_page(bh, real->b_page, bh_offset(real));
539 bh->b_blocknr = blkno;
540 bh->b_size = sdp->sd_sb.sb_bsize;
541 bh->b_bdev = sdp->sd_vfs->s_bdev;
542 bh->b_private = real;
543 bh->b_end_io = gfs2_fake_write_endio;
545 gfs2_log_incr_head(sdp);
546 atomic_inc(&sdp->sd_log_in_flight);
551 static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail)
553 unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail);
555 ail2_empty(sdp, new_tail);
558 atomic_add(dist, &sdp->sd_log_blks_free);
559 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks);
560 gfs2_log_unlock(sdp);
562 sdp->sd_log_tail = new_tail;
566 * log_write_header - Get and initialize a journal header buffer
567 * @sdp: The GFS2 superblock
569 * Returns: the initialized log buffer descriptor
572 static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull)
574 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
575 struct buffer_head *bh;
576 struct gfs2_log_header *lh;
580 bh = sb_getblk(sdp->sd_vfs, blkno);
582 memset(bh->b_data, 0, bh->b_size);
583 set_buffer_uptodate(bh);
584 clear_buffer_dirty(bh);
587 gfs2_ail1_empty(sdp, 0);
588 tail = current_tail(sdp);
590 lh = (struct gfs2_log_header *)bh->b_data;
591 memset(lh, 0, sizeof(struct gfs2_log_header));
592 lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
593 lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
594 lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
595 lh->lh_sequence = cpu_to_be64(sdp->sd_log_sequence++);
596 lh->lh_flags = cpu_to_be32(flags);
597 lh->lh_tail = cpu_to_be32(tail);
598 lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head);
599 hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header));
600 lh->lh_hash = cpu_to_be32(hash);
602 set_buffer_dirty(bh);
603 if (sync_dirty_buffer(bh))
604 gfs2_io_error_bh(sdp, bh);
607 if (sdp->sd_log_tail != tail)
608 log_pull_tail(sdp, tail);
610 gfs2_assert_withdraw(sdp, !pull);
612 sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
613 gfs2_log_incr_head(sdp);
616 static void log_flush_commit(struct gfs2_sbd *sdp)
620 if (atomic_read(&sdp->sd_log_in_flight)) {
622 prepare_to_wait(&sdp->sd_log_flush_wait, &wait,
623 TASK_UNINTERRUPTIBLE);
624 if (atomic_read(&sdp->sd_log_in_flight))
626 } while(atomic_read(&sdp->sd_log_in_flight));
627 finish_wait(&sdp->sd_log_flush_wait, &wait);
630 log_write_header(sdp, 0, 0);
633 static void gfs2_ordered_write(struct gfs2_sbd *sdp)
635 struct gfs2_bufdata *bd;
636 struct buffer_head *bh;
640 while (!list_empty(&sdp->sd_log_le_ordered)) {
641 bd = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_bufdata, bd_le.le_list);
642 list_move(&bd->bd_le.le_list, &written);
644 if (!buffer_dirty(bh))
647 gfs2_log_unlock(sdp);
649 if (buffer_mapped(bh) && test_clear_buffer_dirty(bh)) {
650 bh->b_end_io = end_buffer_write_sync;
651 submit_bh(WRITE, bh);
658 list_splice(&written, &sdp->sd_log_le_ordered);
659 gfs2_log_unlock(sdp);
662 static void gfs2_ordered_wait(struct gfs2_sbd *sdp)
664 struct gfs2_bufdata *bd;
665 struct buffer_head *bh;
668 while (!list_empty(&sdp->sd_log_le_ordered)) {
669 bd = list_entry(sdp->sd_log_le_ordered.prev, struct gfs2_bufdata, bd_le.le_list);
671 if (buffer_locked(bh)) {
673 gfs2_log_unlock(sdp);
679 list_del_init(&bd->bd_le.le_list);
681 gfs2_log_unlock(sdp);
685 * gfs2_log_flush - flush incore transaction(s)
686 * @sdp: the filesystem
687 * @gl: The glock structure to flush. If NULL, flush the whole incore log
691 void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
695 down_write(&sdp->sd_log_flush_lock);
697 /* Log might have been flushed while we waited for the flush lock */
698 if (gl && !test_bit(GLF_LFLUSH, &gl->gl_flags)) {
699 up_write(&sdp->sd_log_flush_lock);
703 ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL);
704 INIT_LIST_HEAD(&ai->ai_ail1_list);
705 INIT_LIST_HEAD(&ai->ai_ail2_list);
707 if (sdp->sd_log_num_buf != sdp->sd_log_commited_buf) {
708 printk(KERN_INFO "GFS2: log buf %u %u\n", sdp->sd_log_num_buf,
709 sdp->sd_log_commited_buf);
710 gfs2_assert_withdraw(sdp, 0);
712 if (sdp->sd_log_num_databuf != sdp->sd_log_commited_databuf) {
713 printk(KERN_INFO "GFS2: log databuf %u %u\n",
714 sdp->sd_log_num_databuf, sdp->sd_log_commited_databuf);
715 gfs2_assert_withdraw(sdp, 0);
717 gfs2_assert_withdraw(sdp,
718 sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke);
720 sdp->sd_log_flush_head = sdp->sd_log_head;
721 sdp->sd_log_flush_wrapped = 0;
722 ai->ai_first = sdp->sd_log_flush_head;
724 gfs2_ordered_write(sdp);
725 lops_before_commit(sdp);
726 gfs2_ordered_wait(sdp);
728 if (sdp->sd_log_head != sdp->sd_log_flush_head)
729 log_flush_commit(sdp);
730 else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){
732 atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */
733 gfs2_log_unlock(sdp);
734 log_write_header(sdp, 0, PULL);
736 lops_after_commit(sdp, ai);
739 sdp->sd_log_head = sdp->sd_log_flush_head;
740 sdp->sd_log_blks_reserved = 0;
741 sdp->sd_log_commited_buf = 0;
742 sdp->sd_log_commited_databuf = 0;
743 sdp->sd_log_commited_revoke = 0;
745 if (!list_empty(&ai->ai_ail1_list)) {
746 list_add(&ai->ai_list, &sdp->sd_ail1_list);
749 gfs2_log_unlock(sdp);
751 sdp->sd_vfs->s_dirt = 0;
752 up_write(&sdp->sd_log_flush_lock);
757 static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
759 unsigned int reserved;
764 sdp->sd_log_commited_buf += tr->tr_num_buf_new - tr->tr_num_buf_rm;
765 sdp->sd_log_commited_databuf += tr->tr_num_databuf_new -
766 tr->tr_num_databuf_rm;
767 gfs2_assert_withdraw(sdp, (((int)sdp->sd_log_commited_buf) >= 0) ||
768 (((int)sdp->sd_log_commited_databuf) >= 0));
769 sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm;
770 gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0);
771 reserved = calc_reserved(sdp);
772 gfs2_assert_withdraw(sdp, sdp->sd_log_blks_reserved + tr->tr_reserved >= reserved);
773 unused = sdp->sd_log_blks_reserved - reserved + tr->tr_reserved;
774 atomic_add(unused, &sdp->sd_log_blks_free);
775 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <=
776 sdp->sd_jdesc->jd_blocks);
777 sdp->sd_log_blks_reserved = reserved;
779 gfs2_log_unlock(sdp);
782 static void buf_lo_incore_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
784 struct list_head *head = &tr->tr_list_buf;
785 struct gfs2_bufdata *bd;
788 while (!list_empty(head)) {
789 bd = list_entry(head->next, struct gfs2_bufdata, bd_list_tr);
790 list_del_init(&bd->bd_list_tr);
793 gfs2_log_unlock(sdp);
794 gfs2_assert_warn(sdp, !tr->tr_num_buf);
798 * gfs2_log_commit - Commit a transaction to the log
799 * @sdp: the filesystem
800 * @tr: the transaction
805 void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
808 buf_lo_incore_commit(sdp, tr);
810 sdp->sd_vfs->s_dirt = 1;
811 up_read(&sdp->sd_log_flush_lock);
814 if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks))
815 wake_up_process(sdp->sd_logd_process);
816 gfs2_log_unlock(sdp);
820 * gfs2_log_shutdown - write a shutdown header into a journal
821 * @sdp: the filesystem
825 void gfs2_log_shutdown(struct gfs2_sbd *sdp)
827 down_write(&sdp->sd_log_flush_lock);
829 gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved);
830 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf);
831 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
832 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg);
833 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf);
834 gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list));
836 sdp->sd_log_flush_head = sdp->sd_log_head;
837 sdp->sd_log_flush_wrapped = 0;
839 log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT,
840 (sdp->sd_log_tail == current_tail(sdp)) ? 0 : PULL);
842 gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks);
843 gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail);
844 gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list));
846 sdp->sd_log_head = sdp->sd_log_flush_head;
847 sdp->sd_log_tail = sdp->sd_log_head;
849 up_write(&sdp->sd_log_flush_lock);
854 * gfs2_meta_syncfs - sync all the buffers in a filesystem
855 * @sdp: the filesystem
859 void gfs2_meta_syncfs(struct gfs2_sbd *sdp)
861 gfs2_log_flush(sdp, NULL);
863 gfs2_ail1_start(sdp, DIO_ALL);
864 if (gfs2_ail1_empty(sdp, DIO_ALL))
872 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
873 * @sdp: Pointer to GFS2 superblock
875 * Also, periodically check to make sure that we're using the most recent
879 int gfs2_logd(void *data)
881 struct gfs2_sbd *sdp = data;
885 while (!kthread_should_stop()) {
886 /* Advance the log tail */
888 t = sdp->sd_log_flush_time +
889 gfs2_tune_get(sdp, gt_log_flush_secs) * HZ;
891 gfs2_ail1_empty(sdp, DIO_ALL);
893 need_flush = sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks);
894 gfs2_log_unlock(sdp);
895 if (need_flush || time_after_eq(jiffies, t)) {
896 gfs2_log_flush(sdp, NULL);
897 sdp->sd_log_flush_time = jiffies;
900 t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
901 if (freezing(current))
903 schedule_timeout_interruptible(t);