Whamcloud - gitweb
4e10448579ad23dcf6b013c91af8d61479b99dfb
[fs/lustre-release.git] / lustre / include / liblustre.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Whamcloud, Inc.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/include/liblustre.h
37  *
38  * User-space Lustre headers.
39  */
40
41 #ifndef LIBLUSTRE_H__
42 #define LIBLUSTRE_H__
43
44 /** \defgroup liblustre liblustre
45  *
46  * @{
47  */
48 #include <fcntl.h>
49 #include <sys/queue.h>
50
51 #ifdef __KERNEL__
52 #error Kernel files should not #include <liblustre.h>
53 #endif
54
55 #include <libcfs/libcfs.h>
56 #include <lnet/lnet.h>
57
58 /* definitions for liblustre */
59
60 #ifdef __CYGWIN__
61
62 #define loff_t long long
63 #define ERESTART 2001
64 typedef unsigned short cfs_umode_t;
65
66 #endif
67
68 #ifndef page_private
69 #define page_private(page) ((page)->private)
70 #define set_page_private(page, v) ((page)->private = (v))
71 #endif
72
73
74 /*
75  * The inter_module_get implementation is specific to liblustre, so this needs
76  * to stay here for now.
77  */
78 static inline void inter_module_put(void *a)
79 {
80         return;
81 }
82 void *inter_module_get(char *arg);
83
84 /* bits ops */
85
86 /* a long can be more than 32 bits, so use BITS_PER_LONG
87  * to allow the compiler to adjust the bit shifting accordingly
88  */
89
90 static __inline__ int ext2_set_bit(int nr, void *addr)
91 {
92 #ifdef __BIG_ENDIAN
93         return cfs_set_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
94 #else
95         return cfs_set_bit(nr, addr);
96 #endif
97 }
98
99 static __inline__ int ext2_clear_bit(int nr, void *addr)
100 {
101 #ifdef __BIG_ENDIAN
102         return cfs_clear_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
103 #else
104         return cfs_clear_bit(nr, addr);
105 #endif
106 }
107
108 static __inline__ int ext2_test_bit(int nr, void *addr)
109 {
110 #ifdef __BIG_ENDIAN
111         __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
112         return (tmp[nr >> 3] >> (nr & 7)) & 1;
113 #else
114         return cfs_test_bit(nr, addr);
115 #endif
116 }
117
118
119 /* module initialization */
120 extern int init_obdclass(void);
121 extern int ptlrpc_init(void);
122 extern int ldlm_init(void);
123 extern int osc_init(void);
124 extern int lov_init(void);
125 extern int mdc_init(void);
126 extern int lmv_init(void);
127 extern int mgc_init(void);
128 extern int echo_client_init(void);
129
130
131
132 /* general stuff */
133
134 typedef __u64 kdev_t;
135
136 #ifndef min
137 #define min(x,y) ((x)<(y) ? (x) : (y))
138 #endif
139
140 #ifndef max
141 #define max(x,y) ((x)>(y) ? (x) : (y))
142 #endif
143
144 #ifndef min_t
145 #define min_t(type,x,y) \
146         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
147 #endif
148 #ifndef max_t
149 #define max_t(type,x,y) \
150         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
151 #endif
152
153 #define simple_strtol strtol
154
155 /* registering symbols */
156 #ifndef ERESTARTSYS
157 #define ERESTARTSYS ERESTART
158 #endif
159 #define CFS_HZ 1
160
161 /* random */
162
163 void cfs_get_random_bytes(void *ptr, int size);
164
165 /* memory */
166
167 /* memory size: used for some client tunables */
168 #define cfs_num_physpages  (256 * 1024) /* 1GB */
169 #define CFS_NUM_CACHEPAGES cfs_num_physpages
170
171
172 /* VFS stuff */
173 #define ATTR_MODE       0x0001
174 #define ATTR_UID        0x0002
175 #define ATTR_GID        0x0004
176 #define ATTR_SIZE       0x0008
177 #define ATTR_ATIME      0x0010
178 #define ATTR_MTIME      0x0020
179 #define ATTR_CTIME      0x0040
180 #define ATTR_ATIME_SET  0x0080
181 #define ATTR_MTIME_SET  0x0100
182 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
183 #define ATTR_ATTR_FLAG  0x0400
184 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
185 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
186 #define ATTR_CTIME_SET  0x2000
187 #define ATTR_BLOCKS     0x4000
188 #define ATTR_KILL_SUID  0
189 #define ATTR_KILL_SGID  0
190 #define ATTR_FILE       0
191
192 struct iattr {
193         unsigned int    ia_valid;
194         cfs_umode_t     ia_mode;
195         uid_t           ia_uid;
196         gid_t           ia_gid;
197         loff_t          ia_size;
198         time_t          ia_atime;
199         time_t          ia_mtime;
200         time_t          ia_ctime;
201         unsigned int    ia_attr_flags;
202 };
203
204 /* defined in kernel header include/linux/namei.h */
205 #define INTENT_MAGIC 0x19620323
206
207 struct lustre_intent_data {
208         int       it_disposition;
209         int       it_status;
210         __u64     it_lock_handle;
211         void     *it_data;
212         int       it_lock_mode;
213 };
214 struct lookup_intent {
215         int     it_magic;
216         void    (*it_op_release)(struct lookup_intent *);
217         int     it_op;
218         int     it_flags;
219         int     it_create_mode;
220         union {
221                 struct lustre_intent_data lustre;
222         } d;
223 };
224
225 static inline void intent_init(struct lookup_intent *it, int op, int flags)
226 {
227         memset(it, 0, sizeof(*it));
228         it->it_magic = INTENT_MAGIC;
229         it->it_op = op;
230         it->it_flags = flags;
231 }
232
233 struct dentry {
234         int d_count;
235 };
236
237 struct vfsmount {
238         void *pwd;
239 };
240
241 struct signal {
242         int signal;
243 };
244
245 #undef  LL_TASK_CL_ENV
246 #define LL_TASK_CL_ENV          cl_env
247
248 struct task_struct {
249         int state;
250         struct signal pending;
251         char comm[32];
252         int uid;
253         int gid;
254         int pid;
255         int fsuid;
256         int fsgid;
257         int max_groups;
258         int ngroups;
259         gid_t *groups;
260         void  *cl_env;
261         __u32 cap_effective;
262 };
263
264
265 typedef struct task_struct cfs_task_t;
266 #define cfs_current()           current
267 #define cfs_curproc_pid()       (current->pid)
268 #define cfs_curproc_comm()      (current->comm)
269 #define cfs_curproc_fsuid()     (current->fsuid)
270 #define cfs_curproc_fsgid()     (current->fsgid)
271
272 extern struct task_struct *current;
273 int cfs_curproc_is_in_groups(gid_t gid);
274
275 #define cfs_set_current_state(foo) do { current->state = foo; } while (0)
276
277 #define cfs_wait_event_interruptible(wq, condition, ret)                \
278 {                                                                       \
279         struct l_wait_info lwi;                                         \
280         int timeout = 100000000;/* for ever */                          \
281         int ret;                                                        \
282                                                                         \
283         lwi = LWI_TIMEOUT(timeout, NULL, NULL);                         \
284         ret = l_wait_event(NULL, condition, &lwi);                      \
285                                                                         \
286         ret;                                                            \
287 }
288
289 #define daemonize(l) do {} while (0)
290 #define sigfillset(l) do {} while (0)
291 #define recalc_sigpending(l) do {} while (0)
292
293 #define USERMODEHELPER(path, argv, envp) (0)
294 #define SIGNAL_MASK_ASSERT()
295 #define CFS_KERN_INFO
296
297 #if CFS_HZ != 1
298 #error "liblustre's jiffies currently expects HZ to be 1"
299 #endif
300 #define jiffies                                 \
301 ({                                              \
302         unsigned long _ret = 0;                 \
303         struct timeval tv;                      \
304         if (gettimeofday(&tv, NULL) == 0)       \
305                 _ret = tv.tv_sec;               \
306         _ret;                                   \
307 })
308 #define get_jiffies_64()  (__u64)jiffies
309
310 #ifndef likely
311 #define likely(exp) (exp)
312 #endif
313 #ifndef unlikely
314 #define unlikely(exp) (exp)
315 #endif
316
317 #define cfs_might_sleep()
318 #define might_sleep_if(c)
319 #define smp_mb()
320
321 /* FIXME sys/capability will finally included linux/fs.h thus
322  * cause numerous trouble on x86-64. as temporary solution for
323  * build broken at Cray, we copy definition we need from capability.h
324  * FIXME
325  */
326 struct _cap_struct;
327 typedef struct _cap_struct *cap_t;
328 typedef int cap_value_t;
329 typedef enum {
330     CAP_EFFECTIVE=0,
331     CAP_PERMITTED=1,
332     CAP_INHERITABLE=2
333 } cap_flag_t;
334 typedef enum {
335     CAP_CLEAR=0,
336     CAP_SET=1
337 } cap_flag_value_t;
338
339 cap_t   cap_get_proc(void);
340 int     cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
341
342 static inline void libcfs_run_lbug_upcall(char *file, const char *fn,
343                                            const int l){}
344
345
346 struct liblustre_wait_callback {
347         cfs_list_t              llwc_list;
348         const char             *llwc_name;
349         int                   (*llwc_fn)(void *arg);
350         void                   *llwc_arg;
351 };
352
353 void *liblustre_register_wait_callback(const char *name,
354                                        int (*fn)(void *arg), void *arg);
355 void liblustre_deregister_wait_callback(void *notifier);
356 int liblustre_wait_event(int timeout);
357
358 void *liblustre_register_idle_callback(const char *name,
359                                        int (*fn)(void *arg), void *arg);
360 void liblustre_deregister_idle_callback(void *notifier);
361 void liblustre_wait_idle(void);
362
363 /* flock related */
364 struct nfs_lock_info {
365         __u32             state;
366         __u32             flags;
367         void            *host;
368 };
369
370 typedef struct file_lock {
371         struct file_lock *fl_next;  /* singly linked list for this inode  */
372         cfs_list_t fl_link;   /* doubly linked list of all locks */
373         cfs_list_t fl_block;  /* circular list of blocked processes */
374         void *fl_owner;
375         unsigned int fl_pid;
376         cfs_waitq_t fl_wait;
377         struct file *fl_file;
378         unsigned char fl_flags;
379         unsigned char fl_type;
380         loff_t fl_start;
381         loff_t fl_end;
382
383         void (*fl_notify)(struct file_lock *);  /* unblock callback */
384         void (*fl_insert)(struct file_lock *);  /* lock insertion callback */
385         void (*fl_remove)(struct file_lock *);  /* lock removal callback */
386
387         void *fl_fasync; /* for lease break notifications */
388         unsigned long fl_break_time;    /* for nonblocking lease breaks */
389
390         union {
391                 struct nfs_lock_info    nfs_fl;
392         } fl_u;
393 } cfs_flock_t;
394
395 #define cfs_flock_type(fl)                  ((fl)->fl_type)
396 #define cfs_flock_set_type(fl, type)        do { (fl)->fl_type = (type); } while(0)
397 #define cfs_flock_pid(fl)                   ((fl)->fl_pid)
398 #define cfs_flock_set_pid(fl, pid)          do { (fl)->fl_pid = (pid); } while(0)
399 #define cfs_flock_start(fl)                 ((fl)->fl_start)
400 #define cfs_flock_set_start(fl, start)      do { (fl)->fl_start = (start); } while(0)
401 #define cfs_flock_end(fl)                   ((fl)->fl_end)
402 #define cfs_flock_set_end(fl, end)          do { (fl)->fl_end = (end); } while(0)
403
404 #ifndef OFFSET_MAX
405 #define INT_LIMIT(x)    (~((x)1 << (sizeof(x)*8 - 1)))
406 #define OFFSET_MAX      INT_LIMIT(loff_t)
407 #endif
408
409 #define i_atime                     i_stbuf.st_atime
410 #define i_mtime                     i_stbuf.st_mtime
411 #define i_ctime                     i_stbuf.st_ctime
412 /* use i_size_read() i_size_write() to access i_stbuf.st_size */
413 #define i_blocks                    i_stbuf.st_blocks
414 #define i_blksize                   i_stbuf.st_blksize
415 #define i_mode                      i_stbuf.st_mode
416 #define i_uid                       i_stbuf.st_uid
417 #define i_gid                       i_stbuf.st_gid
418
419 /* XXX: defined in kernel */
420 #define FL_POSIX        1
421 #define FL_SLEEP        128
422
423 /* quota */
424 #define QUOTA_OK 0
425 #define NO_QUOTA 1
426
427 /* ACL */
428 typedef struct {
429         __u16           e_tag;
430         __u16           e_perm;
431         __u32           e_id;
432 } posix_acl_xattr_entry;
433
434 struct posix_acl {
435         cfs_atomic_t           a_refcount;
436         unsigned int           a_count;
437         posix_acl_xattr_entry  a_entries[0];
438 };
439
440 typedef struct {
441         __u32                 a_version;
442         posix_acl_xattr_entry a_entries[0];
443 } posix_acl_xattr_header;
444
445 static inline size_t posix_acl_xattr_size(int count)
446 {
447         return sizeof(posix_acl_xattr_header) + count *
448                sizeof(posix_acl_xattr_entry);
449 }
450
451 static inline
452 struct posix_acl * posix_acl_from_xattr(const void *value, size_t size)
453 {
454         return NULL;
455 }
456
457 static inline
458 int posix_acl_valid(const struct posix_acl *acl)
459 {
460         return 0;
461 }
462
463 static inline
464 void posix_acl_release(struct posix_acl *acl)
465 {
466 }
467
468 #if defined(LIBLUSTRE_POSIX_ACL) && !defined(CONFIG_FS_POSIX_ACL)
469 # define CONFIG_FS_POSIX_ACL 1
470 #endif
471
472 #ifndef ENOTSUPP
473 #define ENOTSUPP ENOTSUP
474 #endif
475
476 typedef int mm_segment_t;
477 enum {
478         KERNEL_DS,
479         USER_DS
480 };
481 static inline mm_segment_t get_fs(void)
482 {
483         return USER_DS;
484 }
485
486 static inline void set_fs(mm_segment_t seg)
487 {
488 }
489
490 #define S_IRWXUGO       (S_IRWXU|S_IRWXG|S_IRWXO)
491 #define S_IALLUGO       (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
492
493 #include <obd_support.h>
494 #include <lustre/lustre_idl.h>
495 #include <lustre_lib.h>
496 #include <lustre_import.h>
497 #include <lustre_export.h>
498 #include <lustre_net.h>
499
500 /** @} liblustre */
501
502 #endif