2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 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>
36 * gfs2_struct2blk - compute stuff
37 * @sdp: the filesystem
38 * @nstruct: the number of structures
39 * @ssize: the size of the structures
41 * Compute the number of log descriptor blocks needed to hold a certain number
42 * of structures of a certain size.
44 * Returns: the number of blocks needed (minimum is always 1)
47 unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
51 unsigned int first, second;
54 first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / ssize;
56 if (nstruct > first) {
57 second = (sdp->sd_sb.sb_bsize -
58 sizeof(struct gfs2_meta_header)) / ssize;
59 blks += DIV_ROUND_UP(nstruct - first, second);
66 * gfs2_remove_from_ail - Remove an entry from the ail lists, updating counters
67 * @mapping: The associated mapping (maybe NULL)
68 * @bd: The gfs2_bufdata to remove
70 * The log lock _must_ be held when calling this function
74 void gfs2_remove_from_ail(struct gfs2_bufdata *bd)
77 list_del_init(&bd->bd_ail_st_list);
78 list_del_init(&bd->bd_ail_gl_list);
79 atomic_dec(&bd->bd_gl->gl_ail_count);
84 * gfs2_ail1_start_one - Start I/O on a part of the AIL
85 * @sdp: the filesystem
86 * @tr: the part of the AIL
90 static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
92 struct gfs2_bufdata *bd, *s;
93 struct buffer_head *bh;
96 BUG_ON(!spin_is_locked(&sdp->sd_log_lock));
101 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
105 gfs2_assert(sdp, bd->bd_ail == ai);
107 if (!buffer_busy(bh)) {
108 if (!buffer_uptodate(bh))
109 gfs2_io_error_bh(sdp, bh);
110 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
114 if (!buffer_dirty(bh))
117 list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list);
120 gfs2_log_unlock(sdp);
122 if (test_clear_buffer_dirty(bh)) {
123 bh->b_end_io = end_buffer_write_sync;
124 submit_bh(WRITE, bh);
138 * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced
139 * @sdp: the filesystem
144 static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags)
146 struct gfs2_bufdata *bd, *s;
147 struct buffer_head *bh;
149 list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
153 gfs2_assert(sdp, bd->bd_ail == ai);
155 if (buffer_busy(bh)) {
162 if (!buffer_uptodate(bh))
163 gfs2_io_error_bh(sdp, bh);
165 list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
168 return list_empty(&ai->ai_ail1_list);
171 static void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags)
173 struct list_head *head;
175 struct list_head *first;
176 struct gfs2_ail *first_ai, *ai, *tmp;
180 head = &sdp->sd_ail1_list;
181 if (list_empty(head)) {
182 gfs2_log_unlock(sdp);
185 sync_gen = sdp->sd_ail_sync_gen++;
188 first_ai = list_entry(first, struct gfs2_ail, ai_list);
189 first_ai->ai_sync_gen = sync_gen;
190 gfs2_ail1_start_one(sdp, first_ai); /* This may drop log lock */
196 if (first && (head->prev != first ||
197 gfs2_ail1_empty_one(sdp, first_ai, 0)))
201 list_for_each_entry_safe_reverse(ai, tmp, head, ai_list) {
202 if (ai->ai_sync_gen >= sync_gen)
204 ai->ai_sync_gen = sync_gen;
205 gfs2_ail1_start_one(sdp, ai); /* This may drop log lock */
211 gfs2_log_unlock(sdp);
214 static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
216 struct gfs2_ail *ai, *s;
221 list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) {
222 if (gfs2_ail1_empty_one(sdp, ai, flags))
223 list_move(&ai->ai_list, &sdp->sd_ail2_list);
224 else if (!(flags & DIO_ALL))
228 ret = list_empty(&sdp->sd_ail1_list);
230 gfs2_log_unlock(sdp);
237 * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced
238 * @sdp: the filesystem
243 static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
245 struct list_head *head = &ai->ai_ail2_list;
246 struct gfs2_bufdata *bd;
248 while (!list_empty(head)) {
249 bd = list_entry(head->prev, struct gfs2_bufdata,
251 gfs2_assert(sdp, bd->bd_ail == ai);
252 gfs2_remove_from_ail(bd);
256 static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
258 struct gfs2_ail *ai, *safe;
259 unsigned int old_tail = sdp->sd_log_tail;
260 int wrap = (new_tail < old_tail);
265 list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) {
266 a = (old_tail <= ai->ai_first);
267 b = (ai->ai_first < new_tail);
268 rm = (wrap) ? (a || b) : (a && b);
272 gfs2_ail2_empty_one(sdp, ai);
273 list_del(&ai->ai_list);
274 gfs2_assert_warn(sdp, list_empty(&ai->ai_ail1_list));
275 gfs2_assert_warn(sdp, list_empty(&ai->ai_ail2_list));
279 gfs2_log_unlock(sdp);
283 * gfs2_log_reserve - Make a log reservation
284 * @sdp: The GFS2 superblock
285 * @blks: The number of blocks to reserve
287 * Note that we never give out the last few blocks of the journal. Thats
288 * due to the fact that there is a small number of header blocks
289 * associated with each log flush. The exact number can't be known until
290 * flush time, so we ensure that we have just enough free blocks at all
291 * times to avoid running out during a log flush.
296 int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
298 unsigned int try = 0;
299 unsigned reserved_blks = 6 * (4096 / sdp->sd_vfs->s_blocksize);
301 if (gfs2_assert_warn(sdp, blks) ||
302 gfs2_assert_warn(sdp, blks <= sdp->sd_jdesc->jd_blocks))
305 mutex_lock(&sdp->sd_log_reserve_mutex);
307 while(atomic_read(&sdp->sd_log_blks_free) <= (blks + reserved_blks)) {
308 gfs2_log_unlock(sdp);
309 gfs2_ail1_empty(sdp, 0);
310 gfs2_log_flush(sdp, NULL);
313 gfs2_ail1_start(sdp, 0);
316 atomic_sub(blks, &sdp->sd_log_blks_free);
317 gfs2_log_unlock(sdp);
318 mutex_unlock(&sdp->sd_log_reserve_mutex);
320 down_read(&sdp->sd_log_flush_lock);
326 * gfs2_log_release - Release a given number of log blocks
327 * @sdp: The GFS2 superblock
328 * @blks: The number of blocks
332 void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
336 atomic_add(blks, &sdp->sd_log_blks_free);
337 gfs2_assert_withdraw(sdp,
338 atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks);
339 gfs2_log_unlock(sdp);
340 up_read(&sdp->sd_log_flush_lock);
343 static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn)
345 struct inode *inode = sdp->sd_jdesc->jd_inode;
347 struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 };
349 bh_map.b_size = 1 << inode->i_blkbits;
350 error = gfs2_block_map(inode, lbn, 0, &bh_map);
351 if (error || !bh_map.b_blocknr)
352 printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error,
353 (unsigned long long)bh_map.b_blocknr, lbn);
354 gfs2_assert_withdraw(sdp, !error && bh_map.b_blocknr);
356 return bh_map.b_blocknr;
360 * log_distance - Compute distance between two journal blocks
361 * @sdp: The GFS2 superblock
362 * @newer: The most recent journal block of the pair
363 * @older: The older journal block of the pair
365 * Compute the distance (in the journal direction) between two
366 * blocks in the journal
368 * Returns: the distance in blocks
371 static inline unsigned int log_distance(struct gfs2_sbd *sdp, unsigned int newer,
376 dist = newer - older;
378 dist += sdp->sd_jdesc->jd_blocks;
384 * calc_reserved - Calculate the number of blocks to reserve when
385 * refunding a transaction's unused buffers.
386 * @sdp: The GFS2 superblock
388 * This is complex. We need to reserve room for all our currently used
389 * metadata buffers (e.g. normal file I/O rewriting file time stamps) and
390 * all our journaled data buffers for journaled files (e.g. files in the
391 * meta_fs like rindex, or files for which chattr +j was done.)
392 * If we don't reserve enough space, gfs2_log_refund and gfs2_log_flush
393 * will count it as free space (sd_log_blks_free) and corruption will follow.
395 * We can have metadata bufs and jdata bufs in the same journal. So each
396 * type gets its own log header, for which we need to reserve a block.
397 * In fact, each type has the potential for needing more than one header
398 * in cases where we have more buffers than will fit on a journal page.
399 * Metadata journal entries take up half the space of journaled buffer entries.
400 * Thus, metadata entries have buf_limit (502) and journaled buffers have
401 * databuf_limit (251) before they cause a wrap around.
403 * Also, we need to reserve blocks for revoke journal entries and one for an
404 * overall header for the lot.
406 * Returns: the number of blocks reserved
408 static unsigned int calc_reserved(struct gfs2_sbd *sdp)
410 unsigned int reserved = 0;
411 unsigned int mbuf_limit, metabufhdrs_needed;
412 unsigned int dbuf_limit, databufhdrs_needed;
413 unsigned int revokes = 0;
415 mbuf_limit = buf_limit(sdp);
416 metabufhdrs_needed = (sdp->sd_log_commited_buf +
417 (mbuf_limit - 1)) / mbuf_limit;
418 dbuf_limit = databuf_limit(sdp);
419 databufhdrs_needed = (sdp->sd_log_commited_databuf +
420 (dbuf_limit - 1)) / dbuf_limit;
422 if (sdp->sd_log_commited_revoke)
423 revokes = gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke,
426 reserved = sdp->sd_log_commited_buf + metabufhdrs_needed +
427 sdp->sd_log_commited_databuf + databufhdrs_needed +
429 /* One for the overall header */
435 static unsigned int current_tail(struct gfs2_sbd *sdp)
442 if (list_empty(&sdp->sd_ail1_list)) {
443 tail = sdp->sd_log_head;
445 ai = list_entry(sdp->sd_ail1_list.prev, struct gfs2_ail, ai_list);
449 gfs2_log_unlock(sdp);
454 void gfs2_log_incr_head(struct gfs2_sbd *sdp)
456 if (sdp->sd_log_flush_head == sdp->sd_log_tail)
457 BUG_ON(sdp->sd_log_flush_head != sdp->sd_log_head);
459 if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) {
460 sdp->sd_log_flush_head = 0;
461 sdp->sd_log_flush_wrapped = 1;
466 * gfs2_log_write_endio - End of I/O for a log buffer
467 * @bh: The buffer head
468 * @uptodate: I/O Status
472 static void gfs2_log_write_endio(struct buffer_head *bh, int uptodate)
474 struct gfs2_sbd *sdp = bh->b_private;
475 bh->b_private = NULL;
477 end_buffer_write_sync(bh, uptodate);
478 if (atomic_dec_and_test(&sdp->sd_log_in_flight))
479 wake_up(&sdp->sd_log_flush_wait);
483 * gfs2_log_get_buf - Get and initialize a buffer to use for log control data
484 * @sdp: The GFS2 superblock
486 * Returns: the buffer_head
489 struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp)
491 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
492 struct buffer_head *bh;
494 bh = sb_getblk(sdp->sd_vfs, blkno);
496 memset(bh->b_data, 0, bh->b_size);
497 set_buffer_uptodate(bh);
498 clear_buffer_dirty(bh);
499 gfs2_log_incr_head(sdp);
500 atomic_inc(&sdp->sd_log_in_flight);
502 bh->b_end_io = gfs2_log_write_endio;
508 * gfs2_fake_write_endio -
509 * @bh: The buffer head
510 * @uptodate: The I/O Status
514 static void gfs2_fake_write_endio(struct buffer_head *bh, int uptodate)
516 struct buffer_head *real_bh = bh->b_private;
517 struct gfs2_bufdata *bd = real_bh->b_private;
518 struct gfs2_sbd *sdp = bd->bd_gl->gl_sbd;
520 end_buffer_write_sync(bh, uptodate);
521 free_buffer_head(bh);
522 unlock_buffer(real_bh);
524 if (atomic_dec_and_test(&sdp->sd_log_in_flight))
525 wake_up(&sdp->sd_log_flush_wait);
529 * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log
530 * @sdp: the filesystem
531 * @data: the data the buffer_head should point to
533 * Returns: the log buffer descriptor
536 struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp,
537 struct buffer_head *real)
539 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
540 struct buffer_head *bh;
542 bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL);
543 atomic_set(&bh->b_count, 1);
544 bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate) | (1 << BH_Lock);
545 set_bh_page(bh, real->b_page, bh_offset(real));
546 bh->b_blocknr = blkno;
547 bh->b_size = sdp->sd_sb.sb_bsize;
548 bh->b_bdev = sdp->sd_vfs->s_bdev;
549 bh->b_private = real;
550 bh->b_end_io = gfs2_fake_write_endio;
552 gfs2_log_incr_head(sdp);
553 atomic_inc(&sdp->sd_log_in_flight);
558 static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail)
560 unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail);
562 ail2_empty(sdp, new_tail);
565 atomic_add(dist, &sdp->sd_log_blks_free);
566 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks);
567 gfs2_log_unlock(sdp);
569 sdp->sd_log_tail = new_tail;
573 * log_write_header - Get and initialize a journal header buffer
574 * @sdp: The GFS2 superblock
576 * Returns: the initialized log buffer descriptor
579 static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull)
581 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
582 struct buffer_head *bh;
583 struct gfs2_log_header *lh;
587 bh = sb_getblk(sdp->sd_vfs, blkno);
589 memset(bh->b_data, 0, bh->b_size);
590 set_buffer_uptodate(bh);
591 clear_buffer_dirty(bh);
594 gfs2_ail1_empty(sdp, 0);
595 tail = current_tail(sdp);
597 lh = (struct gfs2_log_header *)bh->b_data;
598 memset(lh, 0, sizeof(struct gfs2_log_header));
599 lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
600 lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
601 lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
602 lh->lh_sequence = cpu_to_be64(sdp->sd_log_sequence++);
603 lh->lh_flags = cpu_to_be32(flags);
604 lh->lh_tail = cpu_to_be32(tail);
605 lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head);
606 hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header));
607 lh->lh_hash = cpu_to_be32(hash);
609 set_buffer_dirty(bh);
610 if (sync_dirty_buffer(bh))
611 gfs2_io_error_bh(sdp, bh);
614 if (sdp->sd_log_tail != tail)
615 log_pull_tail(sdp, tail);
617 gfs2_assert_withdraw(sdp, !pull);
619 sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
620 gfs2_log_incr_head(sdp);
623 static void log_flush_commit(struct gfs2_sbd *sdp)
627 if (atomic_read(&sdp->sd_log_in_flight)) {
629 prepare_to_wait(&sdp->sd_log_flush_wait, &wait,
630 TASK_UNINTERRUPTIBLE);
631 if (atomic_read(&sdp->sd_log_in_flight))
633 } while(atomic_read(&sdp->sd_log_in_flight));
634 finish_wait(&sdp->sd_log_flush_wait, &wait);
637 log_write_header(sdp, 0, 0);
640 static void gfs2_ordered_write(struct gfs2_sbd *sdp)
642 struct gfs2_bufdata *bd;
643 struct buffer_head *bh;
647 while (!list_empty(&sdp->sd_log_le_ordered)) {
648 bd = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_bufdata, bd_le.le_list);
649 list_move(&bd->bd_le.le_list, &written);
651 if (!buffer_dirty(bh))
654 gfs2_log_unlock(sdp);
656 if (buffer_mapped(bh) && test_clear_buffer_dirty(bh)) {
657 bh->b_end_io = end_buffer_write_sync;
658 submit_bh(WRITE, bh);
665 list_splice(&written, &sdp->sd_log_le_ordered);
666 gfs2_log_unlock(sdp);
669 static void gfs2_ordered_wait(struct gfs2_sbd *sdp)
671 struct gfs2_bufdata *bd;
672 struct buffer_head *bh;
675 while (!list_empty(&sdp->sd_log_le_ordered)) {
676 bd = list_entry(sdp->sd_log_le_ordered.prev, struct gfs2_bufdata, bd_le.le_list);
678 if (buffer_locked(bh)) {
680 gfs2_log_unlock(sdp);
686 list_del_init(&bd->bd_le.le_list);
688 gfs2_log_unlock(sdp);
692 * gfs2_log_flush - flush incore transaction(s)
693 * @sdp: the filesystem
694 * @gl: The glock structure to flush. If NULL, flush the whole incore log
698 void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
702 down_write(&sdp->sd_log_flush_lock);
704 /* Log might have been flushed while we waited for the flush lock */
705 if (gl && !test_bit(GLF_LFLUSH, &gl->gl_flags)) {
706 up_write(&sdp->sd_log_flush_lock);
710 ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL);
711 INIT_LIST_HEAD(&ai->ai_ail1_list);
712 INIT_LIST_HEAD(&ai->ai_ail2_list);
714 if (sdp->sd_log_num_buf != sdp->sd_log_commited_buf) {
715 printk(KERN_INFO "GFS2: log buf %u %u\n", sdp->sd_log_num_buf,
716 sdp->sd_log_commited_buf);
717 gfs2_assert_withdraw(sdp, 0);
719 if (sdp->sd_log_num_databuf != sdp->sd_log_commited_databuf) {
720 printk(KERN_INFO "GFS2: log databuf %u %u\n",
721 sdp->sd_log_num_databuf, sdp->sd_log_commited_databuf);
722 gfs2_assert_withdraw(sdp, 0);
724 gfs2_assert_withdraw(sdp,
725 sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke);
727 sdp->sd_log_flush_head = sdp->sd_log_head;
728 sdp->sd_log_flush_wrapped = 0;
729 ai->ai_first = sdp->sd_log_flush_head;
731 gfs2_ordered_write(sdp);
732 lops_before_commit(sdp);
733 gfs2_ordered_wait(sdp);
735 if (sdp->sd_log_head != sdp->sd_log_flush_head)
736 log_flush_commit(sdp);
737 else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){
739 atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */
740 gfs2_log_unlock(sdp);
741 log_write_header(sdp, 0, PULL);
743 lops_after_commit(sdp, ai);
746 sdp->sd_log_head = sdp->sd_log_flush_head;
747 sdp->sd_log_blks_reserved = 0;
748 sdp->sd_log_commited_buf = 0;
749 sdp->sd_log_commited_databuf = 0;
750 sdp->sd_log_commited_revoke = 0;
752 if (!list_empty(&ai->ai_ail1_list)) {
753 list_add(&ai->ai_list, &sdp->sd_ail1_list);
756 gfs2_log_unlock(sdp);
758 sdp->sd_vfs->s_dirt = 0;
759 up_write(&sdp->sd_log_flush_lock);
764 static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
766 unsigned int reserved;
771 sdp->sd_log_commited_buf += tr->tr_num_buf_new - tr->tr_num_buf_rm;
772 sdp->sd_log_commited_databuf += tr->tr_num_databuf_new -
773 tr->tr_num_databuf_rm;
774 gfs2_assert_withdraw(sdp, (((int)sdp->sd_log_commited_buf) >= 0) ||
775 (((int)sdp->sd_log_commited_databuf) >= 0));
776 sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm;
777 gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0);
778 reserved = calc_reserved(sdp);
779 old = atomic_read(&sdp->sd_log_blks_free);
780 atomic_add(tr->tr_reserved - (reserved - sdp->sd_log_blks_reserved),
781 &sdp->sd_log_blks_free);
783 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) >= old);
784 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <=
785 sdp->sd_jdesc->jd_blocks);
787 sdp->sd_log_blks_reserved = reserved;
789 gfs2_log_unlock(sdp);
793 * gfs2_log_commit - Commit a transaction to the log
794 * @sdp: the filesystem
795 * @tr: the transaction
800 void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
803 lops_incore_commit(sdp, tr);
805 sdp->sd_vfs->s_dirt = 1;
806 up_read(&sdp->sd_log_flush_lock);
809 if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks))
810 wake_up_process(sdp->sd_logd_process);
811 gfs2_log_unlock(sdp);
815 * gfs2_log_shutdown - write a shutdown header into a journal
816 * @sdp: the filesystem
820 void gfs2_log_shutdown(struct gfs2_sbd *sdp)
822 down_write(&sdp->sd_log_flush_lock);
824 gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved);
825 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf);
826 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
827 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg);
828 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf);
829 gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list));
831 sdp->sd_log_flush_head = sdp->sd_log_head;
832 sdp->sd_log_flush_wrapped = 0;
834 log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT,
835 (sdp->sd_log_tail == current_tail(sdp)) ? 0 : PULL);
837 gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks);
838 gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail);
839 gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list));
841 sdp->sd_log_head = sdp->sd_log_flush_head;
842 sdp->sd_log_tail = sdp->sd_log_head;
844 up_write(&sdp->sd_log_flush_lock);
849 * gfs2_meta_syncfs - sync all the buffers in a filesystem
850 * @sdp: the filesystem
854 void gfs2_meta_syncfs(struct gfs2_sbd *sdp)
856 gfs2_log_flush(sdp, NULL);
858 gfs2_ail1_start(sdp, DIO_ALL);
859 if (gfs2_ail1_empty(sdp, DIO_ALL))
867 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
868 * @sdp: Pointer to GFS2 superblock
870 * Also, periodically check to make sure that we're using the most recent
874 int gfs2_logd(void *data)
876 struct gfs2_sbd *sdp = data;
877 struct gfs2_holder ji_gh;
881 while (!kthread_should_stop()) {
882 /* Advance the log tail */
884 t = sdp->sd_log_flush_time +
885 gfs2_tune_get(sdp, gt_log_flush_secs) * HZ;
887 gfs2_ail1_empty(sdp, DIO_ALL);
889 need_flush = sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks);
890 gfs2_log_unlock(sdp);
891 if (need_flush || time_after_eq(jiffies, t)) {
892 gfs2_log_flush(sdp, NULL);
893 sdp->sd_log_flush_time = jiffies;
896 /* Check for latest journal index */
898 t = sdp->sd_jindex_refresh_time +
899 gfs2_tune_get(sdp, gt_jindex_refresh_secs) * HZ;
901 if (time_after_eq(jiffies, t)) {
902 if (!gfs2_jindex_hold(sdp, &ji_gh))
903 gfs2_glock_dq_uninit(&ji_gh);
904 sdp->sd_jindex_refresh_time = jiffies;
907 t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
908 if (freezing(current))
910 schedule_timeout_interruptible(t);