Whamcloud - gitweb
b=23076 fix for o2iblnd reconnect to retry one more time
[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 <linux/fs_struct.h>
44 #include <libcfs/libcfs.h>
45
46 #if defined(CONFIG_KGDB)
47 #include <asm/kgdb.h>
48 #endif
49
50 void cfs_enter_debugger(void)
51 {
52 #if defined(CONFIG_KGDB)
53 //        BREAKPOINT();
54 #elif defined(__arch_um__)
55         asm("int $3");
56 #else
57         /* nothing */
58 #endif
59 }
60
61 void cfs_daemonize(char *str) {
62         unsigned long flags;
63
64         lock_kernel();
65         daemonize(str);
66         SIGNAL_MASK_LOCK(current, flags);
67         sigfillset(&current->blocked);
68         RECALC_SIGPENDING;
69         SIGNAL_MASK_UNLOCK(current, flags);
70         unlock_kernel();
71 }
72
73 int cfs_daemonize_ctxt(char *str) {
74
75         cfs_daemonize(str);
76 #ifndef HAVE_UNSHARE_FS_STRUCT
77         {
78         struct task_struct *tsk = current;
79         struct fs_struct *fs = NULL;
80         fs = copy_fs_struct(tsk->fs);
81         if (fs == NULL)
82                 return -ENOMEM;
83         exit_fs(tsk);
84         tsk->fs = fs;
85         }
86 #else
87         unshare_fs_struct();
88 #endif
89         return 0;
90 }
91
92 sigset_t
93 cfs_get_blockedsigs(void)
94 {
95         unsigned long          flags;
96         sigset_t        old;
97
98         SIGNAL_MASK_LOCK(current, flags);
99         old = current->blocked;
100         SIGNAL_MASK_UNLOCK(current, flags);
101         return old;
102 }
103
104 sigset_t
105 cfs_block_allsigs(void)
106 {
107         unsigned long          flags;
108         sigset_t        old;
109
110         SIGNAL_MASK_LOCK(current, flags);
111         old = current->blocked;
112         sigfillset(&current->blocked);
113         RECALC_SIGPENDING;
114         SIGNAL_MASK_UNLOCK(current, flags);
115
116         return old;
117 }
118
119 sigset_t
120 cfs_block_sigs(sigset_t bits)
121 {
122         unsigned long  flags;
123         sigset_t        old;
124
125         SIGNAL_MASK_LOCK(current, flags);
126         old = current->blocked;
127         current->blocked = bits;
128         RECALC_SIGPENDING;
129         SIGNAL_MASK_UNLOCK(current, flags);
130         return old;
131 }
132
133 void
134 cfs_restore_sigs (cfs_sigset_t old)
135 {
136         unsigned long  flags;
137
138         SIGNAL_MASK_LOCK(current, flags);
139         current->blocked = old;
140         RECALC_SIGPENDING;
141         SIGNAL_MASK_UNLOCK(current, flags);
142 }
143
144 int
145 cfs_signal_pending(void)
146 {
147         return signal_pending(current);
148 }
149
150 void
151 cfs_clear_sigpending(void)
152 {
153         unsigned long flags;
154
155         SIGNAL_MASK_LOCK(current, flags);
156         CLEAR_SIGPENDING;
157         SIGNAL_MASK_UNLOCK(current, flags);
158 }
159
160 int
161 libcfs_arch_init(void)
162 {
163         return 0;
164 }
165
166 void
167 libcfs_arch_cleanup(void)
168 {
169         return;
170 }
171
172 EXPORT_SYMBOL(libcfs_arch_init);
173 EXPORT_SYMBOL(libcfs_arch_cleanup);
174 EXPORT_SYMBOL(cfs_daemonize);
175 EXPORT_SYMBOL(cfs_daemonize_ctxt);
176 EXPORT_SYMBOL(cfs_block_allsigs);
177 EXPORT_SYMBOL(cfs_block_sigs);
178 EXPORT_SYMBOL(cfs_get_blockedsigs);
179 EXPORT_SYMBOL(cfs_restore_sigs);
180 EXPORT_SYMBOL(cfs_signal_pending);
181 EXPORT_SYMBOL(cfs_clear_sigpending);