Whamcloud - gitweb
LU-1756 kernel: clean up 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, Whamcloud, Inc.
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)   cfs_write_lock(&(fs)->lock)
48 # define UNLOCK_FS_STRUCT(fs) cfs_write_unlock(&(fs)->lock)
49 #else
50 # define LOCK_FS_STRUCT(fs)   cfs_spin_lock(&(fs)->lock)
51 # define UNLOCK_FS_STRUCT(fs) cfs_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 #ifdef HAVE_DENTRY_OPEN_4ARGS
144 #define ll_dentry_open(a, b, c, d) dentry_open(a, b, c, d)
145 #else
146 #define ll_dentry_open(a, b, c, d) dentry_open(a, b, c)
147 #endif
148
149 #ifdef HAVE_KIOBUF_KIO_BLOCKS
150 #define KIOBUF_GET_BLOCKS(k) ((k)->kio_blocks)
151 #else
152 #define KIOBUF_GET_BLOCKS(k) ((k)->blocks)
153 #endif
154
155 #ifdef HAVE_SECURITY_PLUG
156 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
157                 vfs_symlink(dir, dentry, mnt, path, mode)
158 #else
159 #ifdef HAVE_4ARGS_VFS_SYMLINK
160 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
161                 vfs_symlink(dir, dentry, path, mode)
162 #else
163 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
164                        vfs_symlink(dir, dentry, path)
165 #endif
166
167 #endif
168
169 #ifndef container_of
170 #define container_of(ptr, type, member) ({                      \
171                 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
172                 (type *)( (char *)__mptr - offsetof(type,member) );})
173 #endif
174
175 #define UP_WRITE_I_ALLOC_SEM(i)   up_write(&(i)->i_alloc_sem)
176 #define DOWN_WRITE_I_ALLOC_SEM(i) down_write(&(i)->i_alloc_sem)
177 #define LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i) LASSERT(down_read_trylock(&(i)->i_alloc_sem) == 0)
178
179 #define UP_READ_I_ALLOC_SEM(i)    up_read(&(i)->i_alloc_sem)
180 #define DOWN_READ_I_ALLOC_SEM(i)  down_read(&(i)->i_alloc_sem)
181 #define LASSERT_I_ALLOC_SEM_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
182
183 #include <linux/mpage.h>        /* for generic_writepages */
184
185 #ifdef HAVE_HIDE_VFSMOUNT_GUTS
186 # include <../fs/mount.h>
187 #else
188 # define real_mount(mnt)        (mnt)
189 #endif
190
191 static inline const char *mnt_get_devname(struct vfsmount *mnt)
192 {
193         return real_mount(mnt)->mnt_devname;
194 }
195
196 #ifndef HAVE_ATOMIC_MNT_COUNT
197 static inline unsigned int mnt_get_count(struct vfsmount *mnt)
198 {
199 #ifdef CONFIG_SMP
200         unsigned int count = 0;
201         int cpu;
202
203         for_each_possible_cpu(cpu) {
204                 count += per_cpu_ptr(real_mount(mnt)->mnt_pcp, cpu)->mnt_count;
205         }
206
207         return count;
208 #else
209         return real_mount(mnt)->mnt_count;
210 #endif
211 }
212 #else
213 # define mnt_get_count(mnt)      cfs_atomic_read(&(real_mount(mnt)->mnt_count))
214 #endif
215
216 #ifdef HAVE_RW_TREE_LOCK
217 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
218 #define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
219 #else
220 #define TREE_READ_LOCK_IRQ(mapping) cfs_spin_lock_irq(&(mapping)->tree_lock)
221 #define TREE_READ_UNLOCK_IRQ(mapping) cfs_spin_unlock_irq(&(mapping)->tree_lock)
222 #endif
223
224 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
225 #define ll_unregister_blkdev(a,b)       unregister_blkdev((a),(b))
226 #else
227 static inline
228 int ll_unregister_blkdev(unsigned int dev, const char *name)
229 {
230         unregister_blkdev(dev, name);
231         return 0;
232 }
233 #endif
234
235 #ifdef HAVE_INVALIDATE_BDEV_2ARG
236 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a),(b))
237 #else
238 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a))
239 #endif
240
241 #ifndef FS_HAS_FIEMAP
242 #define FS_HAS_FIEMAP                   (0)
243 #endif
244
245 #ifndef HAVE_FS_RENAME_DOES_D_MOVE
246 #define FS_RENAME_DOES_D_MOVE           FS_ODD_RENAME
247 #endif
248
249 #ifndef HAVE_D_OBTAIN_ALIAS
250 /* The old d_alloc_anon() didn't free the inode reference on error
251  * like d_obtain_alias().  Hide that difference/inconvenience here. */
252 static inline struct dentry *d_obtain_alias(struct inode *inode)
253 {
254         struct dentry *anon = d_alloc_anon(inode);
255
256         if (anon == NULL) {
257                 iput(inode);
258                 anon = ERR_PTR(-ENOMEM);
259         }
260
261         return anon;
262 }
263 #endif
264
265 /* add a lustre compatible layer for crypto API */
266 #include <linux/crypto.h>
267 #ifdef HAVE_ASYNC_BLOCK_CIPHER
268 #define ll_crypto_hash          crypto_hash
269 #define ll_crypto_cipher        crypto_blkcipher
270 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
271 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
272 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
273 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
274 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
275 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
276                 crypto_blkcipher_setkey(tfm, key, keylen)
277 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
278                 crypto_blkcipher_set_iv(tfm, src, len)
279 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
280                 crypto_blkcipher_get_iv(tfm, dst, len)
281 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
282                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
283 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
284                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
285 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
286                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
287 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
288                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
289
290 static inline
291 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char *name,
292                                                    u32 type, u32 mask)
293 {
294         struct ll_crypto_cipher *rtn = crypto_alloc_blkcipher(name, type, mask);
295
296         return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
297 }
298
299 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
300                                  u8 *key, unsigned int *keylen,
301                                  struct scatterlist *sg,
302                                  unsigned int size, u8 *result)
303 {
304         struct hash_desc desc;
305         int              rv;
306         desc.tfm   = tfm;
307         desc.flags = 0;
308         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
309         if (rv) {
310                 CERROR("failed to hash setkey: %d\n", rv);
311                 return rv;
312         }
313         return crypto_hash_digest(&desc, sg, size, result);
314 }
315 static inline
316 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
317 {
318         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
319 }
320 static inline
321 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
322 {
323         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
324 }
325
326 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
327 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
328 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
329 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
330 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
331 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
332 #else /* HAVE_ASYNC_BLOCK_CIPHER */
333 #include <linux/scatterlist.h>
334 #define ll_crypto_hash          crypto_tfm
335 #define ll_crypto_cipher        crypto_tfm
336 #ifndef HAVE_STRUCT_HASH_DESC
337 struct hash_desc {
338         struct ll_crypto_hash *tfm;
339         u32                    flags;
340 };
341 #endif
342 #ifndef HAVE_STRUCT_BLKCIPHER_DESC
343 struct blkcipher_desc {
344         struct ll_crypto_cipher *tfm;
345         void                    *info;
346         u32                      flags;
347 };
348 #endif
349 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
350         crypto_cipher_setkey(tfm, key, keylen)
351 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
352         crypto_cipher_set_iv(tfm, src, len)
353 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
354         crypto_cipher_get_iv(tfm, dst, len)
355 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
356         crypto_cipher_encrypt((desc)->tfm, dst, src, bytes)
357 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
358         crypto_cipher_decrypt((desc)->tfm, dst, src, bytes)
359 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
360         crypto_cipher_decrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
361 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
362         crypto_cipher_encrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
363
364 static inline
365 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char * algname,
366                                                    u32 type, u32 mask)
367 {
368         struct ll_crypto_cipher *rtn;
369         char                     buf[CRYPTO_MAX_ALG_NAME + 1];
370         const char              *pan = algname;
371         u32                      flag = 0;
372
373         if (strncmp("cbc(", algname, 4) == 0)
374                 flag |= CRYPTO_TFM_MODE_CBC;
375         else if (strncmp("ecb(", algname, 4) == 0)
376                 flag |= CRYPTO_TFM_MODE_ECB;
377         if (flag) {
378                 char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
379                 if (vp) {
380                         memcpy(buf, algname + 4, vp - algname - 4);
381                         buf[vp - algname - 4] = '\0';
382                         pan = buf;
383                 } else {
384                         flag = 0;
385                 }
386         }
387         rtn = crypto_alloc_tfm(pan, flag);
388         return (rtn == NULL ?  ERR_PTR(-ENOMEM) : rtn);
389 }
390
391 static inline
392 struct ll_crypto_hash *ll_crypto_alloc_hash(const char *alg, u32 type, u32 mask)
393 {
394         char        buf[CRYPTO_MAX_ALG_NAME + 1];
395         const char *pan = alg;
396
397         if (strncmp("hmac(", alg, 5) == 0) {
398                 char *vp = strnchr(alg, CRYPTO_MAX_ALG_NAME, ')');
399                 if (vp) {
400                         memcpy(buf, alg+ 5, vp - alg- 5);
401                         buf[vp - alg - 5] = 0x00;
402                         pan = buf;
403                 }
404         }
405         return crypto_alloc_tfm(pan, 0);
406 }
407 static inline int ll_crypto_hash_init(struct hash_desc *desc)
408 {
409        crypto_digest_init(desc->tfm); return 0;
410 }
411 static inline int ll_crypto_hash_update(struct hash_desc *desc,
412                                         struct scatterlist *sg,
413                                         unsigned int nbytes)
414 {
415         struct scatterlist *sl = sg;
416         unsigned int        count;
417                 /*
418                  * This way is very weakness. We must ensure that
419                  * the sum of sg[0..i]->length isn't greater than nbytes.
420                  * In the upstream kernel the crypto_hash_update() also
421                  * via the nbytes computed the count of sg[...].
422                  * The old style is more safely. but it gone.
423                  */
424         for (count = 0; nbytes > 0; count ++, sl ++) {
425                 nbytes -= sl->length;
426         }
427         crypto_digest_update(desc->tfm, sg, count); return 0;
428 }
429 static inline int ll_crypto_hash_final(struct hash_desc *desc, u8 *out)
430 {
431         crypto_digest_final(desc->tfm, out); return 0;
432 }
433 static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
434                                  u8 *key, unsigned int *keylen,
435                                  struct scatterlist *sg,
436                                  unsigned int nbytes,
437                                  u8 *out)
438 {
439         struct scatterlist *sl = sg;
440         int                 count;
441         for (count = 0; nbytes > 0; count ++, sl ++) {
442                 nbytes -= sl->length;
443         }
444         crypto_hmac(tfm, key, keylen, sg, count, out);
445         return 0;
446 }
447
448 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_digest_setkey(tfm, key, keylen)
449 #define ll_crypto_blkcipher_blocksize(tfm)      crypto_tfm_alg_blocksize(tfm)
450 #define ll_crypto_blkcipher_ivsize(tfm) crypto_tfm_alg_ivsize(tfm)
451 #define ll_crypto_hash_digestsize(tfm)  crypto_tfm_alg_digestsize(tfm)
452 #define ll_crypto_hash_blocksize(tfm)   crypto_tfm_alg_blocksize(tfm)
453 #define ll_crypto_free_hash(tfm)        crypto_free_tfm(tfm)
454 #define ll_crypto_free_blkcipher(tfm)   crypto_free_tfm(tfm)
455 #define ll_crypto_tfm_alg_min_keysize   crypto_tfm_alg_min_keysize
456 #define ll_crypto_tfm_alg_max_keysize   crypto_tfm_alg_max_keysize
457 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
458
459 #ifdef HAVE_SECURITY_PLUG
460 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
461 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
462 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
463 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
464 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
465                 vfs_mknod(dir,entry,mnt,mode,dev)
466 #define ll_security_inode_unlink(dir,entry,mnt)         \
467                 security_inode_unlink(dir,entry,mnt)
468 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
469                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
470 #else
471 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
472 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
473 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
474 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
475 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
476 #define ll_security_inode_unlink(dir,entry,mnt) security_inode_unlink(dir,entry)
477 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
478                 vfs_rename(old,old_dir,new,new_dir)
479 #endif /* HAVE_SECURITY_PLUG */
480
481 #ifdef for_each_possible_cpu
482 #define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
483 #elif defined(for_each_cpu)
484 #define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
485 #endif
486
487 #ifdef HAVE_BIO_ENDIO_2ARG
488 #define cfs_bio_io_error(a,b)   bio_io_error((a))
489 #define cfs_bio_endio(a,b,c)    bio_endio((a),(c))
490 #else
491 #define cfs_bio_io_error(a,b)   bio_io_error((a),(b))
492 #define cfs_bio_endio(a,b,c)    bio_endio((a),(b),(c))
493 #endif
494
495 #ifdef HAVE_FS_STRUCT_USE_PATH
496 #define cfs_fs_pwd(fs)       ((fs)->pwd.dentry)
497 #define cfs_fs_mnt(fs)       ((fs)->pwd.mnt)
498 #define cfs_path_put(nd)     path_put(&(nd)->path)
499 #else
500 #define cfs_fs_pwd(fs)       ((fs)->pwd)
501 #define cfs_fs_mnt(fs)       ((fs)->pwdmnt)
502 #define cfs_path_put(nd)     path_release(nd)
503 #endif
504
505 #ifndef HAVE_SIMPLE_SETATTR
506 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
507 #endif
508
509 #ifndef SLAB_DESTROY_BY_RCU
510 #define SLAB_DESTROY_BY_RCU 0
511 #endif
512
513 #ifndef HAVE_SB_HAS_QUOTA_ACTIVE
514 #define sb_has_quota_active(sb, type) sb_has_quota_enabled(sb, type)
515 #endif
516
517 #ifndef HAVE_SB_ANY_QUOTA_LOADED
518 # ifdef HAVE_SB_ANY_QUOTA_ACTIVE
519 # define sb_any_quota_loaded(sb) sb_any_quota_active(sb)
520 # else
521 # define sb_any_quota_loaded(sb) sb_any_quota_enabled(sb)
522 # endif
523 #endif
524
525 static inline int
526 ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
527 {
528         int rc;
529
530         if (sb->s_qcop->quota_on) {
531 #ifdef HAVE_QUOTA_ON_USE_PATH
532                 struct path path;
533
534                 rc = kern_path(name, LOOKUP_FOLLOW, &path);
535                 if (!rc)
536                         return rc;
537 #endif
538                 rc = sb->s_qcop->quota_on(sb, off, ver
539 #ifdef HAVE_QUOTA_ON_USE_PATH
540                                             , &path
541 #else
542                                             , name
543 #endif
544 #ifdef HAVE_QUOTA_ON_5ARGS
545                                             , remount
546 #endif
547                                            );
548 #ifdef HAVE_QUOTA_ON_USE_PATH
549                 path_put(&path);
550 #endif
551                 return rc;
552         }
553         else
554                 return -ENOSYS;
555 }
556
557 static inline int ll_quota_off(struct super_block *sb, int off, int remount)
558 {
559         if (sb->s_qcop->quota_off) {
560                 return sb->s_qcop->quota_off(sb, off
561 #ifdef HAVE_QUOTA_OFF_3ARGS
562                                              , remount
563 #endif
564                                             );
565         }
566         else
567                 return -ENOSYS;
568 }
569
570 #ifndef HAVE_BLK_QUEUE_LOG_BLK_SIZE /* added in 2.6.31 */
571 #define blk_queue_logical_block_size(q, sz) blk_queue_hardsect_size(q, sz)
572 #endif
573
574 #ifndef HAVE_VFS_DQ_OFF
575 # define ll_vfs_dq_init             DQUOT_INIT
576 # define ll_vfs_dq_drop             DQUOT_DROP
577 # define ll_vfs_dq_transfer         DQUOT_TRANSFER
578 # define ll_vfs_dq_off(sb, remount) DQUOT_OFF(sb)
579 #else
580 # define ll_vfs_dq_init             vfs_dq_init
581 # define ll_vfs_dq_drop             vfs_dq_drop
582 # define ll_vfs_dq_transfer         vfs_dq_transfer
583 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
584 #endif
585
586 #ifdef HAVE_BDI_INIT
587 #define ll_bdi_init(bdi)    bdi_init(bdi)
588 #define ll_bdi_destroy(bdi) bdi_destroy(bdi)
589 #else
590 #define ll_bdi_init(bdi)    0
591 #define ll_bdi_destroy(bdi) do { } while(0)
592 #endif
593
594 #ifdef HAVE_NEW_BACKING_DEV_INFO
595 # define ll_bdi_wb_cnt(bdi) ((bdi).wb_cnt)
596 #else
597 # define ll_bdi_wb_cnt(bdi) 1
598 #endif
599
600 #ifdef HAVE_BLK_QUEUE_MAX_SECTORS /* removed in rhel6 */
601 #define blk_queue_max_hw_sectors(q, sect) blk_queue_max_sectors(q, sect)
602 #endif
603
604 #ifndef HAVE_BLKDEV_GET_BY_DEV
605 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
606 #endif
607
608 #ifndef HAVE_REQUEST_QUEUE_LIMITS
609 #define queue_max_sectors(rq)             ((rq)->max_sectors)
610 #define queue_max_hw_sectors(rq)          ((rq)->max_hw_sectors)
611 #define queue_max_phys_segments(rq)       ((rq)->max_phys_segments)
612 #define queue_max_hw_segments(rq)         ((rq)->max_hw_segments)
613 #endif
614
615 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
616 #define blk_queue_max_segments(rq, seg)                      \
617         do { blk_queue_max_phys_segments(rq, seg);           \
618              blk_queue_max_hw_segments(rq, seg); } while (0)
619 #else
620 #define queue_max_phys_segments(rq)       queue_max_segments(rq)
621 #define queue_max_hw_segments(rq)         queue_max_segments(rq)
622 #endif
623
624
625 #ifndef HAVE_BI_HW_SEGMENTS
626 #define bio_hw_segments(q, bio) 0
627 #endif
628
629 #ifndef HAVE_PAGEVEC_LRU_ADD_FILE
630 #define pagevec_lru_add_file pagevec_lru_add
631 #endif
632
633 #ifdef HAVE_ADD_TO_PAGE_CACHE_LRU
634 #define ll_add_to_page_cache_lru(pg, mapping, off, gfp) \
635         add_to_page_cache_lru(pg, mapping, off, gfp)
636 #define ll_pagevec_init(pv, cold)       do {} while (0)
637 #define ll_pagevec_add(pv, pg)          (0)
638 #define ll_pagevec_lru_add_file(pv)     do {} while (0)
639 #else
640 #define ll_add_to_page_cache_lru(pg, mapping, off, gfp) \
641         add_to_page_cache(pg, mapping, off, gfp)
642 #define ll_pagevec_init(pv, cold)       pagevec_init(&lru_pvec, cold);
643 #define ll_pagevec_add(pv, pg)                                  \
644 ({                                                              \
645         int __ret;                                              \
646                                                                 \
647         page_cache_get(pg);                                     \
648         __ret = pagevec_add(pv, pg);                            \
649 })
650 #define ll_pagevec_lru_add_file(pv)     pagevec_lru_add_file(pv)
651 #endif
652
653 #if !defined(HAVE_NODE_TO_CPUMASK) && defined(HAVE_CPUMASK_OF_NODE)
654 #define node_to_cpumask(i)         (*(cpumask_of_node(i)))
655 #define HAVE_NODE_TO_CPUMASK
656 #endif
657
658 #ifndef QUOTA_OK
659 # define QUOTA_OK 0
660 #endif
661 #ifndef NO_QUOTA
662 # define NO_QUOTA (-EDQUOT)
663 #endif
664
665 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
666 # define ext2_set_bit             __test_and_set_bit_le
667 # define ext2_clear_bit           __test_and_clear_bit_le
668 # define ext2_test_bit            test_bit_le
669 # define ext2_find_first_zero_bit find_first_zero_bit_le
670 # define ext2_find_next_zero_bit  find_next_zero_bit_le
671 #endif
672
673 #ifdef ATTR_TIMES_SET
674 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
675 #else
676 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
677 #endif
678
679 #ifndef HAVE_SELINUX_IS_ENABLED
680 static inline bool selinux_is_enabled(void)
681 {
682         return 0;
683 }
684 #endif
685
686 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
687 # define lm_compare_owner       fl_compare_owner
688 #endif
689
690 #endif /* _COMPAT25_H */