Whamcloud - gitweb
6bee6341c3b672a20ed59dc22b339f2ef90f0b2b
[fs/lustre-release.git] / libcfs / 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 [sun.com URL with a
20  * copy of GPLv2].
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 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,63))
65         daemonize(str);
66 #else
67         daemonize();
68         exit_files(current);
69         reparent_to_init();
70         snprintf (current->comm, sizeof (current->comm), "%s", str);
71 #endif
72         SIGNAL_MASK_LOCK(current, flags);
73         sigfillset(&current->blocked);
74         RECALC_SIGPENDING;
75         SIGNAL_MASK_UNLOCK(current, flags);
76         unlock_kernel();
77 }
78
79 int cfs_daemonize_ctxt(char *str) {
80         struct task_struct *tsk = current;
81         struct fs_struct *fs = NULL;
82
83         cfs_daemonize(str);
84         fs = copy_fs_struct(tsk->fs);
85         if (fs == NULL)
86                 return -ENOMEM;
87         exit_fs(tsk);
88         tsk->fs = fs;
89         return 0;
90 }
91
92
93 sigset_t
94 cfs_get_blockedsigs(void)
95 {
96         unsigned long          flags;
97         sigset_t        old;
98
99         SIGNAL_MASK_LOCK(current, flags);
100         old = current->blocked;
101         SIGNAL_MASK_UNLOCK(current, flags);
102         return old;
103 }
104
105 sigset_t
106 cfs_block_allsigs(void)
107 {
108         unsigned long          flags;
109         sigset_t        old;
110
111         SIGNAL_MASK_LOCK(current, flags);
112         old = current->blocked;
113         sigfillset(&current->blocked);
114         RECALC_SIGPENDING;
115         SIGNAL_MASK_UNLOCK(current, flags);
116
117         return old;
118 }
119
120 sigset_t
121 cfs_block_sigs(sigset_t bits)
122 {
123         unsigned long  flags;
124         sigset_t        old;
125
126         SIGNAL_MASK_LOCK(current, flags);
127         old = current->blocked;
128         current->blocked = bits;
129         RECALC_SIGPENDING;
130         SIGNAL_MASK_UNLOCK(current, flags);
131         return old;
132 }
133
134 void
135 cfs_restore_sigs (cfs_sigset_t old)
136 {
137         unsigned long  flags;
138
139         SIGNAL_MASK_LOCK(current, flags);
140         current->blocked = old;
141         RECALC_SIGPENDING;
142         SIGNAL_MASK_UNLOCK(current, flags);
143 }
144
145 int
146 cfs_signal_pending(void)
147 {
148         return signal_pending(current);
149 }
150
151 void
152 cfs_clear_sigpending(void)
153 {
154         unsigned long flags;
155
156         SIGNAL_MASK_LOCK(current, flags);
157         CLEAR_SIGPENDING;
158         SIGNAL_MASK_UNLOCK(current, flags);
159 }
160
161 int
162 libcfs_arch_init(void)
163 {
164         return 0;
165 }
166
167 void
168 libcfs_arch_cleanup(void)
169 {
170         return;
171 }
172
173 EXPORT_SYMBOL(libcfs_arch_init);
174 EXPORT_SYMBOL(libcfs_arch_cleanup);
175 EXPORT_SYMBOL(cfs_daemonize);
176 EXPORT_SYMBOL(cfs_daemonize_ctxt);
177 EXPORT_SYMBOL(cfs_block_allsigs);
178 EXPORT_SYMBOL(cfs_block_sigs);
179 EXPORT_SYMBOL(cfs_get_blockedsigs);
180 EXPORT_SYMBOL(cfs_restore_sigs);
181 EXPORT_SYMBOL(cfs_signal_pending);
182 EXPORT_SYMBOL(cfs_clear_sigpending);