Whamcloud - gitweb
b=22683 store cl_env in task_struct for redhat kernel and liblustre.
[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 /*
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 #define EXPORT_SYMBOL(S)
139
140 typedef __u64 kdev_t;
141
142 #ifndef min
143 #define min(x,y) ((x)<(y) ? (x) : (y))
144 #endif
145
146 #ifndef max
147 #define max(x,y) ((x)>(y) ? (x) : (y))
148 #endif
149
150 #ifndef min_t
151 #define min_t(type,x,y) \
152         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
153 #endif
154 #ifndef max_t
155 #define max_t(type,x,y) \
156         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
157 #endif
158
159 #define simple_strtol strtol
160
161 /* registering symbols */
162 #ifndef ERESTARTSYS
163 #define ERESTARTSYS ERESTART
164 #endif
165 #define CFS_HZ 1
166
167 /* random */
168
169 void cfs_get_random_bytes(void *ptr, int size);
170
171 /* memory */
172
173 /* memory size: used for some client tunables */
174 #define cfs_num_physpages  (256 * 1024) /* 1GB */
175 #define CFS_NUM_CACHEPAGES cfs_num_physpages
176
177
178 /* VFS stuff */
179 #define ATTR_MODE       0x0001
180 #define ATTR_UID        0x0002
181 #define ATTR_GID        0x0004
182 #define ATTR_SIZE       0x0008
183 #define ATTR_ATIME      0x0010
184 #define ATTR_MTIME      0x0020
185 #define ATTR_CTIME      0x0040
186 #define ATTR_ATIME_SET  0x0080
187 #define ATTR_MTIME_SET  0x0100
188 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
189 #define ATTR_ATTR_FLAG  0x0400
190 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
191 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
192 #define ATTR_CTIME_SET  0x2000
193 #define ATTR_BLOCKS     0x4000
194 #define ATTR_KILL_SUID  0
195 #define ATTR_KILL_SGID  0
196
197 struct iattr {
198         unsigned int    ia_valid;
199         cfs_umode_t     ia_mode;
200         uid_t           ia_uid;
201         gid_t           ia_gid;
202         loff_t          ia_size;
203         time_t          ia_atime;
204         time_t          ia_mtime;
205         time_t          ia_ctime;
206         unsigned int    ia_attr_flags;
207 };
208
209 #define ll_iattr iattr
210
211 #define IT_OPEN     0x0001
212 #define IT_CREAT    0x0002
213 #define IT_READDIR  0x0004
214 #define IT_GETATTR  0x0008
215 #define IT_LOOKUP   0x0010
216 #define IT_UNLINK   0x0020
217 #define IT_GETXATTR 0x0040
218 #define IT_EXEC     0x0080
219 #define IT_PIN      0x0100
220
221 #define IT_FL_LOCKED   0x0001
222 #define IT_FL_FOLLOWED 0x0002 /* set by vfs_follow_link */
223
224 #define INTENT_MAGIC 0x19620323
225
226 struct lustre_intent_data {
227         int       it_disposition;
228         int       it_status;
229         __u64     it_lock_handle;
230         void     *it_data;
231         int       it_lock_mode;
232         int it_int_flags;
233 };
234 struct lookup_intent {
235         int     it_magic;
236         void    (*it_op_release)(struct lookup_intent *);
237         int     it_op;
238         int     it_flags;
239         int     it_create_mode;
240         union {
241                 struct lustre_intent_data lustre;
242         } d;
243 };
244
245 static inline void intent_init(struct lookup_intent *it, int op, int flags)
246 {
247         memset(it, 0, sizeof(*it));
248         it->it_magic = INTENT_MAGIC;
249         it->it_op = op;
250         it->it_flags = flags;
251 }
252
253 struct dentry {
254         int d_count;
255 };
256
257 struct vfsmount {
258         void *pwd;
259 };
260
261 struct signal {
262         int signal;
263 };
264
265 #undef  LL_TASK_CL_ENV
266 #define LL_TASK_CL_ENV          cl_env
267
268 struct task_struct {
269         int state;
270         struct signal pending;
271         char comm[32];
272         int uid;
273         int gid;
274         int pid;
275         int fsuid;
276         int fsgid;
277         int max_groups;
278         int ngroups;
279         gid_t *groups;
280         void  *cl_env;
281         __u32 cap_effective;
282 };
283
284
285 typedef struct task_struct cfs_task_t;
286 #define cfs_current()           current
287 #define cfs_curproc_pid()       (current->pid)
288 #define cfs_curproc_comm()      (current->comm)
289 #define cfs_curproc_fsuid()     (current->fsuid)
290 #define cfs_curproc_fsgid()     (current->fsgid)
291
292 extern struct task_struct *current;
293 int cfs_curproc_is_in_groups(gid_t gid);
294
295 #define cfs_set_current_state(foo) do { current->state = foo; } while (0)
296
297 #define cfs_wait_event_interruptible(wq, condition, ret)                \
298 {                                                                       \
299         struct l_wait_info lwi;                                         \
300         int timeout = 100000000;/* for ever */                          \
301         int ret;                                                        \
302                                                                         \
303         lwi = LWI_TIMEOUT(timeout, NULL, NULL);                         \
304         ret = l_wait_event(NULL, condition, &lwi);                      \
305                                                                         \
306         ret;                                                            \
307 }
308
309 #define cfs_lock_kernel() do {} while (0)
310 #define cfs_unlock_kernel() do {} while (0)
311 #define daemonize(l) do {} while (0)
312 #define sigfillset(l) do {} while (0)
313 #define recalc_sigpending(l) do {} while (0)
314
315 #define USERMODEHELPER(path, argv, envp) (0)
316 #define SIGNAL_MASK_ASSERT()
317 #define CFS_KERN_INFO
318
319 #if CFS_HZ != 1
320 #error "liblustre's jiffies currently expects HZ to be 1"
321 #endif
322 #define jiffies                                 \
323 ({                                              \
324         unsigned long _ret = 0;                 \
325         struct timeval tv;                      \
326         if (gettimeofday(&tv, NULL) == 0)       \
327                 _ret = tv.tv_sec;               \
328         _ret;                                   \
329 })
330 #define get_jiffies_64()  (__u64)jiffies
331
332 #ifndef likely
333 #define likely(exp) (exp)
334 #endif
335 #ifndef unlikely
336 #define unlikely(exp) (exp)
337 #endif
338
339 #define cfs_might_sleep()
340 #define might_sleep_if(c)
341 #define smp_mb()
342
343 /* FIXME sys/capability will finally included linux/fs.h thus
344  * cause numerous trouble on x86-64. as temporary solution for
345  * build broken at Cray, we copy definition we need from capability.h
346  * FIXME
347  */
348 struct _cap_struct;
349 typedef struct _cap_struct *cap_t;
350 typedef int cap_value_t;
351 typedef enum {
352     CAP_EFFECTIVE=0,
353     CAP_PERMITTED=1,
354     CAP_INHERITABLE=2
355 } cap_flag_t;
356 typedef enum {
357     CAP_CLEAR=0,
358     CAP_SET=1
359 } cap_flag_value_t;
360
361 cap_t   cap_get_proc(void);
362 int     cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
363
364 static inline void libcfs_run_lbug_upcall(char *file, const char *fn,
365                                            const int l){}
366
367
368 struct liblustre_wait_callback {
369         cfs_list_t              llwc_list;
370         const char             *llwc_name;
371         int                   (*llwc_fn)(void *arg);
372         void                   *llwc_arg;
373 };
374
375 void *liblustre_register_wait_callback(const char *name,
376                                        int (*fn)(void *arg), void *arg);
377 void liblustre_deregister_wait_callback(void *notifier);
378 int liblustre_wait_event(int timeout);
379
380 void *liblustre_register_idle_callback(const char *name,
381                                        int (*fn)(void *arg), void *arg);
382 void liblustre_deregister_idle_callback(void *notifier);
383 void liblustre_wait_idle(void);
384
385 /* flock related */
386 struct nfs_lock_info {
387         __u32             state;
388         __u32             flags;
389         void            *host;
390 };
391
392 typedef struct file_lock {
393         struct file_lock *fl_next;  /* singly linked list for this inode  */
394         cfs_list_t fl_link;   /* doubly linked list of all locks */
395         cfs_list_t fl_block;  /* circular list of blocked processes */
396         void *fl_owner;
397         unsigned int fl_pid;
398         cfs_waitq_t fl_wait;
399         struct file *fl_file;
400         unsigned char fl_flags;
401         unsigned char fl_type;
402         loff_t fl_start;
403         loff_t fl_end;
404
405         void (*fl_notify)(struct file_lock *);  /* unblock callback */
406         void (*fl_insert)(struct file_lock *);  /* lock insertion callback */
407         void (*fl_remove)(struct file_lock *);  /* lock removal callback */
408
409         void *fl_fasync; /* for lease break notifications */
410         unsigned long fl_break_time;    /* for nonblocking lease breaks */
411
412         union {
413                 struct nfs_lock_info    nfs_fl;
414         } fl_u;
415 } cfs_flock_t;
416
417 #define cfs_flock_type(fl)                  ((fl)->fl_type)
418 #define cfs_flock_set_type(fl, type)        do { (fl)->fl_type = (type); } while(0)
419 #define cfs_flock_pid(fl)                   ((fl)->fl_pid)
420 #define cfs_flock_set_pid(fl, pid)          do { (fl)->fl_pid = (pid); } while(0)
421 #define cfs_flock_start(fl)                 ((fl)->fl_start)
422 #define cfs_flock_set_start(fl, start)      do { (fl)->fl_start = (start); } while(0)
423 #define cfs_flock_end(fl)                   ((fl)->fl_end)
424 #define cfs_flock_set_end(fl, end)          do { (fl)->fl_end = (end); } while(0)
425
426 #ifndef OFFSET_MAX
427 #define INT_LIMIT(x)    (~((x)1 << (sizeof(x)*8 - 1)))
428 #define OFFSET_MAX      INT_LIMIT(loff_t)
429 #endif
430
431 #define i_atime                     i_stbuf.st_atime
432 #define i_mtime                     i_stbuf.st_mtime
433 #define i_ctime                     i_stbuf.st_ctime
434 #define i_size                      i_stbuf.st_size
435 #define i_blocks                    i_stbuf.st_blocks
436 #define i_blksize                   i_stbuf.st_blksize
437 #define i_mode                      i_stbuf.st_mode
438 #define i_uid                       i_stbuf.st_uid
439 #define i_gid                       i_stbuf.st_gid
440
441 /* XXX: defined in kernel */
442 #define FL_POSIX        1
443 #define FL_SLEEP        128
444
445 /* quota */
446 #define QUOTA_OK 0
447 #define NO_QUOTA 1
448
449 /* ACL */
450 struct posix_acl_entry {
451         short                   e_tag;
452         unsigned short          e_perm;
453         unsigned int            e_id;
454 };
455
456 struct posix_acl {
457         cfs_atomic_t            a_refcount;
458         unsigned int            a_count;
459         struct posix_acl_entry  a_entries[0];
460 };
461
462 typedef struct {
463         __u16           e_tag;
464         __u16           e_perm;
465         __u32           e_id;
466 } xattr_acl_entry;
467
468 typedef struct {
469         __u32           a_version;
470         xattr_acl_entry a_entries[0];
471 } xattr_acl_header;
472
473 static inline size_t xattr_acl_size(int count)
474 {
475         return sizeof(xattr_acl_header) + count * sizeof(xattr_acl_entry);
476 }
477
478 static inline
479 struct posix_acl * posix_acl_from_xattr(const void *value, size_t size)
480 {
481         return NULL;
482 }
483
484 static inline
485 int posix_acl_valid(const struct posix_acl *acl)
486 {
487         return 0;
488 }
489
490 static inline
491 void posix_acl_release(struct posix_acl *acl)
492 {
493 }
494
495 #ifdef LIBLUSTRE_POSIX_ACL
496 # ifndef posix_acl_xattr_entry
497 #  define posix_acl_xattr_entry xattr_acl_entry
498 # endif
499 # ifndef posix_acl_xattr_header
500 #  define posix_acl_xattr_header xattr_acl_header
501 # endif
502 # ifndef posix_acl_xattr_size
503 #  define posix_acl_xattr_size(entry) xattr_acl_size(entry)
504 # endif
505 # ifndef CONFIG_FS_POSIX_ACL
506 #  define CONFIG_FS_POSIX_ACL 1
507 # endif
508 #endif
509
510 #ifndef ENOTSUPP
511 #define ENOTSUPP ENOTSUP
512 #endif
513
514 typedef int mm_segment_t;
515 enum {
516         KERNEL_DS,
517         USER_DS
518 };
519 static inline mm_segment_t get_fs(void)
520 {
521         return USER_DS;
522 }
523
524 static inline void set_fs(mm_segment_t seg)
525 {
526 }
527
528 #define S_IRWXUGO       (S_IRWXU|S_IRWXG|S_IRWXO)
529 #define S_IALLUGO       (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
530
531 #include <obd_support.h>
532 #include <lustre/lustre_idl.h>
533 #include <lustre_lib.h>
534 #include <lustre_import.h>
535 #include <lustre_export.h>
536 #include <lustre_net.h>
537
538 /** @} liblustre */
539
540 #endif