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 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
55 struct dentry *dentry)
73 * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
74 * ATTR_* attributes (see bug 13828)
76 #define ATTR_BLOCKS (1 << 27)
78 #define current_ngroups current_cred()->group_info->ngroups
79 #define current_groups current_cred()->group_info->small_block
82 * OBD need working random driver, thus all our
83 * initialization routines must be called after device
84 * driver initialization
88 #define module_init(a) late_initcall(a)
91 #define LTIME_S(time) (time.tv_sec)
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)
100 # define ll_generic_permission(inode, mask, flags, check_acl) \
101 generic_permission(inode, mask, check_acl)
104 #ifdef HAVE_DENTRY_OPEN_USE_PATH
105 #define ll_dentry_open(a,b,c) dentry_open(a,b,c)
108 * dentry_open handles its own reference counting since Linux v3.6
109 * (commit 765927b2). Callers should free their own references.
111 * Prior versions expected the caller to increment the references.
112 * The references are retained on success and freed on error.
114 static inline struct file *ll_dentry_open(struct path *path, int flags,
115 const struct cred *cred)
119 return dentry_open(path->dentry, path->mnt, flags, cred);
123 #ifdef HAVE_4ARGS_VFS_SYMLINK
124 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
125 vfs_symlink(dir, dentry, path, mode)
127 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
128 vfs_symlink(dir, dentry, path)
131 #if !defined(HAVE_FILE_LLSEEK_SIZE) || defined(HAVE_FILE_LLSEEK_SIZE_5ARGS)
132 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
133 generic_file_llseek_size(file, offset, origin, maxbytes, eof);
135 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
136 generic_file_llseek_size(file, offset, origin, maxbytes);
139 #ifdef HAVE_INODE_DIO_WAIT
140 /* inode_dio_wait(i) use as-is for write lock */
141 # define inode_dio_write_done(i) do {} while (0) /* for write unlock */
142 # define inode_dio_read(i) atomic_inc(&(i)->i_dio_count)
143 /* inode_dio_done(i) use as-is for read unlock */
145 # define inode_dio_wait(i) down_write(&(i)->i_alloc_sem)
146 # define inode_dio_write_done(i) up_write(&(i)->i_alloc_sem)
147 # define inode_dio_read(i) down_read(&(i)->i_alloc_sem)
148 # define inode_dio_done(i) up_read(&(i)->i_alloc_sem)
151 #ifdef HAVE_RW_TREE_LOCK
152 #define TREE_READ_LOCK_IRQ(mapping) read_lock_irq(&(mapping)->tree_lock)
153 #define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
155 #define TREE_READ_LOCK_IRQ(mapping) spin_lock_irq(&(mapping)->tree_lock)
156 #define TREE_READ_UNLOCK_IRQ(mapping) spin_unlock_irq(&(mapping)->tree_lock)
159 #ifndef FS_HAS_FIEMAP
160 #define FS_HAS_FIEMAP (0)
163 #ifndef HAVE_FS_RENAME_DOES_D_MOVE
164 #define FS_RENAME_DOES_D_MOVE FS_ODD_RENAME
167 /* add a lustre compatible layer for crypto API */
168 #include <linux/crypto.h>
169 #define ll_crypto_hash crypto_hash
170 #define ll_crypto_cipher crypto_blkcipher
171 #define ll_crypto_alloc_hash(name, type, mask) crypto_alloc_hash(name, type, mask)
172 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
173 #define ll_crypto_hash_init(desc) crypto_hash_init(desc)
174 #define ll_crypto_hash_update(desc, sl, bytes) crypto_hash_update(desc, sl, bytes)
175 #define ll_crypto_hash_final(desc, out) crypto_hash_final(desc, out)
176 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
177 crypto_blkcipher_setkey(tfm, key, keylen)
178 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
179 crypto_blkcipher_set_iv(tfm, src, len)
180 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
181 crypto_blkcipher_get_iv(tfm, dst, len)
182 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
183 crypto_blkcipher_encrypt(desc, dst, src, bytes)
184 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
185 crypto_blkcipher_decrypt(desc, dst, src, bytes)
186 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
187 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
188 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
189 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
192 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char *name,
195 struct ll_crypto_cipher *rtn = crypto_alloc_blkcipher(name, type, mask);
197 return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
200 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
201 u8 *key, unsigned int *keylen,
202 struct scatterlist *sg,
203 unsigned int size, u8 *result)
205 struct hash_desc desc;
209 rv = crypto_hash_setkey(desc.tfm, key, *keylen);
211 CERROR("failed to hash setkey: %d\n", rv);
214 return crypto_hash_digest(&desc, sg, size, result);
217 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
219 return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
222 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
224 return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
227 #define ll_crypto_hash_blocksize(tfm) crypto_hash_blocksize(tfm)
228 #define ll_crypto_hash_digestsize(tfm) crypto_hash_digestsize(tfm)
229 #define ll_crypto_blkcipher_ivsize(tfm) crypto_blkcipher_ivsize(tfm)
230 #define ll_crypto_blkcipher_blocksize(tfm) crypto_blkcipher_blocksize(tfm)
231 #define ll_crypto_free_hash(tfm) crypto_free_hash(tfm)
232 #define ll_crypto_free_blkcipher(tfm) crypto_free_blkcipher(tfm)
234 #ifdef for_each_possible_cpu
235 #define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
236 #elif defined(for_each_cpu)
237 #define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
240 #ifdef HAVE_BIO_ENDIO_2ARG
241 #define cfs_bio_io_error(a,b) bio_io_error((a))
242 #define cfs_bio_endio(a,b,c) bio_endio((a),(c))
244 #define cfs_bio_io_error(a,b) bio_io_error((a),(b))
245 #define cfs_bio_endio(a,b,c) bio_endio((a),(b),(c))
248 #ifndef HAVE_SIMPLE_SETATTR
249 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
252 #ifndef SLAB_DESTROY_BY_RCU
253 #define SLAB_DESTROY_BY_RCU 0
257 ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
261 if (sb->s_qcop->quota_on) {
262 #ifdef HAVE_QUOTA_ON_USE_PATH
265 rc = kern_path(name, LOOKUP_FOLLOW, &path);
269 rc = sb->s_qcop->quota_on(sb, off, ver
270 #ifdef HAVE_QUOTA_ON_USE_PATH
275 #ifdef HAVE_QUOTA_ON_5ARGS
279 #ifdef HAVE_QUOTA_ON_USE_PATH
288 static inline int ll_quota_off(struct super_block *sb, int off, int remount)
290 if (sb->s_qcop->quota_off) {
291 return sb->s_qcop->quota_off(sb, off
292 #ifdef HAVE_QUOTA_OFF_3ARGS
301 #ifndef HAVE_DQUOT_SUSPEND
302 # define ll_vfs_dq_init vfs_dq_init
303 # define ll_vfs_dq_drop vfs_dq_drop
304 # define ll_vfs_dq_transfer vfs_dq_transfer
305 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
307 # define ll_vfs_dq_init dquot_initialize
308 # define ll_vfs_dq_drop dquot_drop
309 # define ll_vfs_dq_transfer dquot_transfer
310 # define ll_vfs_dq_off(sb, remount) dquot_suspend(sb, -1)
313 #ifndef HAVE_BLKDEV_GET_BY_DEV
314 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
317 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
318 #define blk_queue_max_segments(rq, seg) \
319 do { blk_queue_max_phys_segments(rq, seg); \
320 blk_queue_max_hw_segments(rq, seg); } while (0)
322 #define queue_max_phys_segments(rq) queue_max_segments(rq)
323 #define queue_max_hw_segments(rq) queue_max_segments(rq)
326 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
327 #define ll_kmap_atomic(a, b) kmap_atomic(a)
328 #define ll_kunmap_atomic(a, b) kunmap_atomic(a)
330 #define ll_kmap_atomic(a, b) kmap_atomic(a, b)
331 #define ll_kunmap_atomic(a, b) kunmap_atomic(a, b)
334 #ifndef HAVE_CLEAR_INODE
335 #define clear_inode(i) end_writeback(i)
338 #ifdef HAVE_DENTRY_D_ALIAS_HLIST
339 #define ll_d_hlist_node hlist_node
340 #define ll_d_hlist_empty(list) hlist_empty(list)
341 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
342 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
343 #ifdef HAVE_HLIST_FOR_EACH_3ARG
344 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
345 p = NULL; hlist_for_each_entry(dentry, i_dentry, alias)
347 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
348 hlist_for_each_entry(dentry, p, i_dentry, alias)
350 #define DECLARE_LL_D_HLIST_NODE_PTR(name) struct ll_d_hlist_node *name
352 #define ll_d_hlist_node list_head
353 #define ll_d_hlist_empty(list) list_empty(list)
354 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
355 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
356 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
357 list_for_each_entry(dentry, i_dentry, alias)
358 #define DECLARE_LL_D_HLIST_NODE_PTR(name) /* nothing */
362 #ifndef HAVE_BI_HW_SEGMENTS
363 #define bio_hw_segments(q, bio) 0
370 # define NO_QUOTA (-EDQUOT)
374 #define SEEK_DATA 3 /* seek to the next data */
377 #define SEEK_HOLE 4 /* seek to the next hole */
380 #ifndef FMODE_UNSIGNED_OFFSET
381 #define FMODE_UNSIGNED_OFFSET ((__force fmode_t)0x2000)
384 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
385 # define ext2_set_bit __test_and_set_bit_le
386 # define ext2_clear_bit __test_and_clear_bit_le
387 # define ext2_test_bit test_bit_le
388 # define ext2_find_first_zero_bit find_first_zero_bit_le
389 # define ext2_find_next_zero_bit find_next_zero_bit_le
392 #ifdef ATTR_TIMES_SET
393 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
395 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
398 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
399 # define lm_compare_owner fl_compare_owner
403 * After 3.1, kernel's nameidata.intent.open.flags is different
404 * with lustre's lookup_intent.it_flags, as lustre's it_flags'
405 * lower bits equal to FMODE_xxx while kernel doesn't transliterate
406 * lower bits of nameidata.intent.open.flags to FMODE_xxx.
408 #include <linux/version.h>
409 static inline int ll_namei_to_lookup_intent_flag(int flag)
411 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
412 flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
417 #ifdef HAVE_VOID_MAKE_REQUEST_FN
418 # define ll_mrf_ret void
419 # define LL_MRF_RETURN(rc)
421 # define ll_mrf_ret int
422 # define LL_MRF_RETURN(rc) RETURN(rc)
425 #include <linux/fs.h>
426 #ifndef HAVE_PROTECT_I_NLINK
427 static inline void set_nlink(struct inode *inode, unsigned int nlink)
429 inode->i_nlink = nlink;
433 #ifdef HAVE_INODEOPS_USE_UMODE_T
434 # define ll_umode_t umode_t
436 # define ll_umode_t int
439 #include <linux/dcache.h>
440 #ifndef HAVE_D_MAKE_ROOT
441 static inline struct dentry *d_make_root(struct inode *root)
443 struct dentry *res = d_alloc_root(root);
445 if (res == NULL && root)
452 #ifdef HAVE_DIRTY_INODE_HAS_FLAG
453 # define ll_dirty_inode(inode, flag) (inode)->i_sb->s_op->dirty_inode((inode), flag)
455 # define ll_dirty_inode(inode, flag) (inode)->i_sb->s_op->dirty_inode((inode))
458 #endif /* _COMPAT25_H */