Whamcloud - gitweb
LU-2675 cleanup: remove unused mkdirdeep.c and lltrace.h
[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  * Copyright (c) 2012, 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  * 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 #ifndef num_present_cpus
77 # define cfs_num_present_cpus() 1
78 #else
79 # define cfs_num_present_cpus() num_present_cpus()
80 #endif
81 /*
82  * Wait Queue.
83  */
84
85 typedef struct cfs_waitlink {
86         cfs_list_t sleeping;
87         void *process;
88 } cfs_waitlink_t;
89
90 typedef struct cfs_waitq {
91         cfs_list_t sleepers;
92 } cfs_waitq_t;
93
94 #define CFS_DECL_WAITQ(wq) cfs_waitq_t wq
95
96 /*
97  * Task states
98  */
99 typedef long cfs_task_state_t;
100
101 #define CFS_TASK_INTERRUPTIBLE  (0)
102 #define CFS_TASK_UNINT          (1)
103 #define CFS_TASK_RUNNING        (2)
104
105 static inline void cfs_schedule(void)                   {}
106 static inline void cfs_schedule_timeout(int64_t t)      {}
107
108 /*
109  * Lproc
110  */
111 typedef int (cfs_read_proc_t)(char *page, char **start, off_t off,
112                           int count, int *eof, void *data);
113
114 struct file; /* forward ref */
115 typedef int (cfs_write_proc_t)(struct file *file, const char *buffer,
116                                unsigned long count, void *data);
117
118 /*
119  * Signal
120  */
121 typedef sigset_t                        cfs_sigset_t;
122
123 /*
124  * Timer
125  */
126
127 typedef struct {
128         cfs_list_t tl_list;
129         void (*function)(ulong_ptr_t unused);
130         ulong_ptr_t data;
131         long expires;
132 } cfs_timer_t;
133
134
135 #define cfs_in_interrupt()    (0)
136
137 typedef void cfs_psdev_t;
138
139 static inline int cfs_psdev_register(cfs_psdev_t *foo)
140 {
141         return 0;
142 }
143
144 static inline int cfs_psdev_deregister(cfs_psdev_t *foo)
145 {
146         return 0;
147 }
148
149 #define cfs_sigfillset(l)               do {} while (0)
150 #define cfs_recalc_sigpending(l)        do {} while (0)
151 /* Fine, crash, but stop giving me compile warnings */
152 #define cfs_kthread_run(fn,d,fmt,...)   LBUG()
153
154 #define CFS_DAEMON_FLAGS                0
155
156 #define CFS_L1_CACHE_ALIGN(x)           (x)
157
158 #ifdef HAVE_LIBPTHREAD
159 typedef int (*cfs_thread_t)(void *);
160 int cfs_create_thread(cfs_thread_t func, void *arg, unsigned long flags);
161 #else
162 #define cfs_create_thread(l,m) LBUG()
163 #endif
164
165 uid_t cfs_curproc_uid(void);
166 gid_t cfs_curproc_gid(void);
167 uid_t cfs_curproc_fsuid(void);
168 gid_t cfs_curproc_fsgid(void);
169
170 #ifndef HAVE_STRLCPY /* not in glibc for RHEL 5.x, remove when obsolete */
171 size_t strlcpy(char *tgt, const char *src, size_t tgt_len);
172 #endif
173
174 #ifndef HAVE_STRLCAT /* not in glibc for RHEL 5.x, remove when obsolete */
175 size_t strlcat(char *tgt, const char *src, size_t tgt_len);
176 #endif
177
178 #define LIBCFS_REALLOC(ptr, size) realloc(ptr, size)
179
180 #define cfs_online_cpus() sysconf(_SC_NPROCESSORS_ONLN)
181
182 // static inline void local_irq_save(unsigned long flag) {return;}
183 // static inline void local_irq_restore(unsigned long flag) {return;}
184
185 enum {
186         CFS_STACK_TRACE_DEPTH = 16
187 };
188
189 struct cfs_stack_trace {
190         void *frame[CFS_STACK_TRACE_DEPTH];
191 };
192
193 /*
194  * arithmetic
195  */
196 #ifndef do_div /* gcc only, platform-specific will override */
197 #define do_div(a,b)                     \
198         ({                              \
199                 unsigned long remainder;\
200                 remainder = (a) % (b);  \
201                 (a) = (a) / (b);        \
202                 (remainder);            \
203         })
204 #endif
205
206 /*
207  * Groups
208  */
209 typedef struct cfs_group_info {
210
211 } cfs_group_info_t;
212
213 #ifndef min
214 # define min(x,y) ((x)<(y) ? (x) : (y))
215 #endif
216
217 #ifndef max
218 # define max(x,y) ((x)>(y) ? (x) : (y))
219 #endif
220
221 #define cfs_get_random_bytes_prim(val, size)     (*val) = 0
222
223 /* utility libcfs init/fini entries */
224 #ifdef __WINNT__
225 extern int libcfs_arch_init(void);
226 extern void libcfs_arch_cleanup(void);
227 #else /* !__WINNT__ */
228 static inline int libcfs_arch_init(void) {
229         return 0;
230 }
231 static inline void libcfs_arch_cleanup(void) {
232 }
233 /* __WINNT__ */
234 #endif
235
236 /* proc interface wrappers for non-win OS */
237 #ifndef __WINNT__
238 #define cfs_proc_open   open
239 #define cfs_proc_mknod  mknod
240 #define cfs_proc_ioctl  ioctl
241 #define cfs_proc_close  close
242 #define cfs_proc_read   read
243 #define cfs_proc_write  write
244 #define cfs_proc_fopen  fopen
245 #define cfs_proc_fclose fclose
246 #define cfs_proc_fgets  fgets
247 /* !__WINNT__ */
248 #endif
249
250 /* !__KERNEL__ */
251 #endif
252
253 /* __LIBCFS_USER_PRIM_H__ */
254 #endif
255 /*
256  * Local variables:
257  * c-indentation-style: "K&R"
258  * c-basic-offset: 8
259  * tab-width: 8
260  * fill-column: 80
261  * scroll-step: 1
262  * End:
263  */