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
117 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
118 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
119 #define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH)
120 #define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH)
121 #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
125 printf("!!!LBUG at %s:%d\n", __FILE__, __LINE__); \
129 /* always adopt 2.5 definitions */
130 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
131 #define LINUX_VERSION_CODE (2*200+5*10+0)
133 static inline void inter_module_put(void *a)
138 extern ptl_handle_ni_t tcpnal_ni;
140 void *inter_module_get(char *arg);
145 void (*ws_task)(void *arg);
149 static inline void prepare_work(struct work_struct *q, void (*t)(void *),
157 static inline void schedule_work(struct work_struct *q)
159 q->ws_task(q->ws_arg);
163 #define strnlen(a,b) strlen(a)
164 static inline void *kmalloc(int size, int prot)
168 #define vmalloc malloc
170 #define kfree(a) free(a)
172 #define GFP_HIGHUSER 1
175 #define IS_ERR(a) (((a) && abs((long)(a)) < 500) ? 1 : 0)
176 #define PTR_ERR(a) ((long)(a))
177 #define ERR_PTR(a) ((void*)((long)(a)))
183 typedef int (read_proc_t)(char *page, char **start, off_t off,
184 int count, int *eof, void *data);
186 struct file; /* forward ref */
187 typedef int (write_proc_t)(struct file *file, const char *buffer,
188 unsigned long count, void *data);
190 #define NIPQUAD(addr) \
191 ((unsigned char *)&addr)[0], \
192 ((unsigned char *)&addr)[1], \
193 ((unsigned char *)&addr)[2], \
194 ((unsigned char *)&addr)[3]
196 #if defined(__LITTLE_ENDIAN)
197 #define HIPQUAD(addr) \
198 ((unsigned char *)&addr)[3], \
199 ((unsigned char *)&addr)[2], \
200 ((unsigned char *)&addr)[1], \
201 ((unsigned char *)&addr)[0]
202 #elif defined(__BIG_ENDIAN)
203 #define HIPQUAD NIPQUAD
205 #error "Undefined byteorder??"
206 #endif /* __LITTLE_ENDIAN */
209 static __inline__ int set_bit(int nr,long * addr)
214 mask = 1 << (nr & 0x1f);
215 retval = (mask & *addr) != 0;
220 static __inline__ int clear_bit(int nr, long * addr)
225 mask = 1 << (nr & 0x1f);
226 retval = (mask & *addr) != 0;
231 static __inline__ int test_bit(int nr, long * addr)
236 mask = 1 << (nr & 0x1f);
237 return ((mask & *addr) != 0);
240 static __inline__ int test_and_set_bit(int nr, long * addr)
244 res = test_bit(nr, addr);
250 static __inline__ int ext2_set_bit(int nr, void *addr)
252 return set_bit(nr, (long*)addr);
255 static __inline__ int ext2_clear_bit(int nr, void *addr)
257 return clear_bit(nr, (long*)addr);
260 static __inline__ int ext2_test_bit(int nr, void *addr)
262 return test_bit(nr, (long*)addr);
271 #define MODULE_AUTHOR(name)
272 #define MODULE_DESCRIPTION(name)
273 #define MODULE_LICENSE(name)
275 #define module_init(init)
276 #define module_exit(exit)
278 #define THIS_MODULE NULL
285 static inline int misc_register(void *foo)
290 static inline int misc_deregister(void *foo)
295 static inline int request_module(char *name)
300 #define __MOD_INC_USE_COUNT(m) do {} while (0)
301 #define __MOD_DEC_USE_COUNT(m) do {} while (0)
302 #define MOD_INC_USE_COUNT do {} while (0)
303 #define MOD_DEC_USE_COUNT do {} while (0)
304 static inline void __module_get(struct module *module)
308 static inline int try_module_get(struct module *module)
313 static inline void module_put(struct module *module)
317 /* module initialization */
318 extern int init_obdclass(void);
319 extern int ptlrpc_init(void);
320 extern int ldlm_init(void);
321 extern int osc_init(void);
322 extern int lov_init(void);
323 extern int mdc_init(void);
324 extern int echo_client_init(void);
330 #define EXPORT_SYMBOL(S)
332 typedef struct { } spinlock_t;
333 typedef __u64 kdev_t;
335 #define SPIN_LOCK_UNLOCKED (spinlock_t) { }
336 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
338 static inline void spin_lock(spinlock_t *l) {return;}
339 static inline void spin_unlock(spinlock_t *l) {return;}
340 static inline void spin_lock_init(spinlock_t *l) {return;}
341 static inline void local_irq_save(unsigned long flag) {return;}
342 static inline void local_irq_restore(unsigned long flag) {return;}
343 static inline int spin_is_locked(spinlock_t *l) {return 1;}
345 static inline void spin_lock_bh(spinlock_t *l) {}
346 static inline void spin_unlock_bh(spinlock_t *l) {}
347 static inline void spin_lock_irqsave(spinlock_t *a, unsigned long b) {}
348 static inline void spin_unlock_irqrestore(spinlock_t *a, unsigned long b) {}
350 typedef struct { } rwlock_t;
351 #define rwlock_init(x) do {} while(0)
352 #define RW_LOCK_UNLOCKED (rwlock_t) {}
354 #define read_unlock(l)
355 #define write_lock(l)
356 #define write_unlock(l)
358 #define min(x,y) ((x)<(y) ? (x) : (y))
359 #define max(x,y) ((x)>(y) ? (x) : (y))
362 #define min_t(type,x,y) \
363 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
366 #define max_t(type,x,y) \
367 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
370 #define container_of(ptr, type, member) ({ \
371 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
372 (type *)( (char *)__mptr - offsetof(type,member) );})
374 /* registering symbols */
376 #define ERESTARTSYS ERESTART
381 void get_random_bytes(void *ptr, int size);
386 #define num_physpages (16 * 1024)
388 static inline int copy_from_user(void *a,void *b, int c)
394 static inline int copy_to_user(void *a,void *b, int c)
400 static inline long strncpy_from_user(char *dest, const char *src, long n)
403 s = strncpy(dest, src, n);
404 return strnlen(s, n);
411 #define SLAB_HWCACHE_ALIGN 0
412 static inline kmem_cache_t *
413 kmem_cache_create(const char *name, size_t objsize, size_t cdum,
415 void (*e)(void *, kmem_cache_t *, unsigned long),
416 void (*f)(void *, kmem_cache_t *, unsigned long))
419 c = malloc(sizeof(*c));
423 CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
424 name, c, (int)objsize);
428 static inline int kmem_cache_destroy(kmem_cache_t *a)
430 CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", a, a->size);
434 #define kmem_cache_alloc(cache, prio) malloc(cache->size)
435 #define kmem_cache_free(cache, obj) free(obj)
437 #define PAGE_CACHE_SIZE PAGE_SIZE
438 #define PAGE_CACHE_SHIFT PAGE_SHIFT
439 #define PAGE_CACHE_MASK PAGE_MASK
441 /* struct page decl moved out from here into portals/include/libcfs/user-prim.h */
444 #define PAGE_LIST_ENTRY list
445 #define PAGE_LIST(page) ((page)->list)
447 #define page_address(page) ((page)->addr)
448 #define kmap(page) (page)->addr
449 #define kunmap(a) do {} while (0)
451 static inline struct page *alloc_pages(int mask, unsigned long order)
453 struct page *pg = malloc(sizeof(*pg));
457 #if 0 //#ifdef MAP_ANONYMOUS
458 pg->addr = mmap(0, PAGE_SIZE << order, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
460 pg->addr = malloc(PAGE_SIZE << order);
470 #define alloc_page(mask) alloc_pages((mask), 0)
472 static inline void __free_pages(struct page *pg, int what)
474 #if 0 //#ifdef MAP_ANONYMOUS
475 munmap(pg->addr, PAGE_SIZE);
482 #define __free_page(page) __free_pages((page), 0)
483 #define free_page(page) __free_page(page)
485 static inline struct page* __grab_cache_page(unsigned long index)
487 struct page *pg = alloc_pages(0, 0);
494 #define grab_cache_page(index) __grab_cache_page(index)
495 #define page_cache_release(page) __free_pages(page, 0)
498 #define do_div(a,b) \
500 unsigned long remainder;\
501 remainder = (a) % (b); \
507 #define ATTR_MODE 0x0001
508 #define ATTR_UID 0x0002
509 #define ATTR_GID 0x0004
510 #define ATTR_SIZE 0x0008
511 #define ATTR_ATIME 0x0010
512 #define ATTR_MTIME 0x0020
513 #define ATTR_CTIME 0x0040
514 #define ATTR_ATIME_SET 0x0080
515 #define ATTR_MTIME_SET 0x0100
516 #define ATTR_FORCE 0x0200 /* Not a change, but a change it */
517 #define ATTR_ATTR_FLAG 0x0400
518 #define ATTR_RAW 0x0800 /* file system, not vfs will massage attrs */
519 #define ATTR_FROM_OPEN 0x1000 /* called from open path, ie O_TRUNC */
520 /* ATTR_CTIME_SET has been defined in lustre_idl.h */
523 unsigned int ia_valid;
531 unsigned int ia_attr_flags;
534 #define IT_OPEN 0x0001
535 #define IT_CREAT 0x0002
536 #define IT_READDIR 0x0004
537 #define IT_GETATTR 0x0008
538 #define IT_LOOKUP 0x0010
539 #define IT_UNLINK 0x0020
540 #define IT_GETXATTR 0x0040
541 #define IT_EXEC 0x0080
542 #define IT_PIN 0x0100
543 #define IT_CHDIR 0x0200
545 #define IT_FL_LOCKED 0x0001
546 #define IT_FL_FOLLOWED 0x0002 /* set by vfs_follow_link */
548 #define INTENT_MAGIC 0x19620323
550 struct lookup_intent {
552 void (*it_op_release)(struct lookup_intent *);
557 void *fs_data; /* FS-specific intent data */
561 struct lustre_intent_data {
564 __u64 it_lock_handle;
572 #define LUSTRE_IT(it) ((struct lustre_intent_data *)((it)->d.fs_data))
574 static inline void intent_init(struct lookup_intent *it, int op, int flags)
576 memset(it, 0, sizeof(*it));
577 it->it_magic = INTENT_MAGIC;
579 it->it_flags = flags;
592 struct rw_semaphore {
612 unsigned int cit_ivsize;
614 int (*cit_setkey)(struct crypto_tfm *tfm,
615 const __u8 *key, unsigned int keylen);
616 int (*cit_encrypt)(struct crypto_tfm *tfm,
617 struct scatterlist *dst,
618 struct scatterlist *src,
619 unsigned int nbytes);
620 int (*cit_encrypt_iv)(struct crypto_tfm *tfm,
621 struct scatterlist *dst,
622 struct scatterlist *src,
623 unsigned int nbytes, __u8 *iv);
624 int (*cit_decrypt)(struct crypto_tfm *tfm,
625 struct scatterlist *dst,
626 struct scatterlist *src,
627 unsigned int nbytes);
628 int (*cit_decrypt_iv)(struct crypto_tfm *tfm,
629 struct scatterlist *dst,
630 struct scatterlist *src,
631 unsigned int nbytes, __u8 *iv);
632 void (*cit_xor_block)(__u8 *dst, const __u8 *src);
636 void (*dit_init)(struct crypto_tfm *tfm);
637 void (*dit_update)(struct crypto_tfm *tfm,
638 struct scatterlist *sg, unsigned int nsg);
639 void (*dit_update_kernel)(struct crypto_tfm *tfm,
640 const void *data, size_t count);
641 void (*dit_final)(struct crypto_tfm *tfm, __u8 *out);
642 void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg,
643 unsigned int nsg, __u8 *out);
644 int (*dit_setkey)(struct crypto_tfm *tfm,
645 const __u8 *key, unsigned int keylen);
646 #ifdef CONFIG_CRYPTO_HMAC
647 void *dit_hmac_block;
651 struct compress_tfm {
652 int (*cot_compress)(struct crypto_tfm *tfm,
653 const __u8 *src, unsigned int slen,
654 __u8 *dst, unsigned int *dlen);
655 int (*cot_decompress)(struct crypto_tfm *tfm,
656 const __u8 *src, unsigned int slen,
657 __u8 *dst, unsigned int *dlen);
665 struct cipher_tfm cipher;
666 struct digest_tfm digest;
667 struct compress_tfm compress;
670 struct crypto_alg *__crt_alg;
673 /* use the macro's argument to avoid unused warnings */
674 #define down(a) do { (void)a; } while (0)
675 #define up(a) do { (void)a; } while (0)
676 #define down_read(a) do { (void)a; } while (0)
677 #define up_read(a) do { (void)a; } while (0)
678 #define down_write(a) do { (void)a; } while (0)
679 #define up_write(a) do { (void)a; } while (0)
680 #define sema_init(a,b) do { (void)a; } while (0)
681 #define init_rwsem(a) do { (void)a; } while (0)
683 #define DECLARE_MUTEX(name) \
684 struct semaphore name = { 1 }
686 static inline void init_MUTEX (struct semaphore *sem)
691 struct rpc_pipe_msg {
692 struct list_head list;
700 struct list_head task_list;
704 struct list_head sleeping;
717 struct fs_struct *fs;
719 struct signal pending;
732 struct fs_struct __fs;
735 extern struct task_struct *current;
736 int in_group_p(gid_t gid);
737 static inline int capable(int cap)
739 if (current->cap_effective & (1 << cap))
745 #define set_current_state(foo) do { current->state = foo; } while (0)
747 #define init_waitqueue_entry(q,p) do { (q)->process = p; } while (0)
748 #define add_wait_queue(q,p) do { list_add(&(q)->task_list, &(p)->sleeping); } while (0)
749 #define del_wait_queue(p) do { list_del(&(p)->sleeping); } while (0)
750 #define remove_wait_queue(q,p) do { list_del(&(p)->sleeping); } while (0)
752 #define DECLARE_WAIT_QUEUE_HEAD(HEAD) \
753 wait_queue_head_t HEAD = { \
754 .task_list = LIST_HEAD_INIT(HEAD.task_list) \
756 #define init_waitqueue_head(l) INIT_LIST_HEAD(&(l)->task_list)
757 #define wake_up(l) do { int a; a++; } while (0)
758 #define TASK_INTERRUPTIBLE 0
759 #define TASK_UNINTERRUPTIBLE 1
760 #define TASK_RUNNING 2
762 #define wait_event_interruptible(wq, condition) \
764 struct l_wait_info lwi; \
765 int timeout = 100000000;/* for ever */ \
768 lwi = LWI_TIMEOUT(timeout, NULL, NULL); \
769 ret = l_wait_event(NULL, condition, &lwi); \
774 #define in_interrupt() (0)
776 #define schedule() do {} while (0)
777 static inline int schedule_timeout(signed long t)
782 #define lock_kernel() do {} while (0)
783 #define unlock_kernel() do {} while (0)
784 #define daemonize(l) do {} while (0)
785 #define sigfillset(l) do {} while (0)
786 #define recalc_sigpending(l) do {} while (0)
787 #define kernel_thread(l,m,n) LBUG()
789 #define USERMODEHELPER(path, argv, envp) (0)
790 #define SIGNAL_MASK_ASSERT()
793 #include <sys/time.h>
795 #error "liblustre's jiffies currently expects HZ to be 1"
799 unsigned long _ret = 0; \
801 if (gettimeofday(&tv, NULL) == 0) \
805 #define time_after(a, b) ((long)(b) - (long)(a) < 0)
806 #define time_before(a, b) time_after(b,a)
808 static inline unsigned long get_seconds(void)
812 gettimeofday(&tv, NULL);
813 return (tv.tv_sec + tv.tv_usec / 1000000);
817 struct list_head tl_list;
818 void (*function)(unsigned long unused);
823 static inline int timer_pending(struct timer_list *l)
825 if (l->expires > jiffies)
831 static inline int init_timer(struct timer_list *l)
833 INIT_LIST_HEAD(&l->tl_list);
837 static inline void mod_timer(struct timer_list *l, int thetime)
839 l->expires = thetime;
842 static inline void del_timer(struct timer_list *l)
847 typedef struct { volatile int counter; } atomic_t;
849 #define ATOMIC_INIT(i) { (i) }
850 #define atomic_read(a) ((a)->counter)
851 #define atomic_set(a,b) do {(a)->counter = b; } while (0)
852 #define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
853 #define atomic_dec_and_lock(a, l) atomic_dec_and_test(a)
854 #define atomic_inc(a) (((a)->counter)++)
855 #define atomic_dec(a) do { (a)->counter--; } while (0)
856 #define atomic_add(b,a) do {(a)->counter += b;} while (0)
857 #define atomic_sub(b,a) do {(a)->counter -= b;} while (0)
860 #define likely(exp) (exp)
863 #define unlikely(exp) (exp)
866 /* FIXME sys/capability will finally included linux/fs.h thus
867 * cause numerous trouble on x86-64. as temporary solution for
868 * build broken at cary, we copy definition we need from capability.h
872 typedef struct _cap_struct *cap_t;
873 typedef int cap_value_t;
884 #define CAP_DAC_OVERRIDE 1
885 #define CAP_DAC_READ_SEARCH 2
888 #define CAP_SYS_ADMIN 21
890 cap_t cap_get_proc(void);
891 int cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
896 static inline int llog_init_commit_master(void) { return 0; }
897 static inline int llog_cleanup_commit_master(int force) { return 0; }
898 static inline void portals_run_lbug_upcall(char *file, const char *fn,
904 wait_queue_head_t wait;
907 #define COMPLETION_INITIALIZER(work) \
908 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
910 #define DECLARE_COMPLETION(work) \
911 struct completion work = COMPLETION_INITIALIZER(work)
913 #define INIT_COMPLETION(x) ((x).done = 0)
915 static inline void init_completion(struct completion *x)
918 init_waitqueue_head(&x->wait);
921 struct liblustre_wait_callback {
922 struct list_head llwc_list;
923 int (*llwc_fn)(void *arg);
927 void *liblustre_register_wait_callback(int (*fn)(void *arg), void *arg);
928 void liblustre_deregister_wait_callback(void *notifier);
929 int liblustre_wait_event(int timeout);
931 #include <linux/obd_support.h>
932 #include <linux/lustre_idl.h>
933 #include <linux/lustre_lib.h>
934 #include <linux/lustre_import.h>
935 #include <linux/lustre_export.h>
936 #include <linux/lustre_net.h>