Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[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         EXIT;
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         unsigned long flags;
57         ENTRY;
58
59         lock_kernel();
60         daemonize();
61 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
62         spin_lock_irqsave(&current->sigmask_lock, flags);
63         sigfillset(&current->blocked);
64         our_recalc_sigpending(current);
65         spin_unlock_irqrestore(&current->sigmask_lock, flags);
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 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
76         sbi->ll_commitcbd_waketime = CURRENT_TIME;
77 #else
78         sbi->ll_commitcbd_waketime = CURRENT_TIME.tv_sec;
79 #endif
80         sbi->ll_commitcbd_timeout = 10 * HZ;
81         sbi->ll_commitcbd_thread = current;
82         sbi->ll_commitcbd_flags =  LL_COMMITCBD_RUNNING;
83         wake_up(&sbi->ll_commitcbd_ctl_waitq);
84
85         /* And now, loop forever on requests */
86         while (1) {
87                 wait_event(sbi->ll_commitcbd_waitq,
88                            ll_commitcbd_check_event(sbi));
89
90                 spin_lock(&sbi->ll_commitcbd_lock);
91                 if (sbi->ll_commitcbd_flags & LL_COMMITCBD_STOPPING) {
92                         spin_unlock(&sbi->ll_commitcbd_lock);
93                         CERROR("lustre_commitd quitting\n");
94                         EXIT;
95                         break;
96                 }
97
98                 schedule_timeout(sbi->ll_commitcbd_timeout);
99                 CERROR("commit callback daemon woken up - FIXME\n");
100                 spin_unlock(&sbi->ll_commitcbd_lock);
101         }
102
103         sbi->ll_commitcbd_thread = NULL;
104         sbi->ll_commitcbd_flags = LL_COMMITCBD_STOPPED;
105         wake_up(&sbi->ll_commitcbd_ctl_waitq);
106         CDEBUG(D_NET, "commit callback daemon exiting %d\n", current->pid);
107         RETURN(0);
108 }
109
110
111
112 int ll_commitcbd_setup(struct ll_sb_info *sbi)
113 {
114         int rc;
115         ENTRY;
116
117         rc = kernel_thread(ll_commitcbd_main, (void *) sbi,
118                            CLONE_VM | CLONE_FS | CLONE_FILES);
119         if (rc < 0) {
120                 CERROR("cannot start thread\n");
121                 RETURN(rc);
122         }
123         wait_event(sbi->ll_commitcbd_ctl_waitq,
124                    sbi->ll_commitcbd_flags & LL_COMMITCBD_RUNNING);
125         RETURN(0);
126 }
127
128
129 int ll_commitcbd_cleanup(struct ll_sb_info *sbi)
130 {
131         sbi->ll_commitcbd_flags = LL_COMMITCBD_STOPPING;
132
133         wake_up(&sbi->ll_commitcbd_waitq);
134         wait_event(sbi->ll_commitcbd_ctl_waitq,
135                    sbi->ll_commitcbd_flags & LL_COMMITCBD_STOPPED);
136         RETURN(0);
137 }