Whamcloud - gitweb
fe5d61f710fe7c85f22bbc8ca5790982b60fd45c
[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  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  */
8
9 #define DEBUG_SUBSYSTEM S_LNET
10 #ifdef HAVE_KERNEL_CONFIG_H
11 #include <linux/config.h>
12 #endif
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <libcfs/libcfs.h>
16
17 #if defined(CONFIG_KGDB)
18 #include <asm/kgdb.h>
19 #endif
20
21 void cfs_enter_debugger(void)
22 {
23 #if defined(CONFIG_KGDB)
24         BREAKPOINT();
25 #elif defined(__arch_um__)
26         asm("int $3");
27 #else
28         /* nothing */
29 #endif
30 }
31
32 void cfs_daemonize(char *str) {
33         unsigned long flags;
34
35         lock_kernel();
36 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,63))
37         daemonize(str);
38 #else
39         daemonize();
40         exit_files(current);
41         reparent_to_init();
42         snprintf (current->comm, sizeof (current->comm), "%s", str);
43 #endif
44         SIGNAL_MASK_LOCK(current, flags);
45         sigfillset(&current->blocked);
46         RECALC_SIGPENDING;
47         SIGNAL_MASK_UNLOCK(current, flags);
48         unlock_kernel();
49 }
50
51 int cfs_daemonize_ctxt(char *str) {
52         struct task_struct *tsk = current;
53         struct fs_struct *fs = NULL;
54
55         cfs_daemonize(str);
56         fs = copy_fs_struct(tsk->fs);
57         if (fs == NULL)
58                 return -ENOMEM;
59         exit_fs(tsk);
60         tsk->fs = fs;
61         return 0;
62 }
63
64
65 sigset_t
66 cfs_get_blockedsigs(void)
67 {
68         unsigned long          flags;
69         sigset_t        old;
70
71         SIGNAL_MASK_LOCK(current, flags);
72         old = current->blocked;
73         SIGNAL_MASK_UNLOCK(current, flags);
74         return old;
75 }
76
77 sigset_t
78 cfs_block_allsigs(void)
79 {
80         unsigned long          flags;
81         sigset_t        old;
82
83         SIGNAL_MASK_LOCK(current, flags);
84         old = current->blocked;
85         sigfillset(&current->blocked);
86         RECALC_SIGPENDING;
87         SIGNAL_MASK_UNLOCK(current, flags);
88
89         return old;
90 }
91
92 sigset_t
93 cfs_block_sigs(sigset_t bits)
94 {
95         unsigned long  flags;
96         sigset_t        old;
97
98         SIGNAL_MASK_LOCK(current, flags);
99         old = current->blocked;
100         current->blocked = bits;
101         RECALC_SIGPENDING;
102         SIGNAL_MASK_UNLOCK(current, flags);
103         return old;
104 }
105
106 void
107 cfs_restore_sigs (cfs_sigset_t old)
108 {
109         unsigned long  flags;
110
111         SIGNAL_MASK_LOCK(current, flags);
112         current->blocked = old;
113         RECALC_SIGPENDING;
114         SIGNAL_MASK_UNLOCK(current, flags);
115 }
116
117 int
118 cfs_signal_pending(void)
119 {
120         return signal_pending(current);
121 }
122
123 void
124 cfs_clear_sigpending(void)
125 {
126         unsigned long flags;
127
128         SIGNAL_MASK_LOCK(current, flags);
129         CLEAR_SIGPENDING;
130         SIGNAL_MASK_UNLOCK(current, flags);
131 }
132
133 int
134 libcfs_arch_init(void)
135 {
136         return 0;
137 }
138
139 void
140 libcfs_arch_cleanup(void)
141 {
142         return;
143 }
144
145 EXPORT_SYMBOL(libcfs_arch_init);
146 EXPORT_SYMBOL(libcfs_arch_cleanup);
147 EXPORT_SYMBOL(cfs_daemonize);
148 EXPORT_SYMBOL(cfs_daemonize_ctxt);
149 EXPORT_SYMBOL(cfs_block_allsigs);
150 EXPORT_SYMBOL(cfs_block_sigs);
151 EXPORT_SYMBOL(cfs_get_blockedsigs);
152 EXPORT_SYMBOL(cfs_restore_sigs);
153 EXPORT_SYMBOL(cfs_signal_pending);
154 EXPORT_SYMBOL(cfs_clear_sigpending);