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, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef _LUSTRE_COMPAT_H
38 #define _LUSTRE_COMPAT_H
40 #include <linux/fs_struct.h>
41 #include <linux/namei.h>
42 #include <linux/bio.h>
44 #include <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 #ifndef MODULE_ALIAS_FS
92 #define MODULE_ALIAS_FS(name)
95 #define LTIME_S(time) (time.tv_sec)
97 #ifdef HAVE_GENERIC_PERMISSION_2ARGS
98 # define ll_generic_permission(inode, mask, flags, check_acl) \
99 generic_permission(inode, mask)
100 #elif defined HAVE_GENERIC_PERMISSION_4ARGS
101 # define ll_generic_permission(inode, mask, flags, check_acl) \
102 generic_permission(inode, mask, flags, check_acl)
104 # define ll_generic_permission(inode, mask, flags, check_acl) \
105 generic_permission(inode, mask, check_acl)
108 #ifdef HAVE_4ARGS_VFS_SYMLINK
109 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
110 vfs_symlink(dir, dentry, path, mode)
112 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
113 vfs_symlink(dir, dentry, path)
116 #if !defined(HAVE_FILE_LLSEEK_SIZE) || defined(HAVE_FILE_LLSEEK_SIZE_5ARGS)
117 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
118 generic_file_llseek_size(file, offset, origin, maxbytes, eof);
120 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
121 generic_file_llseek_size(file, offset, origin, maxbytes);
124 #ifdef HAVE_INODE_DIO_WAIT
125 /* inode_dio_wait(i) use as-is for write lock */
126 # define inode_dio_write_done(i) do {} while (0) /* for write unlock */
128 # define inode_dio_wait(i) down_write(&(i)->i_alloc_sem)
129 # define inode_dio_write_done(i) up_write(&(i)->i_alloc_sem)
132 #ifndef FS_HAS_FIEMAP
133 #define FS_HAS_FIEMAP (0)
136 /* add a lustre compatible layer for crypto API */
137 #include <linux/crypto.h>
138 static inline int ll_crypto_hmac(struct crypto_hash *tfm,
139 u8 *key, unsigned int *keylen,
140 struct scatterlist *sg,
141 unsigned int size, u8 *result)
143 struct hash_desc desc;
147 rv = crypto_hash_setkey(desc.tfm, key, *keylen);
149 CERROR("failed to hash setkey: %d\n", rv);
152 return crypto_hash_digest(&desc, sg, size, result);
156 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
158 return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
161 #ifndef HAVE_SIMPLE_SETATTR
162 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
165 #ifndef SLAB_DESTROY_BY_RCU
166 #define SLAB_DESTROY_BY_RCU 0
169 #ifndef HAVE_DQUOT_SUSPEND
170 # define ll_vfs_dq_init vfs_dq_init
171 # define ll_vfs_dq_drop vfs_dq_drop
172 # define ll_vfs_dq_transfer vfs_dq_transfer
173 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
175 # define ll_vfs_dq_init dquot_initialize
176 # define ll_vfs_dq_drop dquot_drop
177 # define ll_vfs_dq_transfer dquot_transfer
178 # define ll_vfs_dq_off(sb, remount) dquot_suspend(sb, -1)
181 #ifndef HAVE_BLKDEV_GET_BY_DEV
182 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
185 #ifdef HAVE_BVEC_ITER
186 #define bio_idx(bio) (bio->bi_iter.bi_idx)
187 #define bio_set_sector(bio, sector) (bio->bi_iter.bi_sector = sector)
188 #define bvl_to_page(bvl) (bvl.bv_page)
190 #define bio_idx(bio) (bio->bi_idx)
191 #define bio_set_sector(bio, sector) (bio->bi_sector = sector)
192 #define bio_sectors(bio) ((bio)->bi_size >> 9)
193 #ifndef HAVE_BIO_END_SECTOR
194 #define bio_end_sector(bio) (bio->bi_sector + bio_sectors(bio))
196 #define bvl_to_page(bvl) (bvl->bv_page)
199 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
200 #define blk_queue_max_segments(rq, seg) \
201 do { blk_queue_max_phys_segments(rq, seg); \
202 blk_queue_max_hw_segments(rq, seg); } while (0)
204 #define queue_max_phys_segments(rq) queue_max_segments(rq)
205 #define queue_max_hw_segments(rq) queue_max_segments(rq)
208 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
209 #define ll_kmap_atomic(a, b) kmap_atomic(a)
210 #define ll_kunmap_atomic(a, b) kunmap_atomic(a)
212 #define ll_kmap_atomic(a, b) kmap_atomic(a, b)
213 #define ll_kunmap_atomic(a, b) kunmap_atomic(a, b)
216 #ifndef HAVE_CLEAR_INODE
217 #define clear_inode(i) end_writeback(i)
220 #ifndef HAVE_DENTRY_D_CHILD
221 #define d_child d_u.d_child
224 #ifdef HAVE_DENTRY_D_U_D_ALIAS
225 #define d_alias d_u.d_alias
228 #ifndef DATA_FOR_LLITE_IS_LIST
229 #define ll_d_hlist_node hlist_node
230 #define ll_d_hlist_empty(list) hlist_empty(list)
231 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
232 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
233 # ifdef HAVE_HLIST_FOR_EACH_3ARG
234 # define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
235 p = NULL; hlist_for_each_entry(dentry, i_dentry, d_alias)
237 # define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
238 hlist_for_each_entry(dentry, p, i_dentry, d_alias)
240 #define DECLARE_LL_D_HLIST_NODE_PTR(name) struct ll_d_hlist_node *name
242 #define ll_d_hlist_node list_head
243 #define ll_d_hlist_empty(list) list_empty(list)
244 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
245 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
246 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry) \
247 list_for_each_entry(dentry, i_dentry, d_alias)
248 #define DECLARE_LL_D_HLIST_NODE_PTR(name) /* nothing */
249 #endif /* !DATA_FOR_LLITE_IS_LIST */
255 # define NO_QUOTA (-EDQUOT)
259 #define SEEK_DATA 3 /* seek to the next data */
262 #define SEEK_HOLE 4 /* seek to the next hole */
265 #ifndef FMODE_UNSIGNED_OFFSET
266 #define FMODE_UNSIGNED_OFFSET ((__force fmode_t)0x2000)
269 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
270 # define ext2_set_bit __test_and_set_bit_le
271 # define ext2_clear_bit __test_and_clear_bit_le
272 # define ext2_test_bit test_bit_le
273 # define ext2_find_first_zero_bit find_first_zero_bit_le
274 # define ext2_find_next_zero_bit find_next_zero_bit_le
277 #ifdef ATTR_TIMES_SET
278 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
280 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
283 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
284 # define lm_compare_owner fl_compare_owner
288 * After 3.1, kernel's nameidata.intent.open.flags is different
289 * with lustre's lookup_intent.it_flags, as lustre's it_flags'
290 * lower bits equal to FMODE_xxx while kernel doesn't transliterate
291 * lower bits of nameidata.intent.open.flags to FMODE_xxx.
293 #include <linux/version.h>
294 static inline int ll_namei_to_lookup_intent_flag(int flag)
296 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
297 flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
302 #ifdef HAVE_QC_MAKE_REQUEST_FN
303 # define ll_mrf_ret blk_qc_t
304 # define LL_MRF_RETURN(rc) RETURN(BLK_QC_T_NONE)
306 # ifdef HAVE_VOID_MAKE_REQUEST_FN
307 # define ll_mrf_ret void
308 # define LL_MRF_RETURN(rc)
310 # define ll_mrf_ret int
311 # define LL_MRF_RETURN(rc) RETURN(rc)
315 #include <linux/fs.h>
316 #ifndef HAVE_PROTECT_I_NLINK
317 static inline void set_nlink(struct inode *inode, unsigned int nlink)
319 inode->i_nlink = nlink;
323 #ifdef HAVE_INODEOPS_USE_UMODE_T
324 # define ll_umode_t umode_t
326 # define ll_umode_t int
329 #include <linux/dcache.h>
330 #ifndef HAVE_D_MAKE_ROOT
331 static inline struct dentry *d_make_root(struct inode *root)
333 struct dentry *res = d_alloc_root(root);
335 if (res == NULL && root)
342 #ifdef HAVE_DIRTY_INODE_HAS_FLAG
343 # define ll_dirty_inode(inode, flag) (inode)->i_sb->s_op->dirty_inode((inode), flag)
345 # define ll_dirty_inode(inode, flag) (inode)->i_sb->s_op->dirty_inode((inode))
348 #ifdef HAVE_FILE_F_INODE
349 # define set_file_inode(file, inode) (file)->f_inode = inode
351 # define set_file_inode(file, inode)
354 #ifdef HAVE_OLDSIZE_TRUNCATE_PAGECACHE
355 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, 0, size)
357 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, size)
360 #ifdef HAVE_VFS_RENAME_5ARGS
361 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d, NULL)
362 #elif defined HAVE_VFS_RENAME_6ARGS
363 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d, NULL, 0)
365 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d)
368 #ifdef HAVE_VFS_UNLINK_3ARGS
369 #define ll_vfs_unlink(a, b) vfs_unlink(a, b, NULL)
371 #define ll_vfs_unlink(a, b) vfs_unlink(a, b)
374 #ifndef HAVE_RADIX_EXCEPTION_ENTRY
375 static inline int radix_tree_exceptional_entry(void *arg)
381 #ifndef HAVE_TRUNCATE_INODE_PAGES_FINAL
382 static inline void truncate_inode_pages_final(struct address_space *map)
384 truncate_inode_pages(map, 0);
385 /* Workaround for LU-118 */
387 spin_lock_irq(&map->tree_lock);
388 spin_unlock_irq(&map->tree_lock);
389 } /* Workaround end */
394 #define SIZE_MAX (~(size_t)0)
397 #ifdef HAVE_SECURITY_IINITSEC_CALLBACK
398 # define ll_security_inode_init_security(inode, dir, name, value, len, \
399 initxattrs, dentry) \
400 security_inode_init_security(inode, dir, &((dentry)->d_name), \
402 #elif defined HAVE_SECURITY_IINITSEC_QSTR
403 # define ll_security_inode_init_security(inode, dir, name, value, len, \
404 initxattrs, dentry) \
405 security_inode_init_security(inode, dir, &((dentry)->d_name), \
407 #else /* !HAVE_SECURITY_IINITSEC_CALLBACK && !HAVE_SECURITY_IINITSEC_QSTR */
408 # define ll_security_inode_init_security(inode, dir, name, value, len, \
409 initxattrs, dentry) \
410 security_inode_init_security(inode, dir, name, value, len)
413 #ifndef bio_for_each_segment_all /* since kernel version 3.9 */
414 #ifdef HAVE_BVEC_ITER
415 #define bio_for_each_segment_all(bv, bio, it) \
416 for (it = 0, bv = (bio)->bi_io_vec; it < (bio)->bi_vcnt; it++, bv++)
418 #define bio_for_each_segment_all(bv, bio, it) bio_for_each_segment(bv, bio, it)
422 #endif /* _LUSTRE_COMPAT_H */