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