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 <linux/gfs2_ondisk.h>
18 #include <asm/semaphore.h>
21 #include "lm_interface.h"
32 /* This uses schedule_timeout() instead of msleep() because it's good for
33 the daemons to wake up more often than the timeout when unmounting so
34 the user's unmount doesn't sit there forever.
36 The kthread functions used to start these daemons block and flush signals. */
39 * gfs2_scand - Look for cached glocks and inodes to toss from memory
40 * @sdp: Pointer to GFS2 superblock
42 * One of these daemons runs, finding candidates to add to sd_reclaim_list.
46 int gfs2_scand(void *data
)
48 struct gfs2_sbd
*sdp
= data
;
51 while (!kthread_should_stop()) {
52 gfs2_scand_internal(sdp
);
53 t
= gfs2_tune_get(sdp
, gt_scand_secs
) * HZ
;
54 schedule_timeout_interruptible(t
);
61 * gfs2_glockd - Reclaim unused glock structures
62 * @sdp: Pointer to GFS2 superblock
64 * One or more of these daemons run, reclaiming glocks on sd_reclaim_list.
65 * Number of daemons can be set by user, with num_glockd mount option.
68 int gfs2_glockd(void *data
)
70 struct gfs2_sbd
*sdp
= data
;
72 while (!kthread_should_stop()) {
73 while (atomic_read(&sdp
->sd_reclaim_count
))
74 gfs2_reclaim_glock(sdp
);
76 wait_event_interruptible(sdp
->sd_reclaim_wq
,
77 (atomic_read(&sdp
->sd_reclaim_count
) ||
78 kthread_should_stop()));
85 * gfs2_recoverd - Recover dead machine's journals
86 * @sdp: Pointer to GFS2 superblock
90 int gfs2_recoverd(void *data
)
92 struct gfs2_sbd
*sdp
= data
;
95 while (!kthread_should_stop()) {
96 gfs2_check_journals(sdp
);
97 t
= gfs2_tune_get(sdp
, gt_recoverd_secs
) * HZ
;
98 schedule_timeout_interruptible(t
);
105 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
106 * @sdp: Pointer to GFS2 superblock
108 * Also, periodically check to make sure that we're using the most recent
112 int gfs2_logd(void *data
)
114 struct gfs2_sbd
*sdp
= data
;
115 struct gfs2_holder ji_gh
;
118 while (!kthread_should_stop()) {
119 /* Advance the log tail */
121 t
= sdp
->sd_log_flush_time
+
122 gfs2_tune_get(sdp
, gt_log_flush_secs
) * HZ
;
124 gfs2_ail1_empty(sdp
, DIO_ALL
);
126 if (time_after_eq(jiffies
, t
)) {
127 gfs2_log_flush(sdp
, NULL
);
128 sdp
->sd_log_flush_time
= jiffies
;
131 /* Check for latest journal index */
133 t
= sdp
->sd_jindex_refresh_time
+
134 gfs2_tune_get(sdp
, gt_jindex_refresh_secs
) * HZ
;
136 if (time_after_eq(jiffies
, t
)) {
137 if (!gfs2_jindex_hold(sdp
, &ji_gh
))
138 gfs2_glock_dq_uninit(&ji_gh
);
139 sdp
->sd_jindex_refresh_time
= jiffies
;
142 t
= gfs2_tune_get(sdp
, gt_logd_secs
) * HZ
;
143 schedule_timeout_interruptible(t
);
150 * gfs2_quotad - Write cached quota changes into the quota file
151 * @sdp: Pointer to GFS2 superblock
155 int gfs2_quotad(void *data
)
157 struct gfs2_sbd
*sdp
= data
;
161 while (!kthread_should_stop()) {
162 /* Update the master statfs file */
164 t
= sdp
->sd_statfs_sync_time
+
165 gfs2_tune_get(sdp
, gt_statfs_quantum
) * HZ
;
167 if (time_after_eq(jiffies
, t
)) {
168 error
= gfs2_statfs_sync(sdp
);
171 !test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
172 fs_err(sdp
, "quotad: (1) error=%d\n", error
);
173 sdp
->sd_statfs_sync_time
= jiffies
;
176 /* Update quota file */
178 t
= sdp
->sd_quota_sync_time
+
179 gfs2_tune_get(sdp
, gt_quota_quantum
) * HZ
;
181 if (time_after_eq(jiffies
, t
)) {
182 error
= gfs2_quota_sync(sdp
);
185 !test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
186 fs_err(sdp
, "quotad: (2) error=%d\n", error
);
187 sdp
->sd_quota_sync_time
= jiffies
;
190 gfs2_quota_scan(sdp
);
192 t
= gfs2_tune_get(sdp
, gt_quotad_secs
) * HZ
;
193 schedule_timeout_interruptible(t
);
200 * gfs2_inoded - Deallocate unlinked inodes
201 * @sdp: Pointer to GFS2 superblock
205 int gfs2_inoded(void *data
)
207 struct gfs2_sbd
*sdp
= data
;
211 while (!kthread_should_stop()) {
212 error
= gfs2_unlinked_dealloc(sdp
);
215 !test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
216 fs_err(sdp
, "inoded: error = %d\n", error
);
218 t
= gfs2_tune_get(sdp
, gt_inoded_secs
) * HZ
;
219 schedule_timeout_interruptible(t
);