Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[fs/lustre-release.git] / lustre / include / liblustre.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. <info@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  * User-space Lustre headers.
22  *
23  */
24 #ifndef LIBLUSTRE_H__
25 #define LIBLUSTRE_H__
26
27 #include <sys/mman.h>
28 #include <asm/page.h>
29 #include <stdio.h>
30 #include <sys/ioctl.h>
31 #include <stdint.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <errno.h>
35 #include <sys/stat.h>
36 #include <sys/vfs.h>
37
38 #include <portals/list.h>
39 #include <portals/p30.h>
40
41 /* definitions for liblustre */
42
43 /* always adopt 2.5 definitions */
44 #define LINUX_VERSION_CODE 1
45 #define KERNEL_VERSION(a,b,c) 0
46
47 static inline void inter_module_put(void *a)
48 {
49         return;
50 }
51
52 extern ptl_handle_ni_t         tcpnal_ni;
53
54 static inline void *inter_module_get(char *arg)
55 {
56
57         if (strcmp(arg, "tcpnal_ni") == 0 )
58                 return &tcpnal_ni;
59         else
60                 return NULL;
61
62 }
63
64
65 /* cheats for now */
66
67 struct work_struct {
68         void (*ws_task)(void *arg);
69         void *ws_arg;
70 };
71
72 static inline void prepare_work(struct work_struct *q, void (*t)(void *),
73                                 void *arg)
74 {
75         q->ws_task = t;
76         q->ws_arg = arg;
77         return;
78 }
79
80 static inline void schedule_work(struct work_struct *q)
81 {
82         q->ws_task(q->ws_arg);
83 }
84
85
86 #define strnlen(a,b) strlen(a)
87 static inline void *kmalloc(int size, int prot)
88 {
89         return malloc(size);
90 }
91 #define vmalloc malloc
92 #define vfree free
93 #define kfree(a) free(a)
94 #define GFP_KERNEL 1
95 #define GFP_HIGHUSER 1
96 #define IS_ERR(a) (abs((int)(a)) < 500 ? 1 : 0)
97 #define PTR_ERR(a) ((int)(a))
98
99 #define capable(foo) 1
100 #define CAP_SYS_ADMIN 1
101
102 typedef struct {
103         void *cwd;
104
105 }mm_segment_t;
106
107 typedef void *read_proc_t;
108 typedef void *write_proc_t;
109
110
111 /* modules */
112
113 struct module {
114         int count;
115 };
116
117 static inline void MODULE_AUTHOR(char *name)
118 {
119         printf("%s\n", name);
120 }
121 #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
122 #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
123
124 #define THIS_MODULE NULL
125 #define __init
126 #define __exit
127
128 /* devices */
129
130 static inline int misc_register(void *foo)
131 {
132         return 0;
133 }
134 #define misc_deregister misc_register
135
136 #define __MOD_INC_USE_COUNT(m)  do {int a = 1; a++; } while (0)
137 #define __MOD_DEC_USE_COUNT(m)  do {int a = 1; a++; } while (0)
138 #define MOD_INC_USE_COUNT  do {int a = 1; a++; } while (0)
139 #define MOD_DEC_USE_COUNT  do {int a = 1; a++; } while (0)
140
141 /* module initialization */
142 extern int init_obdclass(void);
143 extern int ptlrpc_init(void);
144 extern int ldlm_init(void);
145 extern int osc_init(void);
146 extern int lov_init(void);
147 extern int echo_client_init(void);
148
149
150
151 /* general stuff */
152 #define jiffies 0
153
154 #define EXPORT_SYMBOL(S)
155
156 typedef int spinlock_t;
157 typedef __u64 kdev_t;
158
159 #define SPIN_LOCK_UNLOCKED 0
160 #define spin_lock(l) do {int a = 1; a++; } while (0)
161 #define spin_unlock(l) do {int a= 1; a++; } while (0)
162 #define spin_lock_init(l) do {int a= 1; a++; } while (0)
163 static inline void spin_lock_bh(spinlock_t *l)
164 {
165         return;
166 }
167 static inline void spin_unlock_bh(spinlock_t *l)
168 {
169         return;
170 }
171 static inline void spin_lock_irqrestore(a,b)
172 {
173         return;
174 }
175 static inline void spin_unlock_irqrestore(a,b)
176 {
177         return;
178 }
179 static inline void spin_lock_irqsave(a,b)
180 {
181         return;
182 }
183
184 #define barrier() do {int a= 1; a++; } while (0)
185
186 /* registering symbols */
187
188 #define ERESTARTSYS ERESTART
189 #define HZ 1
190
191 /* random */
192
193 static inline void get_random_bytes(void *ptr, int size)
194 {
195         static int r;
196         int *p = (int *)ptr;
197         int *end = p + (size / sizeof(int));
198         r = rand();
199         while ( p + sizeof(int) < end ) {
200                 *p = r;
201                 p++;
202         }
203 }
204
205 /* memory */
206
207 static inline int copy_from_user(void *a,void *b, int c)
208 {
209         memcpy(a,b,c);
210         return 0;
211 }
212
213 static inline int copy_to_user(void *a,void *b, int c)
214 {
215         memcpy(a,b,c);
216         return 0;
217 }
218
219
220 /* slabs */
221 typedef struct {
222          int size;
223 } kmem_cache_t;
224 #define SLAB_HWCACHE_ALIGN 0
225 static inline kmem_cache_t *kmem_cache_create(name,objsize,cdum,d,e,f)
226 {
227         kmem_cache_t *c;
228         c = malloc(sizeof(*c));
229         if (!c)
230                 return NULL;
231         c->size = objsize;
232         return c;
233 };
234
235 static inline int kmem_cache_destroy(kmem_cache_t *a)
236 {
237         free(a);
238         return 0;
239 }
240 #define kmem_cache_validate(a,b) 1
241 #define kmem_cache_alloc(cache, prio) malloc(cache->size)
242 #define kmem_cache_free(cache, obj) OBD_FREE(obj, cache->size)
243 #define PORTAL_SLAB_ALLOC(lock,cache,size) do { lock = kmem_cache_alloc(cache,prio); } while (0)
244 #define PORTAL_SLAB_FREE(lock,cache,size) do { lock = kmem_cache_alloc(cache,prio); } while (0)
245
246 struct page {
247         void *addr;
248         int index;
249 };
250
251 #define kmap(page) (page)->addr
252 #define kunmap(a) do { int foo = 1; foo++; } while (0)
253
254 static inline struct page *alloc_pages(mask,foo)
255 {
256         struct page *pg = malloc(sizeof(*pg));
257
258         if (!pg)
259                 return NULL;
260 #ifdef MAP_ANONYMOUS
261         pg->addr = mmap(0, PAGE_SIZE, PROT_WRITE, MAP_ANONYMOUS, 0, 0);
262 #else
263         pg->addr = malloc(PAGE_SIZE);
264 #endif
265
266         if (!pg->addr) {
267                 free(pg);
268                 return NULL;
269         }
270         return pg;
271 }
272
273 static inline void __free_pages(struct page *pg, int what)
274 {
275 #ifdef MAP_ANONYMOUS
276         munmap(pg->addr, PAGE_SIZE);
277 #else
278         free(pg->addr);
279 #endif
280         free(pg);
281 }
282
283 /* arithmetic */
284 #define do_div(a,b) (a)/(b)
285
286 /* dentries / intents */
287 struct lookup_intent {
288         void *it_iattr;
289 };
290
291 struct iattr {
292         int mode;
293 };
294
295 struct dentry {
296         int d_count;
297 };
298 struct file {
299         struct dentry *f_dentry;
300         void *private_data;
301 } ;
302
303 struct vfsmount {
304         void *pwd;
305 };
306 #define cpu_to_le32(x) ((__u32)(x))
307
308 /* semaphores */
309 struct semaphore {
310         int count;
311 };
312
313 #define down(a) do {(a)->count++;} while (0)
314 #define up(a) do {(a)->count--;} while (0)
315 #define sema_init(a,b) do { (a)->count = b; } while (0)
316
317 typedef struct  {
318         struct list_head sleepers;
319 } wait_queue_head_t;
320
321 typedef struct  {
322         struct list_head sleeping;
323         void *process;
324 } wait_queue_t;
325
326 struct signal {
327         int signal;
328 };
329
330 struct task_struct {
331         int state;
332         struct signal pending;
333         char comm[32];
334         int pid;
335 };
336
337 extern struct task_struct *current;
338
339
340
341 #define set_current_state(foo) do { current->state = foo; } while (0)
342
343 #define init_waitqueue_entry(q,p) do { (q)->process = p; } while (0)
344 #define add_wait_queue(q,p) do {  list_add(&(q)->sleepers, &(p)->sleeping); } while (0)
345 #define del_wait_queue(p) do { list_del(&(p)->sleeping); } while (0)
346 #define remove_wait_queue(q,p) do { list_del(&(p)->sleeping); } while (0)
347
348 #define init_waitqueue_head(l) INIT_LIST_HEAD(&(l)->sleepers)
349 #define wake_up(l) do { int a; a++; } while (0)
350 #define wait_event(l,m) do { int a; a++; } while (0)
351 #define TASK_INTERRUPTIBLE 0
352 #define TASK_UNINTERRUPTIBLE 1
353 #define TASK_RUNNING 2
354
355
356 #define schedule() do { int a; a++; } while (0)
357 static inline int schedule_timeout(t)
358 {
359         return 0;
360 }
361
362 #define lock_kernel() do { int a; a++; } while (0)
363 #define daemonize(l) do { int a; a++; } while (0)
364 #define sigfillset(l) do { int a; a++; } while (0)
365 #define recalc_sigpending(l) do { int a; a++; } while (0)
366 #define kernel_thread(l,m,n)
367
368 static inline int call_usermodehelper(char *prog, char **argv, char **evnp)
369 {
370         return 0;
371 }
372
373
374
375 #define KERN_INFO
376
377
378
379 struct timer_list {
380         struct list_head tl_list;
381         void (*function)(unsigned long unused);
382         void *data;
383         int expires;
384 };
385
386 static inline int timer_pending(struct timer_list *l)
387 {
388         if (l->expires > jiffies)
389                 return 1;
390         else
391                 return 0;
392 }
393
394 static inline int init_timer(struct timer_list *l)
395 {
396         INIT_LIST_HEAD(&l->tl_list);
397         return 0;
398 }
399
400 static inline void mod_timer(struct timer_list *l, int thetime)
401 {
402         l->expires = thetime;
403 }
404
405 static inline void del_timer(struct timer_list *l)
406 {
407         free(l);
408 }
409
410 typedef struct { volatile int counter; } atomic_t;
411
412 #define atomic_read(a) ((a)->counter)
413 #define atomic_set(a,b) do {(a)->counter = b; } while (0)
414 #define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
415 #define atomic_inc(a)  (((a)->counter)++)
416 #define atomic_dec(a)  do { (a)->counter--; } while (0)
417 #define atomic_add(b,a)  do {(a)->counter += b;} while (0)
418 #define atomic_sub(b,a)  do {(a)->counter -= b;} while (0)
419
420 #define LBUG() do { sleep(1000000); } while (0)
421
422 #include <linux/obd_support.h>
423 #include <linux/lustre_idl.h>
424 #include <linux/lustre_lib.h>
425 #include <linux/lustre_import.h>
426 #include <linux/lustre_export.h>
427 #include <linux/lustre_net.h>
428
429
430 #endif
431