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, 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 #ifdef __KERNEL__
41
42 #include <linux/fs_struct.h>
43 #include <linux/namei.h>
44 #include <libcfs/linux/portals_compat25.h>
45
46 #include <linux/lustre_patchless_compat.h>
47
48 /* Some old kernels (like 2.6.9) may not define such SEEK_XXX. So the
49  * definition allows to compile lustre client on more OS platforms. */
50 #ifndef SEEK_SET
51  #define SEEK_SET 0
52  #define SEEK_CUR 1
53  #define SEEK_END 2
54 #endif
55
56 #ifdef HAVE_FS_STRUCT_RWLOCK
57 # define LOCK_FS_STRUCT(fs)   cfs_write_lock(&(fs)->lock)
58 # define UNLOCK_FS_STRUCT(fs) cfs_write_unlock(&(fs)->lock)
59 #else
60 # define LOCK_FS_STRUCT(fs)   cfs_spin_lock(&(fs)->lock)
61 # define UNLOCK_FS_STRUCT(fs) cfs_spin_unlock(&(fs)->lock)
62 #endif
63
64 #ifdef HAVE_FS_STRUCT_USE_PATH
65 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
66                                  struct dentry *dentry)
67 {
68         struct path path;
69         struct path old_pwd;
70
71         path.mnt = mnt;
72         path.dentry = dentry;
73         LOCK_FS_STRUCT(fs);
74         old_pwd = fs->pwd;
75         path_get(&path);
76         fs->pwd = path;
77         UNLOCK_FS_STRUCT(fs);
78
79         if (old_pwd.dentry)
80                 path_put(&old_pwd);
81 }
82
83 #else
84
85 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
86                 struct dentry *dentry)
87 {
88         struct dentry *old_pwd;
89         struct vfsmount *old_pwdmnt;
90
91         LOCK_FS_STRUCT(fs);
92         old_pwd = fs->pwd;
93         old_pwdmnt = fs->pwdmnt;
94         fs->pwdmnt = mntget(mnt);
95         fs->pwd = dget(dentry);
96         UNLOCK_FS_STRUCT(fs);
97
98         if (old_pwd) {
99                 dput(old_pwd);
100                 mntput(old_pwdmnt);
101         }
102 }
103 #endif
104
105 /*
106  * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
107  * ATTR_* attributes (see bug 13828)
108  */
109 #define ATTR_BLOCKS    (1 << 27)
110
111 #define current_ngroups current_cred()->group_info->ngroups
112 #define current_groups current_cred()->group_info->small_block
113
114 #ifndef page_private
115 #define page_private(page) ((page)->private)
116 #define set_page_private(page, v) ((page)->private = (v))
117 #endif
118
119 #define ll_kernel_locked()      kernel_locked()
120
121 /*
122  * OBD need working random driver, thus all our
123  * initialization routines must be called after device
124  * driver initialization
125  */
126 #ifndef MODULE
127 #undef module_init
128 #define module_init(a)     late_initcall(a)
129 #endif
130
131 /* XXX our code should be using the 2.6 calls, not the other way around */
132 #ifdef HAVE_TRYLOCK_PAGE
133 #define TestSetPageLocked(page)         (!trylock_page(page))
134 #endif
135
136 #define Page_Uptodate(page)             PageUptodate(page)
137 #define ll_redirty_page(page)           set_page_dirty(page)
138
139 #define KDEVT_INIT(val)                 (val)
140
141 #define LTIME_S(time)                   (time.tv_sec)
142 #define ll_path_lookup                  path_lookup
143
144 #ifdef HAVE_EXPORT_INODE_PERMISSION
145 #define ll_permission(inode,mask,nd)    inode_permission(inode,mask)
146 #else
147 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
148 #endif
149
150 #ifdef HAVE_GENERIC_PERMISSION_2ARGS
151 # define ll_generic_permission(inode, mask, flags, check_acl) \
152          generic_permission(inode, mask)
153 #elif defined HAVE_GENERIC_PERMISSION_4ARGS
154 # define ll_generic_permission(inode, mask, flags, check_acl) \
155          generic_permission(inode, mask, flags, check_acl)
156 #else
157 # define ll_generic_permission(inode, mask, flags, check_acl) \
158          generic_permission(inode, mask, check_acl)
159 #endif
160
161 #define ll_pgcache_lock(mapping)          cfs_spin_lock(&mapping->page_lock)
162 #define ll_pgcache_unlock(mapping)        cfs_spin_unlock(&mapping->page_lock)
163 #define ll_call_writepage(inode, page)  \
164                                 (inode)->i_mapping->a_ops->writepage(page, NULL)
165 #define ll_invalidate_inode_pages(inode) \
166                                 invalidate_inode_pages((inode)->i_mapping)
167
168 #define ll_vfs_create(a,b,c,d)          vfs_create(a,b,c,d)
169 #define ll_dev_t                        dev_t
170 #define kdev_t                          dev_t
171 #define to_kdev_t(dev)                  (dev)
172 #define kdev_t_to_nr(dev)               (dev)
173 #define val_to_kdev(dev)                (dev)
174
175 #ifdef HAVE_BLKDEV_PUT_2ARGS
176 #define ll_blkdev_put(a, b) blkdev_put(a, b)
177 #else
178 #define ll_blkdev_put(a, b) blkdev_put(a)
179 #endif
180
181 #ifdef HAVE_DENTRY_OPEN_4ARGS
182 #define ll_dentry_open(a, b, c, d) dentry_open(a, b, c, d)
183 #else
184 #define ll_dentry_open(a, b, c, d) dentry_open(a, b, c)
185 #endif
186
187 #include <linux/writeback.h>
188
189 static inline int cfs_cleanup_group_info(void)
190 {
191         struct group_info *ginfo;
192
193         ginfo = groups_alloc(0);
194         if (!ginfo)
195                 return -ENOMEM;
196
197         set_current_groups(ginfo);
198         put_group_info(ginfo);
199
200         return 0;
201 }
202
203 #define __set_page_ll_data(page, llap) \
204         do {       \
205                 page_cache_get(page); \
206                 SetPagePrivate(page); \
207                 set_page_private(page, (unsigned long)llap); \
208         } while (0)
209 #define __clear_page_ll_data(page) \
210         do {       \
211                 ClearPagePrivate(page); \
212                 set_page_private(page, 0); \
213                 page_cache_release(page); \
214         } while(0)
215
216 #define kiobuf bio
217
218 #include <linux/proc_fs.h>
219
220 #define CheckWriteback(page, cmd) \
221         ((!PageWriteback(page) && (cmd & OBD_BRW_READ)) || \
222          (PageWriteback(page) && (cmd & OBD_BRW_WRITE)))
223
224 #ifdef HAVE_PAGE_LIST
225 static inline int mapping_has_pages(struct address_space *mapping)
226 {
227         int rc = 1;
228
229         ll_pgcache_lock(mapping);
230         if (cfs_list_empty(&mapping->dirty_pages) &&
231             cfs_list_empty(&mapping->clean_pages) &&
232             cfs_list_empty(&mapping->locked_pages)) {
233                 rc = 0;
234         }
235         ll_pgcache_unlock(mapping);
236
237         return rc;
238 }
239 #else
240 static inline int mapping_has_pages(struct address_space *mapping)
241 {
242         return mapping->nrpages > 0;
243 }
244 #endif
245
246 #ifdef HAVE_KIOBUF_KIO_BLOCKS
247 #define KIOBUF_GET_BLOCKS(k) ((k)->kio_blocks)
248 #else
249 #define KIOBUF_GET_BLOCKS(k) ((k)->blocks)
250 #endif
251
252 #ifdef HAVE_SECURITY_PLUG
253 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
254                 vfs_symlink(dir, dentry, mnt, path, mode)
255 #else
256 #ifdef HAVE_4ARGS_VFS_SYMLINK
257 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
258                 vfs_symlink(dir, dentry, path, mode)
259 #else
260 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
261                        vfs_symlink(dir, dentry, path)
262 #endif
263
264 #endif
265
266 #ifndef container_of
267 #define container_of(ptr, type, member) ({                      \
268                 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
269                 (type *)( (char *)__mptr - offsetof(type,member) );})
270 #endif
271
272 #define UP_WRITE_I_ALLOC_SEM(i)   up_write(&(i)->i_alloc_sem)
273 #define DOWN_WRITE_I_ALLOC_SEM(i) down_write(&(i)->i_alloc_sem)
274 #define LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i) LASSERT(down_read_trylock(&(i)->i_alloc_sem) == 0)
275
276 #define UP_READ_I_ALLOC_SEM(i)    up_read(&(i)->i_alloc_sem)
277 #define DOWN_READ_I_ALLOC_SEM(i)  down_read(&(i)->i_alloc_sem)
278 #define LASSERT_I_ALLOC_SEM_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
279
280 #include <linux/mpage.h>        /* for generic_writepages */
281
282 #ifdef HAVE_HIDE_VFSMOUNT_GUTS
283 # include <../fs/mount.h>
284 #else
285 # define real_mount(mnt)        (mnt)
286 #endif
287
288 static inline const char *mnt_get_devname(struct vfsmount *mnt)
289 {
290         return real_mount(mnt)->mnt_devname;
291 }
292
293 #ifndef HAVE_ATOMIC_MNT_COUNT
294 static inline unsigned int mnt_get_count(struct vfsmount *mnt)
295 {
296 #ifdef CONFIG_SMP
297         unsigned int count = 0;
298         int cpu;
299
300         for_each_possible_cpu(cpu) {
301                 count += per_cpu_ptr(real_mount(mnt)->mnt_pcp, cpu)->mnt_count;
302         }
303
304         return count;
305 #else
306         return real_mount(mnt)->mnt_count;
307 #endif
308 }
309 #else
310 # define mnt_get_count(mnt)      cfs_atomic_read(&(real_mount(mnt)->mnt_count))
311 #endif
312
313 #ifdef HAVE_RW_TREE_LOCK
314 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
315 #define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
316 #else
317 #define TREE_READ_LOCK_IRQ(mapping) cfs_spin_lock_irq(&(mapping)->tree_lock)
318 #define TREE_READ_UNLOCK_IRQ(mapping) cfs_spin_unlock_irq(&(mapping)->tree_lock)
319 #endif
320
321 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
322 #define ll_unregister_blkdev(a,b)       unregister_blkdev((a),(b))
323 #else
324 static inline
325 int ll_unregister_blkdev(unsigned int dev, const char *name)
326 {
327         unregister_blkdev(dev, name);
328         return 0;
329 }
330 #endif
331
332 #ifdef HAVE_INVALIDATE_BDEV_2ARG
333 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a),(b))
334 #else
335 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a))
336 #endif
337
338 #define ll_inode_blksize(a)     (1<<(a)->i_blkbits)
339
340 #ifdef HAVE_FS_RENAME_DOES_D_MOVE
341 #define LL_RENAME_DOES_D_MOVE   FS_RENAME_DOES_D_MOVE
342 #else
343 #define LL_RENAME_DOES_D_MOVE   FS_ODD_RENAME
344 #endif
345
346 #ifndef HAVE_D_OBTAIN_ALIAS
347 /* The old d_alloc_anon() didn't free the inode reference on error
348  * like d_obtain_alias().  Hide that difference/inconvenience here. */
349 static inline struct dentry *d_obtain_alias(struct inode *inode)
350 {
351         struct dentry *anon = d_alloc_anon(inode);
352
353         if (anon == NULL) {
354                 iput(inode);
355                 anon = ERR_PTR(-ENOMEM);
356         }
357
358         return anon;
359 }
360 #endif
361
362 /* add a lustre compatible layer for crypto API */
363 #include <linux/crypto.h>
364 #ifdef HAVE_ASYNC_BLOCK_CIPHER
365 #define ll_crypto_hash          crypto_hash
366 #define ll_crypto_cipher        crypto_blkcipher
367 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
368 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
369 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
370 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
371 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
372 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
373                 crypto_blkcipher_setkey(tfm, key, keylen)
374 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
375                 crypto_blkcipher_set_iv(tfm, src, len)
376 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
377                 crypto_blkcipher_get_iv(tfm, dst, len)
378 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
379                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
380 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
381                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
382 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
383                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
384 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
385                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
386
387 static inline
388 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char *name,
389                                                    u32 type, u32 mask)
390 {
391         struct ll_crypto_cipher *rtn = crypto_alloc_blkcipher(name, type, mask);
392
393         return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
394 }
395
396 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
397                                  u8 *key, unsigned int *keylen,
398                                  struct scatterlist *sg,
399                                  unsigned int size, u8 *result)
400 {
401         struct hash_desc desc;
402         int              rv;
403         desc.tfm   = tfm;
404         desc.flags = 0;
405         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
406         if (rv) {
407                 CERROR("failed to hash setkey: %d\n", rv);
408                 return rv;
409         }
410         return crypto_hash_digest(&desc, sg, size, result);
411 }
412 static inline
413 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
414 {
415         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
416 }
417 static inline
418 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
419 {
420         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
421 }
422
423 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
424 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
425 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
426 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
427 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
428 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
429 #else /* HAVE_ASYNC_BLOCK_CIPHER */
430 #include <linux/scatterlist.h>
431 #define ll_crypto_hash          crypto_tfm
432 #define ll_crypto_cipher        crypto_tfm
433 #ifndef HAVE_STRUCT_HASH_DESC
434 struct hash_desc {
435         struct ll_crypto_hash *tfm;
436         u32                    flags;
437 };
438 #endif
439 #ifndef HAVE_STRUCT_BLKCIPHER_DESC
440 struct blkcipher_desc {
441         struct ll_crypto_cipher *tfm;
442         void                    *info;
443         u32                      flags;
444 };
445 #endif
446 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
447         crypto_cipher_setkey(tfm, key, keylen)
448 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
449         crypto_cipher_set_iv(tfm, src, len)
450 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
451         crypto_cipher_get_iv(tfm, dst, len)
452 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
453         crypto_cipher_encrypt((desc)->tfm, dst, src, bytes)
454 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
455         crypto_cipher_decrypt((desc)->tfm, dst, src, bytes)
456 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
457         crypto_cipher_decrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
458 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
459         crypto_cipher_encrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
460
461 static inline
462 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char * algname,
463                                                    u32 type, u32 mask)
464 {
465         struct ll_crypto_cipher *rtn;
466         char                     buf[CRYPTO_MAX_ALG_NAME + 1];
467         const char              *pan = algname;
468         u32                      flag = 0;
469
470         if (strncmp("cbc(", algname, 4) == 0)
471                 flag |= CRYPTO_TFM_MODE_CBC;
472         else if (strncmp("ecb(", algname, 4) == 0)
473                 flag |= CRYPTO_TFM_MODE_ECB;
474         if (flag) {
475                 char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
476                 if (vp) {
477                         memcpy(buf, algname + 4, vp - algname - 4);
478                         buf[vp - algname - 4] = '\0';
479                         pan = buf;
480                 } else {
481                         flag = 0;
482                 }
483         }
484         rtn = crypto_alloc_tfm(pan, flag);
485         return (rtn == NULL ?  ERR_PTR(-ENOMEM) : rtn);
486 }
487
488 static inline
489 struct ll_crypto_hash *ll_crypto_alloc_hash(const char *alg, u32 type, u32 mask)
490 {
491         char        buf[CRYPTO_MAX_ALG_NAME + 1];
492         const char *pan = alg;
493
494         if (strncmp("hmac(", alg, 5) == 0) {
495                 char *vp = strnchr(alg, CRYPTO_MAX_ALG_NAME, ')');
496                 if (vp) {
497                         memcpy(buf, alg+ 5, vp - alg- 5);
498                         buf[vp - alg - 5] = 0x00;
499                         pan = buf;
500                 }
501         }
502         return crypto_alloc_tfm(pan, 0);
503 }
504 static inline int ll_crypto_hash_init(struct hash_desc *desc)
505 {
506        crypto_digest_init(desc->tfm); return 0;
507 }
508 static inline int ll_crypto_hash_update(struct hash_desc *desc,
509                                         struct scatterlist *sg,
510                                         unsigned int nbytes)
511 {
512         struct scatterlist *sl = sg;
513         unsigned int        count;
514                 /*
515                  * This way is very weakness. We must ensure that
516                  * the sum of sg[0..i]->length isn't greater than nbytes.
517                  * In the upstream kernel the crypto_hash_update() also
518                  * via the nbytes computed the count of sg[...].
519                  * The old style is more safely. but it gone.
520                  */
521         for (count = 0; nbytes > 0; count ++, sl ++) {
522                 nbytes -= sl->length;
523         }
524         crypto_digest_update(desc->tfm, sg, count); return 0;
525 }
526 static inline int ll_crypto_hash_final(struct hash_desc *desc, u8 *out)
527 {
528         crypto_digest_final(desc->tfm, out); return 0;
529 }
530 static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
531                                  u8 *key, unsigned int *keylen,
532                                  struct scatterlist *sg,
533                                  unsigned int nbytes,
534                                  u8 *out)
535 {
536         struct scatterlist *sl = sg;
537         int                 count;
538         for (count = 0; nbytes > 0; count ++, sl ++) {
539                 nbytes -= sl->length;
540         }
541         crypto_hmac(tfm, key, keylen, sg, count, out);
542         return 0;
543 }
544
545 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_digest_setkey(tfm, key, keylen)
546 #define ll_crypto_blkcipher_blocksize(tfm)      crypto_tfm_alg_blocksize(tfm)
547 #define ll_crypto_blkcipher_ivsize(tfm) crypto_tfm_alg_ivsize(tfm)
548 #define ll_crypto_hash_digestsize(tfm)  crypto_tfm_alg_digestsize(tfm)
549 #define ll_crypto_hash_blocksize(tfm)   crypto_tfm_alg_blocksize(tfm)
550 #define ll_crypto_free_hash(tfm)        crypto_free_tfm(tfm)
551 #define ll_crypto_free_blkcipher(tfm)   crypto_free_tfm(tfm)
552 #define ll_crypto_tfm_alg_min_keysize   crypto_tfm_alg_min_keysize
553 #define ll_crypto_tfm_alg_max_keysize   crypto_tfm_alg_max_keysize
554 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
555
556 #ifdef HAVE_SECURITY_PLUG
557 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
558 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
559 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
560 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
561 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
562                 vfs_mknod(dir,entry,mnt,mode,dev)
563 #define ll_security_inode_unlink(dir,entry,mnt)         \
564                 security_inode_unlink(dir,entry,mnt)
565 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
566                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
567 #else
568 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
569 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
570 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
571 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
572 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
573 #define ll_security_inode_unlink(dir,entry,mnt) security_inode_unlink(dir,entry)
574 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
575                 vfs_rename(old,old_dir,new,new_dir)
576 #endif /* HAVE_SECURITY_PLUG */
577
578 #ifdef for_each_possible_cpu
579 #define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
580 #elif defined(for_each_cpu)
581 #define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
582 #endif
583
584 #ifdef HAVE_BIO_ENDIO_2ARG
585 #define cfs_bio_io_error(a,b)   bio_io_error((a))
586 #define cfs_bio_endio(a,b,c)    bio_endio((a),(c))
587 #else
588 #define cfs_bio_io_error(a,b)   bio_io_error((a),(b))
589 #define cfs_bio_endio(a,b,c)    bio_endio((a),(b),(c))
590 #endif
591
592 #ifdef HAVE_FS_STRUCT_USE_PATH
593 #define cfs_fs_pwd(fs)       ((fs)->pwd.dentry)
594 #define cfs_fs_mnt(fs)       ((fs)->pwd.mnt)
595 #define cfs_path_put(nd)     path_put(&(nd)->path)
596 #else
597 #define cfs_fs_pwd(fs)       ((fs)->pwd)
598 #define cfs_fs_mnt(fs)       ((fs)->pwdmnt)
599 #define cfs_path_put(nd)     path_release(nd)
600 #endif
601
602 #ifndef HAVE_SIMPLE_SETATTR
603 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
604 #endif
605
606 #ifndef SLAB_DESTROY_BY_RCU
607 #define SLAB_DESTROY_BY_RCU 0
608 #endif
609
610 #ifndef HAVE_SB_HAS_QUOTA_ACTIVE
611 #define sb_has_quota_active(sb, type) sb_has_quota_enabled(sb, type)
612 #endif
613
614 #ifndef HAVE_SB_ANY_QUOTA_LOADED
615 # ifdef HAVE_SB_ANY_QUOTA_ACTIVE
616 # define sb_any_quota_loaded(sb) sb_any_quota_active(sb)
617 # else
618 # define sb_any_quota_loaded(sb) sb_any_quota_enabled(sb)
619 # endif
620 #endif
621
622 static inline int
623 ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
624 {
625         int rc;
626
627         if (sb->s_qcop->quota_on) {
628 #ifdef HAVE_QUOTA_ON_USE_PATH
629                 struct path path;
630
631                 rc = kern_path(name, LOOKUP_FOLLOW, &path);
632                 if (!rc)
633                         return rc;
634 #endif
635                 rc = sb->s_qcop->quota_on(sb, off, ver
636 #ifdef HAVE_QUOTA_ON_USE_PATH
637                                             , &path
638 #else
639                                             , name
640 #endif
641 #ifdef HAVE_QUOTA_ON_5ARGS
642                                             , remount
643 #endif
644                                            );
645 #ifdef HAVE_QUOTA_ON_USE_PATH
646                 path_put(&path);
647 #endif
648                 return rc;
649         }
650         else
651                 return -ENOSYS;
652 }
653
654 static inline int ll_quota_off(struct super_block *sb, int off, int remount)
655 {
656         if (sb->s_qcop->quota_off) {
657                 return sb->s_qcop->quota_off(sb, off
658 #ifdef HAVE_QUOTA_OFF_3ARGS
659                                              , remount
660 #endif
661                                             );
662         }
663         else
664                 return -ENOSYS;
665 }
666
667 #ifndef HAVE_BLK_QUEUE_LOG_BLK_SIZE /* added in 2.6.31 */
668 #define blk_queue_logical_block_size(q, sz) blk_queue_hardsect_size(q, sz)
669 #endif
670
671 #ifndef HAVE_VFS_DQ_OFF
672 # define ll_vfs_dq_init             DQUOT_INIT
673 # define ll_vfs_dq_drop             DQUOT_DROP
674 # define ll_vfs_dq_transfer         DQUOT_TRANSFER
675 # define ll_vfs_dq_off(sb, remount) DQUOT_OFF(sb)
676 #else
677 # define ll_vfs_dq_init             vfs_dq_init
678 # define ll_vfs_dq_drop             vfs_dq_drop
679 # define ll_vfs_dq_transfer         vfs_dq_transfer
680 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
681 #endif
682
683 #ifdef HAVE_BDI_INIT
684 #define ll_bdi_init(bdi)    bdi_init(bdi)
685 #define ll_bdi_destroy(bdi) bdi_destroy(bdi)
686 #else
687 #define ll_bdi_init(bdi)    0
688 #define ll_bdi_destroy(bdi) do { } while(0)
689 #endif
690
691 #ifdef HAVE_NEW_BACKING_DEV_INFO
692 # define ll_bdi_wb_cnt(bdi) ((bdi).wb_cnt)
693 #else
694 # define ll_bdi_wb_cnt(bdi) 1
695 #endif
696
697 #ifdef HAVE_BLK_QUEUE_MAX_SECTORS /* removed in rhel6 */
698 #define blk_queue_max_hw_sectors(q, sect) blk_queue_max_sectors(q, sect)
699 #endif
700
701 #ifndef HAVE_BLKDEV_GET_BY_DEV
702 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
703 #endif
704
705 #ifndef HAVE_REQUEST_QUEUE_LIMITS
706 #define queue_max_sectors(rq)             ((rq)->max_sectors)
707 #define queue_max_hw_sectors(rq)          ((rq)->max_hw_sectors)
708 #define queue_max_phys_segments(rq)       ((rq)->max_phys_segments)
709 #define queue_max_hw_segments(rq)         ((rq)->max_hw_segments)
710 #endif
711
712 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
713 #define blk_queue_max_segments(rq, seg)                      \
714         do { blk_queue_max_phys_segments(rq, seg);           \
715              blk_queue_max_hw_segments(rq, seg); } while (0)
716 #else
717 #define queue_max_phys_segments(rq)       queue_max_segments(rq)
718 #define queue_max_hw_segments(rq)         queue_max_segments(rq)
719 #endif
720
721
722 #ifndef HAVE_BI_HW_SEGMENTS
723 #define bio_hw_segments(q, bio) 0
724 #endif
725
726 #ifndef HAVE_PAGEVEC_LRU_ADD_FILE
727 #define pagevec_lru_add_file pagevec_lru_add
728 #endif
729
730 #ifdef HAVE_ADD_TO_PAGE_CACHE_LRU
731 #define ll_add_to_page_cache_lru(pg, mapping, off, gfp) \
732         add_to_page_cache_lru(pg, mapping, off, gfp)
733 #define ll_pagevec_init(pv, cold)       do {} while (0)
734 #define ll_pagevec_add(pv, pg)          (0)
735 #define ll_pagevec_lru_add_file(pv)     do {} while (0)
736 #else
737 #define ll_add_to_page_cache_lru(pg, mapping, off, gfp) \
738         add_to_page_cache(pg, mapping, off, gfp)
739 #define ll_pagevec_init(pv, cold)       pagevec_init(&lru_pvec, cold);
740 #define ll_pagevec_add(pv, pg)                                  \
741 ({                                                              \
742         int __ret;                                              \
743                                                                 \
744         page_cache_get(pg);                                     \
745         __ret = pagevec_add(pv, pg);                            \
746 })
747 #define ll_pagevec_lru_add_file(pv)     pagevec_lru_add_file(pv)
748 #endif
749
750 #if !defined(HAVE_NODE_TO_CPUMASK) && defined(HAVE_CPUMASK_OF_NODE)
751 #define node_to_cpumask(i)         (*(cpumask_of_node(i)))
752 #define HAVE_NODE_TO_CPUMASK
753 #endif
754
755 #ifndef QUOTA_OK
756 # define QUOTA_OK 0
757 #endif
758 #ifndef NO_QUOTA
759 # define NO_QUOTA (-EDQUOT)
760 #endif
761
762 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
763 # define ext2_set_bit             __test_and_set_bit_le
764 # define ext2_clear_bit           __test_and_clear_bit_le
765 # define ext2_test_bit            test_bit_le
766 # define ext2_find_first_zero_bit find_first_zero_bit_le
767 # define ext2_find_next_zero_bit  find_next_zero_bit_le
768 #endif
769
770 #ifdef ATTR_TIMES_SET
771 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
772 #else
773 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
774 #endif
775
776 #ifndef HAVE_SELINUX_IS_ENABLED
777 static inline bool selinux_is_enabled(void)
778 {
779         return 0;
780 }
781 #endif
782
783 #endif /* __KERNEL__ */
784 #endif /* _COMPAT25_H */