Whamcloud - gitweb
land b_md onto HEAD:
[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
38 static int ll_commitcbd_check_event(struct ll_sb_info *sbi)
39 {
40         int rc = 0; 
41         ENTRY;
42
43         spin_lock(&sbi->ll_commitcbd_lock); 
44         if (sbi->ll_commitcbd_flags & LL_COMMITCBD_STOPPING) { 
45                 GOTO(out, rc = 1);
46         }
47
48  out:
49         spin_unlock(&sbi->ll_commitcbd_lock);
50         RETURN(rc);
51 }
52
53 static int ll_commitcbd_main(void *arg)
54 {
55         struct ll_sb_info *sbi = (struct ll_sb_info *)arg;
56
57         ENTRY;
58
59         lock_kernel();
60         daemonize();
61 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
62         spin_lock_irq(&current->sigmask_lock);
63         sigfillset(&current->blocked);
64         our_recalc_sigpending(current);
65         spin_unlock_irq(&current->sigmask_lock);
66 #else
67         sigfillset(&current->blocked);
68         our_recalc_sigpending(current);
69 #endif
70
71         sprintf(current->comm, "lustre_commitcbd");
72         unlock_kernel();
73
74         /* Record that the  thread is running */
75         sbi->ll_commitcbd_waketime = CURRENT_TIME;
76         sbi->ll_commitcbd_timeout = 10 * HZ;
77         sbi->ll_commitcbd_thread = current;
78         sbi->ll_commitcbd_flags =  LL_COMMITCBD_RUNNING;
79         wake_up(&sbi->ll_commitcbd_ctl_waitq);
80
81         /* And now, loop forever on requests */
82         while (1) {
83                 wait_event(sbi->ll_commitcbd_waitq, 
84                            ll_commitcbd_check_event(sbi));
85
86                 spin_lock(&sbi->ll_commitcbd_lock);
87                 if (sbi->ll_commitcbd_flags & LL_COMMITCBD_STOPPING) {
88                         spin_unlock(&sbi->ll_commitcbd_lock);
89                         CERROR("lustre_commitd quitting\n"); 
90                         EXIT;
91                         break;
92                 }
93
94                 schedule_timeout(sbi->ll_commitcbd_timeout);
95                 CERROR("commit callback daemon woken up - FIXME\n"); 
96                 spin_unlock(&sbi->ll_commitcbd_lock);
97         }
98
99         sbi->ll_commitcbd_thread = NULL;
100         sbi->ll_commitcbd_flags = LL_COMMITCBD_STOPPED;
101         wake_up(&sbi->ll_commitcbd_ctl_waitq);
102         CDEBUG(D_NET, "commit callback daemon exiting %d\n", current->pid);
103         RETURN(0);
104 }
105
106
107
108 int ll_commitcbd_setup(struct ll_sb_info *sbi)
109 {
110         int rc;
111         ENTRY;
112
113         rc = kernel_thread(ll_commitcbd_main, (void *) sbi,
114                            CLONE_VM | CLONE_FS | CLONE_FILES);
115         if (rc < 0) {
116                 CERROR("cannot start thread\n");
117                 RETURN(rc);
118         }
119         wait_event(sbi->ll_commitcbd_ctl_waitq, 
120                    sbi->ll_commitcbd_flags & LL_COMMITCBD_RUNNING);
121         RETURN(0);
122 }
123
124
125 int ll_commitcbd_cleanup(struct ll_sb_info *sbi)
126 {
127         sbi->ll_commitcbd_flags = LL_COMMITCBD_STOPPING;
128
129         wake_up(&sbi->ll_commitcbd_waitq);
130         wait_event(sbi->ll_commitcbd_ctl_waitq,
131                    sbi->ll_commitcbd_flags & LL_COMMITCBD_STOPPED);
132         RETURN(0);
133 }