Whamcloud - gitweb
Branch HEAD
[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  2008 Sun Microsystems, Inc. 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 #ifdef __KERNEL__
45 #error Kernel files should not #include <liblustre.h>
46 #endif
47
48 #include <libcfs/libcfs.h>
49 #include <lnet/lnet.h>
50
51 /* definitions for liblustre */
52
53 #ifdef __CYGWIN__
54
55 #define loff_t long long
56 #define ERESTART 2001
57 typedef unsigned short umode_t;
58
59 #endif
60
61 /* always adopt 2.5 definitions */
62 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
63 #define LINUX_VERSION_CODE KERNEL_VERSION(2,6,5)
64
65 #ifndef page_private
66 #define page_private(page) ((page)->private)
67 #define set_page_private(page, v) ((page)->private = (v))
68 #endif
69
70
71 /*
72  * The inter_module_get implementation is specific to liblustre, so this needs
73  * to stay here for now.
74  */
75 static inline void inter_module_put(void *a)
76 {
77         return;
78 }
79 void *inter_module_get(char *arg);
80
81 /* bits ops */
82
83 /* a long can be more than 32 bits, so use BITS_PER_LONG
84  * to allow the compiler to adjust the bit shifting accordingly
85  */
86
87 static __inline__ int ext2_set_bit(int nr, void *addr)
88 {
89 #ifdef __BIG_ENDIAN
90         return set_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
91 #else
92         return set_bit(nr, addr);
93 #endif
94 }
95
96 static __inline__ int ext2_clear_bit(int nr, void *addr)
97 {
98 #ifdef __BIG_ENDIAN
99         return clear_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
100 #else
101         return clear_bit(nr, addr);
102 #endif
103 }
104
105 static __inline__ int ext2_test_bit(int nr, void *addr)
106 {
107 #ifdef __BIG_ENDIAN
108         __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
109         return (tmp[nr >> 3] >> (nr & 7)) & 1;
110 #else
111         return test_bit(nr, addr);
112 #endif
113 }
114
115
116 /* module initialization */
117 extern int init_obdclass(void);
118 extern int ptlrpc_init(void);
119 extern int ldlm_init(void);
120 extern int osc_init(void);
121 extern int lov_init(void);
122 extern int mdc_init(void);
123 extern int lmv_init(void);
124 extern int mgc_init(void);
125 extern int echo_client_init(void);
126
127
128
129 /* general stuff */
130
131 #define EXPORT_SYMBOL(S)
132
133 struct rcu_head { };
134
135 typedef __u64 kdev_t;
136
137 #define min(x,y) ((x)<(y) ? (x) : (y))
138 #define max(x,y) ((x)>(y) ? (x) : (y))
139
140 #ifndef min_t
141 #define min_t(type,x,y) \
142         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
143 #endif
144 #ifndef max_t
145 #define max_t(type,x,y) \
146         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
147 #endif
148
149 #define simple_strtol strtol
150
151 /* registering symbols */
152 #ifndef ERESTARTSYS
153 #define ERESTARTSYS ERESTART
154 #endif
155 #define HZ 1
156
157 /* random */
158
159 void get_random_bytes(void *ptr, int size);
160
161 /* memory */
162
163 /* memory size: used for some client tunables */
164 #define num_physpages (256 * 1024) /* 1GB */
165
166
167 /* VFS stuff */
168 #define ATTR_MODE       0x0001
169 #define ATTR_UID        0x0002
170 #define ATTR_GID        0x0004
171 #define ATTR_SIZE       0x0008
172 #define ATTR_ATIME      0x0010
173 #define ATTR_MTIME      0x0020
174 #define ATTR_CTIME      0x0040
175 #define ATTR_ATIME_SET  0x0080
176 #define ATTR_MTIME_SET  0x0100
177 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
178 #define ATTR_ATTR_FLAG  0x0400
179 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
180 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
181 #define ATTR_CTIME_SET  0x2000
182 #define ATTR_BLOCKS     0x4000
183 #define ATTR_KILL_SUID  0
184 #define ATTR_KILL_SGID  0
185
186 struct iattr {
187         unsigned int    ia_valid;
188         umode_t         ia_mode;
189         uid_t           ia_uid;
190         gid_t           ia_gid;
191         loff_t          ia_size;
192         time_t          ia_atime;
193         time_t          ia_mtime;
194         time_t          ia_ctime;
195         unsigned int    ia_attr_flags;
196 };
197
198 #define ll_iattr iattr
199
200 #define IT_OPEN     0x0001
201 #define IT_CREAT    0x0002
202 #define IT_READDIR  0x0004
203 #define IT_GETATTR  0x0008
204 #define IT_LOOKUP   0x0010
205 #define IT_UNLINK   0x0020
206 #define IT_GETXATTR 0x0040
207 #define IT_EXEC     0x0080
208 #define IT_PIN      0x0100
209
210 #define IT_FL_LOCKED   0x0001
211 #define IT_FL_FOLLOWED 0x0002 /* set by vfs_follow_link */
212
213 #define INTENT_MAGIC 0x19620323
214
215 struct lustre_intent_data {
216         int       it_disposition;
217         int       it_status;
218         __u64     it_lock_handle;
219         void     *it_data;
220         int       it_lock_mode;
221         int it_int_flags;
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 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         __u32 cap_effective;
267         void *journal_info;
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
276 extern struct task_struct *current;
277 int in_group_p(gid_t gid);
278
279 #define set_current_state(foo) do { current->state = foo; } while (0)
280
281 #define wait_event_interruptible(wq, condition)                         \
282 ({                                                                      \
283         struct l_wait_info lwi;                                         \
284         int timeout = 100000000;/* for ever */                          \
285         int ret;                                                        \
286                                                                         \
287         lwi = LWI_TIMEOUT(timeout, NULL, NULL);                         \
288         ret = l_wait_event(NULL, condition, &lwi);                      \
289                                                                         \
290         ret;                                                            \
291 })
292
293 #define lock_kernel() do {} while (0)
294 #define unlock_kernel() do {} while (0)
295 #define daemonize(l) do {} while (0)
296 #define sigfillset(l) do {} while (0)
297 #define recalc_sigpending(l) do {} while (0)
298 #define kernel_thread(l,m,n) LBUG()
299
300 #define USERMODEHELPER(path, argv, envp) (0)
301 #define SIGNAL_MASK_ASSERT()
302 #define KERN_INFO
303
304 #if HZ != 1
305 #error "liblustre's jiffies currently expects HZ to be 1"
306 #endif
307 #define jiffies                                 \
308 ({                                              \
309         unsigned long _ret = 0;                 \
310         struct timeval tv;                      \
311         if (gettimeofday(&tv, NULL) == 0)       \
312                 _ret = tv.tv_sec;               \
313         _ret;                                   \
314 })
315 #define get_jiffies_64()  (__u64)jiffies
316
317 #ifndef likely
318 #define likely(exp) (exp)
319 #endif
320 #ifndef unlikely
321 #define unlikely(exp) (exp)
322 #endif
323
324 #define might_sleep()
325 #define might_sleep_if(c)
326 #define smp_mb()
327
328 static inline
329 int test_and_set_bit(int nr, unsigned long *addr)
330 {
331         int oldbit;
332
333         while (nr >= sizeof(long)) {
334                 nr -= sizeof(long);
335                 addr++;
336         }
337
338         oldbit = (*addr) & (1 << nr);
339         *addr |= (1 << nr);
340         return oldbit;
341 }
342
343 static inline
344 int test_and_clear_bit(int nr, unsigned long *addr)
345 {
346         int oldbit;
347
348         while (nr >= sizeof(long)) {
349                 nr -= sizeof(long);
350                 addr++;
351         }
352
353         oldbit = (*addr) & (1 << nr);
354         *addr &= ~(1 << nr);
355         return oldbit;
356 }
357
358 #define libcfs_memory_pressure_get() (0) 
359 #define libcfs_memory_pressure_put() do {} while (0) 
360 #define libcfs_memory_pressure_clr() do {} while (0)
361
362 /* FIXME sys/capability will finally included linux/fs.h thus
363  * cause numerous trouble on x86-64. as temporary solution for
364  * build broken at Cray, we copy definition we need from capability.h
365  * FIXME
366  */
367 struct _cap_struct;
368 typedef struct _cap_struct *cap_t;
369 typedef int cap_value_t;
370 typedef enum {
371     CAP_EFFECTIVE=0,
372     CAP_PERMITTED=1,
373     CAP_INHERITABLE=2
374 } cap_flag_t;
375 typedef enum {
376     CAP_CLEAR=0,
377     CAP_SET=1
378 } cap_flag_value_t;
379
380 cap_t   cap_get_proc(void);
381 int     cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
382
383 static inline void libcfs_run_lbug_upcall(char *file, const char *fn,
384                                            const int l){}
385
386
387 struct liblustre_wait_callback {
388         struct list_head    llwc_list;
389         const char         *llwc_name;
390         int               (*llwc_fn)(void *arg);
391         void               *llwc_arg;
392 };
393
394 void *liblustre_register_wait_callback(const char *name,
395                                        int (*fn)(void *arg), void *arg);
396 void liblustre_deregister_wait_callback(void *notifier);
397 int liblustre_wait_event(int timeout);
398
399 void *liblustre_register_idle_callback(const char *name,
400                                        int (*fn)(void *arg), void *arg);
401 void liblustre_deregister_idle_callback(void *notifier);
402 void liblustre_wait_idle(void);
403
404 /* flock related */
405 struct nfs_lock_info {
406         __u32             state;
407         __u32             flags;
408         void            *host;
409 };
410
411 typedef struct file_lock {
412         struct file_lock *fl_next;      /* singly linked list for this inode  */
413         struct list_head fl_link;       /* doubly linked list of all locks */
414         struct list_head fl_block;      /* circular list of blocked processes */
415         void *fl_owner;
416         unsigned int fl_pid;
417         cfs_waitq_t fl_wait;
418         struct file *fl_file;
419         unsigned char fl_flags;
420         unsigned char fl_type;
421         loff_t fl_start;
422         loff_t fl_end;
423
424         void (*fl_notify)(struct file_lock *);  /* unblock callback */
425         void (*fl_insert)(struct file_lock *);  /* lock insertion callback */
426         void (*fl_remove)(struct file_lock *);  /* lock removal callback */
427
428         void *fl_fasync; /* for lease break notifications */
429         unsigned long fl_break_time;    /* for nonblocking lease breaks */
430
431         union {
432                 struct nfs_lock_info    nfs_fl;
433         } fl_u;
434 } cfs_flock_t;
435
436 #define cfs_flock_type(fl)                  ((fl)->fl_type)
437 #define cfs_flock_set_type(fl, type)        do { (fl)->fl_type = (type); } while(0)
438 #define cfs_flock_pid(fl)                   ((fl)->fl_pid)
439 #define cfs_flock_set_pid(fl, pid)          do { (fl)->fl_pid = (pid); } while(0)
440 #define cfs_flock_start(fl)                 ((fl)->fl_start)
441 #define cfs_flock_set_start(fl, start)      do { (fl)->fl_start = (start); } while(0)
442 #define cfs_flock_end(fl)                   ((fl)->fl_end)
443 #define cfs_flock_set_end(fl, end)          do { (fl)->fl_end = (end); } while(0)
444
445 #ifndef OFFSET_MAX
446 #define INT_LIMIT(x)    (~((x)1 << (sizeof(x)*8 - 1)))
447 #define OFFSET_MAX      INT_LIMIT(loff_t)
448 #endif
449
450 /* XXX: defined in kernel */
451 #define FL_POSIX        1
452 #define FL_SLEEP        128
453
454 /* quota */
455 #define QUOTA_OK 0
456 #define NO_QUOTA 1
457
458 /* ACL */
459 struct posix_acl_entry {
460         short                   e_tag;
461         unsigned short          e_perm;
462         unsigned int            e_id;
463 };
464
465 struct posix_acl {
466         atomic_t                a_refcount;
467         unsigned int            a_count;
468         struct posix_acl_entry  a_entries[0];
469 };
470
471 typedef struct {
472         __u16           e_tag;
473         __u16           e_perm;
474         __u32           e_id;
475 } xattr_acl_entry;
476
477 typedef struct {
478         __u32           a_version;
479         xattr_acl_entry a_entries[0];
480 } xattr_acl_header;
481
482 static inline size_t xattr_acl_size(int count)
483 {
484         return sizeof(xattr_acl_header) + count * sizeof(xattr_acl_entry);
485 }
486
487 static inline
488 struct posix_acl * posix_acl_from_xattr(const void *value, size_t size)
489 {
490         return NULL;
491 }
492
493 static inline
494 int posix_acl_valid(const struct posix_acl *acl)
495 {
496         return 0;
497 }
498
499 static inline
500 void posix_acl_release(struct posix_acl *acl)
501 {
502 }
503
504 #ifdef LIBLUSTRE_POSIX_ACL
505 # ifndef posix_acl_xattr_entry
506 #  define posix_acl_xattr_entry xattr_acl_entry
507 # endif
508 # ifndef posix_acl_xattr_header
509 #  define posix_acl_xattr_header xattr_acl_header
510 # endif
511 # ifndef posix_acl_xattr_size
512 #  define posix_acl_xattr_size(entry) xattr_acl_size(entry)
513 # endif
514 # ifndef CONFIG_FS_POSIX_ACL
515 #  define CONFIG_FS_POSIX_ACL 1
516 # endif
517 #endif
518
519 #ifndef ENOTSUPP
520 #define ENOTSUPP ENOTSUP
521 #endif
522
523 typedef int mm_segment_t;
524 enum {
525         KERNEL_DS,
526         USER_DS
527 };
528 static inline mm_segment_t get_fs(void)
529 {
530         return USER_DS;
531 }
532
533 static inline void set_fs(mm_segment_t seg)
534 {
535 }
536
537 #include <obd_support.h>
538 #include <lustre/lustre_idl.h>
539 #include <lustre_lib.h>
540 #include <lustre_import.h>
541 #include <lustre_export.h>
542 #include <lustre_net.h>
543
544 #endif