GFS2: Clean up & move gfs2_quotad
[linux-2.6-block.git] / fs / gfs2 / daemon.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
4  *
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.
8  */
9
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>
20
21 #include "gfs2.h"
22 #include "incore.h"
23 #include "daemon.h"
24 #include "glock.h"
25 #include "log.h"
26 #include "recovery.h"
27 #include "super.h"
28 #include "util.h"
29
30 /* This uses schedule_timeout() instead of msleep() because it's good for
31    the daemons to wake up more often than the timeout when unmounting so
32    the user's unmount doesn't sit there forever.
33
34    The kthread functions used to start these daemons block and flush signals. */
35
36 /**
37  * gfs2_glockd - Reclaim unused glock structures
38  * @sdp: Pointer to GFS2 superblock
39  *
40  * One or more of these daemons run, reclaiming glocks on sd_reclaim_list.
41  * Number of daemons can be set by user, with num_glockd mount option.
42  */
43
44 int gfs2_glockd(void *data)
45 {
46         struct gfs2_sbd *sdp = data;
47
48         while (!kthread_should_stop()) {
49                 while (atomic_read(&sdp->sd_reclaim_count))
50                         gfs2_reclaim_glock(sdp);
51
52                 wait_event_interruptible(sdp->sd_reclaim_wq,
53                                          (atomic_read(&sdp->sd_reclaim_count) ||
54                                          kthread_should_stop()));
55                 if (freezing(current))
56                         refrigerator();
57         }
58
59         return 0;
60 }
61
62 /**
63  * gfs2_recoverd - Recover dead machine's journals
64  * @sdp: Pointer to GFS2 superblock
65  *
66  */
67
68 int gfs2_recoverd(void *data)
69 {
70         struct gfs2_sbd *sdp = data;
71         unsigned long t;
72
73         while (!kthread_should_stop()) {
74                 gfs2_check_journals(sdp);
75                 t = gfs2_tune_get(sdp,  gt_recoverd_secs) * HZ;
76                 if (freezing(current))
77                         refrigerator();
78                 schedule_timeout_interruptible(t);
79         }
80
81         return 0;
82 }
83