Whamcloud - gitweb
b=18623
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/include/liblustre.h
37  *
38  * User-space Lustre headers.
39  */
40
41 #ifndef LIBLUSTRE_H__
42 #define LIBLUSTRE_H__
43
44 #ifdef __KERNEL__
45 #error Kernel files should not #include <liblustre.h>
46 #else
47 /*
48  * The userspace implementations of linux/spinlock.h vary; we just
49  * include our own for all of them
50  */
51 #define __LINUX_SPINLOCK_H
52 #endif
53
54 #include <sys/mman.h>
55 #ifdef HAVE_STDINT_H
56 # include <stdint.h>
57 #endif
58 #ifdef HAVE_ASM_PAGE_H
59 # include <asm/page.h>
60 #endif
61 #ifdef HAVE_SYS_USER_H
62 # include <sys/user.h>
63 #endif
64 #ifdef HAVE_SYS_IOCTL_H
65 # include <sys/ioctl.h>
66 #endif
67 #ifndef _IOWR
68 # include "ioctl.h"
69 #endif
70
71 #include <stdio.h>
72 #include <sys/ioctl.h>
73 #include <stdlib.h>
74 #include <string.h>
75 #include <errno.h>
76 #include <sys/stat.h>
77 #ifdef HAVE_SYS_VFS_H
78 # include <sys/vfs.h>
79 #endif
80 #include <unistd.h>
81 #include <fcntl.h>
82
83 #include <libcfs/list.h>
84 #include <lnet/lnet.h>
85 #include <libcfs/kp30.h>
86 #include <libcfs/user-bitops.h>
87
88 /* definitions for liblustre */
89
90 #ifdef __CYGWIN__
91
92 #define CFS_PAGE_SHIFT  12
93 #define CFS_PAGE_SIZE   (1UL << CFS_PAGE_SHIFT)
94 #define CFS_PAGE_MASK   (~((__u64)CFS_PAGE_SIZE-1))
95 #define loff_t long long
96 #define ERESTART 2001
97 typedef unsigned short umode_t;
98
99 #endif
100
101 #ifndef CURRENT_SECONDS
102 # define CURRENT_SECONDS time(0)
103 #endif
104
105 #ifndef ARRAY_SIZE
106 #define ARRAY_SIZE(a) ((sizeof (a))/(sizeof ((a)[0])))
107 #endif
108
109 /* This is because lprocfs_status.h gets included here indirectly.  It would
110  * be much better to just avoid lprocfs being included into liblustre entirely
111  * but that requires more header surgery than I can handle right now.
112  */
113 #ifndef smp_processor_id
114 #define smp_processor_id() 0
115 #endif
116 #ifndef num_online_cpus
117 #define num_online_cpus() 1
118 #endif
119 #ifndef num_possible_cpus
120 #define num_possible_cpus() 1
121 #endif
122
123 /* always adopt 2.5 definitions */
124 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
125 #define LINUX_VERSION_CODE KERNEL_VERSION(2,5,0)
126
127 #ifndef page_private
128 #define page_private(page) ((page)->private)
129 #define set_page_private(page, v) ((page)->private = (v))
130 #endif
131
132 static inline void inter_module_put(void *a)
133 {
134         return;
135 }
136
137 void *inter_module_get(char *arg);
138
139 /* cheats for now */
140
141 struct work_struct {
142         void (*ws_task)(void *arg);
143         void *ws_arg;
144 };
145
146 static inline void prepare_work(struct work_struct *q, void (*t)(void *),
147                                 void *arg)
148 {
149         q->ws_task = t;
150         q->ws_arg = arg;
151         return;
152 }
153
154 static inline void schedule_work(struct work_struct *q)
155 {
156         q->ws_task(q->ws_arg);
157 }
158
159
160 #define strnlen(a,b) strlen(a)
161 static inline void *kmalloc(int size, int prot)
162 {
163         return malloc(size);
164 }
165 #define vmalloc malloc
166 #define vfree free
167 #define kfree(a) free(a)
168 #define GFP_KERNEL 1
169 #define GFP_HIGHUSER 1
170 #define GFP_ATOMIC 1
171 #define GFP_NOFS 1
172 #define IS_ERR(a) ((unsigned long)(a) > (unsigned long)-1000L)
173 #define PTR_ERR(a) ((long)(a))
174 #define ERR_PTR(a) ((void*)((long)(a)))
175
176 typedef struct {
177         void *cwd;
178 }mm_segment_t;
179
180 typedef int (read_proc_t)(char *page, char **start, off_t off,
181                           int count, int *eof, void *data);
182
183 struct file; /* forward ref */
184 typedef int (write_proc_t)(struct file *file, const char *buffer,
185                            unsigned long count, void *data);
186
187 #define NIPQUAD(addr) \
188         ((unsigned char *)&addr)[0], \
189         ((unsigned char *)&addr)[1], \
190         ((unsigned char *)&addr)[2], \
191         ((unsigned char *)&addr)[3]
192
193 #if defined(__LITTLE_ENDIAN)
194 #define HIPQUAD(addr) \
195         ((unsigned char *)&addr)[3], \
196         ((unsigned char *)&addr)[2], \
197         ((unsigned char *)&addr)[1], \
198         ((unsigned char *)&addr)[0]
199 #elif defined(__BIG_ENDIAN)
200 #define HIPQUAD NIPQUAD
201 #else
202 #error "Undefined byteorder??"
203 #endif /* __LITTLE_ENDIAN */
204
205 /* bits ops */
206
207 /* a long can be more than 32 bits, so use BITS_PER_LONG
208  * to allow the compiler to adjust the bit shifting accordingly
209  */
210
211 static __inline__ int ext2_set_bit(int nr, void *addr)
212 {
213 #ifdef __BIG_ENDIAN
214         return set_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
215 #else
216         return set_bit(nr, addr);
217 #endif
218 }
219
220 static __inline__ int ext2_clear_bit(int nr, void *addr)
221 {
222 #ifdef __BIG_ENDIAN
223         return clear_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
224 #else
225         return clear_bit(nr, addr);
226 #endif
227 }
228
229 static __inline__ int ext2_test_bit(int nr, void *addr)
230 {
231 #ifdef __BIG_ENDIAN
232         __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
233         return (tmp[nr >> 3] >> (nr & 7)) & 1;
234 #else
235         return test_bit(nr, addr);
236 #endif
237 }
238
239 /* modules */
240
241 struct module {
242         int count;
243 };
244
245 static inline void MODULE_AUTHOR(char *name)
246 {
247         printf("%s\n", name);
248 }
249 #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
250 #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
251
252 #define THIS_MODULE NULL
253 #define __init
254 #define __exit
255
256 /* devices */
257
258 static inline int misc_register(void *foo)
259 {
260         return 0;
261 }
262
263 static inline int misc_deregister(void *foo)
264 {
265         return 0;
266 }
267
268 static inline int request_module(char *name)
269 {
270         return (-EINVAL);
271 }
272
273 #define __MOD_INC_USE_COUNT(m)  do {} while (0)
274 #define __MOD_DEC_USE_COUNT(m)  do {} while (0)
275 #define MOD_INC_USE_COUNT       do {} while (0)
276 #define MOD_DEC_USE_COUNT       do {} while (0)
277 static inline void __module_get(struct module *module)
278 {
279 }
280
281 static inline int try_module_get(struct module *module)
282 {
283         return 1;
284 }
285
286 static inline void module_put(struct module *module)
287 {
288 }
289
290 /* module initialization */
291 extern int init_obdclass(void);
292 extern int ptlrpc_init(void);
293 extern int ldlm_init(void);
294 extern int osc_init(void);
295 extern int lov_init(void);
296 extern int mdc_init(void);
297 extern int mgc_init(void);
298 extern int echo_client_init(void);
299
300
301
302 /* general stuff */
303
304 #define EXPORT_SYMBOL(S)
305
306 struct rcu_head { };
307
308 typedef struct { } spinlock_t;
309 typedef __u64 kdev_t;
310
311 #define SPIN_LOCK_UNLOCKED (spinlock_t) { }
312 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
313 #define LASSERT_SEM_LOCKED(sem) do {} while(0)
314
315 static inline void spin_lock(spinlock_t *l) {return;}
316 static inline void spin_unlock(spinlock_t *l) {return;}
317 static inline void spin_lock_init(spinlock_t *l) {return;}
318 static inline void local_irq_save(unsigned long flag) {return;}
319 static inline void local_irq_restore(unsigned long flag) {return;}
320 static inline int spin_is_locked(spinlock_t *l) {return 1;}
321
322 static inline void spin_lock_bh(spinlock_t *l) {}
323 static inline void spin_unlock_bh(spinlock_t *l) {}
324 static inline void spin_lock_irqsave(spinlock_t *a, unsigned long b) {}
325 static inline void spin_unlock_irqrestore(spinlock_t *a, unsigned long b) {}
326
327 typedef spinlock_t rwlock_t;
328 #define RW_LOCK_UNLOCKED        SPIN_LOCK_UNLOCKED
329 #define read_lock(l)            spin_lock(l)
330 #define read_unlock(l)          spin_unlock(l)
331 #define write_lock(l)           spin_lock(l)
332 #define write_unlock(l)         spin_unlock(l)
333 #define rwlock_init(l)          spin_lock_init(l)
334
335 #define min(x,y) ((x)<(y) ? (x) : (y))
336 #define max(x,y) ((x)>(y) ? (x) : (y))
337
338 #ifndef min_t
339 #define min_t(type,x,y) \
340         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
341 #endif
342 #ifndef max_t
343 #define max_t(type,x,y) \
344         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
345 #endif
346
347 #define simple_strtol strtol
348
349 /* registering symbols */
350 #ifndef ERESTARTSYS
351 #define ERESTARTSYS ERESTART
352 #endif
353 #undef HZ
354 #define HZ 1
355
356 /* random */
357
358 void get_random_bytes(void *ptr, int size);
359
360 /* memory */
361
362 /* memory size: used for some client tunables */
363 #define num_physpages (256 * 1024) /* 1GB */
364
365 static inline int copy_from_user(void *a,void *b, int c)
366 {
367         memcpy(a,b,c);
368         return 0;
369 }
370
371 static inline int copy_to_user(void *a,void *b, int c)
372 {
373         memcpy(a,b,c);
374         return 0;
375 }
376
377
378 /* slabs */
379 typedef struct {
380          int size;
381 } kmem_cache_t;
382 #define SLAB_HWCACHE_ALIGN 0
383 #define SLAB_DESTROY_BY_RCU 0
384 static inline kmem_cache_t *
385 kmem_cache_create(const char *name, size_t objsize, size_t cdum,
386                   unsigned long d,
387                   void (*e)(void *, kmem_cache_t *, unsigned long),
388                   void (*f)(void *, kmem_cache_t *, unsigned long))
389 {
390         kmem_cache_t *c;
391         c = malloc(sizeof(*c));
392         if (!c)
393                 return NULL;
394         c->size = objsize;
395         CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
396                name, c, (int)objsize);
397         return c;
398 };
399
400 static inline int kmem_cache_destroy(kmem_cache_t *a)
401 {
402         CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", a, a->size);
403         free(a);
404         return 0;
405 }
406
407 /* struct page decl moved out from here into portals/include/libcfs/user-prim.h */
408
409 /* 2.4 defines */
410 #define PAGE_LIST_ENTRY list
411 #define PAGE_LIST(page) ((page)->list)
412
413 #define kmap(page) (page)->addr
414 #define kunmap(a) do {} while (0)
415
416 static inline cfs_page_t *alloc_pages(int mask, unsigned long order)
417 {
418         cfs_page_t *pg = malloc(sizeof(*pg));
419
420         if (!pg)
421                 return NULL;
422 #if 0 //#ifdef MAP_ANONYMOUS
423         pg->addr = mmap(0, PAGE_SIZE << order, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
424 #else
425         pg->addr = malloc(CFS_PAGE_SIZE << order);
426 #endif
427
428         if (!pg->addr) {
429                 free(pg);
430                 return NULL;
431         }
432         return pg;
433 }
434 #define cfs_alloc_pages(mask, order)  alloc_pages((mask), (order))
435
436 #define alloc_page(mask)      alloc_pages((mask), 0)
437 #define cfs_alloc_page(mask)  alloc_page(mask)
438
439 static inline void __free_pages(cfs_page_t *pg, int what)
440 {
441 #if 0 //#ifdef MAP_ANONYMOUS
442         munmap(pg->addr, PAGE_SIZE);
443 #else
444         free(pg->addr);
445 #endif
446         free(pg);
447 }
448 #define __cfs_free_pages(pg, order)  __free_pages((pg), (order))
449
450 #define __free_page(page) __free_pages((page), 0)
451 #define free_page(page) __free_page(page)
452 #define __cfs_free_page(page)  __cfs_free_pages((page), 0)
453
454 static inline cfs_page_t* __grab_cache_page(unsigned long index)
455 {
456         cfs_page_t *pg = alloc_pages(0, 0);
457
458         if (pg)
459                 pg->index = index;
460         return pg;
461 }
462
463 #define grab_cache_page(index) __grab_cache_page(index)
464 #define page_cache_release(page) __free_pages(page, 0)
465
466 /* arithmetic */
467 #define do_div(a,b)                     \
468         ({                              \
469                 unsigned long remainder;\
470                 remainder = (a) % (b);  \
471                 (a) = (a) / (b);        \
472                 (remainder);            \
473         })
474
475 /* VFS stuff */
476 #define ATTR_MODE       0x0001
477 #define ATTR_UID        0x0002
478 #define ATTR_GID        0x0004
479 #define ATTR_SIZE       0x0008
480 #define ATTR_ATIME      0x0010
481 #define ATTR_MTIME      0x0020
482 #define ATTR_CTIME      0x0040
483 #define ATTR_ATIME_SET  0x0080
484 #define ATTR_MTIME_SET  0x0100
485 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
486 #define ATTR_ATTR_FLAG  0x0400
487 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
488 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
489 #define ATTR_CTIME_SET  0x2000
490 #define ATTR_KILL_SUID  0
491 #define ATTR_KILL_SGID  0
492
493 struct iattr {
494         unsigned int    ia_valid;
495         umode_t         ia_mode;
496         uid_t           ia_uid;
497         gid_t           ia_gid;
498         loff_t          ia_size;
499         time_t          ia_atime;
500         time_t          ia_mtime;
501         time_t          ia_ctime;
502         unsigned int    ia_attr_flags;
503 };
504 #define ll_iattr_struct iattr
505
506 #define IT_OPEN     0x0001
507 #define IT_CREAT    0x0002
508 #define IT_READDIR  0x0004
509 #define IT_GETATTR  0x0008
510 #define IT_LOOKUP   0x0010
511 #define IT_UNLINK   0x0020
512 #define IT_GETXATTR 0x0040
513 #define IT_EXEC     0x0080
514 #define IT_PIN      0x0100
515
516 #define IT_FL_LOCKED   0x0001
517 #define IT_FL_FOLLOWED 0x0002 /* set by vfs_follow_link */
518
519 #define INTENT_MAGIC 0x19620323
520
521 struct lustre_intent_data {
522         int       it_disposition;
523         int       it_status;
524         __u64     it_lock_handle;
525         void     *it_data;
526         int       it_lock_mode;
527         int it_int_flags;
528 };
529 struct lookup_intent {
530         int     it_magic;
531         void    (*it_op_release)(struct lookup_intent *);
532         int     it_op;
533         int     it_flags;
534         int     it_create_mode;
535         union {
536                 struct lustre_intent_data lustre;
537         } d;
538 };
539
540 static inline void intent_init(struct lookup_intent *it, int op, int flags)
541 {
542         memset(it, 0, sizeof(*it));
543         it->it_magic = INTENT_MAGIC;
544         it->it_op = op;
545         it->it_flags = flags;
546 }
547
548
549 struct dentry {
550         int d_count;
551 };
552
553 struct vfsmount {
554         void *pwd;
555 };
556
557 /* semaphores */
558 struct rw_semaphore {
559         int count;
560 };
561
562 /* semaphores */
563 struct semaphore {
564         int count;
565 };
566
567 /* use the macro's argument to avoid unused warnings */
568 #define down(a) do { (void)a; } while (0)
569 #define mutex_down(a)   down(a)
570 #define up(a) do { (void)a; } while (0)
571 #define mutex_up(a)     up(a)
572 #define down_read(a) do { (void)a; } while (0)
573 #define up_read(a) do { (void)a; } while (0)
574 #define down_write(a) do { (void)a; } while (0)
575 #define up_write(a) do { (void)a; } while (0)
576 #define sema_init(a,b) do { (void)a; } while (0)
577 #define init_rwsem(a) do { (void)a; } while (0)
578 #define DECLARE_MUTEX(name)     \
579         struct semaphore name = { 1 }
580 static inline void init_MUTEX (struct semaphore *sem)
581 {
582         sema_init(sem, 1);
583 }
584 static inline void init_MUTEX_LOCKED (struct semaphore *sem)
585 {
586         sema_init(sem, 0);
587 }
588
589 #define init_mutex(s)   init_MUTEX(s)
590
591 typedef struct  {
592         struct list_head sleepers;
593 } wait_queue_head_t;
594
595 typedef struct  {
596         struct list_head sleeping;
597         void *process;
598 } wait_queue_t;
599
600 struct signal {
601         int signal;
602 };
603
604 struct task_struct {
605         int state;
606         struct signal pending;
607         char comm[32];
608         int pid;
609         int fsuid;
610         int fsgid;
611         int max_groups;
612         int ngroups;
613         gid_t *groups;
614         cfs_cap_t cap_effective;
615 };
616
617 typedef struct task_struct cfs_task_t;
618 #define cfs_current()           current
619 #define cfs_curproc_pid()       (current->pid)
620 #define cfs_curproc_comm()      (current->comm)
621
622 extern struct task_struct *current;
623 int in_group_p(gid_t gid);
624
625 #define set_current_state(foo) do { current->state = foo; } while (0)
626
627 #define init_waitqueue_entry(q,p) do { (q)->process = p; } while (0)
628 #define add_wait_queue(q,p) do {  list_add(&(q)->sleepers, &(p)->sleeping); } while (0)
629 #define del_wait_queue(p) do { list_del(&(p)->sleeping); } while (0)
630 #define remove_wait_queue(q,p) do { list_del(&(p)->sleeping); } while (0)
631
632 #define DECLARE_WAIT_QUEUE_HEAD(HEAD)                           \
633         wait_queue_head_t HEAD = {                              \
634                 .sleepers = CFS_LIST_HEAD_INIT(HEAD.sleepers)       \
635         }
636 #define init_waitqueue_head(l) CFS_INIT_LIST_HEAD(&(l)->sleepers)
637 #define wake_up(l) do { int a = 0; a++; } while (0)
638 #define TASK_INTERRUPTIBLE 0
639 #define TASK_UNINTERRUPTIBLE 1
640 #define TASK_RUNNING 2
641
642 #define wait_event_interruptible(wq, condition)                         \
643 ({                                                                      \
644         struct l_wait_info lwi;                                         \
645         int timeout = 100000000;/* for ever */                          \
646         int ret;                                                        \
647                                                                         \
648         lwi = LWI_TIMEOUT(timeout, NULL, NULL);                         \
649         ret = l_wait_event(NULL, condition, &lwi);                      \
650                                                                         \
651         ret;                                                            \
652 })
653
654 #define in_interrupt() (0)
655
656 #define schedule() do {} while (0)
657 static inline int schedule_timeout(signed long t)
658 {
659         return 0;
660 }
661
662 #define lock_kernel() do {} while (0)
663 #define unlock_kernel() do {} while (0)
664 #define daemonize(l) do {} while (0)
665 #define sigfillset(l) do {} while (0)
666 #define recalc_sigpending(l) do {} while (0)
667 #define kernel_thread(l,m,n) LBUG()
668
669 #define USERMODEHELPER(path, argv, envp) (0)
670 #define SIGNAL_MASK_ASSERT()
671 #define KERN_INFO
672
673 #include <sys/time.h>
674 #if HZ != 1
675 #error "liblustre's jiffies currently expects HZ to be 1"
676 #endif
677 #define jiffies                                 \
678 ({                                              \
679         unsigned long _ret = 0;                 \
680         struct timeval tv;                      \
681         if (gettimeofday(&tv, NULL) == 0)       \
682                 _ret = tv.tv_sec;               \
683         _ret;                                   \
684 })
685 #define get_jiffies_64()  (__u64)jiffies
686 #define time_after(a, b) ((long)(b) - (long)(a) < 0)
687 #define time_before(a, b) time_after(b,a)
688 #define time_after_eq(a,b)      ((long)(a) - (long)(b) >= 0)
689
690 struct timer_list {
691         struct list_head tl_list;
692         void (*function)(unsigned long unused);
693         unsigned long data;
694         long expires;
695 };
696
697 static inline int timer_pending(struct timer_list *l)
698 {
699         if (time_after(l->expires, jiffies))
700                 return 1;
701         else
702                 return 0;
703 }
704
705 static inline int init_timer(struct timer_list *l)
706 {
707         CFS_INIT_LIST_HEAD(&l->tl_list);
708         return 0;
709 }
710
711 static inline void mod_timer(struct timer_list *l, int thetime)
712 {
713         l->expires = thetime;
714 }
715
716 static inline void del_timer(struct timer_list *l)
717 {
718         free(l);
719 }
720
721 typedef struct { volatile int counter; } atomic_t;
722
723 #define ATOMIC_INIT(i) { i }
724
725 #define atomic_read(a) ((a)->counter)
726 #define atomic_set(a,b) do {(a)->counter = b; } while (0)
727 #define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
728 #define atomic_dec_and_lock(a,b) ((--((a)->counter)) == 0)
729 #define atomic_inc(a)  (((a)->counter)++)
730 #define atomic_dec(a)  do { (a)->counter--; } while (0)
731 #define atomic_add(b,a)  do {(a)->counter += b;} while (0)
732 #define atomic_add_return(n,a) ((a)->counter += n)
733 #define atomic_inc_return(a) atomic_add_return(1,a)
734 #define atomic_sub(b,a)  do {(a)->counter -= b;} while (0)
735 #define atomic_sub_return(n,a) ((a)->counter -= n)
736 #define atomic_dec_return(a)  atomic_sub_return(1,a)
737
738 #ifndef likely
739 #define likely(exp) (exp)
740 #endif
741 #ifndef unlikely
742 #define unlikely(exp) (exp)
743 #endif
744
745 /* FIXME sys/capability will finally included linux/fs.h thus
746  * cause numerous trouble on x86-64. as temporary solution for
747  * build broken at cary, we copy definition we need from capability.h
748  * FIXME
749  */
750 struct _cap_struct;
751 typedef struct _cap_struct *cap_t;
752 typedef int cap_value_t;
753 typedef enum {
754     CAP_EFFECTIVE=0,
755     CAP_PERMITTED=1,
756     CAP_INHERITABLE=2
757 } cap_flag_t;
758 typedef enum {
759     CAP_CLEAR=0,
760     CAP_SET=1
761 } cap_flag_value_t;
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 #ifdef LIBLUSTRE_POSIX_ACL
907  #ifndef posix_acl_xattr_entry
908   #define posix_acl_xattr_entry xattr_acl_entry
909  #endif
910  #ifndef posix_acl_xattr_header
911   #define posix_acl_xattr_header xattr_acl_header
912  #endif
913  #ifndef posix_acl_xattr_size
914   #define posix_acl_xattr_size(entry) xattr_acl_size(entry)
915  #endif
916  #ifndef CONFIG_FS_POSIX_ACL
917   #define CONFIG_FS_POSIX_ACL 1
918  #endif
919 #endif
920
921 #ifndef ENOTSUPP
922 #define ENOTSUPP ENOTSUP
923 #endif
924
925 #include <obd_support.h>
926 #include <lustre/lustre_idl.h>
927 #include <lustre_lib.h>
928 #include <lustre_import.h>
929 #include <lustre_export.h>
930 #include <lustre_net.h>
931
932 #endif