1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <info@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
21 * User-space Lustre headers.
31 #ifdef HAVE_ASM_PAGE_H
32 # include <asm/page.h>
34 #ifdef HAVE_SYS_USER_H
35 # include <sys/user.h>
41 #include <sys/ioctl.h>
48 #include <libcfs/list.h>
49 #include <portals/p30.h>
50 #include <libcfs/kp30.h>
52 /* definitions for liblustre */
57 #define PAGE_SIZE (1UL << PAGE_SHIFT)
58 #define PAGE_MASK (~(PAGE_SIZE-1))
59 #define loff_t long long
61 typedef unsigned short umode_t;
65 /* This is because lprocfs_status.h gets included here indirectly. It would
66 * be much better to just avoid lprocfs being included into liblustre entirely
67 * but that requires more header surgery than I can handle right now.
69 #ifndef smp_processor_id
70 #define smp_processor_id() 0
74 #define smp_mb() do {} while (0)
77 #ifndef might_sleep_if
78 #define might_sleep_if(cond) do {} while (0)
82 #define might_sleep() do {} while (0)
85 #ifndef signal_pending
86 #define signal_pending(proc) 0
110 #define FMODE_WRITE 2
119 printf("!!!LBUG at %s:%d\n", __FILE__, __LINE__); \
123 /* always adopt 2.5 definitions */
124 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
125 #define LINUX_VERSION_CODE (2*200+5*10+0)
127 static inline void inter_module_put(void *a)
132 extern ptl_handle_ni_t tcpnal_ni;
134 void *inter_module_get(char *arg);
139 void (*ws_task)(void *arg);
143 static inline void prepare_work(struct work_struct *q, void (*t)(void *),
151 static inline void schedule_work(struct work_struct *q)
153 q->ws_task(q->ws_arg);
157 #define strnlen(a,b) strlen(a)
158 static inline void *kmalloc(int size, int prot)
162 #define vmalloc malloc
164 #define kfree(a) free(a)
166 #define GFP_HIGHUSER 1
169 #define IS_ERR(a) (((a) && abs((long)(a)) < 500) ? 1 : 0)
170 #define PTR_ERR(a) ((long)(a))
171 #define ERR_PTR(a) ((void*)((long)(a)))
177 typedef int (read_proc_t)(char *page, char **start, off_t off,
178 int count, int *eof, void *data);
180 struct file; /* forward ref */
181 typedef int (write_proc_t)(struct file *file, const char *buffer,
182 unsigned long count, void *data);
184 #define NIPQUAD(addr) \
185 ((unsigned char *)&addr)[0], \
186 ((unsigned char *)&addr)[1], \
187 ((unsigned char *)&addr)[2], \
188 ((unsigned char *)&addr)[3]
190 #if defined(__LITTLE_ENDIAN)
191 #define HIPQUAD(addr) \
192 ((unsigned char *)&addr)[3], \
193 ((unsigned char *)&addr)[2], \
194 ((unsigned char *)&addr)[1], \
195 ((unsigned char *)&addr)[0]
196 #elif defined(__BIG_ENDIAN)
197 #define HIPQUAD NIPQUAD
199 #error "Undefined byteorder??"
200 #endif /* __LITTLE_ENDIAN */
203 static __inline__ int set_bit(int nr,long * addr)
208 mask = 1 << (nr & 0x1f);
209 retval = (mask & *addr) != 0;
214 static __inline__ int clear_bit(int nr, long * addr)
219 mask = 1 << (nr & 0x1f);
220 retval = (mask & *addr) != 0;
225 static __inline__ int test_bit(int nr, long * addr)
230 mask = 1 << (nr & 0x1f);
231 return ((mask & *addr) != 0);
234 static __inline__ int test_and_set_bit(int nr, long * addr)
238 res = test_bit(nr, addr);
244 static __inline__ int ext2_set_bit(int nr, void *addr)
246 return set_bit(nr, (long*)addr);
249 static __inline__ int ext2_clear_bit(int nr, void *addr)
251 return clear_bit(nr, (long*)addr);
254 static __inline__ int ext2_test_bit(int nr, void *addr)
256 return test_bit(nr, (long*)addr);
265 #define MODULE_AUTHOR(name)
266 #define MODULE_DESCRIPTION(name)
267 #define MODULE_LICENSE(name)
269 #define module_init(init)
270 #define module_exit(exit)
272 #define THIS_MODULE NULL
279 static inline int misc_register(void *foo)
284 static inline int misc_deregister(void *foo)
289 static inline int request_module(char *name)
294 #define __MOD_INC_USE_COUNT(m) do {} while (0)
295 #define __MOD_DEC_USE_COUNT(m) do {} while (0)
296 #define MOD_INC_USE_COUNT do {} while (0)
297 #define MOD_DEC_USE_COUNT do {} while (0)
298 static inline void __module_get(struct module *module)
302 static inline int try_module_get(struct module *module)
307 static inline void module_put(struct module *module)
311 /* module initialization */
312 extern int init_obdclass(void);
313 extern int ptlrpc_init(void);
314 extern int ldlm_init(void);
315 extern int osc_init(void);
316 extern int lov_init(void);
317 extern int mdc_init(void);
318 extern int echo_client_init(void);
324 #define EXPORT_SYMBOL(S)
326 typedef struct { } spinlock_t;
327 typedef __u64 kdev_t;
329 #define SPIN_LOCK_UNLOCKED (spinlock_t) { }
330 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
332 static inline void spin_lock(spinlock_t *l) {return;}
333 static inline void spin_unlock(spinlock_t *l) {return;}
334 static inline void spin_lock_init(spinlock_t *l) {return;}
335 static inline void local_irq_save(unsigned long flag) {return;}
336 static inline void local_irq_restore(unsigned long flag) {return;}
337 static inline int spin_is_locked(spinlock_t *l) {return 1;}
339 static inline void spin_lock_bh(spinlock_t *l) {}
340 static inline void spin_unlock_bh(spinlock_t *l) {}
341 static inline void spin_lock_irqsave(spinlock_t *a, unsigned long b) {}
342 static inline void spin_unlock_irqrestore(spinlock_t *a, unsigned long b) {}
344 typedef struct { } rwlock_t;
345 #define rwlock_init(x) do {} while(0)
346 #define RW_LOCK_UNLOCKED (rwlock_t) {}
348 #define read_unlock(l)
349 #define write_lock(l)
350 #define write_unlock(l)
352 #define min(x,y) ((x)<(y) ? (x) : (y))
353 #define max(x,y) ((x)>(y) ? (x) : (y))
356 #define min_t(type,x,y) \
357 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
360 #define max_t(type,x,y) \
361 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
364 #define container_of(ptr, type, member) ({ \
365 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
366 (type *)( (char *)__mptr - offsetof(type,member) );})
368 /* registering symbols */
370 #define ERESTARTSYS ERESTART
375 void get_random_bytes(void *ptr, int size);
380 #define num_physpages (16 * 1024)
382 static inline int copy_from_user(void *a,void *b, int c)
388 static inline int copy_to_user(void *a,void *b, int c)
394 static inline long strncpy_from_user(char *dest, const char *src, long n)
397 s = strncpy(dest, src, n);
398 return strnlen(s, n);
405 #define SLAB_HWCACHE_ALIGN 0
406 static inline kmem_cache_t *
407 kmem_cache_create(const char *name, size_t objsize, size_t cdum,
409 void (*e)(void *, kmem_cache_t *, unsigned long),
410 void (*f)(void *, kmem_cache_t *, unsigned long))
413 c = malloc(sizeof(*c));
417 CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
418 name, c, (int)objsize);
422 static inline int kmem_cache_destroy(kmem_cache_t *a)
424 CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", a, a->size);
428 #define kmem_cache_alloc(cache, prio) malloc(cache->size)
429 #define kmem_cache_free(cache, obj) free(obj)
431 #define PAGE_CACHE_SIZE PAGE_SIZE
432 #define PAGE_CACHE_SHIFT PAGE_SHIFT
433 #define PAGE_CACHE_MASK PAGE_MASK
435 /* struct page decl moved out from here into portals/include/libcfs/user-prim.h */
438 #define PAGE_LIST_ENTRY list
439 #define PAGE_LIST(page) ((page)->list)
441 #define page_address(page) ((page)->addr)
442 #define kmap(page) (page)->addr
443 #define kunmap(a) do {} while (0)
445 static inline struct page *alloc_pages(int mask, unsigned long order)
447 struct page *pg = malloc(sizeof(*pg));
451 #if 0 //#ifdef MAP_ANONYMOUS
452 pg->addr = mmap(0, PAGE_SIZE << order, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
454 pg->addr = malloc(PAGE_SIZE << order);
464 #define alloc_page(mask) alloc_pages((mask), 0)
466 static inline void __free_pages(struct page *pg, int what)
468 #if 0 //#ifdef MAP_ANONYMOUS
469 munmap(pg->addr, PAGE_SIZE);
476 #define __free_page(page) __free_pages((page), 0)
477 #define free_page(page) __free_page(page)
479 static inline struct page* __grab_cache_page(unsigned long index)
481 struct page *pg = alloc_pages(0, 0);
488 #define grab_cache_page(index) __grab_cache_page(index)
489 #define page_cache_release(page) __free_pages(page, 0)
492 #define do_div(a,b) \
494 unsigned long remainder;\
495 remainder = (a) % (b); \
501 #define ATTR_MODE 0x0001
502 #define ATTR_UID 0x0002
503 #define ATTR_GID 0x0004
504 #define ATTR_SIZE 0x0008
505 #define ATTR_ATIME 0x0010
506 #define ATTR_MTIME 0x0020
507 #define ATTR_CTIME 0x0040
508 #define ATTR_ATIME_SET 0x0080
509 #define ATTR_MTIME_SET 0x0100
510 #define ATTR_FORCE 0x0200 /* Not a change, but a change it */
511 #define ATTR_ATTR_FLAG 0x0400
512 #define ATTR_RAW 0x0800 /* file system, not vfs will massage attrs */
513 #define ATTR_FROM_OPEN 0x1000 /* called from open path, ie O_TRUNC */
514 /* ATTR_CTIME_SET has been defined in lustre_idl.h */
517 unsigned int ia_valid;
525 unsigned int ia_attr_flags;
528 #define IT_OPEN 0x0001
529 #define IT_CREAT 0x0002
530 #define IT_READDIR 0x0004
531 #define IT_GETATTR 0x0008
532 #define IT_LOOKUP 0x0010
533 #define IT_UNLINK 0x0020
534 #define IT_GETXATTR 0x0040
535 #define IT_EXEC 0x0080
536 #define IT_PIN 0x0100
537 #define IT_CHDIR 0x0200
539 #define IT_FL_LOCKED 0x0001
540 #define IT_FL_FOLLOWED 0x0002 /* set by vfs_follow_link */
542 #define INTENT_MAGIC 0x19620323
544 struct lookup_intent {
546 void (*it_op_release)(struct lookup_intent *);
551 void *fs_data; /* FS-specific intent data */
555 struct lustre_intent_data {
558 __u64 it_lock_handle;
566 #define LUSTRE_IT(it) ((struct lustre_intent_data *)((it)->d.fs_data))
568 static inline void intent_init(struct lookup_intent *it, int op, int flags)
570 memset(it, 0, sizeof(*it));
571 it->it_magic = INTENT_MAGIC;
573 it->it_flags = flags;
586 struct rw_semaphore {
606 unsigned int cit_ivsize;
608 int (*cit_setkey)(struct crypto_tfm *tfm,
609 const __u8 *key, unsigned int keylen);
610 int (*cit_encrypt)(struct crypto_tfm *tfm,
611 struct scatterlist *dst,
612 struct scatterlist *src,
613 unsigned int nbytes);
614 int (*cit_encrypt_iv)(struct crypto_tfm *tfm,
615 struct scatterlist *dst,
616 struct scatterlist *src,
617 unsigned int nbytes, __u8 *iv);
618 int (*cit_decrypt)(struct crypto_tfm *tfm,
619 struct scatterlist *dst,
620 struct scatterlist *src,
621 unsigned int nbytes);
622 int (*cit_decrypt_iv)(struct crypto_tfm *tfm,
623 struct scatterlist *dst,
624 struct scatterlist *src,
625 unsigned int nbytes, __u8 *iv);
626 void (*cit_xor_block)(__u8 *dst, const __u8 *src);
630 void (*dit_init)(struct crypto_tfm *tfm);
631 void (*dit_update)(struct crypto_tfm *tfm,
632 struct scatterlist *sg, unsigned int nsg);
633 void (*dit_update_kernel)(struct crypto_tfm *tfm,
634 const void *data, size_t count);
635 void (*dit_final)(struct crypto_tfm *tfm, __u8 *out);
636 void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg,
637 unsigned int nsg, __u8 *out);
638 int (*dit_setkey)(struct crypto_tfm *tfm,
639 const __u8 *key, unsigned int keylen);
640 #ifdef CONFIG_CRYPTO_HMAC
641 void *dit_hmac_block;
645 struct compress_tfm {
646 int (*cot_compress)(struct crypto_tfm *tfm,
647 const __u8 *src, unsigned int slen,
648 __u8 *dst, unsigned int *dlen);
649 int (*cot_decompress)(struct crypto_tfm *tfm,
650 const __u8 *src, unsigned int slen,
651 __u8 *dst, unsigned int *dlen);
659 struct cipher_tfm cipher;
660 struct digest_tfm digest;
661 struct compress_tfm compress;
664 struct crypto_alg *__crt_alg;
667 /* use the macro's argument to avoid unused warnings */
668 #define down(a) do { (void)a; } while (0)
669 #define up(a) do { (void)a; } while (0)
670 #define down_read(a) do { (void)a; } while (0)
671 #define up_read(a) do { (void)a; } while (0)
672 #define down_write(a) do { (void)a; } while (0)
673 #define up_write(a) do { (void)a; } while (0)
674 #define sema_init(a,b) do { (void)a; } while (0)
675 #define init_rwsem(a) do { (void)a; } while (0)
677 #define DECLARE_MUTEX(name) \
678 struct semaphore name = { 1 }
680 static inline void init_MUTEX (struct semaphore *sem)
685 struct rpc_pipe_msg {
686 struct list_head list;
694 struct list_head task_list;
698 struct list_head sleeping;
711 struct fs_struct *fs;
713 struct signal pending;
726 struct fs_struct __fs;
729 extern struct task_struct *current;
730 int in_group_p(gid_t gid);
731 static inline int capable(int cap)
733 if (current->cap_effective & (1 << cap))
739 #define set_current_state(foo) do { current->state = foo; } while (0)
741 #define init_waitqueue_entry(q,p) do { (q)->process = p; } while (0)
742 #define add_wait_queue(q,p) do { list_add(&(q)->task_list, &(p)->sleeping); } while (0)
743 #define del_wait_queue(p) do { list_del(&(p)->sleeping); } while (0)
744 #define remove_wait_queue(q,p) do { list_del(&(p)->sleeping); } while (0)
746 #define DECLARE_WAIT_QUEUE_HEAD(HEAD) \
747 wait_queue_head_t HEAD = { \
748 .task_list = LIST_HEAD_INIT(HEAD.task_list) \
750 #define init_waitqueue_head(l) INIT_LIST_HEAD(&(l)->task_list)
751 #define wake_up(l) do { int a; a++; } while (0)
752 #define TASK_INTERRUPTIBLE 0
753 #define TASK_UNINTERRUPTIBLE 1
754 #define TASK_RUNNING 2
756 #define wait_event_interruptible(wq, condition) \
758 struct l_wait_info lwi; \
759 int timeout = 100000000;/* for ever */ \
762 lwi = LWI_TIMEOUT(timeout, NULL, NULL); \
763 ret = l_wait_event(NULL, condition, &lwi); \
768 #define in_interrupt() (0)
770 #define schedule() do {} while (0)
771 static inline int schedule_timeout(signed long t)
776 #define lock_kernel() do {} while (0)
777 #define unlock_kernel() do {} while (0)
778 #define daemonize(l) do {} while (0)
779 #define sigfillset(l) do {} while (0)
780 #define recalc_sigpending(l) do {} while (0)
781 #define kernel_thread(l,m,n) LBUG()
783 #define USERMODEHELPER(path, argv, envp) (0)
784 #define SIGNAL_MASK_ASSERT()
787 #include <sys/time.h>
789 #error "liblustre's jiffies currently expects HZ to be 1"
793 unsigned long _ret = 0; \
795 if (gettimeofday(&tv, NULL) == 0) \
799 #define time_after(a, b) ((long)(b) - (long)(a) < 0)
800 #define time_before(a, b) time_after(b,a)
802 static inline unsigned long get_seconds(void)
806 gettimeofday(&tv, NULL);
807 return (tv.tv_sec + tv.tv_usec / 1000000);
811 struct list_head tl_list;
812 void (*function)(unsigned long unused);
817 static inline int timer_pending(struct timer_list *l)
819 if (l->expires > jiffies)
825 static inline int init_timer(struct timer_list *l)
827 INIT_LIST_HEAD(&l->tl_list);
831 static inline void mod_timer(struct timer_list *l, int thetime)
833 l->expires = thetime;
836 static inline void del_timer(struct timer_list *l)
841 typedef struct { volatile int counter; } atomic_t;
843 #define ATOMIC_INIT(i) { (i) }
844 #define atomic_read(a) ((a)->counter)
845 #define atomic_set(a,b) do {(a)->counter = b; } while (0)
846 #define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
847 #define atomic_dec_and_lock(a, l) atomic_dec_and_test(a)
848 #define atomic_inc(a) (((a)->counter)++)
849 #define atomic_dec(a) do { (a)->counter--; } while (0)
850 #define atomic_add(b,a) do {(a)->counter += b;} while (0)
851 #define atomic_sub(b,a) do {(a)->counter -= b;} while (0)
854 #define likely(exp) (exp)
857 #define unlikely(exp) (exp)
860 /* FIXME sys/capability will finally included linux/fs.h thus
861 * cause numerous trouble on x86-64. as temporary solution for
862 * build broken at cary, we copy definition we need from capability.h
866 typedef struct _cap_struct *cap_t;
867 typedef int cap_value_t;
878 #define CAP_DAC_OVERRIDE 1
879 #define CAP_DAC_READ_SEARCH 2
882 #define CAP_SYS_ADMIN 21
884 cap_t cap_get_proc(void);
885 int cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
890 static inline int llog_init_commit_master(void) { return 0; }
891 static inline int llog_cleanup_commit_master(int force) { return 0; }
892 static inline void portals_run_lbug_upcall(char *file, const char *fn,
898 wait_queue_head_t wait;
901 #define COMPLETION_INITIALIZER(work) \
902 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
904 #define DECLARE_COMPLETION(work) \
905 struct completion work = COMPLETION_INITIALIZER(work)
907 #define INIT_COMPLETION(x) ((x).done = 0)
909 static inline void init_completion(struct completion *x)
912 init_waitqueue_head(&x->wait);
915 struct liblustre_wait_callback {
916 struct list_head llwc_list;
917 int (*llwc_fn)(void *arg);
921 void *liblustre_register_wait_callback(int (*fn)(void *arg), void *arg);
922 void liblustre_deregister_wait_callback(void *notifier);
923 int liblustre_wait_event(int timeout);
925 #include <linux/obd_support.h>
926 #include <linux/lustre_idl.h>
927 #include <linux/lustre_lib.h>
928 #include <linux/lustre_import.h>
929 #include <linux/lustre_export.h>
930 #include <linux/lustre_net.h>