1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/include/liblustre.h
38 * User-space Lustre headers.
45 #error Kernel files should not #include <liblustre.h>
48 #include <libcfs/libcfs.h>
49 #include <lnet/lnet.h>
51 /* definitions for liblustre */
55 #define loff_t long long
57 typedef unsigned short umode_t;
61 /* always adopt 2.5 definitions */
62 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
63 #define LINUX_VERSION_CODE KERNEL_VERSION(2,6,5)
66 #define page_private(page) ((page)->private)
67 #define set_page_private(page, v) ((page)->private = (v))
72 * The inter_module_get implementation is specific to liblustre, so this needs
73 * to stay here for now.
75 static inline void inter_module_put(void *a)
79 void *inter_module_get(char *arg);
83 /* a long can be more than 32 bits, so use BITS_PER_LONG
84 * to allow the compiler to adjust the bit shifting accordingly
87 static __inline__ int ext2_set_bit(int nr, void *addr)
90 return set_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
92 return set_bit(nr, addr);
96 static __inline__ int ext2_clear_bit(int nr, void *addr)
99 return clear_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
101 return clear_bit(nr, addr);
105 static __inline__ int ext2_test_bit(int nr, void *addr)
108 __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
109 return (tmp[nr >> 3] >> (nr & 7)) & 1;
111 return test_bit(nr, addr);
116 /* module initialization */
117 extern int init_obdclass(void);
118 extern int ptlrpc_init(void);
119 extern int ldlm_init(void);
120 extern int osc_init(void);
121 extern int lov_init(void);
122 extern int mdc_init(void);
123 extern int lmv_init(void);
124 extern int mgc_init(void);
125 extern int echo_client_init(void);
131 #define EXPORT_SYMBOL(S)
135 typedef __u64 kdev_t;
138 #define min(x,y) ((x)<(y) ? (x) : (y))
142 #define max(x,y) ((x)>(y) ? (x) : (y))
146 #define min_t(type,x,y) \
147 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
150 #define max_t(type,x,y) \
151 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
154 #define simple_strtol strtol
156 /* registering symbols */
158 #define ERESTARTSYS ERESTART
164 void get_random_bytes(void *ptr, int size);
168 /* memory size: used for some client tunables */
169 #define num_physpages (256 * 1024) /* 1GB */
170 #define CFS_NUM_CACHEPAGES num_physpages
174 #define ATTR_MODE 0x0001
175 #define ATTR_UID 0x0002
176 #define ATTR_GID 0x0004
177 #define ATTR_SIZE 0x0008
178 #define ATTR_ATIME 0x0010
179 #define ATTR_MTIME 0x0020
180 #define ATTR_CTIME 0x0040
181 #define ATTR_ATIME_SET 0x0080
182 #define ATTR_MTIME_SET 0x0100
183 #define ATTR_FORCE 0x0200 /* Not a change, but a change it */
184 #define ATTR_ATTR_FLAG 0x0400
185 #define ATTR_RAW 0x0800 /* file system, not vfs will massage attrs */
186 #define ATTR_FROM_OPEN 0x1000 /* called from open path, ie O_TRUNC */
187 #define ATTR_CTIME_SET 0x2000
188 #define ATTR_BLOCKS 0x4000
189 #define ATTR_KILL_SUID 0
190 #define ATTR_KILL_SGID 0
193 unsigned int ia_valid;
201 unsigned int ia_attr_flags;
204 #define ll_iattr iattr
206 #define IT_OPEN 0x0001
207 #define IT_CREAT 0x0002
208 #define IT_READDIR 0x0004
209 #define IT_GETATTR 0x0008
210 #define IT_LOOKUP 0x0010
211 #define IT_UNLINK 0x0020
212 #define IT_GETXATTR 0x0040
213 #define IT_EXEC 0x0080
214 #define IT_PIN 0x0100
216 #define IT_FL_LOCKED 0x0001
217 #define IT_FL_FOLLOWED 0x0002 /* set by vfs_follow_link */
219 #define INTENT_MAGIC 0x19620323
221 struct lustre_intent_data {
224 __u64 it_lock_handle;
229 struct lookup_intent {
231 void (*it_op_release)(struct lookup_intent *);
236 struct lustre_intent_data lustre;
240 static inline void intent_init(struct lookup_intent *it, int op, int flags)
242 memset(it, 0, sizeof(*it));
243 it->it_magic = INTENT_MAGIC;
245 it->it_flags = flags;
262 struct signal pending;
276 typedef struct task_struct cfs_task_t;
277 #define cfs_current() current
278 #define cfs_curproc_pid() (current->pid)
279 #define cfs_curproc_comm() (current->comm)
281 extern struct task_struct *current;
282 int in_group_p(gid_t gid);
284 #define set_current_state(foo) do { current->state = foo; } while (0)
286 #define wait_event_interruptible(wq, condition) \
288 struct l_wait_info lwi; \
289 int timeout = 100000000;/* for ever */ \
292 lwi = LWI_TIMEOUT(timeout, NULL, NULL); \
293 ret = l_wait_event(NULL, condition, &lwi); \
298 #define lock_kernel() do {} while (0)
299 #define unlock_kernel() do {} while (0)
300 #define daemonize(l) do {} while (0)
301 #define sigfillset(l) do {} while (0)
302 #define recalc_sigpending(l) do {} while (0)
303 #define kernel_thread(l,m,n) LBUG()
305 #define USERMODEHELPER(path, argv, envp) (0)
306 #define SIGNAL_MASK_ASSERT()
310 #error "liblustre's jiffies currently expects HZ to be 1"
314 unsigned long _ret = 0; \
316 if (gettimeofday(&tv, NULL) == 0) \
320 #define get_jiffies_64() (__u64)jiffies
323 #define likely(exp) (exp)
326 #define unlikely(exp) (exp)
329 #define might_sleep()
330 #define might_sleep_if(c)
333 #define libcfs_memory_pressure_get() (0)
334 #define libcfs_memory_pressure_put() do {} while (0)
335 #define libcfs_memory_pressure_clr() do {} while (0)
337 /* FIXME sys/capability will finally included linux/fs.h thus
338 * cause numerous trouble on x86-64. as temporary solution for
339 * build broken at Cray, we copy definition we need from capability.h
343 typedef struct _cap_struct *cap_t;
344 typedef int cap_value_t;
355 cap_t cap_get_proc(void);
356 int cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
358 static inline void libcfs_run_lbug_upcall(char *file, const char *fn,
362 struct liblustre_wait_callback {
363 struct list_head llwc_list;
364 const char *llwc_name;
365 int (*llwc_fn)(void *arg);
369 void *liblustre_register_wait_callback(const char *name,
370 int (*fn)(void *arg), void *arg);
371 void liblustre_deregister_wait_callback(void *notifier);
372 int liblustre_wait_event(int timeout);
374 void *liblustre_register_idle_callback(const char *name,
375 int (*fn)(void *arg), void *arg);
376 void liblustre_deregister_idle_callback(void *notifier);
377 void liblustre_wait_idle(void);
380 struct nfs_lock_info {
386 typedef struct file_lock {
387 struct file_lock *fl_next; /* singly linked list for this inode */
388 struct list_head fl_link; /* doubly linked list of all locks */
389 struct list_head fl_block; /* circular list of blocked processes */
393 struct file *fl_file;
394 unsigned char fl_flags;
395 unsigned char fl_type;
399 void (*fl_notify)(struct file_lock *); /* unblock callback */
400 void (*fl_insert)(struct file_lock *); /* lock insertion callback */
401 void (*fl_remove)(struct file_lock *); /* lock removal callback */
403 void *fl_fasync; /* for lease break notifications */
404 unsigned long fl_break_time; /* for nonblocking lease breaks */
407 struct nfs_lock_info nfs_fl;
411 #define cfs_flock_type(fl) ((fl)->fl_type)
412 #define cfs_flock_set_type(fl, type) do { (fl)->fl_type = (type); } while(0)
413 #define cfs_flock_pid(fl) ((fl)->fl_pid)
414 #define cfs_flock_set_pid(fl, pid) do { (fl)->fl_pid = (pid); } while(0)
415 #define cfs_flock_start(fl) ((fl)->fl_start)
416 #define cfs_flock_set_start(fl, start) do { (fl)->fl_start = (start); } while(0)
417 #define cfs_flock_end(fl) ((fl)->fl_end)
418 #define cfs_flock_set_end(fl, end) do { (fl)->fl_end = (end); } while(0)
421 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
422 #define OFFSET_MAX INT_LIMIT(loff_t)
425 /* XXX: defined in kernel */
434 struct posix_acl_entry {
436 unsigned short e_perm;
442 unsigned int a_count;
443 struct posix_acl_entry a_entries[0];
454 xattr_acl_entry a_entries[0];
457 static inline size_t xattr_acl_size(int count)
459 return sizeof(xattr_acl_header) + count * sizeof(xattr_acl_entry);
463 struct posix_acl * posix_acl_from_xattr(const void *value, size_t size)
469 int posix_acl_valid(const struct posix_acl *acl)
475 void posix_acl_release(struct posix_acl *acl)
479 #ifdef LIBLUSTRE_POSIX_ACL
480 # ifndef posix_acl_xattr_entry
481 # define posix_acl_xattr_entry xattr_acl_entry
483 # ifndef posix_acl_xattr_header
484 # define posix_acl_xattr_header xattr_acl_header
486 # ifndef posix_acl_xattr_size
487 # define posix_acl_xattr_size(entry) xattr_acl_size(entry)
489 # ifndef CONFIG_FS_POSIX_ACL
490 # define CONFIG_FS_POSIX_ACL 1
495 #define ENOTSUPP ENOTSUP
498 typedef int mm_segment_t;
503 static inline mm_segment_t get_fs(void)
508 static inline void set_fs(mm_segment_t seg)
512 #include <obd_support.h>
513 #include <lustre/lustre_idl.h>
514 #include <lustre_lib.h>
515 #include <lustre_import.h>
516 #include <lustre_export.h>
517 #include <lustre_net.h>