Whamcloud - gitweb
a39a4d748df2acb8ff053114abedee07ae4a3443
[fs/lustre-release.git] / libcfs / include / libcfs / user-prim.h
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
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
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  * libcfs/include/libcfs/user-prim.h
37  *
38  * Author: Nikita Danilov <nikita@clusterfs.com>
39  */
40
41 #ifndef __LIBCFS_USER_PRIM_H__
42 #define __LIBCFS_USER_PRIM_H__
43
44 #ifndef __LIBCFS_LIBCFS_H__
45 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
46 #endif
47
48 /* Implementations of portable APIs for liblustre */
49
50 /*
51  * liblustre is single-threaded, so most "synchronization" APIs are trivial.
52  */
53
54 #ifndef __KERNEL__
55
56 typedef struct proc_dir_entry           cfs_proc_dir_entry_t;
57
58 /*
59  * Just present a single processor until will add thread support.
60  */
61 #ifndef smp_processor_id
62 #define cfs_smp_processor_id() 0
63 #else
64 #define cfs_smp_processor_id() smp_processor_id()
65 #endif
66 #ifndef num_online_cpus
67 #define cfs_num_online_cpus() 1
68 #else
69 #define cfs_num_online_cpus() num_online_cpus()
70 #endif
71 #ifndef num_possible_cpus
72 #define cfs_num_possible_cpus() 1
73 #else
74 #define cfs_num_possible_cpus() num_possible_cpus()
75 #endif
76
77 /*
78  * Wait Queue.
79  */
80
81 typedef struct cfs_waitlink {
82         cfs_list_t sleeping;
83         void *process;
84 } cfs_waitlink_t;
85
86 typedef struct cfs_waitq {
87         cfs_list_t sleepers;
88 } cfs_waitq_t;
89
90 /*
91  * Task states
92  */
93 typedef long cfs_task_state_t;
94
95 #define CFS_TASK_INTERRUPTIBLE  (0)
96 #define CFS_TASK_UNINT          (1)
97 #define CFS_TASK_RUNNING        (2)
98
99
100 /* 
101  * Lproc
102  */
103 typedef int (cfs_read_proc_t)(char *page, char **start, off_t off,
104                           int count, int *eof, void *data);
105
106 struct file; /* forward ref */
107 typedef int (cfs_write_proc_t)(struct file *file, const char *buffer,
108                                unsigned long count, void *data);
109
110 /*
111  * Signal
112  */
113 typedef sigset_t                        cfs_sigset_t;
114
115 /*
116  * Timer
117  */
118
119 typedef struct {
120         cfs_list_t tl_list;
121         void (*function)(ulong_ptr_t unused);
122         ulong_ptr_t data;
123         long expires;
124 } cfs_timer_t;
125
126
127 #define cfs_in_interrupt()    (0)
128
129 typedef void cfs_psdev_t;
130
131 static inline int cfs_psdev_register(cfs_psdev_t *foo)
132 {
133         return 0;
134 }
135
136 static inline int cfs_psdev_deregister(cfs_psdev_t *foo)
137 {
138         return 0;
139 }
140
141 #define cfs_lock_kernel()               do {} while (0)
142 #define cfs_sigfillset(l)               do {} while (0)
143 #define cfs_recalc_sigpending(l)        do {} while (0)
144 #define cfs_kernel_thread(l,m,n)        LBUG()
145 #define cfs_kthread_run(fn,d,fmt,...)   LBUG()
146
147 #ifdef HAVE_LIBPTHREAD
148 typedef int (*cfs_thread_t)(void *);
149 int cfs_create_thread(cfs_thread_t func, void *arg);
150 #else
151 #define cfs_create_thread(l,m) LBUG()
152 #endif
153
154 uid_t cfs_curproc_uid(void);
155
156 #define LIBCFS_REALLOC(ptr, size) realloc(ptr, size)
157
158 #define cfs_online_cpus() sysconf(_SC_NPROCESSORS_ONLN)
159
160 // static inline void local_irq_save(unsigned long flag) {return;}
161 // static inline void local_irq_restore(unsigned long flag) {return;}
162
163 enum {
164         CFS_STACK_TRACE_DEPTH = 16
165 };
166
167 struct cfs_stack_trace {
168         void *frame[CFS_STACK_TRACE_DEPTH];
169 };
170
171 /*
172  * arithmetic
173  */
174 #ifndef do_div /* gcc only, platform-specific will override */
175 #define do_div(a,b)                     \
176         ({                              \
177                 unsigned long remainder;\
178                 remainder = (a) % (b);  \
179                 (a) = (a) / (b);        \
180                 (remainder);            \
181         })
182 #endif
183
184 /*
185  * Groups
186  */
187 typedef struct cfs_group_info {
188
189 } cfs_group_info_t;
190
191 #ifndef min
192 # define min(x,y) ((x)<(y) ? (x) : (y))
193 #endif
194
195 #ifndef max
196 # define max(x,y) ((x)>(y) ? (x) : (y))
197 #endif
198
199 /* utility libcfs init/fini entries */
200 #ifdef __WINNT__
201 extern int libcfs_arch_init(void);
202 extern void libcfs_arch_cleanup(void);
203 #else /* !__WINNT__ */
204 static inline int libcfs_arch_init(void) {
205         return 0;
206 }
207 static inline void libcfs_arch_cleanup(void) {
208 }
209 /* __WINNT__ */
210 #endif
211
212 /* proc interface wrappers for non-win OS */
213 #ifndef __WINNT__
214 #define cfs_proc_open   open
215 #define cfs_proc_mknod  mknod
216 #define cfs_proc_ioctl  ioctl
217 #define cfs_proc_close  close
218 #define cfs_proc_read   read
219 #define cfs_proc_write  write
220 #define cfs_proc_fopen  fopen
221 #define cfs_proc_fclose fclose
222 #define cfs_proc_fgets  fgets
223 /* !__WINNT__ */
224 #endif
225
226 /* !__KERNEL__ */
227 #endif
228
229 /* __LIBCFS_USER_PRIM_H__ */
230 #endif
231 /*
232  * Local variables:
233  * c-indentation-style: "K&R"
234  * c-basic-offset: 8
235  * tab-width: 8
236  * fill-column: 80
237  * scroll-step: 1
238  * End:
239  */