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