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.
27 #include <asm/byteorder.h>
33 #include <sys/types.h>
37 #include <sys/ioctl.h>
44 #include <portals/list.h>
45 #include <portals/p30.h>
46 #include <linux/kp30.h>
48 /* definitions for liblustre */
53 #define PAGE_SIZE (1UL << PAGE_SHIFT)
54 #define PAGE_MASK (~(PAGE_SIZE-1))
57 typedef unsigned short umode_t;
61 /* This is because lprocfs_status.h gets included here indirectly. It would
62 * be much better to just avoid lprocfs being included into liblustre entirely
63 * but that requires more header surgery than I can handle right now.
65 #ifndef smp_processor_id
66 #define smp_processor_id() 0
69 /* always adopt 2.5 definitions */
70 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
71 #define LINUX_VERSION_CODE (2*200+5*10+0)
73 static inline void inter_module_put(void *a)
78 extern ptl_handle_ni_t tcpnal_ni;
80 void *inter_module_get(char *arg);
85 void (*ws_task)(void *arg);
89 static inline void prepare_work(struct work_struct *q, void (*t)(void *),
97 static inline void schedule_work(struct work_struct *q)
99 q->ws_task(q->ws_arg);
103 #define strnlen(a,b) strlen(a)
104 static inline void *kmalloc(int size, int prot)
108 #define vmalloc malloc
110 #define kfree(a) free(a)
112 #define GFP_HIGHUSER 1
115 #define IS_ERR(a) (((a) && abs((long)(a)) < 500) ? 1 : 0)
116 #define PTR_ERR(a) ((long)(a))
117 #define ERR_PTR(a) ((void*)((long)(a)))
119 #define capable(foo) 1
120 #define CAP_SYS_ADMIN 1
126 typedef int (read_proc_t)(char *page, char **start, off_t off,
127 int count, int *eof, void *data);
129 struct file; /* forward ref */
130 typedef int (write_proc_t)(struct file *file, const char *buffer,
131 unsigned long count, void *data);
133 # define le16_to_cpu(x) __le16_to_cpu(x)
134 # define cpu_to_le16(x) __cpu_to_le16(x)
135 # define le32_to_cpu(x) __le32_to_cpu(x)
136 # define cpu_to_le32(x) __cpu_to_le32(x)
137 # define le64_to_cpu(x) __le64_to_cpu(x)
138 # define cpu_to_le64(x) __cpu_to_le64(x)
140 #define NIPQUAD(addr) \
141 ((unsigned char *)&addr)[0], \
142 ((unsigned char *)&addr)[1], \
143 ((unsigned char *)&addr)[2], \
144 ((unsigned char *)&addr)[3]
146 #if defined(__LITTLE_ENDIAN)
147 #define HIPQUAD(addr) \
148 ((unsigned char *)&addr)[3], \
149 ((unsigned char *)&addr)[2], \
150 ((unsigned char *)&addr)[1], \
151 ((unsigned char *)&addr)[0]
152 #elif defined(__BIG_ENDIAN)
153 #define HIPQUAD NIPQUAD
155 #error "Undefined byteorder??"
156 #endif /* __LITTLE_ENDIAN */
159 static __inline__ int set_bit(int nr,long * addr)
164 mask = 1 << (nr & 0x1f);
165 retval = (mask & *addr) != 0;
170 static __inline__ int clear_bit(int nr, long * addr)
175 mask = 1 << (nr & 0x1f);
176 retval = (mask & *addr) != 0;
181 static __inline__ int test_bit(int nr, long * addr)
186 mask = 1 << (nr & 0x1f);
187 return ((mask & *addr) != 0);
190 static __inline__ int ext2_set_bit(int nr, void *addr)
192 return set_bit(nr, (long*)addr);
195 static __inline__ int ext2_clear_bit(int nr, void *addr)
197 return clear_bit(nr, (long*)addr);
200 static __inline__ int ext2_test_bit(int nr, void *addr)
202 return test_bit(nr, (long*)addr);
211 static inline void MODULE_AUTHOR(char *name)
213 printf("%s\n", name);
215 #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
216 #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
218 #define THIS_MODULE NULL
224 static inline int misc_register(void *foo)
229 static inline int misc_deregister(void *foo)
234 static inline int request_module(char *name)
239 #define __MOD_INC_USE_COUNT(m) do {} while (0)
240 #define __MOD_DEC_USE_COUNT(m) do {} while (0)
241 #define MOD_INC_USE_COUNT do {} while (0)
242 #define MOD_DEC_USE_COUNT do {} while (0)
243 #define try_module_get __MOD_INC_USE_COUNT
244 #define module_put __MOD_DEC_USE_COUNT
246 /* module initialization */
247 extern int init_obdclass(void);
248 extern int ptlrpc_init(void);
249 extern int ldlm_init(void);
250 extern int osc_init(void);
251 extern int lov_init(void);
252 extern int mdc_init(void);
253 extern int echo_client_init(void);
260 #define EXPORT_SYMBOL(S)
262 typedef int spinlock_t;
263 typedef __u64 kdev_t;
265 #define SPIN_LOCK_UNLOCKED 0
266 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
268 static inline void spin_lock(spinlock_t *l) {return;}
269 static inline void spin_unlock(spinlock_t *l) {return;}
270 static inline void spin_lock_init(spinlock_t *l) {return;}
271 static inline void local_irq_save(unsigned long flag) {return;}
272 static inline void local_irq_restore(unsigned long flag) {return;}
273 static inline int spin_is_locked(spinlock_t *l) {return 1;}
275 static inline void spin_lock_bh(spinlock_t *l) {}
276 static inline void spin_unlock_bh(spinlock_t *l) {}
277 static inline void spin_lock_irqsave(spinlock_t *a, unsigned long b) {}
278 static inline void spin_unlock_irqrestore(spinlock_t *a, unsigned long b) {}
280 #define min(x,y) ((x)<(y) ? (x) : (y))
281 #define max(x,y) ((x)>(y) ? (x) : (y))
284 #define min_t(type,x,y) \
285 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
288 #define max_t(type,x,y) \
289 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
292 /* registering symbols */
294 #define ERESTARTSYS ERESTART
299 static inline void get_random_bytes(void *ptr, int size)
302 int i, count = size/sizeof(int);
304 for (i = 0; i< count; i++)
311 #define num_physpages (16 * 1024)
313 static inline int copy_from_user(void *a,void *b, int c)
319 static inline int copy_to_user(void *a,void *b, int c)
330 #define SLAB_HWCACHE_ALIGN 0
331 static inline kmem_cache_t *
332 kmem_cache_create(const char *name, size_t objsize, size_t cdum,
334 void (*e)(void *, kmem_cache_t *, unsigned long),
335 void (*f)(void *, kmem_cache_t *, unsigned long))
338 c = malloc(sizeof(*c));
342 CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
343 name, c, (int)objsize);
347 static inline int kmem_cache_destroy(kmem_cache_t *a)
349 CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", a, a->size);
353 #define kmem_cache_alloc(cache, prio) malloc(cache->size)
354 #define kmem_cache_free(cache, obj) free(obj)
356 #define PAGE_CACHE_SIZE PAGE_SIZE
357 #define PAGE_CACHE_SHIFT 12
358 #define PAGE_CACHE_MASK PAGE_MASK
361 * for this moment, liblusre will not rely OST for non-page-aligned write
363 #define LIBLUSTRE_HANDLE_UNALIGNED_PAGE
368 struct list_head list;
369 unsigned long private;
371 /* internally used by liblustre file i/o */
374 #ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
379 #define kmap(page) (page)->addr
380 #define kunmap(a) do {} while (0)
382 static inline struct page *alloc_pages(int mask, unsigned long order)
384 struct page *pg = malloc(sizeof(*pg));
388 #if 0 //#ifdef MAP_ANONYMOUS
389 pg->addr = mmap(0, PAGE_SIZE << order, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
391 pg->addr = malloc(PAGE_SIZE << order);
401 #define alloc_page(mask) alloc_pages((mask), 0)
403 static inline void __free_pages(struct page *pg, int what)
405 #if 0 //#ifdef MAP_ANONYMOUS
406 munmap(pg->addr, PAGE_SIZE);
413 #define __free_page(page) __free_pages((page), 0)
414 #define free_page(page) __free_page(page)
416 static inline struct page* __grab_cache_page(unsigned long index)
418 struct page *pg = alloc_pages(0, 0);
425 #define grab_cache_page(index) __grab_cache_page(index)
426 #define page_cache_release(page) __free_pages(page, 0)
429 #define do_div(a,b) \
431 unsigned long remainder;\
432 remainder = (a) % (b); \
438 #define ATTR_MODE 0x0001
439 #define ATTR_UID 0x0002
440 #define ATTR_GID 0x0004
441 #define ATTR_SIZE 0x0008
442 #define ATTR_ATIME 0x0010
443 #define ATTR_MTIME 0x0020
444 #define ATTR_CTIME 0x0040
445 #define ATTR_ATIME_SET 0x0080
446 #define ATTR_MTIME_SET 0x0100
447 #define ATTR_FORCE 0x0200 /* Not a change, but a change it */
448 #define ATTR_ATTR_FLAG 0x0400
449 #define ATTR_RAW 0x0800 /* file system, not vfs will massage attrs */
450 #define ATTR_FROM_OPEN 0x1000 /* called from open path, ie O_TRUNC */
451 #define ATTR_CTIME_SET 0x2000
454 unsigned int ia_valid;
462 unsigned int ia_attr_flags;
465 #define IT_OPEN 0x0001
466 #define IT_CREAT 0x0002
467 #define IT_READDIR 0x0004
468 #define IT_GETATTR 0x0008
469 #define IT_LOOKUP 0x0010
470 #define IT_UNLINK 0x0020
471 #define IT_GETXATTR 0x0040
472 #define IT_EXEC 0x0080
473 #define IT_PIN 0x0100
475 #define IT_FL_LOCKED 0x0001
476 #define IT_FL_FOLLOWED 0x0002 /* set by vfs_follow_link */
478 #define INTENT_MAGIC 0x19620323
480 struct lustre_intent_data {
483 __u64 it_lock_handle;
488 struct lookup_intent {
490 void (*it_op_release)(struct lookup_intent *);
495 struct lustre_intent_data lustre;
499 static inline void intent_init(struct lookup_intent *it, int op, int flags)
501 memset(it, 0, sizeof(*it));
502 it->it_magic = INTENT_MAGIC;
504 it->it_flags = flags;
517 struct rw_semaphore {
526 #define down(a) do {} while (0)
527 #define up(a) do {} while (0)
528 #define down_read(a) do {} while (0)
529 #define up_read(a) do {} while (0)
530 #define down_write(a) do {} while (0)
531 #define up_write(a) do {} while (0)
532 #define sema_init(a,b) do {} while (0)
533 #define init_rwsem(a) do {} while (0)
534 #define DECLARE_MUTEX(name) \
535 struct semaphore name = { 1 }
536 static inline void init_MUTEX (struct semaphore *sem)
543 struct list_head sleepers;
547 struct list_head sleeping;
560 struct fs_struct *fs;
562 struct signal pending;
570 extern struct task_struct *current;
572 #define in_group_p(a) 0 /* FIXME */
574 #define set_current_state(foo) do { current->state = foo; } while (0)
576 #define init_waitqueue_entry(q,p) do { (q)->process = p; } while (0)
577 #define add_wait_queue(q,p) do { list_add(&(q)->sleepers, &(p)->sleeping); } while (0)
578 #define del_wait_queue(p) do { list_del(&(p)->sleeping); } while (0)
579 #define remove_wait_queue(q,p) do { list_del(&(p)->sleeping); } while (0)
581 #define DECLARE_WAIT_QUEUE_HEAD(HEAD) \
582 wait_queue_head_t HEAD = { \
583 .sleepers = LIST_HEAD_INIT(HEAD.sleepers) \
585 #define init_waitqueue_head(l) INIT_LIST_HEAD(&(l)->sleepers)
586 #define wake_up(l) do { int a; a++; } while (0)
587 #define TASK_INTERRUPTIBLE 0
588 #define TASK_UNINTERRUPTIBLE 1
589 #define TASK_RUNNING 2
591 #define wait_event_interruptible(wq, condition) \
593 struct l_wait_info lwi; \
594 int timeout = 100000000;/* for ever */ \
597 lwi = LWI_TIMEOUT(timeout, NULL, NULL); \
598 ret = l_wait_event(NULL, condition, &lwi); \
603 #define in_interrupt() (0)
605 #define schedule() do {} while (0)
606 static inline int schedule_timeout(signed long t)
611 #define lock_kernel() do {} while (0)
612 #define daemonize(l) do {} while (0)
613 #define sigfillset(l) do {} while (0)
614 #define recalc_sigpending(l) do {} while (0)
615 #define kernel_thread(l,m,n) LBUG()
617 #define USERMODEHELPER(path, argv, envp) (0)
618 #define SIGNAL_MASK_ASSERT()
623 struct list_head tl_list;
624 void (*function)(unsigned long unused);
629 static inline int timer_pending(struct timer_list *l)
631 if (l->expires > jiffies)
637 static inline int init_timer(struct timer_list *l)
639 INIT_LIST_HEAD(&l->tl_list);
643 static inline void mod_timer(struct timer_list *l, int thetime)
645 l->expires = thetime;
648 static inline void del_timer(struct timer_list *l)
653 #define time_after(a, b) \
658 typedef struct { volatile int counter; } atomic_t;
660 #define atomic_read(a) ((a)->counter)
661 #define atomic_set(a,b) do {(a)->counter = b; } while (0)
662 #define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
663 #define atomic_inc(a) (((a)->counter)++)
664 #define atomic_dec(a) do { (a)->counter--; } while (0)
665 #define atomic_add(b,a) do {(a)->counter += b;} while (0)
666 #define atomic_sub(b,a) do {(a)->counter -= b;} while (0)
669 #define likely(exp) (exp)
672 #define unlikely(exp) (exp)
676 static inline int llog_init_commit_master(void) { return 0; }
677 static inline int llog_cleanup_commit_master(int force) { return 0; }
678 static inline void portals_run_lbug_upcall(char *file, const char *fn,
683 printf("!!!LBUG at %s:%d\n", __FILE__, __LINE__); \
692 wait_queue_head_t wait;
695 #define COMPLETION_INITIALIZER(work) \
696 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
698 #define DECLARE_COMPLETION(work) \
699 struct completion work = COMPLETION_INITIALIZER(work)
701 #define INIT_COMPLETION(x) ((x).done = 0)
703 static inline void init_completion(struct completion *x)
706 init_waitqueue_head(&x->wait);
709 struct liblustre_wait_callback {
710 struct list_head llwc_list;
711 int (*llwc_fn)(void *arg);
715 void *liblustre_register_wait_callback(int (*fn)(void *arg), void *arg);
716 void liblustre_deregister_wait_callback(void *notifier);
717 int liblustre_wait_event(int timeout);
719 #include <linux/obd_support.h>
720 #include <linux/lustre_idl.h>
721 #include <linux/lustre_lib.h>
722 #include <linux/lustre_import.h>
723 #include <linux/lustre_export.h>
724 #include <linux/lustre_net.h>