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.
32 #include <sys/types.h>
36 #include <sys/ioctl.h>
43 #include <portals/list.h>
44 #include <portals/p30.h>
45 #include <linux/kp30.h>
47 /* definitions for liblustre */
52 #define PAGE_SIZE (1UL << PAGE_SHIFT)
53 #define PAGE_MASK (~(PAGE_SIZE-1))
56 typedef unsigned short umode_t;
60 /* always adopt 2.5 definitions */
61 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
62 #define LINUX_VERSION_CODE (2*200+5*10+0)
64 static inline void inter_module_put(void *a)
69 extern ptl_handle_ni_t tcpnal_ni;
71 void *inter_module_get(char *arg);
76 void (*ws_task)(void *arg);
80 static inline void prepare_work(struct work_struct *q, void (*t)(void *),
88 static inline void schedule_work(struct work_struct *q)
90 q->ws_task(q->ws_arg);
94 #define strnlen(a,b) strlen(a)
95 static inline void *kmalloc(int size, int prot)
99 #define vmalloc malloc
101 #define kfree(a) free(a)
103 #define GFP_HIGHUSER 1
104 #define IS_ERR(a) (((a) && abs((int)(a)) < 500) ? 1 : 0)
105 #define PTR_ERR(a) ((int)(a))
107 #define capable(foo) 1
108 #define CAP_SYS_ADMIN 1
115 typedef void *read_proc_t;
116 typedef void *write_proc_t;
120 #define __swab16(x) \
124 (((__u16)(__x) & (__u16)0x00ffU) << 8) | \
125 (((__u16)(__x) & (__u16)0xff00U) >> 8) )); \
128 #define __swab32(x) \
132 (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | \
133 (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | \
134 (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | \
135 (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); \
138 #define __swab64(x) \
142 (__u64)(((__u64)(__x) & (__u64)0x00000000000000ffULL) << 56) | \
143 (__u64)(((__u64)(__x) & (__u64)0x000000000000ff00ULL) << 40) | \
144 (__u64)(((__u64)(__x) & (__u64)0x0000000000ff0000ULL) << 24) | \
145 (__u64)(((__u64)(__x) & (__u64)0x00000000ff000000ULL) << 8) | \
146 (__u64)(((__u64)(__x) & (__u64)0x000000ff00000000ULL) >> 8) | \
147 (__u64)(((__u64)(__x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
148 (__u64)(((__u64)(__x) & (__u64)0x00ff000000000000ULL) >> 40) | \
149 (__u64)(((__u64)(__x) & (__u64)0xff00000000000000ULL) >> 56) )); \
152 #define __swab16s(x) __swab16(*(x))
153 #define __swab32s(x) __swab32(*(x))
154 #define __swab64s(x) __swab64(*(x))
156 #define __LITTLE_ENDIAN__
157 #ifdef __LITTLE_ENDIAN__
158 # define le16_to_cpu(x) ((__u16)(x))
159 # define cpu_to_le16(x) ((__u16)(x))
160 # define le32_to_cpu(x) ((__u32)(x))
161 # define cpu_to_le32(x) ((__u32)(x))
162 # define le64_to_cpu(x) ((__u64)(x))
163 # define cpu_to_le64(x) ((__u64)(x))
165 # define le16_to_cpu(x) __swab16(x)
166 # define cpu_to_le16(x) __swab16(x)
167 # define le32_to_cpu(x) __swab32(x)
168 # define cpu_to_le32(x) __swab32(x)
169 # define le64_to_cpu(x) __swab64(x)
170 # define cpu_to_le64(x) __swab64(x)
171 # error "do more check here!!!"
175 static __inline__ int set_bit(int nr,long * addr)
180 mask = 1 << (nr & 0x1f);
181 retval = (mask & *addr) != 0;
186 static __inline__ int clear_bit(int nr, long * addr)
191 mask = 1 << (nr & 0x1f);
192 retval = (mask & *addr) != 0;
197 static __inline__ int test_bit(int nr, long * addr)
202 mask = 1 << (nr & 0x1f);
203 return ((mask & *addr) != 0);
212 static inline void MODULE_AUTHOR(char *name)
214 printf("%s\n", name);
216 #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
217 #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
219 #define THIS_MODULE NULL
225 static inline int misc_register(void *foo)
229 #define misc_deregister misc_register
231 #define __MOD_INC_USE_COUNT(m) do {int a = 1; a++; } while (0)
232 #define __MOD_DEC_USE_COUNT(m) do {int a = 1; a++; } while (0)
233 #define MOD_INC_USE_COUNT do {int a = 1; a++; } while (0)
234 #define MOD_DEC_USE_COUNT do {int a = 1; a++; } while (0)
236 /* module initialization */
237 extern int init_obdclass(void);
238 extern int ptlrpc_init(void);
239 extern int ldlm_init(void);
240 extern int osc_init(void);
241 extern int lov_init(void);
242 extern int mdc_init(void);
243 extern int echo_client_init(void);
250 #define EXPORT_SYMBOL(S)
252 typedef int spinlock_t;
253 typedef __u64 kdev_t;
255 #define SPIN_LOCK_UNLOCKED 0
256 #define spin_lock(l) do {int a = 1; a++; } while (0)
257 #define spin_unlock(l) do {int a= 1; a++; } while (0)
258 #define spin_lock_init(l) do {int a= 1; a++; } while (0)
259 static inline void spin_lock_bh(spinlock_t *l)
263 static inline void spin_unlock_bh(spinlock_t *l)
267 static inline void spin_unlock_irqrestore(spinlock_t *a, long b)
271 static inline void spin_lock_irqsave(spinlock_t *a, long b)
276 #define barrier() do {int a= 1; a++; } while (0)
278 #define min(x,y) ((x)<(y) ? (x) : (y))
279 #define max(x,y) ((x)>(y) ? (x) : (y))
281 /* registering symbols */
283 #define ERESTARTSYS ERESTART
288 static inline void get_random_bytes(void *ptr, int size)
291 int i, count = size/sizeof(int);
293 for (i = 0; i< count; i++)
300 #define num_physpages (16 * 1024)
302 static inline int copy_from_user(void *a,void *b, int c)
308 static inline int copy_to_user(void *a,void *b, int c)
319 #define SLAB_HWCACHE_ALIGN 0
320 static inline kmem_cache_t *
321 kmem_cache_create(const char *name, size_t objsize, size_t cdum,
323 void (*e)(void *, kmem_cache_t *, unsigned long),
324 void (*f)(void *, kmem_cache_t *, unsigned long))
327 c = malloc(sizeof(*c));
331 CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
332 name, c, (int)objsize);
336 static inline int kmem_cache_destroy(kmem_cache_t *a)
338 CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", a, a->size);
342 #define kmem_cache_validate(a,b) 1
343 #define kmem_cache_alloc(cache, prio) malloc(cache->size)
344 #define kmem_cache_free(cache, obj) free(obj)
346 #define PAGE_CACHE_SIZE PAGE_SIZE
347 #define PAGE_CACHE_SHIFT 12
348 #define PAGE_CACHE_MASK PAGE_MASK
355 #define kmap(page) (page)->addr
356 #define kunmap(a) do { int foo = 1; foo++; } while (0)
358 static inline struct page *alloc_pages(int mask, unsigned long foo)
360 struct page *pg = malloc(sizeof(*pg));
365 pg->addr = mmap(0, PAGE_SIZE, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
367 pg->addr = malloc(PAGE_SIZE);
377 static inline void __free_pages(struct page *pg, int what)
380 munmap(pg->addr, PAGE_SIZE);
387 static inline struct page* __grab_cache_page(int index)
389 struct page *pg = alloc_pages(0, 0);
396 #define grab_cache_page(index) __grab_cache_page(index)
397 #define page_cache_release(page) __free_pages(page, 0)
400 #define do_div(a,b) \
413 #define ATTR_ATIME 16
414 #define ATTR_MTIME 32
415 #define ATTR_CTIME 64
416 #define ATTR_ATIME_SET 128
417 #define ATTR_MTIME_SET 256
418 #define ATTR_FORCE 512 /* Not a change, but a change it */
419 #define ATTR_ATTR_FLAG 1024
420 #define ATTR_RAW 2048 /* file system, not vfs will massage attrs */
421 #define ATTR_FROM_OPEN 4096 /* called from open path, ie O_TRUNC */
424 unsigned int ia_valid;
432 unsigned int ia_attr_flags;
435 /* copy from kernel header */
437 #define IT_CREAT (1<<1)
438 #define IT_READDIR (1<<2)
439 #define IT_GETATTR (1<<3)
440 #define IT_LOOKUP (1<<4)
441 #define IT_UNLINK (1<<5)
443 struct lookup_intent {
449 struct iattr *it_iattr;
450 __u64 it_lock_handle[2];
463 #define cpu_to_le32(x) ((__u32)(x))
470 #define down(a) do {(a)->count++;} while (0)
471 #define up(a) do {(a)->count--;} while (0)
472 #define sema_init(a,b) do { (a)->count = b; } while (0)
475 struct list_head sleepers;
479 struct list_head sleeping;
492 struct fs_struct *fs;
494 struct signal pending;
502 extern struct task_struct *current;
504 #define in_group_p(a) 0 /* FIXME */
506 #define set_current_state(foo) do { current->state = foo; } while (0)
508 #define init_waitqueue_entry(q,p) do { (q)->process = p; } while (0)
509 #define add_wait_queue(q,p) do { list_add(&(q)->sleepers, &(p)->sleeping); } while (0)
510 #define del_wait_queue(p) do { list_del(&(p)->sleeping); } while (0)
511 #define remove_wait_queue(q,p) do { list_del(&(p)->sleeping); } while (0)
513 #define init_waitqueue_head(l) INIT_LIST_HEAD(&(l)->sleepers)
514 #define wake_up(l) do { int a; a++; } while (0)
515 #define TASK_INTERRUPTIBLE 0
516 #define TASK_UNINTERRUPTIBLE 1
517 #define TASK_RUNNING 2
519 #define in_interrupt() (0)
521 #define schedule() do { int a; a++; } while (0)
522 static inline int schedule_timeout(signed long t)
527 #define lock_kernel() do { int a; a++; } while (0)
528 #define daemonize(l) do { int a; a++; } while (0)
529 #define sigfillset(l) do { int a; a++; } while (0)
530 #define recalc_sigpending(l) do { int a; a++; } while (0)
531 #define kernel_thread(l,m,n)
533 static inline int call_usermodehelper(char *prog, char **argv, char **evnp, int unknown)
545 struct list_head tl_list;
546 void (*function)(unsigned long unused);
551 static inline int timer_pending(struct timer_list *l)
553 if (l->expires > jiffies)
559 static inline int init_timer(struct timer_list *l)
561 INIT_LIST_HEAD(&l->tl_list);
565 static inline void mod_timer(struct timer_list *l, int thetime)
567 l->expires = thetime;
570 static inline void del_timer(struct timer_list *l)
575 typedef struct { volatile int counter; } atomic_t;
577 #define atomic_read(a) ((a)->counter)
578 #define atomic_set(a,b) do {(a)->counter = b; } while (0)
579 #define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
580 #define atomic_inc(a) (((a)->counter)++)
581 #define atomic_dec(a) do { (a)->counter--; } while (0)
582 #define atomic_add(b,a) do {(a)->counter += b;} while (0)
583 #define atomic_sub(b,a) do {(a)->counter -= b;} while (0)
587 printf("!!!LBUG at %s:%d\n", __FILE__, __LINE__); \
591 #include <linux/obd_support.h>
592 #include <linux/lustre_idl.h>
593 #include <linux/lustre_lib.h>
594 #include <linux/lustre_import.h>
595 #include <linux/lustre_export.h>
596 #include <linux/lustre_net.h>