Whamcloud - gitweb
LU-2800 autoconf: remove LC_FS_STRUCT_USE_PATH
[fs/lustre-release.git] / lustre / include / linux / lustre_compat25.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
37 #ifndef _LINUX_COMPAT25_H
38 #define _LINUX_COMPAT25_H
39
40 #include <linux/fs_struct.h>
41 #include <linux/namei.h>
42 #include <libcfs/linux/portals_compat25.h>
43
44 #include <linux/lustre_patchless_compat.h>
45
46 #ifdef HAVE_FS_STRUCT_RWLOCK
47 # define LOCK_FS_STRUCT(fs)     write_lock(&(fs)->lock)
48 # define UNLOCK_FS_STRUCT(fs)   write_unlock(&(fs)->lock)
49 #else
50 # define LOCK_FS_STRUCT(fs)     spin_lock(&(fs)->lock)
51 # define UNLOCK_FS_STRUCT(fs)   spin_unlock(&(fs)->lock)
52 #endif
53
54 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
55                                  struct dentry *dentry)
56 {
57         struct path path;
58         struct path old_pwd;
59
60         path.mnt = mnt;
61         path.dentry = dentry;
62         LOCK_FS_STRUCT(fs);
63         old_pwd = fs->pwd;
64         path_get(&path);
65         fs->pwd = path;
66         UNLOCK_FS_STRUCT(fs);
67
68         if (old_pwd.dentry)
69                 path_put(&old_pwd);
70 }
71
72 /*
73  * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
74  * ATTR_* attributes (see bug 13828)
75  */
76 #define ATTR_BLOCKS    (1 << 27)
77
78 #define current_ngroups current_cred()->group_info->ngroups
79 #define current_groups current_cred()->group_info->small_block
80
81 /*
82  * OBD need working random driver, thus all our
83  * initialization routines must be called after device
84  * driver initialization
85  */
86 #ifndef MODULE
87 #undef module_init
88 #define module_init(a)     late_initcall(a)
89 #endif
90
91 #define LTIME_S(time)                   (time.tv_sec)
92
93 #ifdef HAVE_GENERIC_PERMISSION_2ARGS
94 # define ll_generic_permission(inode, mask, flags, check_acl) \
95          generic_permission(inode, mask)
96 #elif defined HAVE_GENERIC_PERMISSION_4ARGS
97 # define ll_generic_permission(inode, mask, flags, check_acl) \
98          generic_permission(inode, mask, flags, check_acl)
99 #else
100 # define ll_generic_permission(inode, mask, flags, check_acl) \
101          generic_permission(inode, mask, check_acl)
102 #endif
103
104 #ifdef HAVE_DENTRY_OPEN_USE_PATH
105 #define ll_dentry_open(a,b,c)   dentry_open(a,b,c)
106 #else
107 /*
108  * dentry_open handles its own reference counting since Linux v3.6
109  * (commit 765927b2). Callers should free their own references.
110  *
111  * Prior versions expected the caller to increment the references.
112  * The references are retained on success and freed on error.
113  */
114 static inline struct file *ll_dentry_open(struct path *path, int flags,
115                                           const struct cred *cred)
116 {
117         mntget(path->mnt);
118         dget(path->dentry);
119         return dentry_open(path->dentry, path->mnt, flags, cred);
120 }
121 #endif
122
123 #ifdef HAVE_SECURITY_PLUG
124 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
125                 vfs_symlink(dir, dentry, mnt, path, mode)
126 #else
127 #ifdef HAVE_4ARGS_VFS_SYMLINK
128 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
129                 vfs_symlink(dir, dentry, path, mode)
130 #else
131 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
132                        vfs_symlink(dir, dentry, path)
133 #endif
134
135 #endif
136
137 #if !defined(HAVE_FILE_LLSEEK_SIZE) || defined(HAVE_FILE_LLSEEK_SIZE_5ARGS)
138 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
139                 generic_file_llseek_size(file, offset, origin, maxbytes, eof);
140 #else
141 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
142                 generic_file_llseek_size(file, offset, origin, maxbytes);
143 #endif
144
145 #ifdef HAVE_INODE_DIO_WAIT
146 /* inode_dio_wait(i) use as-is for write lock */
147 # define inode_dio_write_done(i)        do {} while (0) /* for write unlock */
148 # define inode_dio_read(i)              atomic_inc(&(i)->i_dio_count)
149 /* inode_dio_done(i) use as-is for read unlock */
150 #else
151 # define inode_dio_wait(i)              down_write(&(i)->i_alloc_sem)
152 # define inode_dio_write_done(i)        up_write(&(i)->i_alloc_sem)
153 # define inode_dio_read(i)              down_read(&(i)->i_alloc_sem)
154 # define inode_dio_done(i)              up_read(&(i)->i_alloc_sem)
155 #endif
156
157 #ifdef HAVE_RW_TREE_LOCK
158 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
159 #define TREE_READ_UNLOCK_IRQ(mapping)   read_unlock_irq(&(mapping)->tree_lock)
160 #else
161 #define TREE_READ_LOCK_IRQ(mapping)     spin_lock_irq(&(mapping)->tree_lock)
162 #define TREE_READ_UNLOCK_IRQ(mapping)   spin_unlock_irq(&(mapping)->tree_lock)
163 #endif
164
165 #ifndef FS_HAS_FIEMAP
166 #define FS_HAS_FIEMAP                   (0)
167 #endif
168
169 #ifndef HAVE_FS_RENAME_DOES_D_MOVE
170 #define FS_RENAME_DOES_D_MOVE           FS_ODD_RENAME
171 #endif
172
173 /* add a lustre compatible layer for crypto API */
174 #include <linux/crypto.h>
175 #define ll_crypto_hash          crypto_hash
176 #define ll_crypto_cipher        crypto_blkcipher
177 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
178 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
179 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
180 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
181 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
182 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
183                 crypto_blkcipher_setkey(tfm, key, keylen)
184 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
185                 crypto_blkcipher_set_iv(tfm, src, len)
186 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
187                 crypto_blkcipher_get_iv(tfm, dst, len)
188 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
189                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
190 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
191                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
192 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
193                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
194 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
195                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
196
197 static inline
198 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char *name,
199                                                    u32 type, u32 mask)
200 {
201         struct ll_crypto_cipher *rtn = crypto_alloc_blkcipher(name, type, mask);
202
203         return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
204 }
205
206 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
207                                  u8 *key, unsigned int *keylen,
208                                  struct scatterlist *sg,
209                                  unsigned int size, u8 *result)
210 {
211         struct hash_desc desc;
212         int              rv;
213         desc.tfm   = tfm;
214         desc.flags = 0;
215         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
216         if (rv) {
217                 CERROR("failed to hash setkey: %d\n", rv);
218                 return rv;
219         }
220         return crypto_hash_digest(&desc, sg, size, result);
221 }
222 static inline
223 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
224 {
225         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
226 }
227 static inline
228 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
229 {
230         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
231 }
232
233 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
234 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
235 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
236 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
237 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
238 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
239
240 #ifdef HAVE_SECURITY_PLUG
241 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
242 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
243 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
244 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
245 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
246                 vfs_mknod(dir,entry,mnt,mode,dev)
247 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
248                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
249 #else
250 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
251 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
252 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
253 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
254 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
255 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
256                 vfs_rename(old,old_dir,new,new_dir)
257 #endif /* HAVE_SECURITY_PLUG */
258
259 #ifdef for_each_possible_cpu
260 #define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
261 #elif defined(for_each_cpu)
262 #define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
263 #endif
264
265 #ifdef HAVE_BIO_ENDIO_2ARG
266 #define cfs_bio_io_error(a,b)   bio_io_error((a))
267 #define cfs_bio_endio(a,b,c)    bio_endio((a),(c))
268 #else
269 #define cfs_bio_io_error(a,b)   bio_io_error((a),(b))
270 #define cfs_bio_endio(a,b,c)    bio_endio((a),(b),(c))
271 #endif
272
273 #ifndef HAVE_SIMPLE_SETATTR
274 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
275 #endif
276
277 #ifndef SLAB_DESTROY_BY_RCU
278 #define SLAB_DESTROY_BY_RCU 0
279 #endif
280
281 static inline int
282 ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
283 {
284         int rc;
285
286         if (sb->s_qcop->quota_on) {
287 #ifdef HAVE_QUOTA_ON_USE_PATH
288                 struct path path;
289
290                 rc = kern_path(name, LOOKUP_FOLLOW, &path);
291                 if (!rc)
292                         return rc;
293 #endif
294                 rc = sb->s_qcop->quota_on(sb, off, ver
295 #ifdef HAVE_QUOTA_ON_USE_PATH
296                                             , &path
297 #else
298                                             , name
299 #endif
300 #ifdef HAVE_QUOTA_ON_5ARGS
301                                             , remount
302 #endif
303                                            );
304 #ifdef HAVE_QUOTA_ON_USE_PATH
305                 path_put(&path);
306 #endif
307                 return rc;
308         }
309         else
310                 return -ENOSYS;
311 }
312
313 static inline int ll_quota_off(struct super_block *sb, int off, int remount)
314 {
315         if (sb->s_qcop->quota_off) {
316                 return sb->s_qcop->quota_off(sb, off
317 #ifdef HAVE_QUOTA_OFF_3ARGS
318                                              , remount
319 #endif
320                                             );
321         }
322         else
323                 return -ENOSYS;
324 }
325
326 #ifndef HAVE_DQUOT_SUSPEND
327 # define ll_vfs_dq_init             vfs_dq_init
328 # define ll_vfs_dq_drop             vfs_dq_drop
329 # define ll_vfs_dq_transfer         vfs_dq_transfer
330 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
331 #else
332 # define ll_vfs_dq_init             dquot_initialize
333 # define ll_vfs_dq_drop             dquot_drop
334 # define ll_vfs_dq_transfer         dquot_transfer
335 # define ll_vfs_dq_off(sb, remount) dquot_suspend(sb, -1)
336 #endif
337
338 #ifndef HAVE_BLKDEV_GET_BY_DEV
339 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
340 #endif
341
342 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
343 #define blk_queue_max_segments(rq, seg)                      \
344         do { blk_queue_max_phys_segments(rq, seg);           \
345              blk_queue_max_hw_segments(rq, seg); } while (0)
346 #else
347 #define queue_max_phys_segments(rq)       queue_max_segments(rq)
348 #define queue_max_hw_segments(rq)         queue_max_segments(rq)
349 #endif
350
351 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
352 #define ll_kmap_atomic(a, b)    kmap_atomic(a)
353 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a)
354 #else
355 #define ll_kmap_atomic(a, b)    kmap_atomic(a, b)
356 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a, b)
357 #endif
358
359 #ifndef HAVE_CLEAR_INODE
360 #define clear_inode(i)          end_writeback(i)
361 #endif
362
363 #ifdef HAVE_DENTRY_D_ALIAS_HLIST
364 #define ll_d_hlist_node hlist_node
365 #define ll_d_hlist_empty(list) hlist_empty(list)
366 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
367 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
368 #ifdef HAVE_HLIST_FOR_EACH_3ARG
369 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
370         p = NULL; hlist_for_each_entry(dentry, i_dentry, alias)
371 #else
372 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
373         hlist_for_each_entry(dentry, p, i_dentry, alias)
374 #endif
375 #define DECLARE_LL_D_HLIST_NODE_PTR(name) struct ll_d_hlist_node *name
376 #else
377 #define ll_d_hlist_node list_head
378 #define ll_d_hlist_empty(list) list_empty(list)
379 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
380 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
381 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
382         list_for_each_entry(dentry, i_dentry, alias)
383 #define DECLARE_LL_D_HLIST_NODE_PTR(name) /* nothing */
384 #endif
385
386
387 #ifndef HAVE_BI_HW_SEGMENTS
388 #define bio_hw_segments(q, bio) 0
389 #endif
390
391 #ifndef QUOTA_OK
392 # define QUOTA_OK 0
393 #endif
394 #ifndef NO_QUOTA
395 # define NO_QUOTA (-EDQUOT)
396 #endif
397
398 #ifndef SEEK_DATA
399 #define SEEK_DATA      3       /* seek to the next data */
400 #endif
401 #ifndef SEEK_HOLE
402 #define SEEK_HOLE      4       /* seek to the next hole */
403 #endif
404
405 #ifndef FMODE_UNSIGNED_OFFSET
406 #define FMODE_UNSIGNED_OFFSET   ((__force fmode_t)0x2000)
407 #endif
408
409 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
410 # define ext2_set_bit             __test_and_set_bit_le
411 # define ext2_clear_bit           __test_and_clear_bit_le
412 # define ext2_test_bit            test_bit_le
413 # define ext2_find_first_zero_bit find_first_zero_bit_le
414 # define ext2_find_next_zero_bit  find_next_zero_bit_le
415 #endif
416
417 #ifdef ATTR_TIMES_SET
418 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
419 #else
420 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
421 #endif
422
423 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
424 # define lm_compare_owner       fl_compare_owner
425 #endif
426
427 /*
428  * After 3.1, kernel's nameidata.intent.open.flags is different
429  * with lustre's lookup_intent.it_flags, as lustre's it_flags'
430  * lower bits equal to FMODE_xxx while kernel doesn't transliterate
431  * lower bits of nameidata.intent.open.flags to FMODE_xxx.
432  * */
433 #include <linux/version.h>
434 static inline int ll_namei_to_lookup_intent_flag(int flag)
435 {
436 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
437         flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
438 #endif
439         return flag;
440 }
441
442 #ifdef HAVE_VOID_MAKE_REQUEST_FN
443 # define ll_mrf_ret void
444 # define LL_MRF_RETURN(rc)
445 #else
446 # define ll_mrf_ret int
447 # define LL_MRF_RETURN(rc) RETURN(rc)
448 #endif
449
450 #include <linux/fs.h>
451 #ifndef HAVE_PROTECT_I_NLINK
452 static inline void set_nlink(struct inode *inode, unsigned int nlink)
453 {
454         inode->i_nlink = nlink;
455 }
456 #endif
457
458 #ifdef HAVE_INODEOPS_USE_UMODE_T
459 # define ll_umode_t     umode_t
460 #else
461 # define ll_umode_t     int
462 #endif
463
464 #include <linux/dcache.h>
465 #ifndef HAVE_D_MAKE_ROOT
466 static inline struct dentry *d_make_root(struct inode *root)
467 {
468         struct dentry *res = d_alloc_root(root);
469
470         if (res == NULL && root)
471                 iput(root);
472
473         return res;
474 }
475 #endif
476
477 #ifdef HAVE_DIRTY_INODE_HAS_FLAG
478 # define ll_dirty_inode(inode, flag)    (inode)->i_sb->s_op->dirty_inode((inode), flag)
479 #else
480 # define ll_dirty_inode(inode, flag)    (inode)->i_sb->s_op->dirty_inode((inode))
481 #endif
482
483 #endif /* _COMPAT25_H */