4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef _LINUX_COMPAT25_H
38 #define _LINUX_COMPAT25_H
40 #include <linux/fs_struct.h>
41 #include <linux/namei.h>
42 #include <libcfs/linux/portals_compat25.h>
44 #include <linux/lustre_patchless_compat.h>
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)
50 # define LOCK_FS_STRUCT(fs) spin_lock(&(fs)->lock)
51 # define UNLOCK_FS_STRUCT(fs) spin_unlock(&(fs)->lock)
54 #ifdef HAVE_FS_STRUCT_USE_PATH
55 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
56 struct dentry *dentry)
75 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
76 struct dentry *dentry)
78 struct dentry *old_pwd;
79 struct vfsmount *old_pwdmnt;
83 old_pwdmnt = fs->pwdmnt;
84 fs->pwdmnt = mntget(mnt);
85 fs->pwd = dget(dentry);
96 * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
97 * ATTR_* attributes (see bug 13828)
99 #define ATTR_BLOCKS (1 << 27)
101 #define current_ngroups current_cred()->group_info->ngroups
102 #define current_groups current_cred()->group_info->small_block
105 * OBD need working random driver, thus all our
106 * initialization routines must be called after device
107 * driver initialization
111 #define module_init(a) late_initcall(a)
114 #define LTIME_S(time) (time.tv_sec)
116 #ifdef HAVE_GENERIC_PERMISSION_2ARGS
117 # define ll_generic_permission(inode, mask, flags, check_acl) \
118 generic_permission(inode, mask)
119 #elif defined HAVE_GENERIC_PERMISSION_4ARGS
120 # define ll_generic_permission(inode, mask, flags, check_acl) \
121 generic_permission(inode, mask, flags, check_acl)
123 # define ll_generic_permission(inode, mask, flags, check_acl) \
124 generic_permission(inode, mask, check_acl)
127 #ifdef HAVE_DENTRY_OPEN_USE_PATH
128 #define ll_dentry_open(a,b,c) dentry_open(a,b,c)
131 * dentry_open handles its own reference counting since Linux v3.6
132 * (commit 765927b2). Callers should free their own references.
134 * Prior versions expected the caller to increment the references.
135 * The references are retained on success and freed on error.
137 static inline struct file *ll_dentry_open(struct path *path, int flags,
138 const struct cred *cred)
142 return dentry_open(path->dentry, path->mnt, flags, cred);
146 #ifdef HAVE_SECURITY_PLUG
147 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
148 vfs_symlink(dir, dentry, mnt, path, mode)
150 #ifdef HAVE_4ARGS_VFS_SYMLINK
151 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
152 vfs_symlink(dir, dentry, path, mode)
154 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
155 vfs_symlink(dir, dentry, path)
160 #if !defined(HAVE_FILE_LLSEEK_SIZE) || defined(HAVE_FILE_LLSEEK_SIZE_5ARGS)
161 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
162 generic_file_llseek_size(file, offset, origin, maxbytes, eof);
164 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
165 generic_file_llseek_size(file, offset, origin, maxbytes);
168 #ifdef HAVE_INODE_DIO_WAIT
169 /* inode_dio_wait(i) use as-is for write lock */
170 # define inode_dio_write_done(i) do {} while (0) /* for write unlock */
171 # define inode_dio_read(i) atomic_inc(&(i)->i_dio_count)
172 /* inode_dio_done(i) use as-is for read unlock */
174 # define inode_dio_wait(i) down_write(&(i)->i_alloc_sem)
175 # define inode_dio_write_done(i) up_write(&(i)->i_alloc_sem)
176 # define inode_dio_read(i) down_read(&(i)->i_alloc_sem)
177 # define inode_dio_done(i) up_read(&(i)->i_alloc_sem)
180 #ifdef HAVE_RW_TREE_LOCK
181 #define TREE_READ_LOCK_IRQ(mapping) read_lock_irq(&(mapping)->tree_lock)
182 #define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
184 #define TREE_READ_LOCK_IRQ(mapping) spin_lock_irq(&(mapping)->tree_lock)
185 #define TREE_READ_UNLOCK_IRQ(mapping) spin_unlock_irq(&(mapping)->tree_lock)
188 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
189 #define ll_unregister_blkdev(a,b) unregister_blkdev((a),(b))
192 int ll_unregister_blkdev(unsigned int dev, const char *name)
194 unregister_blkdev(dev, name);
199 #ifndef FS_HAS_FIEMAP
200 #define FS_HAS_FIEMAP (0)
203 #ifndef HAVE_FS_RENAME_DOES_D_MOVE
204 #define FS_RENAME_DOES_D_MOVE FS_ODD_RENAME
207 /* add a lustre compatible layer for crypto API */
208 #include <linux/crypto.h>
209 #define ll_crypto_hash crypto_hash
210 #define ll_crypto_cipher crypto_blkcipher
211 #define ll_crypto_alloc_hash(name, type, mask) crypto_alloc_hash(name, type, mask)
212 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
213 #define ll_crypto_hash_init(desc) crypto_hash_init(desc)
214 #define ll_crypto_hash_update(desc, sl, bytes) crypto_hash_update(desc, sl, bytes)
215 #define ll_crypto_hash_final(desc, out) crypto_hash_final(desc, out)
216 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
217 crypto_blkcipher_setkey(tfm, key, keylen)
218 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
219 crypto_blkcipher_set_iv(tfm, src, len)
220 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
221 crypto_blkcipher_get_iv(tfm, dst, len)
222 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
223 crypto_blkcipher_encrypt(desc, dst, src, bytes)
224 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
225 crypto_blkcipher_decrypt(desc, dst, src, bytes)
226 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
227 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
228 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
229 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
232 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char *name,
235 struct ll_crypto_cipher *rtn = crypto_alloc_blkcipher(name, type, mask);
237 return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
240 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
241 u8 *key, unsigned int *keylen,
242 struct scatterlist *sg,
243 unsigned int size, u8 *result)
245 struct hash_desc desc;
249 rv = crypto_hash_setkey(desc.tfm, key, *keylen);
251 CERROR("failed to hash setkey: %d\n", rv);
254 return crypto_hash_digest(&desc, sg, size, result);
257 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
259 return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
262 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
264 return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
267 #define ll_crypto_hash_blocksize(tfm) crypto_hash_blocksize(tfm)
268 #define ll_crypto_hash_digestsize(tfm) crypto_hash_digestsize(tfm)
269 #define ll_crypto_blkcipher_ivsize(tfm) crypto_blkcipher_ivsize(tfm)
270 #define ll_crypto_blkcipher_blocksize(tfm) crypto_blkcipher_blocksize(tfm)
271 #define ll_crypto_free_hash(tfm) crypto_free_hash(tfm)
272 #define ll_crypto_free_blkcipher(tfm) crypto_free_blkcipher(tfm)
274 #ifdef HAVE_SECURITY_PLUG
275 #define ll_vfs_rmdir(dir,entry,mnt) vfs_rmdir(dir,entry,mnt)
276 #define ll_vfs_mkdir(inode,dir,mnt,mode) vfs_mkdir(inode,dir,mnt,mode)
277 #define ll_vfs_link(old,mnt,dir,new,mnt1) vfs_link(old,mnt,dir,new,mnt1)
278 #define ll_vfs_unlink(inode,entry,mnt) vfs_unlink(inode,entry,mnt)
279 #define ll_vfs_mknod(dir,entry,mnt,mode,dev) \
280 vfs_mknod(dir,entry,mnt,mode,dev)
281 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
282 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
284 #define ll_vfs_rmdir(dir,entry,mnt) vfs_rmdir(dir,entry)
285 #define ll_vfs_mkdir(inode,dir,mnt,mode) vfs_mkdir(inode,dir,mode)
286 #define ll_vfs_link(old,mnt,dir,new,mnt1) vfs_link(old,dir,new)
287 #define ll_vfs_unlink(inode,entry,mnt) vfs_unlink(inode,entry)
288 #define ll_vfs_mknod(dir,entry,mnt,mode,dev) vfs_mknod(dir,entry,mode,dev)
289 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
290 vfs_rename(old,old_dir,new,new_dir)
291 #endif /* HAVE_SECURITY_PLUG */
293 #ifdef for_each_possible_cpu
294 #define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
295 #elif defined(for_each_cpu)
296 #define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
299 #ifdef HAVE_BIO_ENDIO_2ARG
300 #define cfs_bio_io_error(a,b) bio_io_error((a))
301 #define cfs_bio_endio(a,b,c) bio_endio((a),(c))
303 #define cfs_bio_io_error(a,b) bio_io_error((a),(b))
304 #define cfs_bio_endio(a,b,c) bio_endio((a),(b),(c))
307 #ifdef HAVE_FS_STRUCT_USE_PATH
308 #define cfs_fs_pwd(fs) ((fs)->pwd.dentry)
309 #define cfs_fs_mnt(fs) ((fs)->pwd.mnt)
310 #define cfs_path_put(nd) path_put(&(nd)->path)
312 #define cfs_fs_pwd(fs) ((fs)->pwd)
313 #define cfs_fs_mnt(fs) ((fs)->pwdmnt)
314 #define cfs_path_put(nd) path_release(nd)
317 #ifndef HAVE_SIMPLE_SETATTR
318 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
321 #ifndef SLAB_DESTROY_BY_RCU
322 #define SLAB_DESTROY_BY_RCU 0
326 ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
330 if (sb->s_qcop->quota_on) {
331 #ifdef HAVE_QUOTA_ON_USE_PATH
334 rc = kern_path(name, LOOKUP_FOLLOW, &path);
338 rc = sb->s_qcop->quota_on(sb, off, ver
339 #ifdef HAVE_QUOTA_ON_USE_PATH
344 #ifdef HAVE_QUOTA_ON_5ARGS
348 #ifdef HAVE_QUOTA_ON_USE_PATH
357 static inline int ll_quota_off(struct super_block *sb, int off, int remount)
359 if (sb->s_qcop->quota_off) {
360 return sb->s_qcop->quota_off(sb, off
361 #ifdef HAVE_QUOTA_OFF_3ARGS
370 #ifndef HAVE_DQUOT_SUSPEND
371 # define ll_vfs_dq_init vfs_dq_init
372 # define ll_vfs_dq_drop vfs_dq_drop
373 # define ll_vfs_dq_transfer vfs_dq_transfer
374 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
376 # define ll_vfs_dq_init dquot_initialize
377 # define ll_vfs_dq_drop dquot_drop
378 # define ll_vfs_dq_transfer dquot_transfer
379 # define ll_vfs_dq_off(sb, remount) dquot_suspend(sb, -1)
382 #ifndef HAVE_BLKDEV_GET_BY_DEV
383 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
386 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
387 #define blk_queue_max_segments(rq, seg) \
388 do { blk_queue_max_phys_segments(rq, seg); \
389 blk_queue_max_hw_segments(rq, seg); } while (0)
391 #define queue_max_phys_segments(rq) queue_max_segments(rq)
392 #define queue_max_hw_segments(rq) queue_max_segments(rq)
395 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
396 #define ll_kmap_atomic(a, b) kmap_atomic(a)
397 #define ll_kunmap_atomic(a, b) kunmap_atomic(a)
399 #define ll_kmap_atomic(a, b) kmap_atomic(a, b)
400 #define ll_kunmap_atomic(a, b) kunmap_atomic(a, b)
403 #ifndef HAVE_CLEAR_INODE
404 #define clear_inode(i) end_writeback(i)
407 #ifdef HAVE_DENTRY_D_ALIAS_HLIST
408 #define ll_d_hlist_node hlist_node
409 #define ll_d_hlist_empty(list) hlist_empty(list)
410 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
411 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
412 #ifdef HAVE_HLIST_FOR_EACH_3ARG
413 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
414 p = NULL; hlist_for_each_entry(dentry, i_dentry, alias)
416 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
417 hlist_for_each_entry(dentry, p, i_dentry, alias)
419 #define DECLARE_LL_D_HLIST_NODE_PTR(name) struct ll_d_hlist_node *name
421 #define ll_d_hlist_node list_head
422 #define ll_d_hlist_empty(list) list_empty(list)
423 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
424 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
425 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
426 list_for_each_entry(dentry, i_dentry, alias)
427 #define DECLARE_LL_D_HLIST_NODE_PTR(name) /* nothing */
431 #ifndef HAVE_BI_HW_SEGMENTS
432 #define bio_hw_segments(q, bio) 0
439 # define NO_QUOTA (-EDQUOT)
443 #define SEEK_DATA 3 /* seek to the next data */
446 #define SEEK_HOLE 4 /* seek to the next hole */
449 #ifndef FMODE_UNSIGNED_OFFSET
450 #define FMODE_UNSIGNED_OFFSET ((__force fmode_t)0x2000)
453 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
454 # define ext2_set_bit __test_and_set_bit_le
455 # define ext2_clear_bit __test_and_clear_bit_le
456 # define ext2_test_bit test_bit_le
457 # define ext2_find_first_zero_bit find_first_zero_bit_le
458 # define ext2_find_next_zero_bit find_next_zero_bit_le
461 #ifdef ATTR_TIMES_SET
462 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
464 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
467 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
468 # define lm_compare_owner fl_compare_owner
472 * After 3.1, kernel's nameidata.intent.open.flags is different
473 * with lustre's lookup_intent.it_flags, as lustre's it_flags'
474 * lower bits equal to FMODE_xxx while kernel doesn't transliterate
475 * lower bits of nameidata.intent.open.flags to FMODE_xxx.
477 #include <linux/version.h>
478 static inline int ll_namei_to_lookup_intent_flag(int flag)
480 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
481 flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
486 #ifdef HAVE_VOID_MAKE_REQUEST_FN
487 # define ll_mrf_ret void
488 # define LL_MRF_RETURN(rc)
490 # define ll_mrf_ret int
491 # define LL_MRF_RETURN(rc) RETURN(rc)
494 #include <linux/fs.h>
495 #ifndef HAVE_PROTECT_I_NLINK
496 static inline void set_nlink(struct inode *inode, unsigned int nlink)
498 inode->i_nlink = nlink;
502 #ifdef HAVE_INODEOPS_USE_UMODE_T
503 # define ll_umode_t umode_t
505 # define ll_umode_t int
508 #include <linux/dcache.h>
509 #ifndef HAVE_D_MAKE_ROOT
510 static inline struct dentry *d_make_root(struct inode *root)
512 struct dentry *res = d_alloc_root(root);
514 if (res == NULL && root)
521 #ifdef HAVE_DIRTY_INODE_HAS_FLAG
522 # define ll_dirty_inode(inode, flag) (inode)->i_sb->s_op->dirty_inode((inode), flag)
524 # define ll_dirty_inode(inode, flag) (inode)->i_sb->s_op->dirty_inode((inode))
527 #endif /* _COMPAT25_H */