Whamcloud - gitweb
dd2ac35e1417c5f7779546f1c9fa359a1bf41c85
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-prim.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
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 #include <linux/module.h>
39 #include <linux/kernel.h>
40 #include <linux/fs_struct.h>
41 #include <linux/sched.h>
42
43 #include <libcfs/libcfs.h>
44
45 #if defined(CONFIG_KGDB)
46 #include <asm/kgdb.h>
47 #endif
48
49 void cfs_init_timer(struct timer_list *t)
50 {
51         init_timer(t);
52 }
53 EXPORT_SYMBOL(cfs_init_timer);
54
55 void cfs_timer_init(struct timer_list *t, cfs_timer_func_t *func, void *arg)
56 {
57         init_timer(t);
58         t->function = func;
59         t->data = (unsigned long)arg;
60 }
61 EXPORT_SYMBOL(cfs_timer_init);
62
63 void cfs_timer_arm(struct timer_list *t, cfs_time_t deadline)
64 {
65         mod_timer(t, deadline);
66 }
67 EXPORT_SYMBOL(cfs_timer_arm);
68
69 void cfs_timer_disarm(struct timer_list *t)
70 {
71         del_timer(t);
72 }
73 EXPORT_SYMBOL(cfs_timer_disarm);
74
75 int  cfs_timer_is_armed(struct timer_list *t)
76 {
77         return timer_pending(t);
78 }
79 EXPORT_SYMBOL(cfs_timer_is_armed);
80
81 cfs_time_t cfs_timer_deadline(struct timer_list *t)
82 {
83         return t->expires;
84 }
85 EXPORT_SYMBOL(cfs_timer_deadline);
86
87 void cfs_enter_debugger(void)
88 {
89 #if defined(CONFIG_KGDB)
90 //        BREAKPOINT();
91 #else
92         /* nothing */
93 #endif
94 }
95 EXPORT_SYMBOL(cfs_enter_debugger);
96
97 sigset_t
98 cfs_block_allsigs(void)
99 {
100         unsigned long   flags;
101         sigset_t        old;
102
103         spin_lock_irqsave(&current->sighand->siglock, flags);
104         old = current->blocked;
105         sigfillset(&current->blocked);
106         recalc_sigpending();
107         spin_unlock_irqrestore(&current->sighand->siglock, flags);
108         return old;
109 }
110 EXPORT_SYMBOL(cfs_block_allsigs);
111
112 sigset_t cfs_block_sigs(unsigned long sigs)
113 {
114         unsigned long  flags;
115         sigset_t        old;
116
117         spin_lock_irqsave(&current->sighand->siglock, flags);
118         old = current->blocked;
119         sigaddsetmask(&current->blocked, sigs);
120         recalc_sigpending();
121         spin_unlock_irqrestore(&current->sighand->siglock, flags);
122         return old;
123 }
124 EXPORT_SYMBOL(cfs_block_sigs);
125
126 /* Block all signals except for the @sigs */
127 sigset_t cfs_block_sigsinv(unsigned long sigs)
128 {
129         unsigned long flags;
130         sigset_t old;
131
132         spin_lock_irqsave(&current->sighand->siglock, flags);
133         old = current->blocked;
134         sigaddsetmask(&current->blocked, ~sigs);
135         recalc_sigpending();
136         spin_unlock_irqrestore(&current->sighand->siglock, flags);
137         return old;
138 }
139 EXPORT_SYMBOL(cfs_block_sigsinv);
140
141 void
142 cfs_restore_sigs(sigset_t old)
143 {
144         unsigned long  flags;
145
146         spin_lock_irqsave(&current->sighand->siglock, flags);
147         current->blocked = old;
148         recalc_sigpending();
149         spin_unlock_irqrestore(&current->sighand->siglock, flags);
150 }
151 EXPORT_SYMBOL(cfs_restore_sigs);
152
153 void
154 cfs_clear_sigpending(void)
155 {
156         unsigned long flags;
157
158         spin_lock_irqsave(&current->sighand->siglock, flags);
159         clear_tsk_thread_flag(current, TIF_SIGPENDING);
160         spin_unlock_irqrestore(&current->sighand->siglock, flags);
161 }
162 EXPORT_SYMBOL(cfs_clear_sigpending);