Whamcloud - gitweb
update patchless client for support 2.6.20, 2.6.21 and RHEL5 kernels.
[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 #ifdef HAVE_KERNEL_CONFIG_H
34 #include <linux/config.h>
35 #endif
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/version.h>
39 #include <linux/proc_fs.h>
40 #include <linux/mm.h>
41 #include <linux/timer.h>
42
43 #include <linux/miscdevice.h>
44 #include <libcfs/linux/portals_compat25.h>
45 #include <asm/div64.h>
46
47 #include <libcfs/linux/linux-time.h>
48
49 /*
50  * Pseudo device register
51  */
52 typedef struct miscdevice               cfs_psdev_t;
53 #define cfs_psdev_register(dev)         misc_register(dev)
54 #define cfs_psdev_deregister(dev)       misc_deregister(dev)
55
56 /*
57  * Sysctl register
58  */
59 typedef struct ctl_table                cfs_sysctl_table_t;
60 typedef struct ctl_table_header         cfs_sysctl_table_header_t;
61
62 #ifdef HAVE_2ARGS_REGISTER_SYSCTL
63 #define cfs_register_sysctl_table(t, a) register_sysctl_table(t, a)
64 #else
65 #define cfs_register_sysctl_table(t, a) register_sysctl_table(t)
66 #endif
67 #define cfs_unregister_sysctl_table(t)  unregister_sysctl_table(t)
68
69 /*
70  * Symbol register
71  */
72 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
73 #define cfs_symbol_register(s, p)       inter_module_register(s, THIS_MODULE, p)
74 #define cfs_symbol_unregister(s)        inter_module_unregister(s)
75 #define cfs_symbol_get(s)               inter_module_get(s)
76 #define cfs_symbol_put(s)               inter_module_put(s)
77 #define cfs_module_get()                MOD_INC_USE_COUNT
78 #define cfs_module_put()                MOD_DEC_USE_COUNT
79 #else
80 #define cfs_symbol_register(s, p)       do {} while(0)
81 #define cfs_symbol_unregister(s)        do {} while(0)
82 #define cfs_symbol_get(s)               symbol_get(s)
83 #define cfs_symbol_put(s)               symbol_put(s)
84 #define cfs_module_get()                try_module_get(THIS_MODULE)
85 #define cfs_module_put()                module_put(THIS_MODULE)
86 #endif
87
88 /*
89  * Proc file system APIs
90  */
91 typedef read_proc_t                     cfs_read_proc_t;
92 typedef write_proc_t                    cfs_write_proc_t;
93 typedef struct proc_dir_entry           cfs_proc_dir_entry_t;
94 #define cfs_create_proc_entry(n, m, p)  create_proc_entry(n, m, p)
95 #define cfs_free_proc_entry(e)          free_proc_entry(e)
96 #define cfs_remove_proc_entry(n, e)     remove_proc_entry(n, e)
97
98 /*
99  * Wait Queue
100  */
101 #define CFS_TASK_INTERRUPTIBLE          TASK_INTERRUPTIBLE
102 #define CFS_TASK_UNINT                  TASK_UNINTERRUPTIBLE
103
104 typedef wait_queue_t                    cfs_waitlink_t;
105 typedef wait_queue_head_t               cfs_waitq_t;
106
107 typedef long                            cfs_task_state_t;
108
109 #define cfs_waitq_init(w)               init_waitqueue_head(w)
110 #define cfs_waitlink_init(l)            init_waitqueue_entry(l, current)
111 #define cfs_waitq_add(w, l)             add_wait_queue(w, l)
112 #define cfs_waitq_add_exclusive(w, l)   add_wait_queue_exclusive(w, l)
113 #define cfs_waitq_forward(l, w)         do {} while(0)
114 #define cfs_waitq_del(w, l)             remove_wait_queue(w, l)
115 #define cfs_waitq_active(w)             waitqueue_active(w)
116 #define cfs_waitq_signal(w)             wake_up(w)
117 #define cfs_waitq_signal_nr(w,n)        wake_up_nr(w, n)
118 #define cfs_waitq_broadcast(w)          wake_up_all(w)
119 #define cfs_waitq_wait(l, s)            schedule()
120 #define cfs_waitq_timedwait(l, s, t)    schedule_timeout(t)
121 #define cfs_schedule_timeout(s, t)      schedule_timeout(t)
122 #define cfs_schedule()                  schedule()
123
124 /* Kernel thread */
125 typedef int (*cfs_thread_t)(void *);
126 #define cfs_kernel_thread(func, a, f)   kernel_thread(func, a, f)
127
128 /*
129  * Task struct
130  */
131 typedef struct task_struct              cfs_task_t;
132 #define cfs_current()                   current
133 #define cfs_task_lock(t)                task_lock(t)
134 #define cfs_task_unlock(t)              task_unlock(t)
135 #define CFS_DECL_JOURNAL_DATA           void *journal_info
136 #define CFS_PUSH_JOURNAL                do {    \
137         journal_info = current->journal_info;   \
138         current->journal_info = NULL;           \
139         } while(0)
140 #define CFS_POP_JOURNAL                 do {    \
141         current->journal_info = journal_info;   \
142         } while(0)
143
144 /* Module interfaces */
145 #define cfs_module(name, version, init, fini) \
146 module_init(init);                            \
147 module_exit(fini)
148
149 /*
150  * Signal
151  */
152 typedef sigset_t                        cfs_sigset_t;
153
154 /*
155  * Timer
156  */
157 typedef struct timer_list cfs_timer_t;
158 typedef  void (*timer_func_t)(unsigned long);
159
160 #define cfs_init_timer(t)       init_timer(t)
161
162 static inline void cfs_timer_init(cfs_timer_t *t, void (*func)(unsigned long), void *arg)
163 {
164         init_timer(t);
165         t->function = (timer_func_t)func;
166         t->data = (unsigned long)arg;
167 }
168
169 static inline void cfs_timer_done(cfs_timer_t *t)
170 {
171         return;
172 }
173
174 static inline void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline)
175 {
176         mod_timer(t, deadline);
177 }
178
179 static inline void cfs_timer_disarm(cfs_timer_t *t)
180 {
181         del_timer(t);
182 }
183
184 static inline int  cfs_timer_is_armed(cfs_timer_t *t)
185 {
186         return timer_pending(t);
187 }
188
189 static inline cfs_time_t cfs_timer_deadline(cfs_timer_t *t)
190 {
191         return t->expires;
192 }
193
194
195 /* deschedule for a bit... */
196 static inline void cfs_pause(cfs_duration_t ticks)
197 {
198         set_current_state(TASK_UNINTERRUPTIBLE);
199         schedule_timeout(ticks);
200 }
201
202 #else   /* !__KERNEL__ */
203
204 typedef struct proc_dir_entry           cfs_proc_dir_entry_t;
205 #include "../user-prim.h"
206
207 #endif /* __KERNEL__ */
208
209 #endif