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