1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Lustre Metadata Server (mds) request handler
8 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
10 * This code is issued under the GNU General Public License.
11 * See the file COPYING in this distribution
13 * by Peter Braam <braam@clusterfs.com>
15 * This server is single threaded at present (but can easily be multi threaded)
21 #include <linux/version.h>
22 #include <linux/module.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>
30 #define DEBUG_SUBSYSTEM S_LLITE
32 #include <linux/lustre_lite.h>
33 #include <linux/lustre_ha.h>
34 #include <linux/lustre_lib.h>
35 #include <linux/lustre_net.h>
37 static int lustre_ha_check_event(struct lustre_ha_mgr *mgr)
45 static int llite_ha_main(void *arg)
47 struct lustre_ha_thread *data = (struct lustre_ha_thread *)arg;
48 struct lustre_ha_mgr *mgr = data->mgr;
54 spin_lock_irq(¤t->sigmask_lock);
55 sigfillset(¤t->blocked);
56 recalc_sigpending(current);
57 spin_unlock_irq(¤t->sigmask_lock);
59 sprintf(current->comm, data->name);
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);
66 /* And now, loop forever on requests */
68 wait_event_interruptible(mgr->mgr_waitq,
69 lustre_ha_check_event(mgr));
71 spin_lock(&mgr->mgr_lock);
72 schedule_timeout(5 * HZ);
73 if (mgr->mgr_flags & MGR_SIGNAL) {
74 spin_unlock(&mgr->mgr_lock);
79 if (mgr->mgr_flags & MGR_STOPPING) {
80 spin_unlock(&mgr->mgr_lock);
85 if (mgr->mgr_flags & MGR_EVENT) {
86 mgr->mgr_flags = MGR_RUNNING;
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");
95 CERROR("unknown break in service");
96 spin_unlock(&mgr->mgr_lock);
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);
109 int llite_ha_setup(struct obd_device *dev, struct lustre_ha_mgr *mgr,
112 struct lustre_ha_thread d;
120 init_waitqueue_head(&mgr->mgr_waitq);
122 init_waitqueue_head(&mgr->mgr_ctl_waitq);
123 rc = kernel_thread(llite_ha_main, (void *) &d,
124 CLONE_VM | CLONE_FS | CLONE_FILES);
126 CERROR("cannot start thread\n");
129 wait_event(mgr->mgr_ctl_waitq, mgr->mgr_flags & MGR_RUNNING);
135 int llite_ha_cleanup(struct lustre_ha_mgr *mgr)
137 mgr->mgr_flags = MGR_STOPPING;
139 wake_up(&mgr->mgr_waitq);
140 wait_event_interruptible(mgr->mgr_ctl_waitq,
141 (mgr->mgr_flags & MGR_STOPPED));