Whamcloud - gitweb
24412f261f5c04375bd465297fedfbb48444f4ea
[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_4ARGS_VFS_SYMLINK
105 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
106                 vfs_symlink(dir, dentry, path, mode)
107 #else
108 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
109                        vfs_symlink(dir, dentry, path)
110 #endif
111
112 #if !defined(HAVE_FILE_LLSEEK_SIZE) || defined(HAVE_FILE_LLSEEK_SIZE_5ARGS)
113 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
114                 generic_file_llseek_size(file, offset, origin, maxbytes, eof);
115 #else
116 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
117                 generic_file_llseek_size(file, offset, origin, maxbytes);
118 #endif
119
120 #ifdef HAVE_INODE_DIO_WAIT
121 /* inode_dio_wait(i) use as-is for write lock */
122 # define inode_dio_write_done(i)        do {} while (0) /* for write unlock */
123 # define inode_dio_read(i)              atomic_inc(&(i)->i_dio_count)
124 /* inode_dio_done(i) use as-is for read unlock */
125 #else
126 # define inode_dio_wait(i)              down_write(&(i)->i_alloc_sem)
127 # define inode_dio_write_done(i)        up_write(&(i)->i_alloc_sem)
128 # define inode_dio_read(i)              down_read(&(i)->i_alloc_sem)
129 # define inode_dio_done(i)              up_read(&(i)->i_alloc_sem)
130 #endif
131
132 #ifndef FS_HAS_FIEMAP
133 #define FS_HAS_FIEMAP                   (0)
134 #endif
135
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)
142 {
143         struct hash_desc desc;
144         int              rv;
145         desc.tfm   = tfm;
146         desc.flags = 0;
147         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
148         if (rv) {
149                 CERROR("failed to hash setkey: %d\n", rv);
150                 return rv;
151         }
152         return crypto_hash_digest(&desc, sg, size, result);
153 }
154
155 static inline
156 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
157 {
158         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
159 }
160
161 #ifdef for_each_possible_cpu
162 #define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
163 #elif defined(for_each_cpu)
164 #define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
165 #endif
166
167 #ifndef HAVE_SIMPLE_SETATTR
168 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
169 #endif
170
171 #ifndef SLAB_DESTROY_BY_RCU
172 #define SLAB_DESTROY_BY_RCU 0
173 #endif
174
175 #ifndef HAVE_DQUOT_SUSPEND
176 # define ll_vfs_dq_init             vfs_dq_init
177 # define ll_vfs_dq_drop             vfs_dq_drop
178 # define ll_vfs_dq_transfer         vfs_dq_transfer
179 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
180 #else
181 # define ll_vfs_dq_init             dquot_initialize
182 # define ll_vfs_dq_drop             dquot_drop
183 # define ll_vfs_dq_transfer         dquot_transfer
184 # define ll_vfs_dq_off(sb, remount) dquot_suspend(sb, -1)
185 #endif
186
187 #ifndef HAVE_BLKDEV_GET_BY_DEV
188 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
189 #endif
190
191 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
192 #define blk_queue_max_segments(rq, seg)                      \
193         do { blk_queue_max_phys_segments(rq, seg);           \
194              blk_queue_max_hw_segments(rq, seg); } while (0)
195 #else
196 #define queue_max_phys_segments(rq)       queue_max_segments(rq)
197 #define queue_max_hw_segments(rq)         queue_max_segments(rq)
198 #endif
199
200 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
201 #define ll_kmap_atomic(a, b)    kmap_atomic(a)
202 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a)
203 #else
204 #define ll_kmap_atomic(a, b)    kmap_atomic(a, b)
205 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a, b)
206 #endif
207
208 #ifndef HAVE_CLEAR_INODE
209 #define clear_inode(i)          end_writeback(i)
210 #endif
211
212 #ifdef HAVE_DENTRY_D_ALIAS_HLIST
213 #define ll_d_hlist_node hlist_node
214 #define ll_d_hlist_empty(list) hlist_empty(list)
215 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
216 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
217 #ifdef HAVE_HLIST_FOR_EACH_3ARG
218 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
219         p = NULL; hlist_for_each_entry(dentry, i_dentry, alias)
220 #else
221 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
222         hlist_for_each_entry(dentry, p, i_dentry, alias)
223 #endif
224 #define DECLARE_LL_D_HLIST_NODE_PTR(name) struct ll_d_hlist_node *name
225 #else
226 #define ll_d_hlist_node list_head
227 #define ll_d_hlist_empty(list) list_empty(list)
228 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
229 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
230 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
231         list_for_each_entry(dentry, i_dentry, alias)
232 #define DECLARE_LL_D_HLIST_NODE_PTR(name) /* nothing */
233 #endif
234
235 #ifndef QUOTA_OK
236 # define QUOTA_OK 0
237 #endif
238 #ifndef NO_QUOTA
239 # define NO_QUOTA (-EDQUOT)
240 #endif
241
242 #ifndef SEEK_DATA
243 #define SEEK_DATA      3       /* seek to the next data */
244 #endif
245 #ifndef SEEK_HOLE
246 #define SEEK_HOLE      4       /* seek to the next hole */
247 #endif
248
249 #ifndef FMODE_UNSIGNED_OFFSET
250 #define FMODE_UNSIGNED_OFFSET   ((__force fmode_t)0x2000)
251 #endif
252
253 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
254 # define ext2_set_bit             __test_and_set_bit_le
255 # define ext2_clear_bit           __test_and_clear_bit_le
256 # define ext2_test_bit            test_bit_le
257 # define ext2_find_first_zero_bit find_first_zero_bit_le
258 # define ext2_find_next_zero_bit  find_next_zero_bit_le
259 #endif
260
261 #ifdef ATTR_TIMES_SET
262 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
263 #else
264 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
265 #endif
266
267 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
268 # define lm_compare_owner       fl_compare_owner
269 #endif
270
271 /*
272  * After 3.1, kernel's nameidata.intent.open.flags is different
273  * with lustre's lookup_intent.it_flags, as lustre's it_flags'
274  * lower bits equal to FMODE_xxx while kernel doesn't transliterate
275  * lower bits of nameidata.intent.open.flags to FMODE_xxx.
276  * */
277 #include <linux/version.h>
278 static inline int ll_namei_to_lookup_intent_flag(int flag)
279 {
280 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
281         flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
282 #endif
283         return flag;
284 }
285
286 #ifdef HAVE_VOID_MAKE_REQUEST_FN
287 # define ll_mrf_ret void
288 # define LL_MRF_RETURN(rc)
289 #else
290 # define ll_mrf_ret int
291 # define LL_MRF_RETURN(rc) RETURN(rc)
292 #endif
293
294 #include <linux/fs.h>
295 #ifndef HAVE_PROTECT_I_NLINK
296 static inline void set_nlink(struct inode *inode, unsigned int nlink)
297 {
298         inode->i_nlink = nlink;
299 }
300 #endif
301
302 #ifdef HAVE_INODEOPS_USE_UMODE_T
303 # define ll_umode_t     umode_t
304 #else
305 # define ll_umode_t     int
306 #endif
307
308 #include <linux/dcache.h>
309 #ifndef HAVE_D_MAKE_ROOT
310 static inline struct dentry *d_make_root(struct inode *root)
311 {
312         struct dentry *res = d_alloc_root(root);
313
314         if (res == NULL && root)
315                 iput(root);
316
317         return res;
318 }
319 #endif
320
321 #ifdef HAVE_DIRTY_INODE_HAS_FLAG
322 # define ll_dirty_inode(inode, flag)    (inode)->i_sb->s_op->dirty_inode((inode), flag)
323 #else
324 # define ll_dirty_inode(inode, flag)    (inode)->i_sb->s_op->dirty_inode((inode))
325 #endif
326
327 #ifdef HAVE_FILE_F_INODE
328 # define set_file_inode(file, inode)    (file)->f_inode = inode
329 #else
330 # define set_file_inode(file, inode)
331 #endif
332
333 #ifdef HAVE_OLDSIZE_TRUNCATE_PAGECACHE
334 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, 0, size)
335 #else
336 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, size)
337 #endif
338
339 #endif /* _COMPAT25_H */