Whamcloud - gitweb
69bda369c05a031acdc51e65808fa5a4a1c1d482
[fs/lustre-release.git] / lnet / include / libcfs / linux / linux-prim.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Basic library routines.
22  *
23  */
24
25 #ifndef __LIBCFS_LINUX_CFS_PRIM_H__
26 #define __LIBCFS_LINUX_CFS_PRIM_H__
27
28 #ifndef __LIBCFS_LIBCFS_H__
29 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
30 #endif
31
32 #ifdef __KERNEL__
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/version.h>
37 #include <linux/proc_fs.h>
38 #include <linux/mm.h>
39 #include <linux/timer.h>
40
41 #include <linux/miscdevice.h>
42 #include <libcfs/linux/portals_compat25.h>
43 #include <asm/div64.h>
44
45 #include <libcfs/linux/linux-time.h>
46
47 /*
48  * Pseudo device register
49  */
50 typedef struct miscdevice               cfs_psdev_t;
51 #define cfs_psdev_register(dev)         misc_register(dev)
52 #define cfs_psdev_deregister(dev)       misc_deregister(dev)
53
54 /*
55  * Sysctl register
56  */
57 typedef struct ctl_table                cfs_sysctl_table_t;
58 typedef struct ctl_table_header         cfs_sysctl_table_header_t;
59
60 #define register_cfs_sysctl_table(t, a) register_sysctl_table(t, a)
61 #define unregister_cfs_sysctl_table(t)  unregister_sysctl_table(t, a)
62
63 /*
64  * Proc file system APIs
65  */
66 typedef read_proc_t                     cfs_read_proc_t;
67 typedef write_proc_t                    cfs_write_proc_t;
68 typedef struct proc_dir_entry           cfs_proc_dir_entry_t;
69 #define cfs_create_proc_entry(n, m, p)  create_proc_entry(n, m, p)
70 #define cfs_free_proc_entry(e)          free_proc_entry(e)
71 #define cfs_remove_proc_entry(n, e)     remove_proc_entry(n, e)
72
73 /*
74  * Wait Queue
75  */
76 typedef wait_queue_t                    cfs_waitlink_t;
77 typedef wait_queue_head_t               cfs_waitq_t;
78
79 #define cfs_waitq_init(w)               init_waitqueue_head(w)
80 #define cfs_waitlink_init(l)            init_waitqueue_entry(l, current)
81 #define cfs_waitq_add(w, l)             add_wait_queue(w, l)
82 #define cfs_waitq_add_exclusive(w, l)   add_wait_queue_exclusive(w, l)
83 #define cfs_waitq_forward(l, w)         do {} while(0)
84 #define cfs_waitq_del(w, l)             remove_wait_queue(w, l)
85 #define cfs_waitq_active(w)             waitqueue_active(w)
86 #define cfs_waitq_signal(w)             wake_up(w)
87 #define cfs_waitq_signal_nr(w,n)        wake_up_nr(w, n)
88 #define cfs_waitq_broadcast(w)          wake_up_all(w)
89 #define cfs_waitq_wait(l)               schedule()
90 #define cfs_waitq_timedwait(l, t)       schedule_timeout(t)
91
92 /* Kernel thread */
93 typedef int (*cfs_thread_t)(void *);
94 #define cfs_kernel_thread(func, a, f)   kernel_thread(func, a, f)
95
96 /*
97  * Task struct
98  */
99 typedef struct task_struct              cfs_task_t;
100 #define cfs_current()                   current
101 #define CFS_DECL_JOURNAL_DATA           void *journal_info
102 #define CFS_PUSH_JOURNAL                do {    \
103         journal_info = current->journal_info;   \
104         current->journal_info = NULL;           \
105         } while(0)
106 #define CFS_POP_JOURNAL                 do {    \
107         current->journal_info = journal_info;   \
108         } while(0)
109
110 /* Module interfaces */
111 #define cfs_module(name, version, init, fini) \
112 module_init(init);                            \
113 module_exit(fini)
114
115 /*
116  * Signal
117  */
118 #define cfs_sigmask_lock(t, f)          SIGNAL_MASK_LOCK(t, f)
119 #define cfs_sigmask_unlock(t, f)        SIGNAL_MASK_UNLOCK(t, f)
120 #define cfs_recalc_sigpending(t)        RECALC_SIGPENDING
121 #define cfs_signal_pending(t)           signal_pending(t)
122 #define cfs_sigfillset(s)               sigfillset(s)
123
124 #define cfs_set_sig_blocked(t, b)       do { (t)->blocked = b; } while(0)
125 #define cfs_get_sig_blocked(t)          (&(t)->blocked)
126
127 /*
128  * Timer
129  */
130 typedef struct timer_list cfs_timer_t;
131 typedef  void (*timer_func_t)(unsigned long);
132
133 #define cfs_init_timer(t)       init_timer(t)
134
135 static inline void cfs_timer_init(cfs_timer_t *t, void (*func)(unsigned long), void *arg)
136 {
137         init_timer(t);
138         t->function = (timer_func_t)func;
139         t->data = (unsigned long)arg;
140 }
141
142 static inline void cfs_timer_done(cfs_timer_t *t)
143 {
144         return;
145 }
146
147 static inline void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline)
148 {
149         mod_timer(t, deadline);
150 }
151
152 static inline void cfs_timer_disarm(cfs_timer_t *t)
153 {
154         del_timer(t);
155 }
156
157 static inline int  cfs_timer_is_armed(cfs_timer_t *t)
158 {
159         return timer_pending(t);
160 }
161
162 static inline cfs_time_t cfs_timer_deadline(cfs_timer_t *t)
163 {
164         return t->expires;
165 }
166
167 #else   /* !__KERNEL__ */
168
169 #include "../user-prim.h"
170
171 #endif /* __KERNEL__ */
172
173 #endif