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