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