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