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