Whamcloud - gitweb
b=19720
[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(const 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 #define cfs_curproc_fsuid()     (current->fsuid)
622 #define cfs_curproc_fsgid()     (current->fsgid)
623
624 extern struct task_struct *current;
625 int in_group_p(gid_t gid);
626
627 #define set_current_state(foo) do { current->state = foo; } while (0)
628
629 #define init_waitqueue_entry(q,p) do { (q)->process = p; } while (0)
630 #define add_wait_queue(q,p) do {  list_add(&(q)->sleepers, &(p)->sleeping); } while (0)
631 #define del_wait_queue(p) do { list_del(&(p)->sleeping); } while (0)
632 #define remove_wait_queue(q,p) do { list_del(&(p)->sleeping); } while (0)
633
634 #define DECLARE_WAIT_QUEUE_HEAD(HEAD)                           \
635         wait_queue_head_t HEAD = {                              \
636                 .sleepers = CFS_LIST_HEAD_INIT(HEAD.sleepers)       \
637         }
638 #define init_waitqueue_head(l) CFS_INIT_LIST_HEAD(&(l)->sleepers)
639 #define wake_up(l) do { int a = 0; a++; } while (0)
640 #define TASK_INTERRUPTIBLE 0
641 #define TASK_UNINTERRUPTIBLE 1
642 #define TASK_RUNNING 2
643
644 #define wait_event_interruptible(wq, condition)                         \
645 ({                                                                      \
646         struct l_wait_info lwi;                                         \
647         int timeout = 100000000;/* for ever */                          \
648         int ret;                                                        \
649                                                                         \
650         lwi = LWI_TIMEOUT(timeout, NULL, NULL);                         \
651         ret = l_wait_event(NULL, condition, &lwi);                      \
652                                                                         \
653         ret;                                                            \
654 })
655
656 #define in_interrupt() (0)
657
658 #define schedule() do {} while (0)
659 static inline int schedule_timeout(signed long t)
660 {
661         return 0;
662 }
663
664 #define lock_kernel() do {} while (0)
665 #define unlock_kernel() do {} while (0)
666 #define daemonize(l) do {} while (0)
667 #define sigfillset(l) do {} while (0)
668 #define recalc_sigpending(l) do {} while (0)
669 #define kernel_thread(l,m,n) LBUG()
670
671 #define USERMODEHELPER(path, argv, envp) (0)
672 #define SIGNAL_MASK_ASSERT()
673 #define KERN_INFO
674
675 #include <sys/time.h>
676 #if HZ != 1
677 #error "liblustre's jiffies currently expects HZ to be 1"
678 #endif
679 #define jiffies                                 \
680 ({                                              \
681         unsigned long _ret = 0;                 \
682         struct timeval tv;                      \
683         if (gettimeofday(&tv, NULL) == 0)       \
684                 _ret = tv.tv_sec;               \
685         _ret;                                   \
686 })
687 #define get_jiffies_64()  (__u64)jiffies
688 #define time_after(a, b) ((long)(b) - (long)(a) < 0)
689 #define time_before(a, b) time_after(b,a)
690 #define time_after_eq(a,b)      ((long)(a) - (long)(b) >= 0)
691
692 struct timer_list {
693         struct list_head tl_list;
694         void (*function)(unsigned long unused);
695         unsigned long data;
696         long expires;
697 };
698
699 static inline int timer_pending(struct timer_list *l)
700 {
701         if (time_after(l->expires, jiffies))
702                 return 1;
703         else
704                 return 0;
705 }
706
707 static inline int init_timer(struct timer_list *l)
708 {
709         CFS_INIT_LIST_HEAD(&l->tl_list);
710         return 0;
711 }
712
713 static inline void mod_timer(struct timer_list *l, int thetime)
714 {
715         l->expires = thetime;
716 }
717
718 static inline void del_timer(struct timer_list *l)
719 {
720         free(l);
721 }
722
723 typedef struct { volatile int counter; } atomic_t;
724
725 #define ATOMIC_INIT(i) { i }
726
727 #define atomic_read(a) ((a)->counter)
728 #define atomic_set(a,b) do {(a)->counter = b; } while (0)
729 #define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
730 #define atomic_dec_and_lock(a,b) ((--((a)->counter)) == 0)
731 #define atomic_inc(a)  (((a)->counter)++)
732 #define atomic_dec(a)  do { (a)->counter--; } while (0)
733 #define atomic_add(b,a)  do {(a)->counter += b;} while (0)
734 #define atomic_add_return(n,a) ((a)->counter += n)
735 #define atomic_inc_return(a) atomic_add_return(1,a)
736 #define atomic_sub(b,a)  do {(a)->counter -= b;} while (0)
737 #define atomic_sub_return(n,a) ((a)->counter -= n)
738 #define atomic_dec_return(a)  atomic_sub_return(1,a)
739
740 #ifndef likely
741 #define likely(exp) (exp)
742 #endif
743 #ifndef unlikely
744 #define unlikely(exp) (exp)
745 #endif
746
747 #define libcfs_memory_pressure_get() (0) 
748 #define libcfs_memory_pressure_set() do {} while (0) 
749 #define libcfs_memory_pressure_clr() do {} while (0)
750
751 /* FIXME sys/capability will finally included linux/fs.h thus
752  * cause numerous trouble on x86-64. as temporary solution for
753  * build broken at cary, we copy definition we need from capability.h
754  * FIXME
755  */
756 struct _cap_struct;
757 typedef struct _cap_struct *cap_t;
758 typedef int cap_value_t;
759 typedef enum {
760     CAP_EFFECTIVE=0,
761     CAP_PERMITTED=1,
762     CAP_INHERITABLE=2
763 } cap_flag_t;
764 typedef enum {
765     CAP_CLEAR=0,
766     CAP_SET=1
767 } cap_flag_value_t;
768
769 cap_t   cap_get_proc(void);
770 int     cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
771
772 static inline void libcfs_run_lbug_upcall(char *file, const char *fn,
773                                            const int l){}
774
775 /* completion */
776 struct completion {
777         unsigned int done;
778         cfs_waitq_t wait;
779 };
780
781 #define COMPLETION_INITIALIZER(work) \
782         { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
783
784 #define DECLARE_COMPLETION(work) \
785         struct completion work = COMPLETION_INITIALIZER(work)
786
787 #define INIT_COMPLETION(x)      ((x).done = 0)
788
789 static inline void init_completion(struct completion *x)
790 {
791         x->done = 0;
792         init_waitqueue_head(&x->wait);
793 }
794
795 struct liblustre_wait_callback {
796         struct list_head    llwc_list;
797         const char         *llwc_name;
798         int               (*llwc_fn)(void *arg);
799         void               *llwc_arg;
800 };
801
802 void *liblustre_register_wait_callback(const char *name,
803                                        int (*fn)(void *arg), void *arg);
804 void liblustre_deregister_wait_callback(void *notifier);
805 int liblustre_wait_event(int timeout);
806
807 void *liblustre_register_idle_callback(const char *name,
808                                        int (*fn)(void *arg), void *arg);
809 void liblustre_deregister_idle_callback(void *notifier);
810 void liblustre_wait_idle(void);
811
812 /* flock related */
813 struct nfs_lock_info {
814         __u32             state;
815         __u32             flags;
816         void            *host;
817 };
818
819 typedef struct file_lock {
820         struct file_lock *fl_next;      /* singly linked list for this inode  */
821         struct list_head fl_link;       /* doubly linked list of all locks */
822         struct list_head fl_block;      /* circular list of blocked processes */
823         void *fl_owner;
824         unsigned int fl_pid;
825         cfs_waitq_t fl_wait;
826         struct file *fl_file;
827         unsigned char fl_flags;
828         unsigned char fl_type;
829         loff_t fl_start;
830         loff_t fl_end;
831
832         void (*fl_notify)(struct file_lock *);  /* unblock callback */
833         void (*fl_insert)(struct file_lock *);  /* lock insertion callback */
834         void (*fl_remove)(struct file_lock *);  /* lock removal callback */
835
836         void *fl_fasync; /* for lease break notifications */
837         unsigned long fl_break_time;    /* for nonblocking lease breaks */
838
839         union {
840                 struct nfs_lock_info    nfs_fl;
841         } fl_u;
842 } cfs_flock_t;
843
844 #define cfs_flock_type(fl)                  ((fl)->fl_type)
845 #define cfs_flock_set_type(fl, type)        do { (fl)->fl_type = (type); } while(0)
846 #define cfs_flock_pid(fl)                   ((fl)->fl_pid)
847 #define cfs_flock_set_pid(fl, pid)          do { (fl)->fl_pid = (pid); } while(0)
848 #define cfs_flock_start(fl)                 ((fl)->fl_start)
849 #define cfs_flock_set_start(fl, start)      do { (fl)->fl_start = (start); } while(0)
850 #define cfs_flock_end(fl)                   ((fl)->fl_end)
851 #define cfs_flock_set_end(fl, end)          do { (fl)->fl_end = (end); } while(0)
852
853 #ifndef OFFSET_MAX
854 #define INT_LIMIT(x)    (~((x)1 << (sizeof(x)*8 - 1)))
855 #define OFFSET_MAX      INT_LIMIT(loff_t)
856 #endif
857
858 /* XXX: defined in kernel */
859 #define FL_POSIX        1
860 #define FL_SLEEP        128
861
862 /* quota */
863 #define QUOTA_OK 0
864 #define NO_QUOTA 1
865
866 /* ACL */
867 struct posix_acl_entry {
868         short                   e_tag;
869         unsigned short          e_perm;
870         unsigned int            e_id;
871 };
872
873 struct posix_acl {
874         atomic_t                a_refcount;
875         unsigned int            a_count;
876         struct posix_acl_entry  a_entries[0];
877 };
878
879 typedef struct {
880         __u16           e_tag;
881         __u16           e_perm;
882         __u32           e_id;
883 } xattr_acl_entry;
884
885 typedef struct {
886         __u32           a_version;
887         xattr_acl_entry a_entries[0];
888 } xattr_acl_header;
889
890 static inline size_t xattr_acl_size(int count)
891 {
892         return sizeof(xattr_acl_header) + count * sizeof(xattr_acl_entry);
893 }
894
895 static inline
896 struct posix_acl * posix_acl_from_xattr(const void *value, size_t size)
897 {
898         return NULL;
899 }
900
901 static inline
902 int posix_acl_valid(const struct posix_acl *acl)
903 {
904         return 0;
905 }
906
907 static inline
908 void posix_acl_release(struct posix_acl *acl)
909 {
910 }
911
912 #ifdef LIBLUSTRE_POSIX_ACL
913  #ifndef posix_acl_xattr_entry
914   #define posix_acl_xattr_entry xattr_acl_entry
915  #endif
916  #ifndef posix_acl_xattr_header
917   #define posix_acl_xattr_header xattr_acl_header
918  #endif
919  #ifndef posix_acl_xattr_size
920   #define posix_acl_xattr_size(entry) xattr_acl_size(entry)
921  #endif
922  #ifndef CONFIG_FS_POSIX_ACL
923   #define CONFIG_FS_POSIX_ACL 1
924  #endif
925 #endif
926
927 #ifndef ENOTSUPP
928 #define ENOTSUPP ENOTSUP
929 #endif
930
931 #include <obd_support.h>
932 #include <lustre/lustre_idl.h>
933 #include <lustre_lib.h>
934 #include <lustre_import.h>
935 #include <lustre_export.h>
936 #include <lustre_net.h>
937
938 #endif