Whamcloud - gitweb
- name switch: "light" --> "lite"
[fs/lustre-release.git] / lustre / llite / llite_ha.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  linux/mds/handler.c
5  *
6  *  Lustre Metadata Server (mds) request handler
7  *
8  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
9  *
10  *  This code is issued under the GNU General Public License.
11  *  See the file COPYING in this distribution
12  *
13  *  by Peter Braam <braam@clusterfs.com>
14  *
15  *  This server is single threaded at present (but can easily be multi threaded)
16  *
17  */
18
19 #define EXPORT_SYMTAB
20
21 #include <linux/version.h>
22 #include <linux/module.h>
23 #include <linux/fs.h>
24 #include <linux/stat.h>
25 #include <linux/locks.h>
26 #include <linux/quotaops.h>
27 #include <asm/unistd.h>
28 #include <asm/uaccess.h>
29
30 #define DEBUG_SUBSYSTEM S_LLITE
31
32 #include <linux/lustre_lite.h>
33 #include <linux/lustre_ha.h>
34 #include <linux/lustre_lib.h>
35 #include <linux/lustre_net.h>
36
37 static int lustre_ha_check_event(struct lustre_ha_mgr *mgr)
38 {
39
40         
41         return 1;
42 }
43
44
45 static int llite_ha_main(void *arg)
46 {
47         struct lustre_ha_thread *data = (struct lustre_ha_thread *)arg;
48         struct lustre_ha_mgr *mgr = data->mgr;
49
50         ENTRY;
51
52         lock_kernel();
53         daemonize();
54         spin_lock_irq(&current->sigmask_lock);
55         sigfillset(&current->blocked);
56         recalc_sigpending(current);
57         spin_unlock_irq(&current->sigmask_lock);
58
59         sprintf(current->comm, data->name);
60
61         /* Record that the  thread is running */
62         mgr->mgr_thread = current;
63         mgr->mgr_flags = MGR_RUNNING;
64         wake_up(&mgr->mgr_ctl_waitq);
65
66         /* And now, loop forever on requests */
67         while (1) {
68                 wait_event_interruptible(mgr->mgr_waitq, 
69                                          lustre_ha_check_event(mgr));
70
71                 spin_lock(&mgr->mgr_lock);
72                 schedule_timeout(5 * HZ); 
73                 if (mgr->mgr_flags & MGR_SIGNAL) {
74                         spin_unlock(&mgr->mgr_lock);
75                         EXIT;
76                         break;
77                 }
78
79                 if (mgr->mgr_flags & MGR_STOPPING) {
80                         spin_unlock(&mgr->mgr_lock);
81                         EXIT;
82                         break;
83                 }
84
85                 if (mgr->mgr_flags & MGR_EVENT) {
86                         mgr->mgr_flags = MGR_RUNNING;
87
88                         /* FIXME: If we move to an event-driven model,
89                          * we should put the request on the stack of
90                          * mds_handle instead. */
91                         CERROR("MGR event\n"); 
92                         continue;
93                 }
94
95                 CERROR("unknown break in service");
96                 spin_unlock(&mgr->mgr_lock);
97                 EXIT;
98                 break;
99         }
100
101         mgr->mgr_thread = NULL;
102         mgr->mgr_flags = MGR_STOPPED;
103         wake_up(&mgr->mgr_ctl_waitq);
104         CDEBUG(D_NET, "mgr exiting process %d\n", current->pid);
105         return 0;
106 }
107
108
109 int llite_ha_setup(struct obd_device *dev, struct lustre_ha_mgr *mgr,
110                    char *name)
111 {
112         struct lustre_ha_thread d;
113         int rc;
114         ENTRY;
115
116         d.dev = dev;
117         d.mgr = mgr;
118         d.name = name;
119
120         init_waitqueue_head(&mgr->mgr_waitq);
121
122         init_waitqueue_head(&mgr->mgr_ctl_waitq);
123         rc = kernel_thread(llite_ha_main, (void *) &d,
124                            CLONE_VM | CLONE_FS | CLONE_FILES);
125         if (rc < 0) {
126                 CERROR("cannot start thread\n");
127                 RETURN(-EINVAL);
128         }
129         wait_event(mgr->mgr_ctl_waitq, mgr->mgr_flags & MGR_RUNNING);
130
131         RETURN(0);
132 }
133
134
135 int llite_ha_cleanup(struct lustre_ha_mgr *mgr)
136 {
137         mgr->mgr_flags = MGR_STOPPING;
138
139         wake_up(&mgr->mgr_waitq);
140         wait_event_interruptible(mgr->mgr_ctl_waitq,
141                                  (mgr->mgr_flags & MGR_STOPPED));
142         return 0;
143 }