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