GFS2: Daemons and address space operations
Subsystems (2)
PATCH 4/16 GFS2: Daemons and address space operations
[PATCH 04/16] GFS2: Daemons and address space operations
The GFS2 kernel threads, logging operations and page cache interface code.
fs/gfs2/daemon.c | 229 ++++++++++++ fs/gfs2/daemon.h | 20 + fs/gfs2/lops.c | 805 +++++++++++++++++++++++++++++++++++++++++++++ fs/gfs2/lops.h | 96 +++++ fs/gfs2/main.c | 114 ++++++ fs/gfs2/meta_io.c | 889 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/gfs2/meta_io.h | 89 +++++ fs/gfs2/ondisk.c | 517 +++++++++++++++++++++++++++++ fs/gfs2/ops_address.c | 582 ++++++++++++++++++++++++++++++++ fs/gfs2/ops_address.h | 17 10 files changed, 3358 insertions(+)
fs/gfs2/daemon.c new file +229 -0
@@ -0,0 +1,229 @@ +/* +* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +* Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +*/ + +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/completion.h> +#include <linux/buffer_head.h> +#include <linux/kthread.h> +#include <linux/delay.h> +#include <linux/gfs2_ondisk.h> +#include <asm/semaphore.h> + +#include "gfs2.h" +#include "lm_interface.h" +#include "incore.h" +#include "daemon.h" +#include "glock.h" +#include "log.h" +#include "quota.h" +#include "recovery.h" +#include "super.h" +#include "unlinked.h" +#include "util.h" + +/* This uses schedule_timeout() instead of msleep() because it's good for +the daemons to wake up more often than the timeout when unmounting so +the user's unmount doesn't sit there forever. ++ The kthread functions used to start these daemons block and flush signals. */ + +/** +* gfs2_scand - Look for cached glocks and inodes to toss from memory +* @sdp: Pointer to GFS2 superblock +* +* One of these daemons runs, finding candidates to add to sd_reclaim_list. +* See gfs2_glockd() +*/ + +int gfs2_scand (void *data) +{ +struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; +unsigned long t; + +while (!kthread_should_stop ()) { +gfs2_scand_internal (sdp); + t =gfs2_tune_get (sdp, gt_scand_secs) *HZ ; +schedule_timeout_interruptible (t); + } + +return 0 ; +} + +/** +* gfs2_glockd - Reclaim unused glock structures +* @sdp: Pointer to GFS2 superblock +* +* One or more of these daemons run, reclaiming glocks on sd_reclaim_list. +* Number of daemons can be set by user, with num_glockd mount option. +*/ + +int gfs2_glockd (void *data) +{ +struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; +DECLARE_WAITQUEUE (wait_chan, current); + +while (!kthread_should_stop ()) { +while (atomic_read (&sdp->sd_reclaim_count)) +gfs2_reclaim_glock (sdp); + +set_current_state (TASK_INTERRUPTIBLE ); +add_wait_queue (&sdp->sd_reclaim_wq, &wait_chan); +if (!atomic_read (&sdp->sd_reclaim_count) && + !kthread_should_stop ()) +schedule (); +remove_wait_queue (&sdp->sd_reclaim_wq, &wait_chan); +set_current_state (TASK_RUNNING ); + } + +return 0 ; +} + +/** +* gfs2_recoverd - Recover dead machine's journals +* @sdp: Pointer to GFS2 superblock +* +*/ + +int gfs2_recoverd (void *data) +{ +struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; +unsigned long t; + +while (!kthread_should_stop ()) { +gfs2_check_journals (sdp); + t =gfs2_tune_get (sdp, gt_recoverd_secs) *HZ ; +schedule_timeout_interruptible (t); + } + +return 0 ; +} + +/** +* gfs2_logd - Update log tail as Active Items get flushed to in-place blocks +* @sdp: Pointer to GFS2 superblock +* +* Also, periodically check to make sure that we're using the most recent +* journal index. +*/ + +int gfs2_logd (void *data) +{ +struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; +struct gfs2_holder ji_gh; +unsigned long t; + +while (!kthread_should_stop ()) { +/* Advance the log tail */ + + t = sdp->sd_log_flush_time + +gfs2_tune_get (sdp, gt_log_flush_secs) *HZ ; + +gfs2_ail1_empty (sdp,DIO_ALL ); + +if (time_after_eq (jiffies, t)) { +gfs2_log_flush (sdp,NULL ); + sdp->sd_log_flush_time = jiffies; + } + +/* Check for latest journal index */ + + t = sdp->sd_jindex_refresh_time + +gfs2_tune_get (sdp, gt_jindex_refresh_secs) *HZ ; + +if (time_after_eq (jiffies, t)) { +if (!gfs2_jindex_hold (sdp, &ji_gh)) +gfs2_glock_dq_uninit (&ji_gh); + sdp->sd_jindex_refresh_time = jiffies; + } + + t =gfs2_tune_get (sdp, gt_logd_secs) *HZ ; +schedule_timeout_interruptible (t); + } + +return 0 ; +} + +/** +* gfs2_quotad - Write cached quota changes into the quota file +* @sdp: Pointer to GFS2 superblock +* +*/ + +int gfs2_quotad (void *data) +{ +struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; +unsigned long t; +int error; + +while (!kthread_should_stop ()) { +/* Update the master statfs file */ + + t = sdp->sd_statfs_sync_time + +gfs2_tune_get (sdp, gt_statfs_quantum) *HZ ; + +if (time_after_eq (jiffies, t)) { + error =gfs2_statfs_sync (sdp); +if (error && + error != -EROFS && + !test_bit (SDF_SHUTDOWN , &sdp->sd_flags)) +fs_err (sdp,"quotad: (1) error=%d\n" , error); + sdp->sd_statfs_sync_time = jiffies; + } + +/* Update quota file */ + + t = sdp->sd_quota_sync_time + +gfs2_tune_get (sdp, gt_quota_quantum) *HZ ; + +if (time_after_eq (jiffies, t)) { + error =gfs2_quota_sync (sdp); +if (error && + error != -EROFS && + !test_bit (SDF_SHUTDOWN , &sdp->sd_flags)) +fs_err (sdp,"quotad: (2) error=%d\n" , error); + sdp->sd_quota_sync_time = jiffies; + } + +gfs2_quota_scan (sdp); + + t =gfs2_tune_get (sdp, gt_quotad_secs) *HZ ; +schedule_timeout_interruptible (t); + } + +return 0 ; +} + +/** +* gfs2_inoded - Deallocate unlinked inodes +* @sdp: Pointer to GFS2 superblock +* +*/ + +int gfs2_inoded (void *data) +{ +struct gfs2_sbd *sdp = (struct gfs2_sbd *)data; +unsigned long t; +int error; + +while (!kthread_should_stop ()) { + error =gfs2_unlinked_dealloc (sdp); +if (error && + error != -EROFS && + !test_bit (SDF_SHUTDOWN , &sdp->sd_flags)) +fs_err (sdp,"inoded: error = %d\n" , error); + + t =gfs2_tune_get (sdp, gt_inoded_secs) *HZ ; +schedule_timeout_interruptible (t); + } + +return 0 ; +} +
fs/gfs2/daemon.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +* Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +*/ + +#ifndef __DAEMON_DOT_H__ +#define __DAEMON_DOT_H__ + +int gfs2_scand (void *data); +int gfs2_glockd (void *data); +int gfs2_recoverd (void *data); +int gfs2_logd (void *data); +int gfs2_quotad (void *data); +int gfs2_inoded (void *data); + +#endif /* __DAEMON_DOT_H__ */
fs/gfs2/lops.c new file +805 -0
805 lines not on this page · raw message
fs/gfs2/lops.h new file +96 -0
96 lines not on this page · raw message
fs/gfs2/main.c new file +114 -0
114 lines not on this page · raw message
fs/gfs2/meta_io.c new file +889 -0
889 lines not on this page · raw message
fs/gfs2/meta_io.h new file +89 -0
89 lines not on this page · raw message
fs/gfs2/ondisk.c new file +517 -0
517 lines not on this page · raw message
fs/gfs2/ops_address.c new file +582 -0
241 lines not on this page · raw message
fs/gfs2/ops_address.h new file +17 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Steven Whitehouse wrote
Quoted 18 lines
fs/gfs2/ops_address.c new file +15
-0+static int gfs2_writepage (struct page *page,struct writeback_control *wbc) +{ +struct inode *inode = page->mapping->host; +struct gfs2_inode *ip = page->mapping->host->u.generic_ip; +struct gfs2_sbd *sdp = ip->i_sbd; +loff_t i_size =i_size_read (inode); +pgoff_t end_index = i_size >>PAGE_CACHE_SHIFT ; +unsigned offset; +int error; +int done_trans =0 ; + +if (gfs2_assert_withdraw (sdp,gfs2_glock_is_held_excl (ip->i_gl))) { +unlock_page (page); +return -EIO ; + }
fs/gfs2/ops_address.c line 133
Quoted 10 lines
fs/gfs2/ops_address.c new file +10
-0+if (current->journal_info) + goto out_ignore; + +/* Is the page fully outside i_size? (truncate in progress) */ + offset = i_size & (PAGE_CACHE_SIZE -1 ); +if (page->index >= end_index+1 || !offset) { + page->mapping->a_ops->invalidatepage (page,0 ); +unlock_page (page); +return 0 ;/* don't care */ + }
Will above "|| !offset" unconditionally drop the page if the file size happens to be multiples of PAGE_CACHE_SIZE ? Maybe this truncate handling should be removed to let block_write_full_page() handle all the cases ?
Quoted 4 lines
fs/gfs2/ops_address.c new file +2
-0+ error =block_write_full_page (page, get_block_noalloc, wbc); +if (done_trans)
fs/gfs2/ops_address.c line 153
Quoted 10 lines
fs/gfs2/ops_address.c new file +10
-0+gfs2_trans_end (sdp); +gfs2_meta_cache_flush (ip); +return error; + +out_ignore: +redirty_page_for_writepage (wbc, page); +unlock_page (page); +return 0 ; +} +
-- Wendy
Hi,
Quoted 26 lines · Wendy Cheng
Steven Whitehouse wrote
Quoted 24 lines
fs/gfs2/ops_address.c new file +24
-0+static int gfs2_writepage (struct page *page,struct writeback_control *wbc) +{ +struct inode *inode = page->mapping->host; +struct gfs2_inode *ip = page->mapping->host->u.generic_ip; +struct gfs2_sbd *sdp = ip->i_sbd; +loff_t i_size =i_size_read (inode); +pgoff_t end_index = i_size >>PAGE_CACHE_SHIFT ; +unsigned offset; +int error; +int done_trans =0 ; + +if (gfs2_assert_withdraw (sdp,gfs2_glock_is_held_excl (ip->i_gl))) { +unlock_page (page); +return -EIO ; + } +if (current->journal_info) + goto out_ignore; + +/* Is the page fully outside i_size? (truncate in progress) */ + offset = i_size & (PAGE_CACHE_SIZE -1 ); +if (page->index >= end_index+1 || !offset) { + page->mapping->a_ops->invalidatepage (page,0 ); +unlock_page (page); +return 0 ;/* don't care */
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +1
-0+ }Will above "|| !offset" unconditionally drop the page if the file size happens to be multiples of
PAGE_CACHE_SIZE? Maybe this truncate handling should be removed to letblock_write_full_page()handle all the cases ?
This test was incorrectly borrowed from block_write_full_page in order that we would avoid having to start a transaction, or add buffers to pages, in case the page had already been truncated. I've just pushed a patch to fix this:
Steve.