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