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