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 /* This is because lprocfs_status.h gets included here indirectly. It would
61 * be much better to just avoid lprocfs being included into liblustre entirely
62 * but that requires more header surgery than I can handle right now.
64 #ifndef smp_processor_id
65 #define smp_processor_id() 0
68 /* always adopt 2.5 definitions */
69 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
70 #define LINUX_VERSION_CODE (2*200+5*10+0)
72 static inline void inter_module_put(void *a)
77 extern ptl_handle_ni_t tcpnal_ni;
79 void *inter_module_get(char *arg);
84 void (*ws_task)(void *arg);
88 static inline void prepare_work(struct work_struct *q, void (*t)(void *),
96 static inline void schedule_work(struct work_struct *q)
98 q->ws_task(q->ws_arg);
102 #define strnlen(a,b) strlen(a)
103 static inline void *kmalloc(int size, int prot)
107 #define vmalloc malloc
109 #define kfree(a) free(a)
111 #define GFP_HIGHUSER 1
112 #define IS_ERR(a) (((a) && abs((int)(a)) < 500) ? 1 : 0)
113 #define PTR_ERR(a) ((int)(a))
115 #define capable(foo) 1
116 #define CAP_SYS_ADMIN 1
123 typedef void *read_proc_t;
124 typedef void *write_proc_t;
128 #define __swab16(x) \
132 (((__u16)(__x) & (__u16)0x00ffU) << 8) | \
133 (((__u16)(__x) & (__u16)0xff00U) >> 8) )); \
136 #define __swab32(x) \
140 (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | \
141 (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | \
142 (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | \
143 (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); \
146 #define __swab64(x) \
150 (__u64)(((__u64)(__x) & (__u64)0x00000000000000ffULL) << 56) | \
151 (__u64)(((__u64)(__x) & (__u64)0x000000000000ff00ULL) << 40) | \
152 (__u64)(((__u64)(__x) & (__u64)0x0000000000ff0000ULL) << 24) | \
153 (__u64)(((__u64)(__x) & (__u64)0x00000000ff000000ULL) << 8) | \
154 (__u64)(((__u64)(__x) & (__u64)0x000000ff00000000ULL) >> 8) | \
155 (__u64)(((__u64)(__x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
156 (__u64)(((__u64)(__x) & (__u64)0x00ff000000000000ULL) >> 40) | \
157 (__u64)(((__u64)(__x) & (__u64)0xff00000000000000ULL) >> 56) )); \
160 #define __swab16s(x) __swab16(*(x))
161 #define __swab32s(x) __swab32(*(x))
162 #define __swab64s(x) __swab64(*(x))
164 #define __LITTLE_ENDIAN__
165 #ifdef __LITTLE_ENDIAN__
166 # define le16_to_cpu(x) ((__u16)(x))
167 # define cpu_to_le16(x) ((__u16)(x))
168 # define le32_to_cpu(x) ((__u32)(x))
169 # define cpu_to_le32(x) ((__u32)(x))
170 # define le64_to_cpu(x) ((__u64)(x))
171 # define cpu_to_le64(x) ((__u64)(x))
173 # define le16_to_cpu(x) __swab16(x)
174 # define cpu_to_le16(x) __swab16(x)
175 # define le32_to_cpu(x) __swab32(x)
176 # define cpu_to_le32(x) __swab32(x)
177 # define le64_to_cpu(x) __swab64(x)
178 # define cpu_to_le64(x) __swab64(x)
179 # error "do more check here!!!"
183 static __inline__ int set_bit(int nr,long * addr)
188 mask = 1 << (nr & 0x1f);
189 retval = (mask & *addr) != 0;
194 static __inline__ int clear_bit(int nr, long * addr)
199 mask = 1 << (nr & 0x1f);
200 retval = (mask & *addr) != 0;
205 static __inline__ int test_bit(int nr, long * addr)
210 mask = 1 << (nr & 0x1f);
211 return ((mask & *addr) != 0);
220 static inline void MODULE_AUTHOR(char *name)
222 printf("%s\n", name);
224 #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
225 #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
227 #define THIS_MODULE NULL
233 static inline int misc_register(void *foo)
237 #define misc_deregister misc_register
239 #define __MOD_INC_USE_COUNT(m) do {int a = 1; a++; } while (0)
240 #define __MOD_DEC_USE_COUNT(m) do {int a = 1; a++; } while (0)
241 #define MOD_INC_USE_COUNT do {int a = 1; a++; } while (0)
242 #define MOD_DEC_USE_COUNT do {int a = 1; a++; } while (0)
244 /* module initialization */
245 extern int init_obdclass(void);
246 extern int ptlrpc_init(void);
247 extern int ldlm_init(void);
248 extern int osc_init(void);
249 extern int lov_init(void);
250 extern int mdc_init(void);
251 extern int echo_client_init(void);
258 #define EXPORT_SYMBOL(S)
260 typedef int spinlock_t;
261 typedef __u64 kdev_t;
263 #define SPIN_LOCK_UNLOCKED 0
264 #define spin_lock(l) do {int a = 1; a++; } while (0)
265 #define spin_unlock(l) do {int a= 1; a++; } while (0)
266 #define spin_lock_init(l) do {int a= 1; a++; } while (0)
267 static inline void spin_lock_bh(spinlock_t *l)
271 static inline void spin_unlock_bh(spinlock_t *l)
275 static inline void spin_unlock_irqrestore(spinlock_t *a, long b)
279 static inline void spin_lock_irqsave(spinlock_t *a, long b)
284 #define barrier() do {int a= 1; a++; } while (0)
286 #define min(x,y) ((x)<(y) ? (x) : (y))
287 #define max(x,y) ((x)>(y) ? (x) : (y))
289 /* registering symbols */
291 #define ERESTARTSYS ERESTART
296 static inline void get_random_bytes(void *ptr, int size)
299 int i, count = size/sizeof(int);
301 for (i = 0; i< count; i++)
308 #define num_physpages (16 * 1024)
310 static inline int copy_from_user(void *a,void *b, int c)
316 static inline int copy_to_user(void *a,void *b, int c)
327 #define SLAB_HWCACHE_ALIGN 0
328 static inline kmem_cache_t *
329 kmem_cache_create(const char *name, size_t objsize, size_t cdum,
331 void (*e)(void *, kmem_cache_t *, unsigned long),
332 void (*f)(void *, kmem_cache_t *, unsigned long))
335 c = malloc(sizeof(*c));
339 CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
340 name, c, (int)objsize);
344 static inline int kmem_cache_destroy(kmem_cache_t *a)
346 CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", a, a->size);
350 #define kmem_cache_validate(a,b) 1
351 #define kmem_cache_alloc(cache, prio) malloc(cache->size)
352 #define kmem_cache_free(cache, obj) free(obj)
354 #define PAGE_CACHE_SIZE PAGE_SIZE
355 #define PAGE_CACHE_SHIFT 12
356 #define PAGE_CACHE_MASK PAGE_MASK
363 #define kmap(page) (page)->addr
364 #define kunmap(a) do { int foo = 1; foo++; } while (0)
366 static inline struct page *alloc_pages(int mask, unsigned long foo)
368 struct page *pg = malloc(sizeof(*pg));
373 pg->addr = mmap(0, PAGE_SIZE, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
375 pg->addr = malloc(PAGE_SIZE);
385 static inline void __free_pages(struct page *pg, int what)
388 munmap(pg->addr, PAGE_SIZE);
395 static inline struct page* __grab_cache_page(int index)
397 struct page *pg = alloc_pages(0, 0);
404 #define grab_cache_page(index) __grab_cache_page(index)
405 #define page_cache_release(page) __free_pages(page, 0)
408 #define do_div(a,b) \
421 #define ATTR_ATIME 16
422 #define ATTR_MTIME 32
423 #define ATTR_CTIME 64
424 #define ATTR_ATIME_SET 128
425 #define ATTR_MTIME_SET 256
426 #define ATTR_FORCE 512 /* Not a change, but a change it */
427 #define ATTR_ATTR_FLAG 1024
428 #define ATTR_RAW 2048 /* file system, not vfs will massage attrs */
429 #define ATTR_FROM_OPEN 4096 /* called from open path, ie O_TRUNC */
432 unsigned int ia_valid;
440 unsigned int ia_attr_flags;
443 /* copy from kernel header */
445 #define IT_CREAT (1<<1)
446 #define IT_READDIR (1<<2)
447 #define IT_GETATTR (1<<3)
448 #define IT_LOOKUP (1<<4)
449 #define IT_UNLINK (1<<5)
451 struct lookup_intent {
457 struct iattr *it_iattr;
458 __u64 it_lock_handle[2];
471 #define cpu_to_le32(x) ((__u32)(x))
478 #define down(a) do {(a)->count++;} while (0)
479 #define up(a) do {(a)->count--;} while (0)
480 #define sema_init(a,b) do { (a)->count = b; } while (0)
483 struct list_head sleepers;
487 struct list_head sleeping;
500 struct fs_struct *fs;
502 struct signal pending;
510 extern struct task_struct *current;
512 #define in_group_p(a) 0 /* FIXME */
514 #define set_current_state(foo) do { current->state = foo; } while (0)
516 #define init_waitqueue_entry(q,p) do { (q)->process = p; } while (0)
517 #define add_wait_queue(q,p) do { list_add(&(q)->sleepers, &(p)->sleeping); } while (0)
518 #define del_wait_queue(p) do { list_del(&(p)->sleeping); } while (0)
519 #define remove_wait_queue(q,p) do { list_del(&(p)->sleeping); } while (0)
521 #define init_waitqueue_head(l) INIT_LIST_HEAD(&(l)->sleepers)
522 #define wake_up(l) do { int a; a++; } while (0)
523 #define TASK_INTERRUPTIBLE 0
524 #define TASK_UNINTERRUPTIBLE 1
525 #define TASK_RUNNING 2
527 #define in_interrupt() (0)
529 #define schedule() do { int a; a++; } while (0)
530 static inline int schedule_timeout(signed long t)
535 #define lock_kernel() do { int a; a++; } while (0)
536 #define daemonize(l) do { int a; a++; } while (0)
537 #define sigfillset(l) do { int a; a++; } while (0)
538 #define recalc_sigpending(l) do { int a; a++; } while (0)
539 #define kernel_thread(l,m,n)
541 static inline int call_usermodehelper(char *prog, char **argv, char **evnp, int unknown)
553 struct list_head tl_list;
554 void (*function)(unsigned long unused);
559 static inline int timer_pending(struct timer_list *l)
561 if (l->expires > jiffies)
567 static inline int init_timer(struct timer_list *l)
569 INIT_LIST_HEAD(&l->tl_list);
573 static inline void mod_timer(struct timer_list *l, int thetime)
575 l->expires = thetime;
578 static inline void del_timer(struct timer_list *l)
583 typedef struct { volatile int counter; } atomic_t;
585 #define atomic_read(a) ((a)->counter)
586 #define atomic_set(a,b) do {(a)->counter = b; } while (0)
587 #define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
588 #define atomic_inc(a) (((a)->counter)++)
589 #define atomic_dec(a) do { (a)->counter--; } while (0)
590 #define atomic_add(b,a) do {(a)->counter += b;} while (0)
591 #define atomic_sub(b,a) do {(a)->counter -= b;} while (0)
595 printf("!!!LBUG at %s:%d\n", __FILE__, __LINE__); \
599 #include <linux/obd_support.h>
600 #include <linux/lustre_idl.h>
601 #include <linux/lustre_lib.h>
602 #include <linux/lustre_import.h>
603 #include <linux/lustre_export.h>
604 #include <linux/lustre_net.h>