Whamcloud - gitweb
d1a27ad29939123fa2c306bbed082c4cbf102cd6
[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 EXPORT_SYMBOL
55 # define EXPORT_SYMBOL(s)
56 #endif
57
58 typedef struct proc_dir_entry           cfs_proc_dir_entry_t;
59
60 /*
61  * Just present a single processor until will add thread support.
62  */
63 #ifndef smp_processor_id
64 # define smp_processor_id() 0
65 #endif
66 #ifndef num_online_cpus
67 # define num_online_cpus() 1
68 #endif
69 #ifndef num_possible_cpus
70 # define num_possible_cpus() 1
71 #endif
72 #ifndef get_cpu
73 # define get_cpu() 0
74 #endif
75 #ifndef put_cpu
76 # define put_cpu() do {} while (0)
77 #endif
78 #ifndef NR_CPUS
79 # define NR_CPUS 1
80 #endif
81 #ifndef for_each_possible_cpu
82 # define for_each_possible_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++)
83 #endif
84
85 /*
86  * Wait Queue.
87  */
88
89 typedef struct cfs_waitlink {
90         struct list_head sleeping;
91         void *process;
92 } wait_queue_t;
93
94 typedef struct cfs_waitq {
95         struct list_head sleepers;
96 } wait_queue_head_t;
97
98 #define CFS_DECL_WAITQ(wq) wait_queue_head_t wq
99 void init_waitqueue_head(struct cfs_waitq *waitq);
100 void init_waitqueue_entry_current(struct cfs_waitlink *link);
101 void add_wait_queue(struct cfs_waitq *waitq, struct cfs_waitlink *link);
102 void add_wait_queue_exclusive(struct cfs_waitq *waitq, struct cfs_waitlink *link);
103 void add_wait_queue_exclusive_head(struct cfs_waitq *waitq, struct cfs_waitlink *link);
104 void remove_wait_queue(struct cfs_waitq *waitq, struct cfs_waitlink *link);
105 int waitqueue_active(struct cfs_waitq *waitq);
106 void wake_up(struct cfs_waitq *waitq);
107 void wake_up_nr(struct cfs_waitq *waitq, int nr);
108 void wake_up_all(struct cfs_waitq *waitq);
109 void waitq_wait(struct cfs_waitlink *link, long state);
110 int64_t waitq_timedwait(struct cfs_waitlink *link, long state, int64_t timeout);
111 void schedule_timeout_and_set_state(long state, int64_t timeout);
112 void cfs_pause(cfs_duration_t d);
113 int need_resched(void);
114 void cond_resched(void);
115
116 /*
117  * Task states
118  */
119 #define TASK_INTERRUPTIBLE  (0)
120 #define TASK_UNINTERRUPTIBLE          (1)
121 #define TASK_RUNNING        (2)
122
123 static inline void schedule(void)                       {}
124 static inline void schedule_timeout(int64_t t)  {}
125 static inline void set_current_state(int state)
126 {
127 }
128
129 /*
130  * Lproc
131  */
132 typedef int (read_proc_t)(char *page, char **start, off_t off,
133                                 int count, int *eof, void *data);
134
135 struct file; /* forward ref */
136 typedef int (write_proc_t)(struct file *file, const char *buffer,
137                                unsigned long count, void *data);
138
139 /*
140  * Signal
141  */
142
143 /*
144  * Timer
145  */
146
147 struct timer_list {
148         struct list_head tl_list;
149         void (*function)(ulong_ptr_t unused);
150         ulong_ptr_t data;
151         long expires;
152 };
153
154
155 #define in_interrupt()    (0)
156
157 struct miscdevice{
158 };
159
160 static inline int misc_register(struct miscdevice *foo)
161 {
162         return 0;
163 }
164
165 static inline int misc_deregister(struct miscdevice *foo)
166 {
167         return 0;
168 }
169
170 #define cfs_recalc_sigpending(l)        do {} while (0)
171
172 #define DAEMON_FLAGS                0
173
174 #define L1_CACHE_ALIGN(x)               (x)
175
176 #ifdef HAVE_LIBPTHREAD
177 typedef int (*cfs_thread_t)(void *);
178 void *kthread_run(cfs_thread_t func, void *arg, const char namefmt[], ...);
179 #else
180 /* Fine, crash, but stop giving me compile warnings */
181 #define kthread_run(f, a, n, ...) LBUG()
182 #endif
183
184 uid_t current_uid(void);
185 gid_t current_gid(void);
186 uid_t current_fsuid(void);
187 gid_t current_fsgid(void);
188
189 #ifndef HAVE_STRLCPY /* not in glibc for RHEL 5.x, remove when obsolete */
190 size_t strlcpy(char *tgt, const char *src, size_t tgt_len);
191 #endif
192
193 #ifndef HAVE_STRLCAT /* not in glibc for RHEL 5.x, remove when obsolete */
194 size_t strlcat(char *tgt, const char *src, size_t tgt_len);
195 #endif
196
197 #define LIBCFS_REALLOC(ptr, size) realloc(ptr, size)
198
199 #define cfs_online_cpus() sysconf(_SC_NPROCESSORS_ONLN)
200
201 // static inline void local_irq_save(unsigned long flag) {return;}
202 // static inline void local_irq_restore(unsigned long flag) {return;}
203
204 enum {
205         CFS_STACK_TRACE_DEPTH = 16
206 };
207
208 struct cfs_stack_trace {
209         void *frame[CFS_STACK_TRACE_DEPTH];
210 };
211
212 /*
213  * arithmetic
214  */
215 #ifndef do_div /* gcc only, platform-specific will override */
216 #define do_div(a,b)                     \
217         ({                              \
218                 unsigned long remainder;\
219                 remainder = (a) % (b);  \
220                 (a) = (a) / (b);        \
221                 (remainder);            \
222         })
223 #endif
224
225 /*
226  * Groups
227  */
228 struct group_info{ };
229
230 #ifndef min
231 # define min(x,y) ((x)<(y) ? (x) : (y))
232 #endif
233
234 #ifndef max
235 # define max(x,y) ((x)>(y) ? (x) : (y))
236 #endif
237
238 #define get_random_bytes(val, size)     (*val) = 0
239
240 /* utility libcfs init/fini entries */
241 static inline int libcfs_arch_init(void) {
242         return 0;
243 }
244 static inline void libcfs_arch_cleanup(void) {
245 }
246
247 #endif /* __LIBCFS_USER_PRIM_H__ */