2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 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 v.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/kthread.h>
16 #include <linux/delay.h>
17 #include <asm/semaphore.h>
28 /* This uses schedule_timeout() instead of msleep() because it's good for
29 the daemons to wake up more often than the timeout when unmounting so
30 the user's unmount doesn't sit there forever.
32 The kthread functions used to start these daemons block and flush signals. */
35 * gfs2_scand - Look for cached glocks and inodes to toss from memory
36 * @sdp: Pointer to GFS2 superblock
38 * One of these daemons runs, finding candidates to add to sd_reclaim_list.
42 int gfs2_scand(void *data)
44 struct gfs2_sbd *sdp = (struct gfs2_sbd *)data;
47 while (!kthread_should_stop()) {
48 gfs2_scand_internal(sdp);
49 t = gfs2_tune_get(sdp, gt_scand_secs) * HZ;
50 schedule_timeout_interruptible(t);
57 * gfs2_glockd - Reclaim unused glock structures
58 * @sdp: Pointer to GFS2 superblock
60 * One or more of these daemons run, reclaiming glocks on sd_reclaim_list.
61 * Number of daemons can be set by user, with num_glockd mount option.
64 int gfs2_glockd(void *data)
66 struct gfs2_sbd *sdp = (struct gfs2_sbd *)data;
67 DECLARE_WAITQUEUE(wait_chan, current);
69 while (!kthread_should_stop()) {
70 while (atomic_read(&sdp->sd_reclaim_count))
71 gfs2_reclaim_glock(sdp);
73 set_current_state(TASK_INTERRUPTIBLE);
74 add_wait_queue(&sdp->sd_reclaim_wq, &wait_chan);
75 if (!atomic_read(&sdp->sd_reclaim_count) &&
76 !kthread_should_stop())
78 remove_wait_queue(&sdp->sd_reclaim_wq, &wait_chan);
79 set_current_state(TASK_RUNNING);
86 * gfs2_recoverd - Recover dead machine's journals
87 * @sdp: Pointer to GFS2 superblock
91 int gfs2_recoverd(void *data)
93 struct gfs2_sbd *sdp = (struct gfs2_sbd *)data;
96 while (!kthread_should_stop()) {
97 gfs2_check_journals(sdp);
98 t = gfs2_tune_get(sdp, gt_recoverd_secs) * HZ;
99 schedule_timeout_interruptible(t);
106 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
107 * @sdp: Pointer to GFS2 superblock
109 * Also, periodically check to make sure that we're using the most recent
113 int gfs2_logd(void *data)
115 struct gfs2_sbd *sdp = (struct gfs2_sbd *)data;
116 struct gfs2_holder ji_gh;
119 while (!kthread_should_stop()) {
120 /* Advance the log tail */
122 t = sdp->sd_log_flush_time +
123 gfs2_tune_get(sdp, gt_log_flush_secs) * HZ;
125 gfs2_ail1_empty(sdp, DIO_ALL);
127 if (time_after_eq(jiffies, t)) {
129 sdp->sd_log_flush_time = jiffies;
132 /* Check for latest journal index */
134 t = sdp->sd_jindex_refresh_time +
135 gfs2_tune_get(sdp, gt_jindex_refresh_secs) * HZ;
137 if (time_after_eq(jiffies, t)) {
138 if (!gfs2_jindex_hold(sdp, &ji_gh))
139 gfs2_glock_dq_uninit(&ji_gh);
140 sdp->sd_jindex_refresh_time = jiffies;
143 t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
144 schedule_timeout_interruptible(t);
151 * gfs2_quotad - Write cached quota changes into the quota file
152 * @sdp: Pointer to GFS2 superblock
156 int gfs2_quotad(void *data)
158 struct gfs2_sbd *sdp = (struct gfs2_sbd *)data;
162 while (!kthread_should_stop()) {
163 /* Update the master statfs file */
165 t = sdp->sd_statfs_sync_time +
166 gfs2_tune_get(sdp, gt_statfs_quantum) * HZ;
168 if (time_after_eq(jiffies, t)) {
169 error = gfs2_statfs_sync(sdp);
172 !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
173 fs_err(sdp, "quotad: (1) error=%d\n", error);
174 sdp->sd_statfs_sync_time = jiffies;
177 /* Update quota file */
179 t = sdp->sd_quota_sync_time +
180 gfs2_tune_get(sdp, gt_quota_quantum) * HZ;
182 if (time_after_eq(jiffies, t)) {
183 error = gfs2_quota_sync(sdp);
186 !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
187 fs_err(sdp, "quotad: (2) error=%d\n", error);
188 sdp->sd_quota_sync_time = jiffies;
191 gfs2_quota_scan(sdp);
193 t = gfs2_tune_get(sdp, gt_quotad_secs) * HZ;
194 schedule_timeout_interruptible(t);
201 * gfs2_inoded - Deallocate unlinked inodes
202 * @sdp: Pointer to GFS2 superblock
206 int gfs2_inoded(void *data)
208 struct gfs2_sbd *sdp = (struct gfs2_sbd *)data;
212 while (!kthread_should_stop()) {
213 error = gfs2_unlinked_dealloc(sdp);
216 !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
217 fs_err(sdp, "inoded: error = %d\n", error);
219 t = gfs2_tune_get(sdp, gt_inoded_secs) * HZ;
220 schedule_timeout_interruptible(t);