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/kthread.h>
16 #include <linux/delay.h>
17 #include <linux/gfs2_ondisk.h>
18 #include <linux/lm_interface.h>
19 #include <linux/freezer.h>
31 /* This uses schedule_timeout() instead of msleep() because it's good for
32 the daemons to wake up more often than the timeout when unmounting so
33 the user's unmount doesn't sit there forever.
35 The kthread functions used to start these daemons block and flush signals. */
38 * gfs2_glockd - Reclaim unused glock structures
39 * @sdp: Pointer to GFS2 superblock
41 * One or more of these daemons run, reclaiming glocks on sd_reclaim_list.
42 * Number of daemons can be set by user, with num_glockd mount option.
45 int gfs2_glockd(void *data
)
47 struct gfs2_sbd
*sdp
= data
;
49 while (!kthread_should_stop()) {
50 while (atomic_read(&sdp
->sd_reclaim_count
))
51 gfs2_reclaim_glock(sdp
);
53 wait_event_interruptible(sdp
->sd_reclaim_wq
,
54 (atomic_read(&sdp
->sd_reclaim_count
) ||
55 kthread_should_stop()));
56 if (freezing(current
))
64 * gfs2_recoverd - Recover dead machine's journals
65 * @sdp: Pointer to GFS2 superblock
69 int gfs2_recoverd(void *data
)
71 struct gfs2_sbd
*sdp
= data
;
74 while (!kthread_should_stop()) {
75 gfs2_check_journals(sdp
);
76 t
= gfs2_tune_get(sdp
, gt_recoverd_secs
) * HZ
;
77 if (freezing(current
))
79 schedule_timeout_interruptible(t
);
86 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
87 * @sdp: Pointer to GFS2 superblock
89 * Also, periodically check to make sure that we're using the most recent
93 int gfs2_logd(void *data
)
95 struct gfs2_sbd
*sdp
= data
;
96 struct gfs2_holder ji_gh
;
100 while (!kthread_should_stop()) {
101 /* Advance the log tail */
103 t
= sdp
->sd_log_flush_time
+
104 gfs2_tune_get(sdp
, gt_log_flush_secs
) * HZ
;
106 gfs2_ail1_empty(sdp
, DIO_ALL
);
108 need_flush
= sdp
->sd_log_num_buf
> gfs2_tune_get(sdp
, gt_incore_log_blocks
);
109 gfs2_log_unlock(sdp
);
110 if (need_flush
|| time_after_eq(jiffies
, t
)) {
111 gfs2_log_flush(sdp
, NULL
);
112 sdp
->sd_log_flush_time
= jiffies
;
115 /* Check for latest journal index */
117 t
= sdp
->sd_jindex_refresh_time
+
118 gfs2_tune_get(sdp
, gt_jindex_refresh_secs
) * HZ
;
120 if (time_after_eq(jiffies
, t
)) {
121 if (!gfs2_jindex_hold(sdp
, &ji_gh
))
122 gfs2_glock_dq_uninit(&ji_gh
);
123 sdp
->sd_jindex_refresh_time
= jiffies
;
126 t
= gfs2_tune_get(sdp
, gt_logd_secs
) * HZ
;
127 if (freezing(current
))
129 schedule_timeout_interruptible(t
);
136 * gfs2_quotad - Write cached quota changes into the quota file
137 * @sdp: Pointer to GFS2 superblock
141 int gfs2_quotad(void *data
)
143 struct gfs2_sbd
*sdp
= data
;
147 while (!kthread_should_stop()) {
148 /* Update the master statfs file */
150 t
= sdp
->sd_statfs_sync_time
+
151 gfs2_tune_get(sdp
, gt_statfs_quantum
) * HZ
;
153 if (time_after_eq(jiffies
, t
)) {
154 error
= gfs2_statfs_sync(sdp
);
157 !test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
158 fs_err(sdp
, "quotad: (1) error=%d\n", error
);
159 sdp
->sd_statfs_sync_time
= jiffies
;
162 /* Update quota file */
164 t
= sdp
->sd_quota_sync_time
+
165 gfs2_tune_get(sdp
, gt_quota_quantum
) * HZ
;
167 if (time_after_eq(jiffies
, t
)) {
168 error
= gfs2_quota_sync(sdp
);
171 !test_bit(SDF_SHUTDOWN
, &sdp
->sd_flags
))
172 fs_err(sdp
, "quotad: (2) error=%d\n", error
);
173 sdp
->sd_quota_sync_time
= jiffies
;
176 gfs2_quota_scan(sdp
);
178 t
= gfs2_tune_get(sdp
, gt_quotad_secs
) * HZ
;
179 if (freezing(current
))
181 schedule_timeout_interruptible(t
);