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