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