Whamcloud - gitweb
LU-2430 mdd: add lfs mv to migrate inode.
[fs/lustre-release.git] / lustre / include / liblustre.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
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 umode_t;
65
66 #endif
67
68 #ifndef page_private
69 #define page_private(page) ((page)->private)
70 #define set_page_private(page, v) ((page)->private = (v))
71 #endif
72
73
74 /*
75  * The inter_module_get implementation is specific to liblustre, so this needs
76  * to stay here for now.
77  */
78 static inline void inter_module_put(void *a)
79 {
80         return;
81 }
82 void *inter_module_get(char *arg);
83
84 /* bits ops */
85
86 /* a long can be more than 32 bits, so use BITS_PER_LONG
87  * to allow the compiler to adjust the bit shifting accordingly
88  */
89
90 static __inline__ int ext2_set_bit(int nr, void *addr)
91 {
92 #ifdef __BIG_ENDIAN
93         return set_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
94 #else
95         return set_bit(nr, addr);
96 #endif
97 }
98
99 static inline int ext2_clear_bit(int nr, void *addr)
100 {
101 #ifdef __BIG_ENDIAN
102         return clear_bit((nr ^ ((BITS_PER_LONG-1) & ~0x7)), addr);
103 #else
104         return clear_bit(nr, addr);
105 #endif
106 }
107
108 static __inline__ int ext2_test_bit(int nr, void *addr)
109 {
110 #ifdef __BIG_ENDIAN
111         __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
112         return (tmp[nr >> 3] >> (nr & 7)) & 1;
113 #else
114         return test_bit(nr, addr);
115 #endif
116 }
117
118
119 /* module initialization */
120 extern int init_obdclass(void);
121 extern int ptlrpc_init(void);
122 extern int ldlm_init(void);
123 extern int osc_init(void);
124 extern int lov_init(void);
125 extern int mdc_init(void);
126 extern int lmv_init(void);
127 extern int mgc_init(void);
128 extern int echo_client_init(void);
129
130
131
132 /* general stuff */
133
134 #ifndef min
135 #define min(x,y) ((x)<(y) ? (x) : (y))
136 #endif
137
138 #ifndef max
139 #define max(x,y) ((x)>(y) ? (x) : (y))
140 #endif
141
142 #ifndef min_t
143 #define min_t(type,x,y) \
144         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
145 #endif
146 #ifndef max_t
147 #define max_t(type,x,y) \
148         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
149 #endif
150
151 #define simple_strtol strtol
152
153 /* registering symbols */
154 #ifndef ERESTARTSYS
155 #define ERESTARTSYS ERESTART
156 #endif
157
158 #ifdef HZ
159 #undef HZ
160 #endif
161 #define HZ 1
162
163 /* random */
164
165 void cfs_get_random_bytes(void *ptr, int size);
166
167 /* memory */
168
169 /* memory size: used for some client tunables */
170 #define totalram_pages  (256 * 1024) /* 1GB */
171 #define NUM_CACHEPAGES totalram_pages
172
173
174 /* VFS stuff */
175 #define ATTR_MODE       0x0001
176 #define ATTR_UID        0x0002
177 #define ATTR_GID        0x0004
178 #define ATTR_SIZE       0x0008
179 #define ATTR_ATIME      0x0010
180 #define ATTR_MTIME      0x0020
181 #define ATTR_CTIME      0x0040
182 #define ATTR_ATIME_SET  0x0080
183 #define ATTR_MTIME_SET  0x0100
184 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
185 #define ATTR_ATTR_FLAG  0x0400
186 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
187 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
188 #define ATTR_CTIME_SET  0x2000
189 #define ATTR_BLOCKS     0x4000
190 #define ATTR_KILL_SUID  0
191 #define ATTR_KILL_SGID  0
192 #define ATTR_FILE       0
193
194 struct iattr {
195         unsigned int    ia_valid;
196         umode_t         ia_mode;
197         uid_t           ia_uid;
198         gid_t           ia_gid;
199         loff_t          ia_size;
200         time_t          ia_atime;
201         time_t          ia_mtime;
202         time_t          ia_ctime;
203         unsigned int    ia_attr_flags;
204 };
205
206 /* defined in kernel header include/linux/namei.h */
207 #define INTENT_MAGIC 0x19620323
208
209 struct lustre_intent_data {
210         int       it_disposition;
211         int       it_status;
212         __u64     it_lock_handle;
213         int       it_lock_mode;
214         int       it_remote_lock_mode;
215         __u64     it_remote_lock_handle;
216         void     *it_data;
217
218         unsigned int    it_lock_set:1;
219 };
220
221 struct lookup_intent {
222         int     it_magic;
223         void    (*it_op_release)(struct lookup_intent *);
224         int     it_op;
225         int     it_create_mode;
226         __u64   it_flags;
227         union {
228                 struct lustre_intent_data lustre;
229         } d;
230 };
231
232 static inline int it_disposition(const struct lookup_intent *it, int flag)
233 {
234         return it->d.lustre.it_disposition & flag;
235 }
236
237 static inline void it_set_disposition(struct lookup_intent *it, int flag)
238 {
239         it->d.lustre.it_disposition |= flag;
240 }
241
242 static inline void it_clear_disposition(struct lookup_intent *it, int flag)
243 {
244         it->d.lustre.it_disposition &= ~flag;
245 }
246
247 static inline void intent_init(struct lookup_intent *it, int op, int flags)
248 {
249         memset(it, 0, sizeof(*it));
250         it->it_magic = INTENT_MAGIC;
251         it->it_op = op;
252         it->it_flags = flags;
253 }
254
255 struct dentry {
256         int d_count;
257 };
258
259 struct vfsmount {
260         void *pwd;
261 };
262
263 struct signal {
264         int signal;
265 };
266
267 #undef  LL_TASK_CL_ENV
268 #define LL_TASK_CL_ENV          cl_env
269
270 struct task_struct {
271         int state;
272         struct signal pending;
273         char comm[32];
274         int uid;
275         int gid;
276         int pid;
277         int fsuid;
278         int fsgid;
279         int max_groups;
280         int ngroups;
281         gid_t *groups;
282         void  *cl_env;
283         __u32 cap_effective;
284 };
285
286
287 #define current_pid()       (current->pid)
288 #define current_comm()      (current->comm)
289 #define current_fsuid()     (current->fsuid)
290 #define current_fsgid()     (current->fsgid)
291 #define current_umask()     ({ mode_t mask = umask(0); umask(mask); mask; })
292
293 extern struct task_struct *current;
294 int in_group_p(gid_t gid);
295
296 #define set_current_state(foo) do { current->state = foo; } while (0)
297
298 #define wait_event_interruptible(wq, condition)                         \
299 {                                                                       \
300         struct l_wait_info lwi;                                         \
301         int timeout = 100000000;/* forever */                           \
302         int ret;                                                        \
303                                                                         \
304         lwi = LWI_TIMEOUT(timeout, NULL, NULL);                         \
305         ret = l_wait_event(NULL, condition, &lwi);                      \
306                                                                         \
307         ret;                                                            \
308 }
309
310 #define daemonize(l) do {} while (0)
311 #define sigfillset(l) do {} while (0)
312 #define recalc_sigpending(l) do {} while (0)
313
314 #define call_usermodehelper(path, argv, envp, wait) (0)
315 #define KERN_INFO
316
317 #if HZ != 1
318 #error "liblustre's jiffies currently expects HZ to be 1"
319 #endif
320 #define jiffies                                 \
321 ({                                              \
322         unsigned long _ret = 0;                 \
323         struct timeval tv;                      \
324         if (gettimeofday(&tv, NULL) == 0)       \
325                 _ret = tv.tv_sec;               \
326         _ret;                                   \
327 })
328 #define get_jiffies_64()  (__u64)jiffies
329
330 #ifndef likely
331 #define likely(exp) (exp)
332 #endif
333 #ifndef unlikely
334 #define unlikely(exp) (exp)
335 #endif
336
337 #define might_sleep()
338 #define might_sleep_if(c)
339 #define smp_mb()
340
341 /* FIXME sys/capability will finally included linux/fs.h thus
342  * cause numerous trouble on x86-64. as temporary solution for
343  * build broken at Cray, we copy definition we need from capability.h
344  * FIXME
345  */
346 struct _cap_struct;
347 typedef struct _cap_struct *cap_t;
348 typedef int cap_value_t;
349 typedef enum {
350     CAP_EFFECTIVE=0,
351     CAP_PERMITTED=1,
352     CAP_INHERITABLE=2
353 } cap_flag_t;
354 typedef enum {
355     CAP_CLEAR=0,
356     CAP_SET=1
357 } cap_flag_value_t;
358
359 cap_t   cap_get_proc(void);
360 int     cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
361
362 static inline void libcfs_run_lbug_upcall(char *file, const char *fn,
363                                            const int l){}
364
365
366 struct liblustre_wait_callback {
367         cfs_list_t              llwc_list;
368         const char             *llwc_name;
369         int                   (*llwc_fn)(void *arg);
370         void                   *llwc_arg;
371 };
372
373 void *liblustre_register_wait_callback(const char *name,
374                                        int (*fn)(void *arg), void *arg);
375 void liblustre_deregister_wait_callback(void *notifier);
376 int liblustre_wait_event(int timeout);
377
378 void *liblustre_register_idle_callback(const char *name,
379                                        int (*fn)(void *arg), void *arg);
380 void liblustre_deregister_idle_callback(void *notifier);
381 void liblustre_wait_idle(void);
382
383 /* flock related */
384 struct nfs_lock_info {
385         __u32             state;
386         __u32             flags;
387         void            *host;
388 };
389
390 struct file_lock {
391         struct file_lock *fl_next;  /* singly linked list for this inode  */
392         cfs_list_t fl_link;   /* doubly linked list of all locks */
393         cfs_list_t fl_block;  /* circular list of blocked processes */
394         void *fl_owner;
395         unsigned int fl_pid;
396         wait_queue_head_t fl_wait;
397         struct file *fl_file;
398         unsigned char fl_flags;
399         unsigned char fl_type;
400         loff_t fl_start;
401         loff_t fl_end;
402
403         void (*fl_notify)(struct file_lock *);  /* unblock callback */
404         void (*fl_insert)(struct file_lock *);  /* lock insertion callback */
405         void (*fl_remove)(struct file_lock *);  /* lock removal callback */
406
407         void *fl_fasync; /* for lease break notifications */
408         unsigned long fl_break_time;    /* for nonblocking lease breaks */
409
410         union {
411                 struct nfs_lock_info    nfs_fl;
412         } fl_u;
413 };
414
415 #define flock_type(fl)                  ((fl)->fl_type)
416 #define flock_set_type(fl, type)        do { (fl)->fl_type = (type); } while (0)
417 #define flock_pid(fl)                   ((fl)->fl_pid)
418 #define flock_set_pid(fl, pid)          do { (fl)->fl_pid = (pid); } while (0)
419 #define flock_start(fl)                 ((fl)->fl_start)
420 #define flock_set_start(fl, st)         do { (fl)->fl_start = (st); } while (0)
421 #define flock_end(fl)                   ((fl)->fl_end)
422 #define flock_set_end(fl, end)          do { (fl)->fl_end = (end); } while (0)
423
424 #ifndef OFFSET_MAX
425 #define INT_LIMIT(x)    (~((x)1 << (sizeof(x)*8 - 1)))
426 #define OFFSET_MAX      INT_LIMIT(loff_t)
427 #endif
428
429 #define i_atime                     i_stbuf.st_atime
430 #define i_mtime                     i_stbuf.st_mtime
431 #define i_ctime                     i_stbuf.st_ctime
432 /* use i_size_read() i_size_write() to access i_stbuf.st_size */
433 #define i_blocks                    i_stbuf.st_blocks
434 #define i_blksize                   i_stbuf.st_blksize
435 #define i_mode                      i_stbuf.st_mode
436 #define i_uid                       i_stbuf.st_uid
437 #define i_gid                       i_stbuf.st_gid
438
439 /* XXX: defined in kernel */
440 #define FL_POSIX        1
441 #define FL_SLEEP        128
442
443 /* quota */
444 #define QUOTA_OK 0
445 #define NO_QUOTA 1
446
447 /* ACL */
448 typedef struct {
449         __u16           e_tag;
450         __u16           e_perm;
451         __u32           e_id;
452 } posix_acl_xattr_entry;
453
454 struct posix_acl {
455         atomic_t                a_refcount;
456         unsigned int            a_count;
457         posix_acl_xattr_entry   a_entries[0];
458 };
459
460 typedef struct {
461         __u32                 a_version;
462         posix_acl_xattr_entry a_entries[0];
463 } posix_acl_xattr_header;
464
465 static inline size_t posix_acl_xattr_size(int count)
466 {
467         return sizeof(posix_acl_xattr_header) + count *
468                sizeof(posix_acl_xattr_entry);
469 }
470
471 static inline
472 struct posix_acl * posix_acl_from_xattr(const void *value, size_t size)
473 {
474         return NULL;
475 }
476
477 /* The kernel version takes 3 arguments, so strip that off first. */
478 #define posix_acl_from_xattr(a,b,c)     posix_acl_from_xattr(b,c)
479 #define posix_acl_to_xattr(a,b,c)       posix_acl_to_xattr(b,c)
480
481 static inline
482 int posix_acl_valid(const struct posix_acl *acl)
483 {
484         return 0;
485 }
486
487 static inline
488 void posix_acl_release(struct posix_acl *acl)
489 {
490 }
491
492 #if defined(LIBLUSTRE_POSIX_ACL) && !defined(CONFIG_FS_POSIX_ACL)
493 # define CONFIG_FS_POSIX_ACL 1
494 #endif
495
496 #ifndef ENOTSUPP
497 #define ENOTSUPP ENOTSUP
498 #endif
499
500 typedef int mm_segment_t;
501 enum {
502         KERNEL_DS,
503         USER_DS
504 };
505 static inline mm_segment_t get_fs(void)
506 {
507         return USER_DS;
508 }
509
510 static inline void set_fs(mm_segment_t seg)
511 {
512 }
513
514 #define S_IRWXUGO       (S_IRWXU|S_IRWXG|S_IRWXO)
515 #define S_IALLUGO       (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
516
517 struct inode *igrab(struct inode *inode);
518 void iput(struct inode *inode);
519
520 #include <obd_support.h>
521 #include <lustre/lustre_idl.h>
522 #include <lustre_lib.h>
523 #include <lustre_import.h>
524 #include <lustre_export.h>
525 #include <lustre_net.h>
526
527 /** @} liblustre */
528
529 #endif