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
73 /* always adopt 2.5 definitions */
74 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
75 #define LINUX_VERSION_CODE (2*200+5*10+0)
77 static inline void inter_module_put(void *a)
82 extern ptl_handle_ni_t tcpnal_ni;
84 void *inter_module_get(char *arg);
89 void (*ws_task)(void *arg);
93 static inline void prepare_work(struct work_struct *q, void (*t)(void *),
101 static inline void schedule_work(struct work_struct *q)
103 q->ws_task(q->ws_arg);
107 #define strnlen(a,b) strlen(a)
108 static inline void *kmalloc(int size, int prot)
112 #define vmalloc malloc
114 #define kfree(a) free(a)
116 #define GFP_HIGHUSER 1
119 #define IS_ERR(a) (((a) && abs((long)(a)) < 500) ? 1 : 0)
120 #define PTR_ERR(a) ((long)(a))
121 #define ERR_PTR(a) ((void*)((long)(a)))
127 typedef int (read_proc_t)(char *page, char **start, off_t off,
128 int count, int *eof, void *data);
130 struct file; /* forward ref */
131 typedef int (write_proc_t)(struct file *file, const char *buffer,
132 unsigned long count, void *data);
134 #define NIPQUAD(addr) \
135 ((unsigned char *)&addr)[0], \
136 ((unsigned char *)&addr)[1], \
137 ((unsigned char *)&addr)[2], \
138 ((unsigned char *)&addr)[3]
140 #if defined(__LITTLE_ENDIAN)
141 #define HIPQUAD(addr) \
142 ((unsigned char *)&addr)[3], \
143 ((unsigned char *)&addr)[2], \
144 ((unsigned char *)&addr)[1], \
145 ((unsigned char *)&addr)[0]
146 #elif defined(__BIG_ENDIAN)
147 #define HIPQUAD NIPQUAD
149 #error "Undefined byteorder??"
150 #endif /* __LITTLE_ENDIAN */
153 static __inline__ int set_bit(int nr,long * addr)
158 mask = 1 << (nr & 0x1f);
159 retval = (mask & *addr) != 0;
164 static __inline__ int clear_bit(int nr, long * addr)
169 mask = 1 << (nr & 0x1f);
170 retval = (mask & *addr) != 0;
175 static __inline__ int test_bit(int nr, long * addr)
180 mask = 1 << (nr & 0x1f);
181 return ((mask & *addr) != 0);
184 static __inline__ int ext2_set_bit(int nr, void *addr)
186 return set_bit(nr, (long*)addr);
189 static __inline__ int ext2_clear_bit(int nr, void *addr)
191 return clear_bit(nr, (long*)addr);
194 static __inline__ int ext2_test_bit(int nr, void *addr)
196 return test_bit(nr, (long*)addr);
205 static inline void MODULE_AUTHOR(char *name)
207 printf("%s\n", name);
209 #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
210 #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
212 #define THIS_MODULE NULL
218 static inline int misc_register(void *foo)
223 static inline int misc_deregister(void *foo)
228 static inline int request_module(char *name)
233 #define __MOD_INC_USE_COUNT(m) do {} while (0)
234 #define __MOD_DEC_USE_COUNT(m) do {} while (0)
235 #define MOD_INC_USE_COUNT do {} while (0)
236 #define MOD_DEC_USE_COUNT do {} while (0)
237 static inline void __module_get(struct module *module)
241 static inline int try_module_get(struct module *module)
246 static inline void module_put(struct module *module)
250 /* module initialization */
251 extern int init_obdclass(void);
252 extern int ptlrpc_init(void);
253 extern int ldlm_init(void);
254 extern int osc_init(void);
255 extern int lov_init(void);
256 extern int mdc_init(void);
257 extern int echo_client_init(void);
263 #define EXPORT_SYMBOL(S)
265 typedef struct { } spinlock_t;
266 typedef __u64 kdev_t;
268 #define SPIN_LOCK_UNLOCKED (spinlock_t) { }
269 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
271 static inline void spin_lock(spinlock_t *l) {return;}
272 static inline void spin_unlock(spinlock_t *l) {return;}
273 static inline void spin_lock_init(spinlock_t *l) {return;}
274 static inline void local_irq_save(unsigned long flag) {return;}
275 static inline void local_irq_restore(unsigned long flag) {return;}
276 static inline int spin_is_locked(spinlock_t *l) {return 1;}
278 static inline void spin_lock_bh(spinlock_t *l) {}
279 static inline void spin_unlock_bh(spinlock_t *l) {}
280 static inline void spin_lock_irqsave(spinlock_t *a, unsigned long b) {}
281 static inline void spin_unlock_irqrestore(spinlock_t *a, unsigned long b) {}
283 #define min(x,y) ((x)<(y) ? (x) : (y))
284 #define max(x,y) ((x)>(y) ? (x) : (y))
287 #define min_t(type,x,y) \
288 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
291 #define max_t(type,x,y) \
292 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
295 /* registering symbols */
297 #define ERESTARTSYS ERESTART
302 static inline void get_random_bytes(void *ptr, int size)
305 int i, count = size/sizeof(int);
307 for (i = 0; i< count; i++)
314 #define num_physpages (16 * 1024)
316 static inline int copy_from_user(void *a,void *b, int c)
322 static inline int copy_to_user(void *a,void *b, int c)
333 #define SLAB_HWCACHE_ALIGN 0
334 static inline kmem_cache_t *
335 kmem_cache_create(const char *name, size_t objsize, size_t cdum,
337 void (*e)(void *, kmem_cache_t *, unsigned long),
338 void (*f)(void *, kmem_cache_t *, unsigned long))
341 c = malloc(sizeof(*c));
345 CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
346 name, c, (int)objsize);
350 static inline int kmem_cache_destroy(kmem_cache_t *a)
352 CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", a, a->size);
356 #define kmem_cache_alloc(cache, prio) malloc(cache->size)
357 #define kmem_cache_free(cache, obj) free(obj)
359 #define PAGE_CACHE_SIZE PAGE_SIZE
360 #define PAGE_CACHE_SHIFT PAGE_SHIFT
361 #define PAGE_CACHE_MASK PAGE_MASK
363 /* struct page decl moved out from here into portals/include/libcfs/user-prim.h */
365 #define kmap(page) (page)->addr
366 #define kunmap(a) do {} while (0)
368 static inline struct page *alloc_pages(int mask, unsigned long order)
370 struct page *pg = malloc(sizeof(*pg));
374 #if 0 //#ifdef MAP_ANONYMOUS
375 pg->addr = mmap(0, PAGE_SIZE << order, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
377 pg->addr = malloc(PAGE_SIZE << order);
387 #define alloc_page(mask) alloc_pages((mask), 0)
389 static inline void __free_pages(struct page *pg, int what)
391 #if 0 //#ifdef MAP_ANONYMOUS
392 munmap(pg->addr, PAGE_SIZE);
399 #define __free_page(page) __free_pages((page), 0)
400 #define free_page(page) __free_page(page)
402 static inline struct page* __grab_cache_page(unsigned long index)
404 struct page *pg = alloc_pages(0, 0);
411 #define grab_cache_page(index) __grab_cache_page(index)
412 #define page_cache_release(page) __free_pages(page, 0)
415 #define do_div(a,b) \
417 unsigned long remainder;\
418 remainder = (a) % (b); \
424 #define ATTR_MODE 0x0001
425 #define ATTR_UID 0x0002
426 #define ATTR_GID 0x0004
427 #define ATTR_SIZE 0x0008
428 #define ATTR_ATIME 0x0010
429 #define ATTR_MTIME 0x0020
430 #define ATTR_CTIME 0x0040
431 #define ATTR_ATIME_SET 0x0080
432 #define ATTR_MTIME_SET 0x0100
433 #define ATTR_FORCE 0x0200 /* Not a change, but a change it */
434 #define ATTR_ATTR_FLAG 0x0400
435 #define ATTR_RAW 0x0800 /* file system, not vfs will massage attrs */
436 #define ATTR_FROM_OPEN 0x1000 /* called from open path, ie O_TRUNC */
437 #define ATTR_CTIME_SET 0x2000
440 unsigned int ia_valid;
448 unsigned int ia_attr_flags;
451 #define IT_OPEN 0x0001
452 #define IT_CREAT 0x0002
453 #define IT_READDIR 0x0004
454 #define IT_GETATTR 0x0008
455 #define IT_LOOKUP 0x0010
456 #define IT_UNLINK 0x0020
457 #define IT_GETXATTR 0x0040
458 #define IT_EXEC 0x0080
459 #define IT_PIN 0x0100
461 #define IT_FL_LOCKED 0x0001
462 #define IT_FL_FOLLOWED 0x0002 /* set by vfs_follow_link */
464 #define INTENT_MAGIC 0x19620323
466 struct lustre_intent_data {
469 __u64 it_lock_handle;
474 struct lookup_intent {
476 void (*it_op_release)(struct lookup_intent *);
481 struct lustre_intent_data lustre;
485 static inline void intent_init(struct lookup_intent *it, int op, int flags)
487 memset(it, 0, sizeof(*it));
488 it->it_magic = INTENT_MAGIC;
490 it->it_flags = flags;
503 struct rw_semaphore {
512 /* use the macro's argument to avoid unused warnings */
513 #define down(a) do { (void)a; } while (0)
514 #define up(a) do { (void)a; } while (0)
515 #define down_read(a) do { (void)a; } while (0)
516 #define up_read(a) do { (void)a; } while (0)
517 #define down_write(a) do { (void)a; } while (0)
518 #define up_write(a) do { (void)a; } while (0)
519 #define sema_init(a,b) do { (void)a; } while (0)
520 #define init_rwsem(a) do { (void)a; } while (0)
521 #define DECLARE_MUTEX(name) \
522 struct semaphore name = { 1 }
523 static inline void init_MUTEX (struct semaphore *sem)
530 struct list_head sleepers;
534 struct list_head sleeping;
547 struct fs_struct *fs;
549 struct signal pending;
557 extern struct task_struct *current;
559 #define in_group_p(a) 0 /* FIXME */
561 #define set_current_state(foo) do { current->state = foo; } while (0)
563 #define init_waitqueue_entry(q,p) do { (q)->process = p; } while (0)
564 #define add_wait_queue(q,p) do { list_add(&(q)->sleepers, &(p)->sleeping); } while (0)
565 #define del_wait_queue(p) do { list_del(&(p)->sleeping); } while (0)
566 #define remove_wait_queue(q,p) do { list_del(&(p)->sleeping); } while (0)
568 #define DECLARE_WAIT_QUEUE_HEAD(HEAD) \
569 wait_queue_head_t HEAD = { \
570 .sleepers = LIST_HEAD_INIT(HEAD.sleepers) \
572 #define init_waitqueue_head(l) INIT_LIST_HEAD(&(l)->sleepers)
573 #define wake_up(l) do { int a; a++; } while (0)
574 #define TASK_INTERRUPTIBLE 0
575 #define TASK_UNINTERRUPTIBLE 1
576 #define TASK_RUNNING 2
578 #define wait_event_interruptible(wq, condition) \
580 struct l_wait_info lwi; \
581 int timeout = 100000000;/* for ever */ \
584 lwi = LWI_TIMEOUT(timeout, NULL, NULL); \
585 ret = l_wait_event(NULL, condition, &lwi); \
590 #define in_interrupt() (0)
592 #define schedule() do {} while (0)
593 static inline int schedule_timeout(signed long t)
598 #define lock_kernel() do {} while (0)
599 #define daemonize(l) do {} while (0)
600 #define sigfillset(l) do {} while (0)
601 #define recalc_sigpending(l) do {} while (0)
602 #define kernel_thread(l,m,n) LBUG()
604 #define USERMODEHELPER(path, argv, envp) (0)
605 #define SIGNAL_MASK_ASSERT()
608 #include <sys/time.h>
610 #error "liblustre's jiffies currently expects HZ to be 1"
614 unsigned long _ret = 0; \
616 if (gettimeofday(&tv, NULL) == 0) \
620 #define time_after(a, b) ((long)(b) - (long)(a) < 0)
621 #define time_before(a, b) time_after(b,a)
624 struct list_head tl_list;
625 void (*function)(unsigned long unused);
630 static inline int timer_pending(struct timer_list *l)
632 if (l->expires > jiffies)
638 static inline int init_timer(struct timer_list *l)
640 INIT_LIST_HEAD(&l->tl_list);
644 static inline void mod_timer(struct timer_list *l, int thetime)
646 l->expires = thetime;
649 static inline void del_timer(struct timer_list *l)
654 typedef struct { volatile int counter; } atomic_t;
656 #define atomic_read(a) ((a)->counter)
657 #define atomic_set(a,b) do {(a)->counter = b; } while (0)
658 #define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
659 #define atomic_inc(a) (((a)->counter)++)
660 #define atomic_dec(a) do { (a)->counter--; } while (0)
661 #define atomic_add(b,a) do {(a)->counter += b;} while (0)
662 #define atomic_sub(b,a) do {(a)->counter -= b;} while (0)
665 #define likely(exp) (exp)
668 #define unlikely(exp) (exp)
672 static inline int llog_init_commit_master(void) { return 0; }
673 static inline int llog_cleanup_commit_master(int force) { return 0; }
674 static inline void portals_run_lbug_upcall(char *file, const char *fn,
679 printf("!!!LBUG at %s:%d\n", __FILE__, __LINE__); \
688 wait_queue_head_t wait;
691 #define COMPLETION_INITIALIZER(work) \
692 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
694 #define DECLARE_COMPLETION(work) \
695 struct completion work = COMPLETION_INITIALIZER(work)
697 #define INIT_COMPLETION(x) ((x).done = 0)
699 static inline void init_completion(struct completion *x)
702 init_waitqueue_head(&x->wait);
705 struct liblustre_wait_callback {
706 struct list_head llwc_list;
707 int (*llwc_fn)(void *arg);
711 void *liblustre_register_wait_callback(int (*fn)(void *arg), void *arg);
712 void liblustre_deregister_wait_callback(void *notifier);
713 int liblustre_wait_event(int timeout);
715 #include <linux/obd_support.h>
716 #include <linux/lustre_idl.h>
717 #include <linux/lustre_lib.h>
718 #include <linux/lustre_import.h>
719 #include <linux/lustre_export.h>
720 #include <linux/lustre_net.h>