Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lustre / llite / commit_callback.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  The daemon that causes completed but not committed transactions
5  *   on the MDS to be flushed periodically when they are committed.
6  *   A gratuitous getattr RPC is made to the MDS to discover the
7  *   last committed record.
8  *
9  *  Lustre High Availability Daemon
10  *
11  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
12  *
13  *  This code is issued under the GNU General Public License.
14  *  See the file COPYING in this distribution
15  *
16  *  by Peter Braam <braam@clusterfs.com>
17  *
18  */
19
20 #define EXPORT_SYMTAB
21
22 #include <linux/version.h>
23 #include <linux/module.h>
24 #include <linux/fs.h>
25 #include <linux/stat.h>
26 #include <linux/sched.h>
27 #include <linux/smp_lock.h>
28 #include <linux/kmod.h>
29 #include <linux/quotaops.h>
30 #include <asm/unistd.h>
31 #include <asm/uaccess.h>
32
33 #define DEBUG_SUBSYSTEM S_LLITE
34
35 #include <linux/lustre_lite.h>
36 #include <linux/lustre_lib.h>
37 #include <linux/lustre_compat25.h>
38
39 static int ll_commitcbd_check_event(struct ll_sb_info *sbi)
40 {
41         int rc = 0;
42         ENTRY;
43
44         spin_lock(&sbi->ll_commitcbd_lock);
45         if (sbi->ll_commitcbd_flags & LL_COMMITCBD_STOPPING)
46                 GOTO(out, rc = 1);
47
48         EXIT;
49  out:
50         spin_unlock(&sbi->ll_commitcbd_lock);
51         return rc;
52 }
53
54 static int ll_commitcbd_main(void *arg)
55 {
56         struct ll_sb_info *sbi = (struct ll_sb_info *)arg;
57         unsigned long flags;
58         ENTRY;
59
60         lock_kernel();
61         kportal_daemonize("lustre_commitcbd");
62
63         SIGNAL_MASK_LOCK(current, flags);
64         sigfillset(&current->blocked);
65         RECALC_SIGPENDING;
66         SIGNAL_MASK_UNLOCK(current, flags);
67
68         unlock_kernel();
69
70         /* Record that the  thread is running */
71         sbi->ll_commitcbd_waketime = LTIME_S(CURRENT_TIME);
72         sbi->ll_commitcbd_timeout = 10 * HZ;
73         sbi->ll_commitcbd_thread = current;
74         sbi->ll_commitcbd_flags =  LL_COMMITCBD_RUNNING;
75         wake_up(&sbi->ll_commitcbd_ctl_waitq);
76
77         /* And now, loop forever on requests */
78         while (1) {
79                 struct l_wait_info lwi = { 0 };
80                 l_wait_event(sbi->ll_commitcbd_waitq,
81                              ll_commitcbd_check_event(sbi), &lwi);
82
83                 spin_lock(&sbi->ll_commitcbd_lock);
84                 if (sbi->ll_commitcbd_flags & LL_COMMITCBD_STOPPING) {
85                         spin_unlock(&sbi->ll_commitcbd_lock);
86                         CERROR("lustre_commitd quitting\n");
87                         EXIT;
88                         break;
89                 }
90
91                 schedule_timeout(sbi->ll_commitcbd_timeout);
92                 CERROR("commit callback daemon woken up - FIXME\n");
93                 spin_unlock(&sbi->ll_commitcbd_lock);
94         }
95
96         sbi->ll_commitcbd_thread = NULL;
97         sbi->ll_commitcbd_flags = LL_COMMITCBD_STOPPED;
98         wake_up(&sbi->ll_commitcbd_ctl_waitq);
99         CDEBUG(D_NET, "commit callback daemon exiting %d\n", current->pid);
100         RETURN(0);
101 }
102
103
104
105 int ll_commitcbd_setup(struct ll_sb_info *sbi)
106 {
107         int rc;
108         struct l_wait_info lwi = { 0 };
109         ENTRY;
110
111         rc = kernel_thread(ll_commitcbd_main, (void *) sbi,
112                            CLONE_VM | CLONE_FS | CLONE_FILES);
113         if (rc < 0) {
114                 CERROR("cannot start thread\n");
115                 RETURN(rc);
116         }
117         l_wait_event(sbi->ll_commitcbd_ctl_waitq,
118                      sbi->ll_commitcbd_flags & LL_COMMITCBD_RUNNING, &lwi);
119         RETURN(0);
120 }
121
122
123 int ll_commitcbd_cleanup(struct ll_sb_info *sbi)
124 {
125         struct l_wait_info lwi = { 0 };
126         sbi->ll_commitcbd_flags = LL_COMMITCBD_STOPPING;
127
128         wake_up(&sbi->ll_commitcbd_waitq);
129         l_wait_event(sbi->ll_commitcbd_ctl_waitq,
130                      sbi->ll_commitcbd_flags & LL_COMMITCBD_STOPPED, &lwi);
131         RETURN(0);
132 }