Whamcloud - gitweb
LU-4679 liblustre: remove dead code and clean headers
[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 <endian.h>
50 #include <sys/queue.h>
51
52 #ifdef __KERNEL__
53 #error Kernel files should not #include <liblustre.h>
54 #endif
55
56 #include <libcfs/libcfs.h>
57 #include <lnet/lnet.h>
58
59 /* definitions for liblustre */
60
61 #ifdef __CYGWIN__
62
63 #define loff_t long long
64 #define ERESTART 2001
65 typedef unsigned short umode_t;
66
67 #endif
68
69 #ifndef page_private
70 #define page_private(page) ((page)->private)
71 #define set_page_private(page, v) ((page)->private = (v))
72 #endif
73
74 /* bits ops */
75
76 /* a long can be more than 32 bits, so use BITS_PER_LONG
77  * to allow the compiler to adjust the bit shifting accordingly
78  */
79
80 static inline int ext2_set_bit(int nr, void *addr)
81 {
82 #if __BYTE_ORDER == __BIG_ENDIAN
83         return set_bit((nr ^ ((BITS_PER_LONG - 1) & ~0x7)), addr);
84 #else
85         return set_bit(nr, addr);
86 #endif
87 }
88
89 static inline int ext2_clear_bit(int nr, void *addr)
90 {
91 #if __BYTE_ORDER == __BIG_ENDIAN
92         return clear_bit((nr ^ ((BITS_PER_LONG - 1) & ~0x7)), addr);
93 #else
94         return clear_bit(nr, addr);
95 #endif
96 }
97
98 static inline int ext2_test_bit(int nr, const void *addr)
99 {
100 #if __BYTE_ORDER == __BIG_ENDIAN
101         const unsigned char *tmp = addr;
102         return (tmp[nr >> 3] >> (nr & 7)) & 1;
103 #else
104         return test_bit(nr, addr);
105 #endif
106 }
107
108 /* module initialization */
109 extern int init_obdclass(void);
110 extern int ptlrpc_init(void);
111 extern int ldlm_init(void);
112 extern int osc_init(void);
113 extern int lov_init(void);
114 extern int mdc_init(void);
115 extern int lmv_init(void);
116 extern int mgc_init(void);
117
118 /* general stuff */
119
120 #ifndef min
121 #define min(x,y) ((x)<(y) ? (x) : (y))
122 #endif
123
124 #ifndef max
125 #define max(x,y) ((x)>(y) ? (x) : (y))
126 #endif
127
128 #ifndef min_t
129 #define min_t(type,x,y) \
130         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
131 #endif
132 #ifndef max_t
133 #define max_t(type,x,y) \
134         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
135 #endif
136
137 /* registering symbols */
138 #ifndef ERESTARTSYS
139 #define ERESTARTSYS ERESTART
140 #endif
141
142 #ifdef HZ
143 #undef HZ
144 #endif
145 #define HZ 1
146
147 /* random */
148
149 void cfs_get_random_bytes(void *ptr, int size);
150
151 /* memory */
152
153 /* memory size: used for some client tunables */
154 #define totalram_pages  (256 * 1024) /* 1GB */
155 #define NUM_CACHEPAGES totalram_pages
156
157
158 /* VFS stuff */
159 #define ATTR_MODE       0x0001
160 #define ATTR_UID        0x0002
161 #define ATTR_GID        0x0004
162 #define ATTR_SIZE       0x0008
163 #define ATTR_ATIME      0x0010
164 #define ATTR_MTIME      0x0020
165 #define ATTR_CTIME      0x0040
166 #define ATTR_ATIME_SET  0x0080
167 #define ATTR_MTIME_SET  0x0100
168 #define ATTR_FORCE      0x0200  /* Not a change, but a change it */
169 #define ATTR_ATTR_FLAG  0x0400
170 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
171 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
172 #define ATTR_CTIME_SET  0x2000
173 #define ATTR_BLOCKS     0x4000
174 #define ATTR_KILL_SUID  0
175 #define ATTR_KILL_SGID  0
176 #define ATTR_FILE       0
177
178 struct iattr {
179         unsigned int    ia_valid;
180         umode_t         ia_mode;
181         uid_t           ia_uid;
182         gid_t           ia_gid;
183         loff_t          ia_size;
184         time_t          ia_atime;
185         time_t          ia_mtime;
186         time_t          ia_ctime;
187         unsigned int    ia_attr_flags;
188 };
189
190 /* defined in kernel header include/linux/namei.h */
191 #define INTENT_MAGIC 0x19620323
192
193 struct lustre_intent_data {
194         int       it_disposition;
195         int       it_status;
196         __u64     it_lock_handle;
197         int       it_lock_mode;
198         int       it_remote_lock_mode;
199         __u64     it_remote_lock_handle;
200         void     *it_data;
201
202         unsigned int    it_lock_set:1;
203 };
204
205 struct lookup_intent {
206         int     it_magic;
207         void    (*it_op_release)(struct lookup_intent *);
208         int     it_op;
209         int     it_create_mode;
210         __u64   it_flags;
211         union {
212                 struct lustre_intent_data lustre;
213         } d;
214 };
215
216 static inline int it_disposition(const struct lookup_intent *it, int flag)
217 {
218         return it->d.lustre.it_disposition & flag;
219 }
220
221 static inline void it_set_disposition(struct lookup_intent *it, int flag)
222 {
223         it->d.lustre.it_disposition |= flag;
224 }
225
226 static inline void it_clear_disposition(struct lookup_intent *it, int flag)
227 {
228         it->d.lustre.it_disposition &= ~flag;
229 }
230
231 #undef  LL_TASK_CL_ENV
232 #define LL_TASK_CL_ENV          cl_env
233
234 struct task_struct {
235         int state;
236         char comm[32];
237         int uid;
238         int gid;
239         int pid;
240         int fsuid;
241         int fsgid;
242         int max_groups;
243         int ngroups;
244         gid_t *groups;
245         void  *cl_env;
246         __u32 cap_effective;
247 };
248
249
250 #define current_pid()       (current->pid)
251 #define current_comm()      (current->comm)
252 #define current_fsuid()     (current->fsuid)
253 #define current_fsgid()     (current->fsgid)
254 #define current_umask()     ({ mode_t mask = umask(0); umask(mask); mask; })
255
256 extern struct task_struct *current;
257 int in_group_p(gid_t gid);
258
259 #define set_current_state(foo) do { current->state = foo; } while (0)
260
261 #define wait_event_interruptible(wq, condition)                         \
262 {                                                                       \
263         struct l_wait_info lwi;                                         \
264         int timeout = 100000000;/* forever */                           \
265         int ret;                                                        \
266                                                                         \
267         lwi = LWI_TIMEOUT(timeout, NULL, NULL);                         \
268         ret = l_wait_event(NULL, condition, &lwi);                      \
269                                                                         \
270         ret;                                                            \
271 }
272
273 #define call_usermodehelper(path, argv, envp, wait) (0)
274
275 #if HZ != 1
276 #error "liblustre's jiffies currently expects HZ to be 1"
277 #endif
278 #define jiffies                                 \
279 ({                                              \
280         unsigned long _ret = 0;                 \
281         struct timeval tv;                      \
282         if (gettimeofday(&tv, NULL) == 0)       \
283                 _ret = tv.tv_sec;               \
284         _ret;                                   \
285 })
286 #define get_jiffies_64()  (__u64)jiffies
287
288 #ifndef likely
289 #define likely(exp) (exp)
290 #endif
291 #ifndef unlikely
292 #define unlikely(exp) (exp)
293 #endif
294
295 #define might_sleep()
296 #define might_sleep_if(c)
297 #define smp_mb()
298
299 /* FIXME sys/capability will finally included linux/fs.h thus
300  * cause numerous trouble on x86-64. as temporary solution for
301  * build broken at Cray, we copy definition we need from capability.h
302  * FIXME
303  */
304 struct _cap_struct;
305 typedef struct _cap_struct *cap_t;
306 typedef int cap_value_t;
307 typedef enum {
308     CAP_EFFECTIVE=0,
309     CAP_PERMITTED=1,
310     CAP_INHERITABLE=2
311 } cap_flag_t;
312 typedef enum {
313     CAP_CLEAR=0,
314     CAP_SET=1
315 } cap_flag_value_t;
316
317 cap_t   cap_get_proc(void);
318 int     cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
319
320 struct liblustre_wait_callback {
321         cfs_list_t              llwc_list;
322         const char             *llwc_name;
323         int                   (*llwc_fn)(void *arg);
324         void                   *llwc_arg;
325 };
326
327 void *liblustre_register_wait_callback(const char *name,
328                                        int (*fn)(void *arg), void *arg);
329 void liblustre_deregister_wait_callback(void *notifier);
330 int liblustre_wait_event(int timeout);
331
332 void *liblustre_register_idle_callback(const char *name,
333                                        int (*fn)(void *arg), void *arg);
334 void liblustre_deregister_idle_callback(void *notifier);
335 void liblustre_wait_idle(void);
336
337 struct file_lock {
338         struct file_lock *fl_next;  /* singly linked list for this inode  */
339         cfs_list_t fl_link;   /* doubly linked list of all locks */
340         cfs_list_t fl_block;  /* circular list of blocked processes */
341         void *fl_owner;
342         unsigned int fl_pid;
343         wait_queue_head_t fl_wait;
344         struct file *fl_file;
345         unsigned char fl_flags;
346         unsigned char fl_type;
347         loff_t fl_start;
348         loff_t fl_end;
349
350         void (*fl_notify)(struct file_lock *);  /* unblock callback */
351         void (*fl_insert)(struct file_lock *);  /* lock insertion callback */
352         void (*fl_remove)(struct file_lock *);  /* lock removal callback */
353
354         void *fl_fasync; /* for lease break notifications */
355         unsigned long fl_break_time;    /* for nonblocking lease breaks */
356 };
357
358 #define flock_type(fl)                  ((fl)->fl_type)
359 #define flock_set_type(fl, type)        do { (fl)->fl_type = (type); } while (0)
360 #define flock_pid(fl)                   ((fl)->fl_pid)
361 #define flock_set_pid(fl, pid)          do { (fl)->fl_pid = (pid); } while (0)
362 #define flock_start(fl)                 ((fl)->fl_start)
363 #define flock_set_start(fl, st)         do { (fl)->fl_start = (st); } while (0)
364 #define flock_end(fl)                   ((fl)->fl_end)
365 #define flock_set_end(fl, end)          do { (fl)->fl_end = (end); } while (0)
366
367 #ifndef OFFSET_MAX
368 #define INT_LIMIT(x)    (~((x)1 << (sizeof(x)*8 - 1)))
369 #define OFFSET_MAX      INT_LIMIT(loff_t)
370 #endif
371
372 #define i_atime                     i_stbuf.st_atime
373 #define i_mtime                     i_stbuf.st_mtime
374 #define i_ctime                     i_stbuf.st_ctime
375 /* use i_size_read() i_size_write() to access i_stbuf.st_size */
376 #define i_blocks                    i_stbuf.st_blocks
377 #define i_blksize                   i_stbuf.st_blksize
378 #define i_mode                      i_stbuf.st_mode
379 #define i_uid                       i_stbuf.st_uid
380 #define i_gid                       i_stbuf.st_gid
381
382 /* XXX: defined in kernel */
383 #define FL_POSIX        1
384 #define FL_SLEEP        128
385
386 /* quota */
387 #define QUOTA_OK 0
388 #define NO_QUOTA 1
389
390 /* ACL */
391 typedef struct {
392         __u16           e_tag;
393         __u16           e_perm;
394         __u32           e_id;
395 } posix_acl_xattr_entry;
396
397 struct posix_acl {
398         atomic_t                a_refcount;
399         unsigned int            a_count;
400         posix_acl_xattr_entry   a_entries[0];
401 };
402
403 typedef struct {
404         __u32                 a_version;
405         posix_acl_xattr_entry a_entries[0];
406 } posix_acl_xattr_header;
407
408 static inline size_t posix_acl_xattr_size(int count)
409 {
410         return sizeof(posix_acl_xattr_header) + count *
411                sizeof(posix_acl_xattr_entry);
412 }
413
414 static inline
415 struct posix_acl * posix_acl_from_xattr(const void *value, size_t size)
416 {
417         return NULL;
418 }
419
420 /* The kernel version takes 3 arguments, so strip that off first. */
421 #define posix_acl_from_xattr(a,b,c)     posix_acl_from_xattr(b,c)
422 #define posix_acl_to_xattr(a,b,c)       posix_acl_to_xattr(b,c)
423
424 static inline
425 int posix_acl_valid(const struct posix_acl *acl)
426 {
427         return 0;
428 }
429
430 static inline
431 void posix_acl_release(struct posix_acl *acl)
432 {
433 }
434
435 #if defined(LIBLUSTRE_POSIX_ACL) && !defined(CONFIG_FS_POSIX_ACL)
436 # define CONFIG_FS_POSIX_ACL 1
437 #endif
438
439 #ifndef ENOTSUPP
440 #define ENOTSUPP ENOTSUP
441 #endif
442
443 typedef int mm_segment_t;
444
445 #define S_IRWXUGO       (S_IRWXU|S_IRWXG|S_IRWXO)
446 #define S_IALLUGO       (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
447
448 #include <obd_support.h>
449 #include <lustre/lustre_idl.h>
450 #include <lustre_lib.h>
451 #include <lustre_import.h>
452 #include <lustre_export.h>
453 #include <lustre_net.h>
454
455 /** @} liblustre */
456
457 #endif