4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
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.
44 /** \defgroup liblustre liblustre
50 #include <sys/queue.h>
53 #error Kernel files should not #include <liblustre.h>
56 #include <libcfs/libcfs.h>
57 #include <lnet/lnet.h>
59 /* definitions for liblustre */
63 #define loff_t long long
65 typedef unsigned short umode_t;
70 #define page_private(page) ((page)->private)
71 #define set_page_private(page, v) ((page)->private = (v))
76 * The inter_module_get implementation is specific to liblustre, so this needs
77 * to stay here for now.
79 static inline void inter_module_put(void *a)
83 void *inter_module_get(char *arg);
87 /* a long can be more than 32 bits, so use BITS_PER_LONG
88 * to allow the compiler to adjust the bit shifting accordingly
91 static __inline__ int ext2_set_bit(int nr, void *addr)
93 #if __BYTE_ORDER == __BIG_ENDIAN
94 return set_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
96 return set_bit(nr, addr);
100 static inline int ext2_clear_bit(int nr, void *addr)
102 #if __BYTE_ORDER == __BIG_ENDIAN
103 return clear_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
105 return clear_bit(nr, addr);
109 static __inline__ int ext2_test_bit(int nr, void *addr)
111 #if __BYTE_ORDER == __BIG_ENDIAN
112 __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
113 return (tmp[nr >> 3] >> (nr & 7)) & 1;
115 return test_bit(nr, addr);
120 /* module initialization */
121 extern int init_obdclass(void);
122 extern int ptlrpc_init(void);
123 extern int ldlm_init(void);
124 extern int osc_init(void);
125 extern int lov_init(void);
126 extern int mdc_init(void);
127 extern int lmv_init(void);
128 extern int mgc_init(void);
129 extern int echo_client_init(void);
136 #define min(x,y) ((x)<(y) ? (x) : (y))
140 #define max(x,y) ((x)>(y) ? (x) : (y))
144 #define min_t(type,x,y) \
145 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
148 #define max_t(type,x,y) \
149 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
152 #define simple_strtol strtol
154 /* registering symbols */
156 #define ERESTARTSYS ERESTART
166 void cfs_get_random_bytes(void *ptr, int size);
170 /* memory size: used for some client tunables */
171 #define totalram_pages (256 * 1024) /* 1GB */
172 #define NUM_CACHEPAGES totalram_pages
176 #define ATTR_MODE 0x0001
177 #define ATTR_UID 0x0002
178 #define ATTR_GID 0x0004
179 #define ATTR_SIZE 0x0008
180 #define ATTR_ATIME 0x0010
181 #define ATTR_MTIME 0x0020
182 #define ATTR_CTIME 0x0040
183 #define ATTR_ATIME_SET 0x0080
184 #define ATTR_MTIME_SET 0x0100
185 #define ATTR_FORCE 0x0200 /* Not a change, but a change it */
186 #define ATTR_ATTR_FLAG 0x0400
187 #define ATTR_RAW 0x0800 /* file system, not vfs will massage attrs */
188 #define ATTR_FROM_OPEN 0x1000 /* called from open path, ie O_TRUNC */
189 #define ATTR_CTIME_SET 0x2000
190 #define ATTR_BLOCKS 0x4000
191 #define ATTR_KILL_SUID 0
192 #define ATTR_KILL_SGID 0
196 unsigned int ia_valid;
204 unsigned int ia_attr_flags;
207 /* defined in kernel header include/linux/namei.h */
208 #define INTENT_MAGIC 0x19620323
210 struct lustre_intent_data {
213 __u64 it_lock_handle;
215 int it_remote_lock_mode;
216 __u64 it_remote_lock_handle;
219 unsigned int it_lock_set:1;
222 struct lookup_intent {
224 void (*it_op_release)(struct lookup_intent *);
229 struct lustre_intent_data lustre;
233 static inline int it_disposition(const struct lookup_intent *it, int flag)
235 return it->d.lustre.it_disposition & flag;
238 static inline void it_set_disposition(struct lookup_intent *it, int flag)
240 it->d.lustre.it_disposition |= flag;
243 static inline void it_clear_disposition(struct lookup_intent *it, int flag)
245 it->d.lustre.it_disposition &= ~flag;
248 static inline void intent_init(struct lookup_intent *it, int op, int flags)
250 memset(it, 0, sizeof(*it));
251 it->it_magic = INTENT_MAGIC;
253 it->it_flags = flags;
268 #undef LL_TASK_CL_ENV
269 #define LL_TASK_CL_ENV cl_env
273 struct signal pending;
288 #define current_pid() (current->pid)
289 #define current_comm() (current->comm)
290 #define current_fsuid() (current->fsuid)
291 #define current_fsgid() (current->fsgid)
292 #define current_umask() ({ mode_t mask = umask(0); umask(mask); mask; })
294 extern struct task_struct *current;
295 int in_group_p(gid_t gid);
297 #define set_current_state(foo) do { current->state = foo; } while (0)
299 #define wait_event_interruptible(wq, condition) \
301 struct l_wait_info lwi; \
302 int timeout = 100000000;/* forever */ \
305 lwi = LWI_TIMEOUT(timeout, NULL, NULL); \
306 ret = l_wait_event(NULL, condition, &lwi); \
311 #define daemonize(l) do {} while (0)
312 #define sigfillset(l) do {} while (0)
313 #define recalc_sigpending(l) do {} while (0)
315 #define call_usermodehelper(path, argv, envp, wait) (0)
319 #error "liblustre's jiffies currently expects HZ to be 1"
323 unsigned long _ret = 0; \
325 if (gettimeofday(&tv, NULL) == 0) \
329 #define get_jiffies_64() (__u64)jiffies
332 #define likely(exp) (exp)
335 #define unlikely(exp) (exp)
338 #define might_sleep()
339 #define might_sleep_if(c)
342 /* FIXME sys/capability will finally included linux/fs.h thus
343 * cause numerous trouble on x86-64. as temporary solution for
344 * build broken at Cray, we copy definition we need from capability.h
348 typedef struct _cap_struct *cap_t;
349 typedef int cap_value_t;
360 cap_t cap_get_proc(void);
361 int cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
363 static inline void libcfs_run_lbug_upcall(char *file, const char *fn,
367 struct liblustre_wait_callback {
368 cfs_list_t llwc_list;
369 const char *llwc_name;
370 int (*llwc_fn)(void *arg);
374 void *liblustre_register_wait_callback(const char *name,
375 int (*fn)(void *arg), void *arg);
376 void liblustre_deregister_wait_callback(void *notifier);
377 int liblustre_wait_event(int timeout);
379 void *liblustre_register_idle_callback(const char *name,
380 int (*fn)(void *arg), void *arg);
381 void liblustre_deregister_idle_callback(void *notifier);
382 void liblustre_wait_idle(void);
385 struct nfs_lock_info {
392 struct file_lock *fl_next; /* singly linked list for this inode */
393 cfs_list_t fl_link; /* doubly linked list of all locks */
394 cfs_list_t fl_block; /* circular list of blocked processes */
397 wait_queue_head_t fl_wait;
398 struct file *fl_file;
399 unsigned char fl_flags;
400 unsigned char fl_type;
404 void (*fl_notify)(struct file_lock *); /* unblock callback */
405 void (*fl_insert)(struct file_lock *); /* lock insertion callback */
406 void (*fl_remove)(struct file_lock *); /* lock removal callback */
408 void *fl_fasync; /* for lease break notifications */
409 unsigned long fl_break_time; /* for nonblocking lease breaks */
412 struct nfs_lock_info nfs_fl;
416 #define flock_type(fl) ((fl)->fl_type)
417 #define flock_set_type(fl, type) do { (fl)->fl_type = (type); } while (0)
418 #define flock_pid(fl) ((fl)->fl_pid)
419 #define flock_set_pid(fl, pid) do { (fl)->fl_pid = (pid); } while (0)
420 #define flock_start(fl) ((fl)->fl_start)
421 #define flock_set_start(fl, st) do { (fl)->fl_start = (st); } while (0)
422 #define flock_end(fl) ((fl)->fl_end)
423 #define flock_set_end(fl, end) do { (fl)->fl_end = (end); } while (0)
426 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
427 #define OFFSET_MAX INT_LIMIT(loff_t)
430 #define i_atime i_stbuf.st_atime
431 #define i_mtime i_stbuf.st_mtime
432 #define i_ctime i_stbuf.st_ctime
433 /* use i_size_read() i_size_write() to access i_stbuf.st_size */
434 #define i_blocks i_stbuf.st_blocks
435 #define i_blksize i_stbuf.st_blksize
436 #define i_mode i_stbuf.st_mode
437 #define i_uid i_stbuf.st_uid
438 #define i_gid i_stbuf.st_gid
440 /* XXX: defined in kernel */
453 } posix_acl_xattr_entry;
457 unsigned int a_count;
458 posix_acl_xattr_entry a_entries[0];
463 posix_acl_xattr_entry a_entries[0];
464 } posix_acl_xattr_header;
466 static inline size_t posix_acl_xattr_size(int count)
468 return sizeof(posix_acl_xattr_header) + count *
469 sizeof(posix_acl_xattr_entry);
473 struct posix_acl * posix_acl_from_xattr(const void *value, size_t size)
478 /* The kernel version takes 3 arguments, so strip that off first. */
479 #define posix_acl_from_xattr(a,b,c) posix_acl_from_xattr(b,c)
480 #define posix_acl_to_xattr(a,b,c) posix_acl_to_xattr(b,c)
483 int posix_acl_valid(const struct posix_acl *acl)
489 void posix_acl_release(struct posix_acl *acl)
493 #if defined(LIBLUSTRE_POSIX_ACL) && !defined(CONFIG_FS_POSIX_ACL)
494 # define CONFIG_FS_POSIX_ACL 1
498 #define ENOTSUPP ENOTSUP
501 typedef int mm_segment_t;
506 static inline mm_segment_t get_fs(void)
511 static inline void set_fs(mm_segment_t seg)
515 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
516 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
518 struct inode *igrab(struct inode *inode);
519 void iput(struct inode *inode);
521 #include <obd_support.h>
522 #include <lustre/lustre_idl.h>
523 #include <lustre_lib.h>
524 #include <lustre_import.h>
525 #include <lustre_export.h>
526 #include <lustre_net.h>