Whamcloud - gitweb
b=19860
[fs/lustre-release.git] / lnet / libcfs / linux / linux-prim.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #define DEBUG_SUBSYSTEM S_LNET
38 #ifndef AUTOCONF_INCLUDED
39 #include <linux/config.h>
40 #endif
41 #include <linux/module.h>
42 #include <linux/kernel.h>
43 #include <libcfs/libcfs.h>
44
45 #if defined(CONFIG_KGDB)
46 #include <asm/kgdb.h>
47 #endif
48
49 void cfs_enter_debugger(void)
50 {
51 #if defined(CONFIG_KGDB)
52 //        BREAKPOINT();
53 #elif defined(__arch_um__)
54         asm("int $3");
55 #else
56         /* nothing */
57 #endif
58 }
59
60 void cfs_daemonize(char *str) {
61         unsigned long flags;
62
63         lock_kernel();
64         daemonize(str);
65         SIGNAL_MASK_LOCK(current, flags);
66         sigfillset(&current->blocked);
67         RECALC_SIGPENDING;
68         SIGNAL_MASK_UNLOCK(current, flags);
69         unlock_kernel();
70 }
71
72 int cfs_daemonize_ctxt(char *str) {
73         struct task_struct *tsk = current;
74         struct fs_struct *fs = NULL;
75
76         cfs_daemonize(str);
77         fs = copy_fs_struct(tsk->fs);
78         if (fs == NULL)
79                 return -ENOMEM;
80         exit_fs(tsk);
81         tsk->fs = fs;
82         return 0;
83 }
84
85
86 sigset_t
87 cfs_get_blockedsigs(void)
88 {
89         unsigned long          flags;
90         sigset_t        old;
91
92         SIGNAL_MASK_LOCK(current, flags);
93         old = current->blocked;
94         SIGNAL_MASK_UNLOCK(current, flags);
95         return old;
96 }
97
98 sigset_t
99 cfs_block_allsigs(void)
100 {
101         unsigned long          flags;
102         sigset_t        old;
103
104         SIGNAL_MASK_LOCK(current, flags);
105         old = current->blocked;
106         sigfillset(&current->blocked);
107         RECALC_SIGPENDING;
108         SIGNAL_MASK_UNLOCK(current, flags);
109
110         return old;
111 }
112
113 sigset_t
114 cfs_block_sigs(sigset_t bits)
115 {
116         unsigned long  flags;
117         sigset_t        old;
118
119         SIGNAL_MASK_LOCK(current, flags);
120         old = current->blocked;
121         current->blocked = bits;
122         RECALC_SIGPENDING;
123         SIGNAL_MASK_UNLOCK(current, flags);
124         return old;
125 }
126
127 void
128 cfs_restore_sigs (cfs_sigset_t old)
129 {
130         unsigned long  flags;
131
132         SIGNAL_MASK_LOCK(current, flags);
133         current->blocked = old;
134         RECALC_SIGPENDING;
135         SIGNAL_MASK_UNLOCK(current, flags);
136 }
137
138 int
139 cfs_signal_pending(void)
140 {
141         return signal_pending(current);
142 }
143
144 void
145 cfs_clear_sigpending(void)
146 {
147         unsigned long flags;
148
149         SIGNAL_MASK_LOCK(current, flags);
150         CLEAR_SIGPENDING;
151         SIGNAL_MASK_UNLOCK(current, flags);
152 }
153
154 int
155 libcfs_arch_init(void)
156 {
157         return 0;
158 }
159
160 void
161 libcfs_arch_cleanup(void)
162 {
163         return;
164 }
165
166 EXPORT_SYMBOL(libcfs_arch_init);
167 EXPORT_SYMBOL(libcfs_arch_cleanup);
168 EXPORT_SYMBOL(cfs_daemonize);
169 EXPORT_SYMBOL(cfs_daemonize_ctxt);
170 EXPORT_SYMBOL(cfs_block_allsigs);
171 EXPORT_SYMBOL(cfs_block_sigs);
172 EXPORT_SYMBOL(cfs_get_blockedsigs);
173 EXPORT_SYMBOL(cfs_restore_sigs);
174 EXPORT_SYMBOL(cfs_signal_pending);
175 EXPORT_SYMBOL(cfs_clear_sigpending);