Whamcloud - gitweb
04f138cc39b78934e82942d89aae0a842480e20c
[fs/lustre-release.git] / lustre / include / linux / lustre_compat25.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
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 <libcfs/linux/portals_compat25.h>
47
48 #include <linux/lustre_patchless_compat.h>
49
50 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
51 struct ll_iattr {
52         struct iattr    iattr;
53         unsigned int    ia_attr_flags;
54 };
55 #else
56 #define ll_iattr iattr
57 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14) */
58
59 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
60                 struct dentry *dentry)
61 {
62         struct dentry *old_pwd;
63         struct vfsmount *old_pwdmnt;
64
65         write_lock(&fs->lock);
66         old_pwd = fs->pwd;
67         old_pwdmnt = fs->pwdmnt;
68         fs->pwdmnt = mntget(mnt);
69         fs->pwd = dget(dentry);
70         write_unlock(&fs->lock);
71
72         if (old_pwd) {
73                 dput(old_pwd);
74                 mntput(old_pwdmnt);
75         }
76 }
77
78 /*
79  * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
80  * ATTR_* attributes (see bug 13828)
81  */
82 #define ATTR_BLOCKS    (1 << 27)
83
84 #if HAVE_INODE_I_MUTEX
85 #define UNLOCK_INODE_MUTEX(inode) do {mutex_unlock(&(inode)->i_mutex); } while(0)
86 #define LOCK_INODE_MUTEX(inode) do {mutex_lock(&(inode)->i_mutex); } while(0)
87 #define LOCK_INODE_MUTEX_PARENT(inode) \
88 do {mutex_lock_nested(&(inode)->i_mutex, I_MUTEX_PARENT); } while(0)
89 #define TRYLOCK_INODE_MUTEX(inode) mutex_trylock(&(inode)->i_mutex)
90 #else
91 #define UNLOCK_INODE_MUTEX(inode) do {up(&(inode)->i_sem); } while(0)
92 #define LOCK_INODE_MUTEX(inode) do {down(&(inode)->i_sem); } while(0)
93 #define TRYLOCK_INODE_MUTEX(inode) (!down_trylock(&(inode)->i_sem))
94 #define LOCK_INODE_MUTEX_PARENT(inode) LOCK_INODE_MUTEX(inode)
95 #endif /* HAVE_INODE_I_MUTEX */
96
97 #ifdef HAVE_SEQ_LOCK
98 #define LL_SEQ_LOCK(seq) mutex_lock(&(seq)->lock)
99 #define LL_SEQ_UNLOCK(seq) mutex_unlock(&(seq)->lock)
100 #else
101 #define LL_SEQ_LOCK(seq) down(&(seq)->sem)
102 #define LL_SEQ_UNLOCK(seq) up(&(seq)->sem)
103 #endif
104
105 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
106 #define d_child d_u.d_child
107 #define d_rcu d_u.d_rcu
108 #endif
109
110 #ifdef HAVE_DQUOTOFF_MUTEX
111 #define UNLOCK_DQONOFF_MUTEX(dqopt) do {mutex_unlock(&(dqopt)->dqonoff_mutex); } while(0)
112 #define LOCK_DQONOFF_MUTEX(dqopt) do {mutex_lock(&(dqopt)->dqonoff_mutex); } while(0)
113 #else
114 #define UNLOCK_DQONOFF_MUTEX(dqopt) do {up(&(dqopt)->dqonoff_sem); } while(0)
115 #define LOCK_DQONOFF_MUTEX(dqopt) do {down(&(dqopt)->dqonoff_sem); } while(0)
116 #endif /* HAVE_DQUOTOFF_MUTEX */
117
118 #define current_ngroups current->group_info->ngroups
119 #define current_groups current->group_info->small_block
120
121 #ifndef page_private
122 #define page_private(page) ((page)->private)
123 #define set_page_private(page, v) ((page)->private = (v))
124 #endif
125
126 #ifndef HAVE_GFP_T
127 #define gfp_t int
128 #endif
129
130 #define lock_dentry(___dentry)          spin_lock(&(___dentry)->d_lock)
131 #define unlock_dentry(___dentry)        spin_unlock(&(___dentry)->d_lock)
132
133 #define ll_kernel_locked()      kernel_locked()
134
135 /*
136  * OBD need working random driver, thus all our
137  * initialization routines must be called after device
138  * driver initialization
139  */
140 #ifndef MODULE
141 #undef module_init
142 #define module_init(a)     late_initcall(a)
143 #endif
144
145 /* XXX our code should be using the 2.6 calls, not the other way around */
146 #define TryLockPage(page)               TestSetPageLocked(page)
147 #define Page_Uptodate(page)             PageUptodate(page)
148 #define ll_redirty_page(page)           set_page_dirty(page)
149
150 #define KDEVT_INIT(val)                 (val)
151
152 #define LTIME_S(time)                   (time.tv_sec)
153 #define ll_path_lookup                  path_lookup
154 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
155
156 #define ll_pgcache_lock(mapping)          spin_lock(&mapping->page_lock)
157 #define ll_pgcache_unlock(mapping)        spin_unlock(&mapping->page_lock)
158 #define ll_call_writepage(inode, page)  \
159                                 (inode)->i_mapping->a_ops->writepage(page, NULL)
160 #define ll_invalidate_inode_pages(inode) \
161                                 invalidate_inode_pages((inode)->i_mapping)
162 #define ll_truncate_complete_page(page) \
163                                 truncate_complete_page(page->mapping, page)
164
165 #define ll_vfs_create(a,b,c,d)          vfs_create(a,b,c,d)
166 #define ll_dev_t                        dev_t
167 #define kdev_t                          dev_t
168 #define to_kdev_t(dev)                  (dev)
169 #define kdev_t_to_nr(dev)               (dev)
170 #define val_to_kdev(dev)                (dev)
171 #define ILOOKUP(sb, ino, test, data)    ilookup5(sb, ino, test, data);
172
173 #include <linux/writeback.h>
174
175 static inline int cleanup_group_info(void)
176 {
177         struct group_info *ginfo;
178
179         ginfo = groups_alloc(0);
180         if (!ginfo)
181                 return -ENOMEM;
182
183         set_current_groups(ginfo);
184         put_group_info(ginfo);
185
186         return 0;
187 }
188
189 #define __set_page_ll_data(page, llap) \
190         do {       \
191                 page_cache_get(page); \
192                 SetPagePrivate(page); \
193                 set_page_private(page, (unsigned long)llap); \
194         } while (0)
195 #define __clear_page_ll_data(page) \
196         do {       \
197                 ClearPagePrivate(page); \
198                 set_page_private(page, 0); \
199                 page_cache_release(page); \
200         } while(0)
201
202 #define kiobuf bio
203
204 #include <linux/proc_fs.h>
205
206 #if !defined(HAVE_D_REHASH_COND) && defined(HAVE___D_REHASH)
207 #define d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
208 extern void __d_rehash(struct dentry *dentry, int lock);
209 #endif
210
211 #if !defined(HAVE_D_MOVE_LOCKED) && defined(HAVE___D_MOVE)
212 #define d_move_locked(dentry, target) __d_move(dentry, target)
213 extern void __d_move(struct dentry *dentry, struct dentry *target);
214 #endif
215
216 #ifdef HAVE_CAN_SLEEP_ARG
217 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
218         flock_lock_file_wait(file, lock, can_sleep)
219 #else
220 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
221         flock_lock_file_wait(file, lock)
222 #endif
223
224 #define CheckWriteback(page, cmd) \
225         ((!PageWriteback(page) && (cmd & OBD_BRW_READ)) || \
226          (PageWriteback(page) && (cmd & OBD_BRW_WRITE)))
227
228 #ifdef HAVE_PAGE_LIST
229 static inline int mapping_has_pages(struct address_space *mapping)
230 {
231         int rc = 1;
232
233         ll_pgcache_lock(mapping);
234         if (list_empty(&mapping->dirty_pages) &&
235             list_empty(&mapping->clean_pages) &&
236             list_empty(&mapping->locked_pages)) {
237                 rc = 0;
238         }
239         ll_pgcache_unlock(mapping);
240
241         return rc;
242 }
243 #else
244 static inline int mapping_has_pages(struct address_space *mapping)
245 {
246         return mapping->nrpages > 0;
247 }
248 #endif
249
250 #ifdef HAVE_KIOBUF_KIO_BLOCKS
251 #define KIOBUF_GET_BLOCKS(k) ((k)->kio_blocks)
252 #else
253 #define KIOBUF_GET_BLOCKS(k) ((k)->blocks)
254 #endif
255
256 #ifdef HAVE_SECURITY_PLUG
257 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
258                 vfs_symlink(dir, dentry, mnt, path, mode)
259 #else
260 #ifdef HAVE_4ARGS_VFS_SYMLINK
261 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
262                 vfs_symlink(dir, dentry, path, mode)
263 #else
264 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
265                        vfs_symlink(dir, dentry, path)
266 #endif
267 #endif
268
269 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
270 #define ll_set_dflags(dentry, flags) do { dentry->d_vfs_flags |= flags; } while(0)
271 #else
272 #define ll_set_dflags(dentry, flags) do { \
273                 spin_lock(&dentry->d_lock); \
274                 dentry->d_flags |= flags; \
275                 spin_unlock(&dentry->d_lock); \
276         } while(0)
277 #endif
278
279 #ifndef container_of
280 #define container_of(ptr, type, member) ({                      \
281                 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
282                 (type *)( (char *)__mptr - offsetof(type,member) );})
283 #endif
284
285 #define UP_WRITE_I_ALLOC_SEM(i)   up_write(&(i)->i_alloc_sem)
286 #define DOWN_WRITE_I_ALLOC_SEM(i) down_write(&(i)->i_alloc_sem)
287 #define LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i) LASSERT(down_read_trylock(&(i)->i_alloc_sem) == 0)
288
289 #define UP_READ_I_ALLOC_SEM(i)    up_read(&(i)->i_alloc_sem)
290 #define DOWN_READ_I_ALLOC_SEM(i)  down_read(&(i)->i_alloc_sem)
291 #define LASSERT_I_ALLOC_SEM_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
292
293 #ifndef HAVE_GRAB_CACHE_PAGE_NOWAIT_GFP
294 #define grab_cache_page_nowait_gfp(x, y, z) grab_cache_page_nowait((x), (y))
295 #endif
296
297 #include <linux/mpage.h>        /* for generic_writepages */
298 #ifndef HAVE_FILEMAP_FDATAWRITE_RANGE
299 #include <linux/backing-dev.h>  /* for mapping->backing_dev_info */
300 static inline int filemap_fdatawrite_range(struct address_space *mapping,
301                                            loff_t start, loff_t end)
302 {
303         int rc;
304         struct writeback_control wbc = {
305                 .sync_mode = WB_SYNC_ALL,
306                 .nr_to_write = (end - start + PAGE_SIZE - 1) >> PAGE_SHIFT,
307         };
308
309 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
310         wbc.range_start = start;
311         wbc.range_end = end;
312 #else
313         wbc.start = start;
314         wbc.end = end;
315 #endif
316
317 #ifdef mapping_cap_writeback_dirty
318         if (!mapping_cap_writeback_dirty(mapping))
319                 rc = 0;
320 #else
321         if (mapping->backing_dev_info->memory_backed)
322                 rc = 0;
323 #endif
324         /* do_writepages() */
325         else if (mapping->a_ops->writepages)
326                 rc = mapping->a_ops->writepages(mapping, &wbc);
327         else
328                 rc = generic_writepages(mapping, &wbc);
329         return rc;
330 }
331 #else
332 int filemap_fdatawrite_range(struct address_space *mapping,
333                              loff_t start, loff_t end);
334 #endif /* HAVE_FILEMAP_FDATAWRITE_RANGE */
335
336 #ifdef HAVE_VFS_KERN_MOUNT
337 static inline struct vfsmount *
338 ll_kern_mount(const char *fstype, int flags, const char *name, void *data)
339 {
340         struct file_system_type *type = get_fs_type(fstype);
341         struct vfsmount *mnt;
342         if (!type)
343                 return ERR_PTR(-ENODEV);
344         mnt = vfs_kern_mount(type, flags, name, data);
345         module_put(type->owner);
346         return mnt;
347 }
348 #else
349 #define ll_kern_mount(fstype, flags, name, data) do_kern_mount((fstype), (flags), (name), (data))
350 #endif
351
352 #ifdef HAVE_STATFS_DENTRY_PARAM
353 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb)->s_root, (sfs))
354 #else
355 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb), (sfs))
356 #endif
357
358 #ifndef HAVE_SB_TIME_GRAN
359 #ifndef HAVE_S_TIME_GRAN
360 #error Need s_time_gran patch!
361 #endif
362 static inline u32 get_sb_time_gran(struct super_block *sb)
363 {
364         return sb->s_time_gran;
365 }
366 #endif
367
368 #ifdef HAVE_RW_TREE_LOCK
369 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
370 #define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
371 #else
372 #define TREE_READ_LOCK_IRQ(mapping) spin_lock_irq(&(mapping)->tree_lock)
373 #define TREE_READ_UNLOCK_IRQ(mapping) spin_unlock_irq(&(mapping)->tree_lock)
374 #endif
375
376 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
377 #define ll_unregister_blkdev(a,b)       unregister_blkdev((a),(b))
378 #else
379 static inline
380 int ll_unregister_blkdev(unsigned int dev, const char *name)
381 {
382         unregister_blkdev(dev, name);
383         return 0;
384 }
385 #endif
386
387 #ifdef HAVE_INVALIDATE_BDEV_2ARG
388 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a),(b))
389 #else
390 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a))
391 #endif
392
393 #ifdef HAVE_INODE_BLKSIZE
394 #define ll_inode_blksize(a)     (a)->i_blksize
395 #else
396 #define ll_inode_blksize(a)     (1<<(a)->i_blkbits)
397 #endif
398
399 #ifdef HAVE_FS_RENAME_DOES_D_MOVE
400 #define LL_RENAME_DOES_D_MOVE   FS_RENAME_DOES_D_MOVE
401 #else
402 #define LL_RENAME_DOES_D_MOVE   FS_ODD_RENAME
403 #endif
404
405 /* add a lustre compatible layer for crypto API */
406 #include <linux/crypto.h>
407 #ifdef HAVE_ASYNC_BLOCK_CIPHER
408 #define ll_crypto_hash          crypto_hash
409 #define ll_crypto_cipher        crypto_blkcipher
410 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
411 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
412 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
413 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
414 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
415 #define ll_crypto_alloc_blkcipher(name, type, mask) \
416                 crypto_alloc_blkcipher(name ,type, mask)
417 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
418                 crypto_blkcipher_setkey(tfm, key, keylen)
419 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
420                 crypto_blkcipher_set_iv(tfm, src, len)
421 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
422                 crypto_blkcipher_get_iv(tfm, dst, len)
423 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
424                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
425 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
426                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
427 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
428                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
429 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
430                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
431
432 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
433                                  u8 *key, unsigned int *keylen,
434                                  struct scatterlist *sg,
435                                  unsigned int size, u8 *result)
436 {
437         struct hash_desc desc;
438         int              rv;
439         desc.tfm   = tfm;
440         desc.flags = 0;
441         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
442         if (rv) {
443                 CERROR("failed to hash setkey: %d\n", rv);
444                 return rv;
445         }
446         return crypto_hash_digest(&desc, sg, size, result);
447 }
448 static inline
449 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
450 {
451         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
452 }
453 static inline
454 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
455 {
456         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
457 }
458
459 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
460 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
461 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
462 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
463 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
464 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
465 #else /* HAVE_ASYNC_BLOCK_CIPHER */
466 #include <linux/scatterlist.h>
467 #define ll_crypto_hash          crypto_tfm
468 #define ll_crypto_cipher        crypto_tfm
469 #ifndef HAVE_STRUCT_HASH_DESC
470 struct hash_desc {
471         struct ll_crypto_hash *tfm;
472         u32                    flags;
473 };
474 #endif
475 #ifndef HAVE_STRUCT_BLKCIPHER_DESC
476 struct blkcipher_desc {
477         struct ll_crypto_cipher *tfm;
478         void                    *info;
479         u32                      flags;
480 };
481 #endif
482 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
483         crypto_cipher_setkey(tfm, key, keylen)
484 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
485         crypto_cipher_set_iv(tfm, src, len)
486 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
487         crypto_cipher_get_iv(tfm, dst, len)
488 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
489         crypto_cipher_encrypt((desc)->tfm, dst, src, bytes)
490 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
491         crypto_cipher_decrypt((desc)->tfm, dst, src, bytes)
492 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
493         crypto_cipher_decrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
494 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
495         crypto_cipher_encrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
496
497 static inline
498 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char * algname,
499                                                    u32 type, u32 mask)
500 {
501         char        buf[CRYPTO_MAX_ALG_NAME + 1];
502         const char *pan = algname;
503         u32         flag = 0;
504
505         if (strncmp("cbc(", algname, 4) == 0)
506                 flag |= CRYPTO_TFM_MODE_CBC;
507         else if (strncmp("ecb(", algname, 4) == 0)
508                 flag |= CRYPTO_TFM_MODE_ECB;
509         if (flag) {
510                 char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
511                 if (vp) {
512                         memcpy(buf, algname + 4, vp - algname - 4);
513                         buf[vp - algname - 4] = '\0';
514                         pan = buf;
515                 } else {
516                         flag = 0;
517                 }
518         }
519         return crypto_alloc_tfm(pan, flag);
520 }
521
522 static inline
523 struct ll_crypto_hash *ll_crypto_alloc_hash(const char *alg, u32 type, u32 mask)
524 {
525         char        buf[CRYPTO_MAX_ALG_NAME + 1];
526         const char *pan = alg;
527
528         if (strncmp("hmac(", alg, 5) == 0) {
529                 char *vp = strnchr(alg, CRYPTO_MAX_ALG_NAME, ')');
530                 if (vp) {
531                         memcpy(buf, alg+ 5, vp - alg- 5);
532                         buf[vp - alg - 5] = 0x00;
533                         pan = buf;
534                 }
535         }
536         return crypto_alloc_tfm(pan, 0);
537 }
538 static inline int ll_crypto_hash_init(struct hash_desc *desc)
539 {
540        crypto_digest_init(desc->tfm); return 0;
541 }
542 static inline int ll_crypto_hash_update(struct hash_desc *desc,
543                                         struct scatterlist *sg,
544                                         unsigned int nbytes)
545 {
546         struct scatterlist *sl = sg;
547         unsigned int        count;
548                 /*
549                  * This way is very weakness. We must ensure that
550                  * the sum of sg[0..i]->length isn't greater than nbytes.
551                  * In the upstream kernel the crypto_hash_update() also
552                  * via the nbytes computed the count of sg[...].
553                  * The old style is more safely. but it gone.
554                  */
555         for (count = 0; nbytes > 0; count ++, sl ++) {
556                 nbytes -= sl->length;
557         }
558         crypto_digest_update(desc->tfm, sg, count); return 0;
559 }
560 static inline int ll_crypto_hash_final(struct hash_desc *desc, u8 *out)
561 {
562         crypto_digest_final(desc->tfm, out); return 0;
563 }
564 static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
565                                  u8 *key, unsigned int *keylen,
566                                  struct scatterlist *sg,
567                                  unsigned int nbytes,
568                                  u8 *out)
569 {
570         struct scatterlist *sl = sg;
571         int                 count;
572         for (count = 0; nbytes > 0; count ++, sl ++) {
573                 nbytes -= sl->length;
574         }
575         crypto_hmac(tfm, key, keylen, sg, count, out);
576         return 0;
577 }
578
579 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_digest_setkey(tfm, key, keylen)
580 #define ll_crypto_blkcipher_blocksize(tfm)      crypto_tfm_alg_blocksize(tfm)
581 #define ll_crypto_blkcipher_ivsize(tfm) crypto_tfm_alg_ivsize(tfm)
582 #define ll_crypto_hash_digestsize(tfm)  crypto_tfm_alg_digestsize(tfm)
583 #define ll_crypto_hash_blocksize(tfm)   crypto_tfm_alg_blocksize(tfm)
584 #define ll_crypto_free_hash(tfm)        crypto_free_tfm(tfm)
585 #define ll_crypto_free_blkcipher(tfm)   crypto_free_tfm(tfm)
586 #define ll_crypto_tfm_alg_min_keysize   crypto_tfm_alg_min_keysize
587 #define ll_crypto_tfm_alg_max_keysize   crypto_tfm_alg_max_keysize
588 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
589
590 #ifndef HAVE_SYNCHRONIZE_RCU
591 #define synchronize_rcu() synchronize_kernel()
592 #endif
593
594 #ifdef HAVE_SECURITY_PLUG
595 #define ll_remove_suid(inode,mnt)               remove_suid(inode,mnt)
596 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
597 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
598 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
599 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
600 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
601                 vfs_mknod(dir,entry,mnt,mode,dev)
602 #define ll_security_inode_unlink(dir,entry,mnt)         \
603                 security_inode_unlink(dir,entry,mnt)
604 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
605                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
606 #else
607 #define ll_remove_suid(inode,mnt)               remove_suid(inode)
608 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
609 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
610 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
611 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
612 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
613 #define ll_security_inode_unlink(dir,entry,mnt) security_inode_unlink(dir,entry)
614 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
615                 vfs_rename(old,old_dir,new,new_dir)
616 #endif /* HAVE_SECURITY_PLUG */
617
618 #ifndef for_each_possible_cpu
619 #define for_each_possible_cpu(i) for_each_cpu(i)
620 #endif
621
622 #ifndef cpu_to_node
623 #define cpu_to_node(cpu)         0
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 /* Using kernel fls(). Userspace will use one defined in user-bitops.h. */
641 #ifndef __fls
642 #define __fls fls
643 #endif
644
645 #ifdef HAVE_INVALIDATE_INODE_PAGES
646 #define invalidate_mapping_pages(mapping,s,e) invalidate_inode_pages(mapping)
647 #endif
648
649 #ifdef HAVE_INODE_IPRIVATE
650 #define INODE_PRIVATE_DATA(inode)       ((inode)->i_private)
651 #else
652 #define INODE_PRIVATE_DATA(inode)       ((inode)->u.generic_ip)
653 #endif
654
655 #ifndef SLAB_DESTROY_BY_RCU
656 #define SLAB_DESTROY_BY_RCU 0
657 #endif
658
659 #ifdef HAVE_VFS_RENAME_MUTEX
660 #define VFS_RENAME_LOCK(inode) mutex_lock(&((inode)->i_sb->s_vfs_rename_mutex))
661 #define VFS_RENAME_UNLOCK(inode) mutex_unlock(&((inode)->i_sb->s_vfs_rename_mutex))
662 #else
663 #define VFS_RENAME_LOCK(inode) down(&((inode)->i_sb->s_vfs_rename_sem))
664 #define VFS_RENAME_UNLOCK(inode) up(&((inode)->i_sb->s_vfs_rename_sem))
665 #endif
666
667 #endif /* __KERNEL__ */
668 #endif /* _COMPAT25_H */