Whamcloud - gitweb
LU-1756 kernel: cleanup lustre_compat25.h
[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, 2012, 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 #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)
57 {
58         struct path path;
59         struct path old_pwd;
60
61         path.mnt = mnt;
62         path.dentry = dentry;
63         LOCK_FS_STRUCT(fs);
64         old_pwd = fs->pwd;
65         path_get(&path);
66         fs->pwd = path;
67         UNLOCK_FS_STRUCT(fs);
68
69         if (old_pwd.dentry)
70                 path_put(&old_pwd);
71 }
72
73 #else
74
75 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
76                 struct dentry *dentry)
77 {
78         struct dentry *old_pwd;
79         struct vfsmount *old_pwdmnt;
80
81         LOCK_FS_STRUCT(fs);
82         old_pwd = fs->pwd;
83         old_pwdmnt = fs->pwdmnt;
84         fs->pwdmnt = mntget(mnt);
85         fs->pwd = dget(dentry);
86         UNLOCK_FS_STRUCT(fs);
87
88         if (old_pwd) {
89                 dput(old_pwd);
90                 mntput(old_pwdmnt);
91         }
92 }
93 #endif
94
95 /*
96  * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
97  * ATTR_* attributes (see bug 13828)
98  */
99 #define ATTR_BLOCKS    (1 << 27)
100
101 #define current_ngroups current_cred()->group_info->ngroups
102 #define current_groups current_cred()->group_info->small_block
103
104 /*
105  * OBD need working random driver, thus all our
106  * initialization routines must be called after device
107  * driver initialization
108  */
109 #ifndef MODULE
110 #undef module_init
111 #define module_init(a)     late_initcall(a)
112 #endif
113
114 #ifndef HAVE_TRYLOCK_PAGE
115 #define trylock_page(page)              (!TestSetPageLocked(page))
116 #endif
117
118 #define LTIME_S(time)                   (time.tv_sec)
119
120 #ifdef HAVE_EXPORT_INODE_PERMISSION
121 #define ll_permission(inode,mask,nd)    inode_permission(inode,mask)
122 #else
123 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
124 #endif
125
126 #ifdef HAVE_GENERIC_PERMISSION_2ARGS
127 # define ll_generic_permission(inode, mask, flags, check_acl) \
128          generic_permission(inode, mask)
129 #elif defined HAVE_GENERIC_PERMISSION_4ARGS
130 # define ll_generic_permission(inode, mask, flags, check_acl) \
131          generic_permission(inode, mask, flags, check_acl)
132 #else
133 # define ll_generic_permission(inode, mask, flags, check_acl) \
134          generic_permission(inode, mask, check_acl)
135 #endif
136
137 #ifdef HAVE_BLKDEV_PUT_2ARGS
138 #define ll_blkdev_put(a, b) blkdev_put(a, b)
139 #else
140 #define ll_blkdev_put(a, b) blkdev_put(a)
141 #endif
142
143 static inline struct file *ll_dentry_open(struct dentry *dentry,
144                                           struct vfsmount *mnt, int flags,
145                                           const struct cred *cred)
146 {
147 #ifdef HAVE_DENTRY_OPEN_USE_PATH
148         struct path path = { .mnt = mnt, .dentry = dentry };
149         return dentry_open(&path, flags, cred);
150 #elif defined HAVE_DENTRY_OPEN_4ARGS
151         return dentry_open(dentry, mnt, flags, cred);
152 #else
153         return dentry_open(dentry, mnt, flags);
154 #endif
155 }
156
157 #ifdef HAVE_SECURITY_PLUG
158 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
159                 vfs_symlink(dir, dentry, mnt, path, mode)
160 #else
161 #ifdef HAVE_4ARGS_VFS_SYMLINK
162 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
163                 vfs_symlink(dir, dentry, path, mode)
164 #else
165 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
166                        vfs_symlink(dir, dentry, path)
167 #endif
168
169 #endif
170
171 #ifdef HAVE_INODE_DIO_WAIT
172 /* inode_dio_wait(i) use as-is for write lock */
173 # define inode_dio_write_done(i)        do {} while (0) /* for write unlock */
174 # define inode_dio_read(i)              atomic_inc(&(i)->i_dio_count)
175 /* inode_dio_done(i) use as-is for read unlock */
176 #else
177 # define inode_dio_wait(i)              down_write(&(i)->i_alloc_sem)
178 # define inode_dio_write_done(i)        up_write(&(i)->i_alloc_sem)
179 # define inode_dio_read(i)              down_read(&(i)->i_alloc_sem)
180 # define inode_dio_done(i)              up_read(&(i)->i_alloc_sem)
181 #endif
182
183 #ifdef HAVE_RW_TREE_LOCK
184 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
185 #define TREE_READ_UNLOCK_IRQ(mapping)   read_unlock_irq(&(mapping)->tree_lock)
186 #else
187 #define TREE_READ_LOCK_IRQ(mapping)     spin_lock_irq(&(mapping)->tree_lock)
188 #define TREE_READ_UNLOCK_IRQ(mapping)   spin_unlock_irq(&(mapping)->tree_lock)
189 #endif
190
191 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
192 #define ll_unregister_blkdev(a,b)       unregister_blkdev((a),(b))
193 #else
194 static inline
195 int ll_unregister_blkdev(unsigned int dev, const char *name)
196 {
197         unregister_blkdev(dev, name);
198         return 0;
199 }
200 #endif
201
202 #ifdef HAVE_INVALIDATE_BDEV_2ARG
203 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a),(b))
204 #else
205 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a))
206 #endif
207
208 #ifndef FS_HAS_FIEMAP
209 #define FS_HAS_FIEMAP                   (0)
210 #endif
211
212 #ifndef HAVE_FS_RENAME_DOES_D_MOVE
213 #define FS_RENAME_DOES_D_MOVE           FS_ODD_RENAME
214 #endif
215
216 #ifndef HAVE_D_OBTAIN_ALIAS
217 /* The old d_alloc_anon() didn't free the inode reference on error
218  * like d_obtain_alias().  Hide that difference/inconvenience here. */
219 static inline struct dentry *d_obtain_alias(struct inode *inode)
220 {
221         struct dentry *anon = d_alloc_anon(inode);
222
223         if (anon == NULL) {
224                 iput(inode);
225                 anon = ERR_PTR(-ENOMEM);
226         }
227
228         return anon;
229 }
230 #endif
231
232 /* add a lustre compatible layer for crypto API */
233 #include <linux/crypto.h>
234 #ifdef HAVE_ASYNC_BLOCK_CIPHER
235 #define ll_crypto_hash          crypto_hash
236 #define ll_crypto_cipher        crypto_blkcipher
237 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
238 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
239 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
240 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
241 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
242 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
243                 crypto_blkcipher_setkey(tfm, key, keylen)
244 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
245                 crypto_blkcipher_set_iv(tfm, src, len)
246 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
247                 crypto_blkcipher_get_iv(tfm, dst, len)
248 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
249                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
250 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
251                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
252 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
253                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
254 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
255                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
256
257 static inline
258 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char *name,
259                                                    u32 type, u32 mask)
260 {
261         struct ll_crypto_cipher *rtn = crypto_alloc_blkcipher(name, type, mask);
262
263         return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
264 }
265
266 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
267                                  u8 *key, unsigned int *keylen,
268                                  struct scatterlist *sg,
269                                  unsigned int size, u8 *result)
270 {
271         struct hash_desc desc;
272         int              rv;
273         desc.tfm   = tfm;
274         desc.flags = 0;
275         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
276         if (rv) {
277                 CERROR("failed to hash setkey: %d\n", rv);
278                 return rv;
279         }
280         return crypto_hash_digest(&desc, sg, size, result);
281 }
282 static inline
283 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
284 {
285         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
286 }
287 static inline
288 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
289 {
290         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
291 }
292
293 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
294 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
295 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
296 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
297 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
298 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
299 #else /* HAVE_ASYNC_BLOCK_CIPHER */
300 #include <linux/scatterlist.h>
301 #define ll_crypto_hash          crypto_tfm
302 #define ll_crypto_cipher        crypto_tfm
303 #ifndef HAVE_STRUCT_HASH_DESC
304 struct hash_desc {
305         struct ll_crypto_hash *tfm;
306         u32                    flags;
307 };
308 #endif
309 #ifndef HAVE_STRUCT_BLKCIPHER_DESC
310 struct blkcipher_desc {
311         struct ll_crypto_cipher *tfm;
312         void                    *info;
313         u32                      flags;
314 };
315 #endif
316 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
317         crypto_cipher_setkey(tfm, key, keylen)
318 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
319         crypto_cipher_set_iv(tfm, src, len)
320 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
321         crypto_cipher_get_iv(tfm, dst, len)
322 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
323         crypto_cipher_encrypt((desc)->tfm, dst, src, bytes)
324 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
325         crypto_cipher_decrypt((desc)->tfm, dst, src, bytes)
326 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
327         crypto_cipher_decrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
328 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
329         crypto_cipher_encrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
330
331 static inline
332 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char * algname,
333                                                    u32 type, u32 mask)
334 {
335         struct ll_crypto_cipher *rtn;
336         char                     buf[CRYPTO_MAX_ALG_NAME + 1];
337         const char              *pan = algname;
338         u32                      flag = 0;
339
340         if (strncmp("cbc(", algname, 4) == 0)
341                 flag |= CRYPTO_TFM_MODE_CBC;
342         else if (strncmp("ecb(", algname, 4) == 0)
343                 flag |= CRYPTO_TFM_MODE_ECB;
344         if (flag) {
345                 char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
346                 if (vp) {
347                         memcpy(buf, algname + 4, vp - algname - 4);
348                         buf[vp - algname - 4] = '\0';
349                         pan = buf;
350                 } else {
351                         flag = 0;
352                 }
353         }
354         rtn = crypto_alloc_tfm(pan, flag);
355         return (rtn == NULL ?  ERR_PTR(-ENOMEM) : rtn);
356 }
357
358 static inline
359 struct ll_crypto_hash *ll_crypto_alloc_hash(const char *alg, u32 type, u32 mask)
360 {
361         char        buf[CRYPTO_MAX_ALG_NAME + 1];
362         const char *pan = alg;
363
364         if (strncmp("hmac(", alg, 5) == 0) {
365                 char *vp = strnchr(alg, CRYPTO_MAX_ALG_NAME, ')');
366                 if (vp) {
367                         memcpy(buf, alg+ 5, vp - alg- 5);
368                         buf[vp - alg - 5] = 0x00;
369                         pan = buf;
370                 }
371         }
372         return crypto_alloc_tfm(pan, 0);
373 }
374 static inline int ll_crypto_hash_init(struct hash_desc *desc)
375 {
376        crypto_digest_init(desc->tfm); return 0;
377 }
378 static inline int ll_crypto_hash_update(struct hash_desc *desc,
379                                         struct scatterlist *sg,
380                                         unsigned int nbytes)
381 {
382         struct scatterlist *sl = sg;
383         unsigned int        count;
384                 /*
385                  * This way is very weakness. We must ensure that
386                  * the sum of sg[0..i]->length isn't greater than nbytes.
387                  * In the upstream kernel the crypto_hash_update() also
388                  * via the nbytes computed the count of sg[...].
389                  * The old style is more safely. but it gone.
390                  */
391         for (count = 0; nbytes > 0; count ++, sl ++) {
392                 nbytes -= sl->length;
393         }
394         crypto_digest_update(desc->tfm, sg, count); return 0;
395 }
396 static inline int ll_crypto_hash_final(struct hash_desc *desc, u8 *out)
397 {
398         crypto_digest_final(desc->tfm, out); return 0;
399 }
400 static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
401                                  u8 *key, unsigned int *keylen,
402                                  struct scatterlist *sg,
403                                  unsigned int nbytes,
404                                  u8 *out)
405 {
406         struct scatterlist *sl = sg;
407         int                 count;
408         for (count = 0; nbytes > 0; count ++, sl ++) {
409                 nbytes -= sl->length;
410         }
411         crypto_hmac(tfm, key, keylen, sg, count, out);
412         return 0;
413 }
414
415 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_digest_setkey(tfm, key, keylen)
416 #define ll_crypto_blkcipher_blocksize(tfm)      crypto_tfm_alg_blocksize(tfm)
417 #define ll_crypto_blkcipher_ivsize(tfm) crypto_tfm_alg_ivsize(tfm)
418 #define ll_crypto_hash_digestsize(tfm)  crypto_tfm_alg_digestsize(tfm)
419 #define ll_crypto_hash_blocksize(tfm)   crypto_tfm_alg_blocksize(tfm)
420 #define ll_crypto_free_hash(tfm)        crypto_free_tfm(tfm)
421 #define ll_crypto_free_blkcipher(tfm)   crypto_free_tfm(tfm)
422 #define ll_crypto_tfm_alg_min_keysize   crypto_tfm_alg_min_keysize
423 #define ll_crypto_tfm_alg_max_keysize   crypto_tfm_alg_max_keysize
424 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
425
426 #ifdef HAVE_SECURITY_PLUG
427 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
428 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
429 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
430 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
431 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
432                 vfs_mknod(dir,entry,mnt,mode,dev)
433 #define ll_security_inode_unlink(dir,entry,mnt)         \
434                 security_inode_unlink(dir,entry,mnt)
435 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
436                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
437 #else
438 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
439 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
440 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
441 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
442 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
443 #define ll_security_inode_unlink(dir,entry,mnt) security_inode_unlink(dir,entry)
444 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
445                 vfs_rename(old,old_dir,new,new_dir)
446 #endif /* HAVE_SECURITY_PLUG */
447
448 #ifdef for_each_possible_cpu
449 #define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
450 #elif defined(for_each_cpu)
451 #define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
452 #endif
453
454 #ifdef HAVE_BIO_ENDIO_2ARG
455 #define cfs_bio_io_error(a,b)   bio_io_error((a))
456 #define cfs_bio_endio(a,b,c)    bio_endio((a),(c))
457 #else
458 #define cfs_bio_io_error(a,b)   bio_io_error((a),(b))
459 #define cfs_bio_endio(a,b,c)    bio_endio((a),(b),(c))
460 #endif
461
462 #ifdef HAVE_FS_STRUCT_USE_PATH
463 #define cfs_fs_pwd(fs)       ((fs)->pwd.dentry)
464 #define cfs_fs_mnt(fs)       ((fs)->pwd.mnt)
465 #define cfs_path_put(nd)     path_put(&(nd)->path)
466 #else
467 #define cfs_fs_pwd(fs)       ((fs)->pwd)
468 #define cfs_fs_mnt(fs)       ((fs)->pwdmnt)
469 #define cfs_path_put(nd)     path_release(nd)
470 #endif
471
472 #ifndef HAVE_SIMPLE_SETATTR
473 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
474 #endif
475
476 #ifndef SLAB_DESTROY_BY_RCU
477 #define SLAB_DESTROY_BY_RCU 0
478 #endif
479
480 #ifndef HAVE_SB_HAS_QUOTA_ACTIVE
481 #define sb_has_quota_active(sb, type) sb_has_quota_enabled(sb, type)
482 #endif
483
484 #ifndef HAVE_SB_ANY_QUOTA_LOADED
485 # ifdef HAVE_SB_ANY_QUOTA_ACTIVE
486 # define sb_any_quota_loaded(sb) sb_any_quota_active(sb)
487 # else
488 # define sb_any_quota_loaded(sb) sb_any_quota_enabled(sb)
489 # endif
490 #endif
491
492 static inline int
493 ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
494 {
495         int rc;
496
497         if (sb->s_qcop->quota_on) {
498 #ifdef HAVE_QUOTA_ON_USE_PATH
499                 struct path path;
500
501                 rc = kern_path(name, LOOKUP_FOLLOW, &path);
502                 if (!rc)
503                         return rc;
504 #endif
505                 rc = sb->s_qcop->quota_on(sb, off, ver
506 #ifdef HAVE_QUOTA_ON_USE_PATH
507                                             , &path
508 #else
509                                             , name
510 #endif
511 #ifdef HAVE_QUOTA_ON_5ARGS
512                                             , remount
513 #endif
514                                            );
515 #ifdef HAVE_QUOTA_ON_USE_PATH
516                 path_put(&path);
517 #endif
518                 return rc;
519         }
520         else
521                 return -ENOSYS;
522 }
523
524 static inline int ll_quota_off(struct super_block *sb, int off, int remount)
525 {
526         if (sb->s_qcop->quota_off) {
527                 return sb->s_qcop->quota_off(sb, off
528 #ifdef HAVE_QUOTA_OFF_3ARGS
529                                              , remount
530 #endif
531                                             );
532         }
533         else
534                 return -ENOSYS;
535 }
536
537 #ifndef HAVE_BLK_QUEUE_LOG_BLK_SIZE /* added in 2.6.31 */
538 #define blk_queue_logical_block_size(q, sz) blk_queue_hardsect_size(q, sz)
539 #endif
540
541 #ifndef HAVE_VFS_DQ_OFF
542 # define ll_vfs_dq_init             DQUOT_INIT
543 # define ll_vfs_dq_drop             DQUOT_DROP
544 # define ll_vfs_dq_transfer         DQUOT_TRANSFER
545 # define ll_vfs_dq_off(sb, remount) DQUOT_OFF(sb)
546 #else
547 # define ll_vfs_dq_init             vfs_dq_init
548 # define ll_vfs_dq_drop             vfs_dq_drop
549 # define ll_vfs_dq_transfer         vfs_dq_transfer
550 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
551 #endif
552
553 #ifndef HAVE_BDI_INIT
554 #define bdi_init(bdi)    0
555 #define bdi_destroy(bdi) do { } while (0)
556 #endif
557
558 #ifdef HAVE_BLK_QUEUE_MAX_SECTORS /* removed in rhel6 */
559 #define blk_queue_max_hw_sectors(q, sect) blk_queue_max_sectors(q, sect)
560 #endif
561
562 #ifndef HAVE_BLKDEV_GET_BY_DEV
563 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
564 #endif
565
566 #ifndef HAVE_REQUEST_QUEUE_LIMITS
567 #define queue_max_sectors(rq)             ((rq)->max_sectors)
568 #define queue_max_hw_sectors(rq)          ((rq)->max_hw_sectors)
569 #define queue_max_phys_segments(rq)       ((rq)->max_phys_segments)
570 #define queue_max_hw_segments(rq)         ((rq)->max_hw_segments)
571 #endif
572
573 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
574 #define blk_queue_max_segments(rq, seg)                      \
575         do { blk_queue_max_phys_segments(rq, seg);           \
576              blk_queue_max_hw_segments(rq, seg); } while (0)
577 #else
578 #define queue_max_phys_segments(rq)       queue_max_segments(rq)
579 #define queue_max_hw_segments(rq)         queue_max_segments(rq)
580 #endif
581
582 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
583 #define ll_kmap_atomic(a, b)    kmap_atomic(a)
584 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a)
585 #else
586 #define ll_kmap_atomic(a, b)    kmap_atomic(a, b)
587 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a, b)
588 #endif
589
590 #ifndef HAVE_CLEAR_INODE
591 #define clear_inode(i)          end_writeback(i)
592 #endif
593
594 #ifdef HAVE_DENTRY_D_ALIAS_HLIST
595 #define ll_d_hlist_node hlist_node
596 #define ll_d_hlist_empty(list) hlist_empty(list)
597 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
598 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
599 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
600         hlist_for_each_entry(dentry, p, i_dentry, alias)
601 #else
602 #define ll_d_hlist_node list_head
603 #define ll_d_hlist_empty(list) list_empty(list)
604 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
605 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
606 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
607         p = NULL; list_for_each_entry(dentry, i_dentry, alias)
608 #endif
609
610
611 #ifndef HAVE_BI_HW_SEGMENTS
612 #define bio_hw_segments(q, bio) 0
613 #endif
614
615 #ifndef HAVE_PAGEVEC_LRU_ADD_FILE
616 #define pagevec_lru_add_file pagevec_lru_add
617 #endif
618
619 #ifdef HAVE_ADD_TO_PAGE_CACHE_LRU
620 #define ll_pagevec_init(pv, cold)       do {} while (0)
621 #define ll_pagevec_add(pv, pg)          (0)
622 #define ll_pagevec_lru_add_file(pv)     do {} while (0)
623 #else
624 #define add_to_page_cache_lru(pg, mapping, off, gfp) \
625         add_to_page_cache(pg, mapping, off, gfp)
626 #define ll_pagevec_init(pv, cold)       pagevec_init(pv, cold);
627 #define ll_pagevec_add(pv, pg)                                  \
628 ({                                                              \
629         int __ret;                                              \
630                                                                 \
631         page_cache_get(pg);                                     \
632         __ret = pagevec_add(pv, pg);                            \
633 })
634 #define ll_pagevec_lru_add_file(pv)     pagevec_lru_add_file(pv)
635 #endif
636
637 #if !defined(HAVE_CPUMASK_OF_NODE) && defined(HAVE_NODE_TO_CPUMASK)
638 # ifdef HAVE_OFED_CPUMASK_OF_NODE
639 # undef cpumask_of_node
640 # define HAVE_CPUMASK_OF_NODE
641 # endif
642 #define cpumask_of_node(i)      (&node_to_cpumask(i))
643 #endif
644
645 #ifndef QUOTA_OK
646 # define QUOTA_OK 0
647 #endif
648 #ifndef NO_QUOTA
649 # define NO_QUOTA (-EDQUOT)
650 #endif
651
652 #ifndef SEEK_DATA
653 #define SEEK_DATA      3       /* seek to the next data */
654 #endif
655 #ifndef SEEK_HOLE
656 #define SEEK_HOLE      4       /* seek to the next hole */
657 #endif
658
659 #ifndef FMODE_UNSIGNED_OFFSET
660 #define FMODE_UNSIGNED_OFFSET   ((__force fmode_t)0x2000)
661 #endif
662
663 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
664 # define ext2_set_bit             __test_and_set_bit_le
665 # define ext2_clear_bit           __test_and_clear_bit_le
666 # define ext2_test_bit            test_bit_le
667 # define ext2_find_first_zero_bit find_first_zero_bit_le
668 # define ext2_find_next_zero_bit  find_next_zero_bit_le
669 #endif
670
671 #ifdef ATTR_TIMES_SET
672 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
673 #else
674 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
675 #endif
676
677 #ifndef HAVE_SELINUX_IS_ENABLED
678 static inline bool selinux_is_enabled(void)
679 {
680         return 0;
681 }
682 #endif
683
684 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
685 # define lm_compare_owner       fl_compare_owner
686 #endif
687
688 /*
689  * After 3.1, kernel's nameidata.intent.open.flags is different
690  * with lustre's lookup_intent.it_flags, as lustre's it_flags'
691  * lower bits equal to FMODE_xxx while kernel doesn't transliterate
692  * lower bits of nameidata.intent.open.flags to FMODE_xxx.
693  * */
694 #include <linux/version.h>
695 static inline int ll_namei_to_lookup_intent_flag(int flag)
696 {
697 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
698         flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
699 #endif
700         return flag;
701 }
702
703 #ifdef HAVE_VOID_MAKE_REQUEST_FN
704 # define ll_mrf_ret void
705 # define LL_MRF_RETURN(rc)
706 #else
707 # define ll_mrf_ret int
708 # define LL_MRF_RETURN(rc) RETURN(rc)
709 #endif
710
711 #include <linux/fs.h>
712 #ifndef HAVE_PROTECT_I_NLINK
713 static inline void set_nlink(struct inode *inode, unsigned int nlink)
714 {
715         inode->i_nlink = nlink;
716 }
717 #endif
718
719 #ifdef HAVE_INODEOPS_USE_UMODE_T
720 # define ll_umode_t     umode_t
721 #else
722 # define ll_umode_t     int
723 #endif
724
725 #include <linux/dcache.h>
726 #ifndef HAVE_D_MAKE_ROOT
727 static inline struct dentry *d_make_root(struct inode *root)
728 {
729         struct dentry *res = d_alloc_root(root);
730
731         if (res == NULL && root)
732                 iput(root);
733
734         return res;
735 }
736 #endif
737
738 #endif /* _COMPAT25_H */