Whamcloud - gitweb
- many fixes about using ENTRY, RETURN, GOTO and EXIT.
[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 #ifdef HAVE_STDINT_H
29 # include <stdint.h>
30 #endif
31 #ifdef HAVE_ASM_PAGE_H
32 # include <asm/page.h>
33 #endif
34 #ifdef HAVE_SYS_USER_H
35 # include <sys/user.h>
36 #endif
37
38 #include "ioctl.h"
39
40 #include <stdio.h>
41 #include <sys/ioctl.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <errno.h>
45 #include <sys/stat.h>
46 #include <sys/vfs.h>
47
48 #include <libcfs/list.h>
49 #include <portals/p30.h>
50 #include <libcfs/kp30.h>
51
52 /* definitions for liblustre */
53
54 #ifdef __CYGWIN__
55
56 #define PAGE_SHIFT 12
57 #define PAGE_SIZE (1UL << PAGE_SHIFT)
58 #define PAGE_MASK (~(PAGE_SIZE-1))
59 #define loff_t long long
60 #define ERESTART 2001
61 typedef unsigned short umode_t;
62
63 #endif
64
65 /* This is because lprocfs_status.h gets included here indirectly.  It would
66  * be much better to just avoid lprocfs being included into liblustre entirely
67  * but that requires more header surgery than I can handle right now.
68  */
69 #ifndef smp_processor_id
70 #define smp_processor_id() 0
71 #endif
72
73 #ifndef smp_mb
74 #define smp_mb() do {} while (0)
75 #endif
76
77 #ifndef might_sleep_if
78 #define might_sleep_if(cond) do {} while (0)
79 #endif
80
81 #ifndef might_sleep
82 #define might_sleep() do {} while (0)
83 #endif
84
85 #ifndef signal_pending
86 #define signal_pending(proc) 0
87 #endif
88
89 #ifndef MAY_EXEC
90 #define MAY_EXEC 1
91 #endif
92
93 #ifndef MAY_WRITE
94 #define MAY_WRITE 2
95 #endif
96
97 #ifndef MAY_READ
98 #define MAY_READ 4
99 #endif
100
101 #ifndef MAY_APPEND
102 #define MAY_APPEND 8
103 #endif
104
105 #ifndef FMODE_READ
106 #define FMODE_READ 1
107 #endif
108
109 #ifndef FMODE_WRITE
110 #define FMODE_WRITE 2
111 #endif
112
113 #ifndef FMODE_EXEC
114 #define FMODE_EXEC 4
115 #endif
116
117 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
118 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
119 #define S_IRUGO   (S_IRUSR|S_IRGRP|S_IROTH)
120 #define S_IWUGO   (S_IWUSR|S_IWGRP|S_IWOTH)
121 #define S_IXUGO   (S_IXUSR|S_IXGRP|S_IXOTH)
122
123 #define LBUG()                                                          \
124         do {                                                            \
125                 printf("!!!LBUG at %s:%d\n", __FILE__, __LINE__);       \
126                 sleep(1000000);                                         \
127         } while (0)
128
129 /* always adopt 2.5 definitions */
130 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
131 #define LINUX_VERSION_CODE (2*200+5*10+0)
132
133 static inline void inter_module_put(void *a)
134 {
135         return;
136 }
137
138 extern ptl_handle_ni_t         tcpnal_ni;
139
140 void *inter_module_get(char *arg);
141
142 /* cheats for now */
143
144 struct work_struct {
145         void (*ws_task)(void *arg);
146         void *ws_arg;
147 };
148
149 static inline void prepare_work(struct work_struct *q, void (*t)(void *),
150                                 void *arg)
151 {
152         q->ws_task = t;
153         q->ws_arg = arg;
154         return;
155 }
156
157 static inline void schedule_work(struct work_struct *q)
158 {
159         q->ws_task(q->ws_arg);
160 }
161
162
163 #define strnlen(a,b) strlen(a)
164 static inline void *kmalloc(int size, int prot)
165 {
166         return malloc(size);
167 }
168 #define vmalloc malloc
169 #define vfree free
170 #define kfree(a) free(a)
171 #define GFP_KERNEL 1
172 #define GFP_HIGHUSER 1
173 #define GFP_ATOMIC 1
174 #define GFP_NOFS 1
175 #define IS_ERR(a) (((a) && abs((long)(a)) < 500) ? 1 : 0)
176 #define PTR_ERR(a) ((long)(a))
177 #define ERR_PTR(a) ((void*)((long)(a)))
178
179 typedef struct {
180         void *cwd;
181 } mm_segment_t;
182
183 typedef int (read_proc_t)(char *page, char **start, off_t off,
184                           int count, int *eof, void *data);
185
186 struct file; /* forward ref */
187 typedef int (write_proc_t)(struct file *file, const char *buffer,
188                            unsigned long count, void *data);
189
190 #define NIPQUAD(addr) \
191         ((unsigned char *)&addr)[0], \
192         ((unsigned char *)&addr)[1], \
193         ((unsigned char *)&addr)[2], \
194         ((unsigned char *)&addr)[3]
195
196 #if defined(__LITTLE_ENDIAN)
197 #define HIPQUAD(addr) \
198         ((unsigned char *)&addr)[3], \
199         ((unsigned char *)&addr)[2], \
200         ((unsigned char *)&addr)[1], \
201         ((unsigned char *)&addr)[0]
202 #elif defined(__BIG_ENDIAN)
203 #define HIPQUAD NIPQUAD
204 #else
205 #error "Undefined byteorder??"
206 #endif /* __LITTLE_ENDIAN */
207
208 /* bits ops */
209 static __inline__ int set_bit(int nr,long * addr)
210 {
211         int     mask, retval;
212
213         addr += nr >> 5;
214         mask = 1 << (nr & 0x1f);
215         retval = (mask & *addr) != 0;
216         *addr |= mask;
217         return retval;
218 }
219
220 static __inline__ int clear_bit(int nr, long * addr)
221 {
222         int     mask, retval;
223
224         addr += nr >> 5;
225         mask = 1 << (nr & 0x1f);
226         retval = (mask & *addr) != 0;
227         *addr &= ~mask;
228         return retval;
229 }
230
231 static __inline__ int test_bit(int nr, long * addr)
232 {
233         int     mask;
234
235         addr += nr >> 5;
236         mask = 1 << (nr & 0x1f);
237         return ((mask & *addr) != 0);
238 }
239
240 static __inline__ int test_and_set_bit(int nr, long * addr)
241 {
242         int     res;
243
244         res = test_bit(nr, addr);
245         set_bit(nr, addr);
246         
247         return res;
248 }
249
250 static __inline__ int ext2_set_bit(int nr, void *addr)
251 {
252         return set_bit(nr, (long*)addr);
253 }
254
255 static __inline__ int ext2_clear_bit(int nr, void *addr)
256 {
257         return clear_bit(nr, (long*)addr);
258 }
259
260 static __inline__ int ext2_test_bit(int nr, void *addr)
261 {
262         return test_bit(nr, (long*)addr);
263 }
264
265 /* modules */
266
267 struct module {
268         int count;
269 };
270
271 #define MODULE_AUTHOR(name)
272 #define MODULE_DESCRIPTION(name)
273 #define MODULE_LICENSE(name)
274
275 #define module_init(init)
276 #define module_exit(exit)
277
278 #define THIS_MODULE NULL
279 #define __init
280 #define __exit
281 #define __user
282
283 /* devices */
284
285 static inline int misc_register(void *foo)
286 {
287         return 0;
288 }
289
290 static inline int misc_deregister(void *foo)
291 {
292         return 0;
293 }
294
295 static inline int request_module(char *name)
296 {
297         return (-EINVAL);
298 }
299
300 #define __MOD_INC_USE_COUNT(m)  do {} while (0)
301 #define __MOD_DEC_USE_COUNT(m)  do {} while (0)
302 #define MOD_INC_USE_COUNT       do {} while (0)
303 #define MOD_DEC_USE_COUNT       do {} while (0)
304 static inline void __module_get(struct module *module)
305 {
306 }
307
308 static inline int try_module_get(struct module *module)
309 {
310         return 1;
311 }
312
313 static inline void module_put(struct module *module)
314 {
315 }
316
317 /* module initialization */
318 extern int init_obdclass(void);
319 extern int ptlrpc_init(void);
320 extern int ldlm_init(void);
321 extern int osc_init(void);
322 extern int lov_init(void);
323 extern int mdc_init(void);
324 extern int echo_client_init(void);
325
326
327
328 /* general stuff */
329
330 #define EXPORT_SYMBOL(S)
331
332 typedef struct { } spinlock_t;
333 typedef __u64 kdev_t;
334
335 #define SPIN_LOCK_UNLOCKED (spinlock_t) { }
336 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
337
338 static inline void spin_lock(spinlock_t *l) {return;}
339 static inline void spin_unlock(spinlock_t *l) {return;}
340 static inline void spin_lock_init(spinlock_t *l) {return;}
341 static inline void local_irq_save(unsigned long flag) {return;}
342 static inline void local_irq_restore(unsigned long flag) {return;}
343 static inline int spin_is_locked(spinlock_t *l) {return 1;}
344
345 static inline void spin_lock_bh(spinlock_t *l) {}
346 static inline void spin_unlock_bh(spinlock_t *l) {}
347 static inline void spin_lock_irqsave(spinlock_t *a, unsigned long b) {}
348 static inline void spin_unlock_irqrestore(spinlock_t *a, unsigned long b) {}
349
350 typedef struct { } rwlock_t;
351 #define rwlock_init(x) do {} while(0)
352 #define RW_LOCK_UNLOCKED (rwlock_t) {}
353 #define read_lock(l)
354 #define read_unlock(l)
355 #define write_lock(l)
356 #define write_unlock(l)
357
358 #define min(x,y) ((x)<(y) ? (x) : (y))
359 #define max(x,y) ((x)>(y) ? (x) : (y))
360
361 #ifndef min_t
362 #define min_t(type,x,y) \
363         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
364 #endif
365 #ifndef max_t
366 #define max_t(type,x,y) \
367         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
368 #endif
369
370 #define container_of(ptr, type, member) ({                      \
371         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
372         (type *)( (char *)__mptr - offsetof(type,member) );})
373
374 /* registering symbols */
375
376 #define ERESTARTSYS ERESTART
377 #define HZ 1
378
379 /* random */
380
381 void get_random_bytes(void *ptr, int size);
382
383 /* memory */
384
385 /* FIXME */
386 #define num_physpages (16 * 1024)
387
388 static inline int copy_from_user(void *a,void *b, int c)
389 {
390         memcpy(a,b,c);
391         return 0;
392 }
393
394 static inline int copy_to_user(void *a,void *b, int c)
395 {
396         memcpy(a,b,c);
397         return 0;
398 }
399
400 static inline long strncpy_from_user(char *dest, const char *src, long n)
401 {
402         char *s;
403         s = strncpy(dest, src, n);
404         return strnlen(s, n);
405 }
406
407 /* slabs */
408 typedef struct {
409          int size;
410 } kmem_cache_t;
411 #define SLAB_HWCACHE_ALIGN 0
412 static inline kmem_cache_t *
413 kmem_cache_create(const char *name, size_t objsize, size_t cdum,
414                   unsigned long d,
415                   void (*e)(void *, kmem_cache_t *, unsigned long),
416                   void (*f)(void *, kmem_cache_t *, unsigned long))
417 {
418         kmem_cache_t *c;
419         c = malloc(sizeof(*c));
420         if (!c)
421                 return NULL;
422         c->size = objsize;
423         CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
424                name, c, (int)objsize);
425         return c;
426 };
427
428 static inline int kmem_cache_destroy(kmem_cache_t *a)
429 {
430         CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", a, a->size);
431         free(a);
432         return 0;
433 }
434 #define kmem_cache_alloc(cache, prio) malloc(cache->size)
435 #define kmem_cache_free(cache, obj) free(obj)
436
437 #define PAGE_CACHE_SIZE  PAGE_SIZE
438 #define PAGE_CACHE_SHIFT PAGE_SHIFT
439 #define PAGE_CACHE_MASK  PAGE_MASK
440
441 /* struct page decl moved out from here into portals/include/libcfs/user-prim.h */
442
443 /* 2.4 defines */
444 #define PAGE_LIST_ENTRY list
445 #define PAGE_LIST(page) ((page)->list)
446
447 #define page_address(page) ((page)->addr)
448 #define kmap(page) (page)->addr
449 #define kunmap(a) do {} while (0)
450
451 static inline struct page *alloc_pages(int mask, unsigned long order)
452 {
453         struct page *pg = malloc(sizeof(*pg));
454
455         if (!pg)
456                 return NULL;
457 #if 0 //#ifdef MAP_ANONYMOUS
458         pg->addr = mmap(0, PAGE_SIZE << order, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
459 #else
460         pg->addr = malloc(PAGE_SIZE << order);
461 #endif
462
463         if (!pg->addr) {
464                 free(pg);
465                 return NULL;
466         }
467         return pg;
468 }
469
470 #define alloc_page(mask) alloc_pages((mask), 0)
471
472 static inline void __free_pages(struct page *pg, int what)
473 {
474 #if 0 //#ifdef MAP_ANONYMOUS
475         munmap(pg->addr, PAGE_SIZE);
476 #else
477         free(pg->addr);
478 #endif
479         free(pg);
480 }
481
482 #define __free_page(page) __free_pages((page), 0)
483 #define free_page(page) __free_page(page)
484
485 static inline struct page* __grab_cache_page(unsigned long index)
486 {
487         struct page *pg = alloc_pages(0, 0);
488
489         if (pg)
490                 pg->index = index;
491         return pg;
492 }
493
494 #define grab_cache_page(index) __grab_cache_page(index)
495 #define page_cache_release(page) __free_pages(page, 0)
496
497 /* arithmetic */
498 #define do_div(a,b)                     \
499         ({                              \
500                 unsigned long remainder;\
501                 remainder = (a) % (b);  \
502                 (a) = (a) / (b);        \
503                 (remainder);            \
504         })
505
506 /* VFS stuff */
507 #define ATTR_MODE       0x0001
508 #define ATTR_UID        0x0002
509 #define ATTR_GID        0x0004
510 #define ATTR_SIZE       0x0008
511 #define ATTR_ATIME      0x0010
512 #define ATTR_MTIME      0x0020
513 #define ATTR_CTIME      0x0040
514 #define ATTR_ATIME_SET  0x0080
515 #define ATTR_MTIME_SET  0x0100
516 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
517 #define ATTR_ATTR_FLAG  0x0400
518 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
519 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
520 /* ATTR_CTIME_SET has been defined in lustre_idl.h */
521
522 struct iattr {
523         unsigned int    ia_valid;
524         umode_t         ia_mode;
525         uid_t           ia_uid;
526         gid_t           ia_gid;
527         loff_t          ia_size;
528         time_t          ia_atime;
529         time_t          ia_mtime;
530         time_t          ia_ctime;
531         unsigned int    ia_attr_flags;
532 };
533
534 #define IT_OPEN     0x0001
535 #define IT_CREAT    0x0002
536 #define IT_READDIR  0x0004
537 #define IT_GETATTR  0x0008
538 #define IT_LOOKUP   0x0010
539 #define IT_UNLINK   0x0020
540 #define IT_GETXATTR 0x0040
541 #define IT_EXEC     0x0080
542 #define IT_PIN      0x0100
543 #define IT_CHDIR    0x0200
544
545 #define IT_FL_LOCKED   0x0001
546 #define IT_FL_FOLLOWED 0x0002 /* set by vfs_follow_link */
547
548 #define INTENT_MAGIC 0x19620323
549
550 struct lookup_intent {
551         int     it_magic;
552         void    (*it_op_release)(struct lookup_intent *);
553         int     it_op;
554         int     it_flags;
555         int     it_create_mode;
556         union {
557                 void *fs_data; /* FS-specific intent data */
558         } d;
559 };
560
561 struct lustre_intent_data {
562         int     it_disposition;
563         int     it_status;
564         __u64   it_lock_handle;
565         void    *it_data;
566         int     it_lock_mode;
567         int     it_int_flags;
568         void    *it_key;
569         int     it_key_size;
570 };
571
572 #define LUSTRE_IT(it) ((struct lustre_intent_data *)((it)->d.fs_data))
573
574 static inline void intent_init(struct lookup_intent *it, int op, int flags)
575 {
576         memset(it, 0, sizeof(*it));
577         it->it_magic = INTENT_MAGIC;
578         it->it_op = op;
579         it->it_flags = flags;
580 }
581
582
583 struct dentry {
584         int d_count;
585 };
586
587 struct vfsmount {
588         void *pwd;
589 };
590
591 /* semaphores */
592 struct rw_semaphore {
593         int count;
594 };
595
596 /* semaphores */
597 struct semaphore {
598         int count;
599 };
600
601 struct crypto_tfm;
602
603 struct scatterlist {
604     struct page         *page;
605     unsigned int        offset;
606     __u32               dma_address;
607     unsigned int        length;
608 };
609
610 struct cipher_tfm {
611         void *cit_iv;
612         unsigned int cit_ivsize;
613         __u32 cit_mode;
614         int (*cit_setkey)(struct crypto_tfm *tfm,
615                           const __u8 *key, unsigned int keylen);
616         int (*cit_encrypt)(struct crypto_tfm *tfm,
617                            struct scatterlist *dst,
618                            struct scatterlist *src,
619                            unsigned int nbytes);
620         int (*cit_encrypt_iv)(struct crypto_tfm *tfm,
621                               struct scatterlist *dst,
622                               struct scatterlist *src,
623                               unsigned int nbytes, __u8 *iv);
624         int (*cit_decrypt)(struct crypto_tfm *tfm,
625                            struct scatterlist *dst,
626                            struct scatterlist *src,
627                            unsigned int nbytes);
628         int (*cit_decrypt_iv)(struct crypto_tfm *tfm,
629                            struct scatterlist *dst,
630                            struct scatterlist *src,
631                            unsigned int nbytes, __u8 *iv);
632         void (*cit_xor_block)(__u8 *dst, const __u8 *src);
633 };
634
635 struct digest_tfm {
636         void (*dit_init)(struct crypto_tfm *tfm);
637         void (*dit_update)(struct crypto_tfm *tfm,
638                            struct scatterlist *sg, unsigned int nsg);
639         void (*dit_update_kernel)(struct crypto_tfm *tfm,
640                                   const void *data, size_t count);
641         void (*dit_final)(struct crypto_tfm *tfm, __u8 *out);
642         void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg,
643                            unsigned int nsg, __u8 *out);
644         int (*dit_setkey)(struct crypto_tfm *tfm,
645                           const __u8 *key, unsigned int keylen);
646 #ifdef CONFIG_CRYPTO_HMAC
647         void *dit_hmac_block;
648 #endif
649 };
650
651 struct compress_tfm {
652         int (*cot_compress)(struct crypto_tfm *tfm,
653                             const __u8 *src, unsigned int slen,
654                             __u8 *dst, unsigned int *dlen);
655         int (*cot_decompress)(struct crypto_tfm *tfm,
656                               const __u8 *src, unsigned int slen,
657                               __u8 *dst, unsigned int *dlen);
658 };
659
660 struct crypto_tfm {
661
662         __u32 crt_flags;
663
664         union {
665                 struct cipher_tfm cipher;
666                 struct digest_tfm digest;
667                 struct compress_tfm compress;
668         } crt_u;
669
670         struct crypto_alg *__crt_alg;
671 };
672
673 /* use the macro's argument to avoid unused warnings */
674 #define down(a) do { (void)a; } while (0)
675 #define up(a) do { (void)a; } while (0)
676 #define down_read(a) do { (void)a; } while (0)
677 #define up_read(a) do { (void)a; } while (0)
678 #define down_write(a) do { (void)a; } while (0)
679 #define up_write(a) do { (void)a; } while (0)
680 #define sema_init(a,b) do { (void)a; } while (0)
681 #define init_rwsem(a) do { (void)a; } while (0)
682
683 #define DECLARE_MUTEX(name)     \
684         struct semaphore name = { 1 }
685
686 static inline void init_MUTEX (struct semaphore *sem)
687 {
688         sema_init(sem, 1);
689 }
690
691 struct rpc_pipe_msg {
692         struct list_head list;
693         void *data;
694         size_t len;
695         size_t copied;
696         int error;
697 };
698
699 typedef struct  {
700         struct list_head task_list;
701 } wait_queue_head_t;
702
703 typedef struct  {
704         struct list_head sleeping;
705         void *process;
706 } wait_queue_t;
707
708 struct signal {
709         int signal;
710 };
711
712 struct fs_struct {
713         int umask;
714 };
715
716 struct task_struct {
717         struct fs_struct *fs;
718         int state;
719         struct signal pending;
720         char comm[32];
721         int pid;
722         uid_t uid;
723         gid_t gid;
724         int fsuid;
725         int fsgid;
726         int max_groups;
727         int ngroups;
728         gid_t *groups;
729         __u32 cap_effective;
730         __u32 pag;
731
732         struct fs_struct __fs;
733 };
734
735 extern struct task_struct *current;
736 int in_group_p(gid_t gid);
737 static inline int capable(int cap)
738 {
739         if (current->cap_effective & (1 << cap))
740                 return 1;
741         else
742                 return 0;
743 }
744
745 #define set_current_state(foo) do { current->state = foo; } while (0)
746
747 #define init_waitqueue_entry(q,p) do { (q)->process = p; } while (0)
748 #define add_wait_queue(q,p) do {  list_add(&(q)->task_list, &(p)->sleeping); } while (0)
749 #define del_wait_queue(p) do { list_del(&(p)->sleeping); } while (0)
750 #define remove_wait_queue(q,p) do { list_del(&(p)->sleeping); } while (0)
751
752 #define DECLARE_WAIT_QUEUE_HEAD(HEAD)                           \
753         wait_queue_head_t HEAD = {                              \
754                 .task_list = LIST_HEAD_INIT(HEAD.task_list)       \
755         }
756 #define init_waitqueue_head(l) INIT_LIST_HEAD(&(l)->task_list)
757 #define wake_up(l) do { int a; a++; } while (0)
758 #define TASK_INTERRUPTIBLE 0
759 #define TASK_UNINTERRUPTIBLE 1
760 #define TASK_RUNNING 2
761
762 #define wait_event_interruptible(wq, condition)                         \
763 ({                                                                      \
764         struct l_wait_info lwi;                                         \
765         int timeout = 100000000;/* for ever */                          \
766         int ret;                                                        \
767                                                                         \
768         lwi = LWI_TIMEOUT(timeout, NULL, NULL);                         \
769         ret = l_wait_event(NULL, condition, &lwi);                      \
770                                                                         \
771         ret;                                                            \
772 })
773
774 #define in_interrupt() (0)
775
776 #define schedule() do {} while (0)
777 static inline int schedule_timeout(signed long t)
778 {
779         return 0;
780 }
781
782 #define lock_kernel() do {} while (0)
783 #define unlock_kernel() do {} while (0)
784 #define daemonize(l) do {} while (0)
785 #define sigfillset(l) do {} while (0)
786 #define recalc_sigpending(l) do {} while (0)
787 #define kernel_thread(l,m,n) LBUG()
788
789 #define USERMODEHELPER(path, argv, envp) (0)
790 #define SIGNAL_MASK_ASSERT()
791 #define KERN_INFO
792
793 #include <sys/time.h>
794 #if HZ != 1
795 #error "liblustre's jiffies currently expects HZ to be 1"
796 #endif
797 #define jiffies                                 \
798 ({                                              \
799         unsigned long _ret = 0;                 \
800         struct timeval tv;                      \
801         if (gettimeofday(&tv, NULL) == 0)       \
802                 _ret = tv.tv_sec;               \
803         _ret;                                   \
804 })
805 #define time_after(a, b) ((long)(b) - (long)(a) < 0)
806 #define time_before(a, b) time_after(b,a)
807
808 static inline unsigned long get_seconds(void)
809 {
810         struct timeval tv;
811
812         gettimeofday(&tv, NULL);
813         return (tv.tv_sec + tv.tv_usec / 1000000);
814 }
815
816 struct timer_list {
817         struct list_head tl_list;
818         void (*function)(unsigned long unused);
819         unsigned long data;
820         long expires;
821 };
822
823 static inline int timer_pending(struct timer_list *l)
824 {
825         if (l->expires > jiffies)
826                 return 1;
827         else
828                 return 0;
829 }
830
831 static inline int init_timer(struct timer_list *l)
832 {
833         INIT_LIST_HEAD(&l->tl_list);
834         return 0;
835 }
836
837 static inline void mod_timer(struct timer_list *l, int thetime)
838 {
839         l->expires = thetime;
840 }
841
842 static inline void del_timer(struct timer_list *l)
843 {
844         free(l);
845 }
846
847 typedef struct { volatile int counter; } atomic_t;
848
849 #define ATOMIC_INIT(i) { (i) }
850 #define atomic_read(a) ((a)->counter)
851 #define atomic_set(a,b) do {(a)->counter = b; } while (0)
852 #define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
853 #define atomic_dec_and_lock(a, l) atomic_dec_and_test(a)
854 #define atomic_inc(a)  (((a)->counter)++)
855 #define atomic_dec(a)  do { (a)->counter--; } while (0)
856 #define atomic_add(b,a)  do {(a)->counter += b;} while (0)
857 #define atomic_sub(b,a)  do {(a)->counter -= b;} while (0)
858
859 #ifndef likely
860 #define likely(exp) (exp)
861 #endif
862 #ifndef unlikely
863 #define unlikely(exp) (exp)
864 #endif
865
866 /* FIXME sys/capability will finally included linux/fs.h thus
867  * cause numerous trouble on x86-64. as temporary solution for
868  * build broken at cary, we copy definition we need from capability.h
869  * FIXME
870  */
871 struct _cap_struct;
872 typedef struct _cap_struct *cap_t;
873 typedef int cap_value_t;
874 typedef enum {
875     CAP_EFFECTIVE=0,
876     CAP_PERMITTED=1,
877     CAP_INHERITABLE=2
878 } cap_flag_t;
879 typedef enum {
880     CAP_CLEAR=0,
881     CAP_SET=1
882 } cap_flag_value_t;
883
884 #define CAP_DAC_OVERRIDE        1
885 #define CAP_DAC_READ_SEARCH     2
886 #define CAP_FOWNER              3
887 #define CAP_FSETID              4
888 #define CAP_SYS_ADMIN          21
889
890 cap_t   cap_get_proc(void);
891 int     cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
892
893
894
895 /* log related */
896 static inline int llog_init_commit_master(void) { return 0; }
897 static inline int llog_cleanup_commit_master(int force) { return 0; }
898 static inline void portals_run_lbug_upcall(char *file, const char *fn,
899                                            const int l){}
900
901 /* completion */
902 struct completion {
903         unsigned int done;
904         wait_queue_head_t wait;
905 };
906
907 #define COMPLETION_INITIALIZER(work) \
908         { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
909
910 #define DECLARE_COMPLETION(work) \
911         struct completion work = COMPLETION_INITIALIZER(work)
912
913 #define INIT_COMPLETION(x)      ((x).done = 0)
914
915 static inline void init_completion(struct completion *x)
916 {
917         x->done = 0;
918         init_waitqueue_head(&x->wait);
919 }
920
921 struct liblustre_wait_callback {
922         struct list_head    llwc_list;
923         int               (*llwc_fn)(void *arg);
924         void               *llwc_arg;
925 };
926
927 void *liblustre_register_wait_callback(int (*fn)(void *arg), void *arg);
928 void liblustre_deregister_wait_callback(void *notifier);
929 int liblustre_wait_event(int timeout);
930
931 #include <linux/obd_support.h>
932 #include <linux/lustre_idl.h>
933 #include <linux/lustre_lib.h>
934 #include <linux/lustre_import.h>
935 #include <linux/lustre_export.h>
936 #include <linux/lustre_net.h>
937
938 #endif