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