Whamcloud - gitweb
Branch HEAD
[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 [sun.com URL with a
20  * copy of GPLv2].
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 #ifndef HAVE_SET_FS_PWD
60 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
61                 struct dentry *dentry)
62 {
63         struct dentry *old_pwd;
64         struct vfsmount *old_pwdmnt;
65
66         write_lock(&fs->lock);
67         old_pwd = fs->pwd;
68         old_pwdmnt = fs->pwdmnt;
69         fs->pwdmnt = mntget(mnt);
70         fs->pwd = dget(dentry);
71         write_unlock(&fs->lock);
72
73         if (old_pwd) {
74                 dput(old_pwd);
75                 mntput(old_pwdmnt);
76         }
77 }
78 #else
79 #define ll_set_fs_pwd set_fs_pwd
80 #endif /* HAVE_SET_FS_PWD */
81
82 /*
83  * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
84  * ATTR_* attributes (see bug 13828)
85  */
86 #define ATTR_BLOCKS    (1 << 27)
87
88 #if HAVE_INODE_I_MUTEX
89 #define UNLOCK_INODE_MUTEX(inode) do {mutex_unlock(&(inode)->i_mutex); } while(0)
90 #define LOCK_INODE_MUTEX(inode) do {mutex_lock(&(inode)->i_mutex); } while(0)
91 #define TRYLOCK_INODE_MUTEX(inode) mutex_trylock(&(inode)->i_mutex)
92 #else
93 #define UNLOCK_INODE_MUTEX(inode) do {up(&(inode)->i_sem); } while(0)
94 #define LOCK_INODE_MUTEX(inode) do {down(&(inode)->i_sem); } while(0)
95 #define TRYLOCK_INODE_MUTEX(inode) (!down_trylock(&(inode)->i_sem))
96 #endif /* HAVE_INODE_I_MUTEX */
97
98 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
99 #define d_child d_u.d_child
100 #define d_rcu d_u.d_rcu
101 #endif
102
103 #ifdef HAVE_DQUOTOFF_MUTEX
104 #define UNLOCK_DQONOFF_MUTEX(dqopt) do {mutex_unlock(&(dqopt)->dqonoff_mutex); } while(0)
105 #define LOCK_DQONOFF_MUTEX(dqopt) do {mutex_lock(&(dqopt)->dqonoff_mutex); } while(0)
106 #else
107 #define UNLOCK_DQONOFF_MUTEX(dqopt) do {up(&(dqopt)->dqonoff_sem); } while(0)
108 #define LOCK_DQONOFF_MUTEX(dqopt) do {down(&(dqopt)->dqonoff_sem); } while(0)
109 #endif /* HAVE_DQUOTOFF_MUTEX */
110
111 #define current_ngroups current->group_info->ngroups
112 #define current_groups current->group_info->small_block
113
114 #ifndef page_private
115 #define page_private(page) ((page)->private)
116 #define set_page_private(page, v) ((page)->private = (v))
117 #endif
118
119 #ifndef HAVE_GFP_T
120 #define gfp_t int
121 #endif
122
123 #define lock_dentry(___dentry)          spin_lock(&(___dentry)->d_lock)
124 #define unlock_dentry(___dentry)        spin_unlock(&(___dentry)->d_lock)
125
126 #define ll_kernel_locked()      kernel_locked()
127
128 /*
129  * OBD need working random driver, thus all our
130  * initialization routines must be called after device
131  * driver initialization
132  */
133 #ifndef MODULE
134 #undef module_init
135 #define module_init(a)     late_initcall(a)
136 #endif
137
138 /* XXX our code should be using the 2.6 calls, not the other way around */
139 #define TryLockPage(page)               TestSetPageLocked(page)
140 #define Page_Uptodate(page)             PageUptodate(page)
141 #define ll_redirty_page(page)           set_page_dirty(page)
142
143 #define KDEVT_INIT(val)                 (val)
144
145 #define LTIME_S(time)                   (time.tv_sec)
146 #define ll_path_lookup                  path_lookup
147 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
148
149 #define ll_pgcache_lock(mapping)          spin_lock(&mapping->page_lock)
150 #define ll_pgcache_unlock(mapping)        spin_unlock(&mapping->page_lock)
151 #define ll_call_writepage(inode, page)  \
152                                 (inode)->i_mapping->a_ops->writepage(page, NULL)
153 #define ll_invalidate_inode_pages(inode) \
154                                 invalidate_inode_pages((inode)->i_mapping)
155 #define ll_truncate_complete_page(page) \
156                                 truncate_complete_page(page->mapping, page)
157
158 #define ll_vfs_create(a,b,c,d)          vfs_create(a,b,c,d)
159 #define ll_dev_t                        dev_t
160 #define kdev_t                          dev_t
161 #define to_kdev_t(dev)                  (dev)
162 #define kdev_t_to_nr(dev)               (dev)
163 #define val_to_kdev(dev)                (dev)
164 #define ILOOKUP(sb, ino, test, data)    ilookup5(sb, ino, test, data);
165
166 #include <linux/writeback.h>
167
168 static inline int cleanup_group_info(void)
169 {
170         struct group_info *ginfo;
171
172         ginfo = groups_alloc(0);
173         if (!ginfo)
174                 return -ENOMEM;
175
176         set_current_groups(ginfo);
177         put_group_info(ginfo);
178
179         return 0;
180 }
181
182 #define __set_page_ll_data(page, llap) \
183         do {       \
184                 page_cache_get(page); \
185                 SetPagePrivate(page); \
186                 set_page_private(page, (unsigned long)llap); \
187         } while (0)
188 #define __clear_page_ll_data(page) \
189         do {       \
190                 ClearPagePrivate(page); \
191                 set_page_private(page, 0); \
192                 page_cache_release(page); \
193         } while(0)
194
195 #define kiobuf bio
196
197 #include <linux/proc_fs.h>
198
199 #if !defined(HAVE_D_REHASH_COND) && defined(HAVE___D_REHASH)
200 #define d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
201 extern void __d_rehash(struct dentry *dentry, int lock);
202 #endif
203
204 #if !defined(HAVE_D_MOVE_LOCKED) && defined(HAVE___D_MOVE)
205 #define d_move_locked(dentry, target) __d_move(dentry, target)
206 extern void __d_move(struct dentry *dentry, struct dentry *target);
207 #endif
208
209 #ifdef HAVE_CAN_SLEEP_ARG
210 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
211         flock_lock_file_wait(file, lock, can_sleep)
212 #else
213 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
214         flock_lock_file_wait(file, lock)
215 #endif
216
217 #define CheckWriteback(page, cmd) \
218         ((!PageWriteback(page) && (cmd & OBD_BRW_READ)) || \
219          (PageWriteback(page) && (cmd & OBD_BRW_WRITE)))
220
221 #ifdef HAVE_PAGE_LIST
222 static inline int mapping_has_pages(struct address_space *mapping)
223 {
224         int rc = 1;
225
226         ll_pgcache_lock(mapping);
227         if (list_empty(&mapping->dirty_pages) &&
228             list_empty(&mapping->clean_pages) &&
229             list_empty(&mapping->locked_pages)) {
230                 rc = 0;
231         }
232         ll_pgcache_unlock(mapping);
233
234         return rc;
235 }
236 #else
237 static inline int mapping_has_pages(struct address_space *mapping)
238 {
239         return mapping->nrpages > 0;
240 }
241 #endif
242
243 #ifdef HAVE_KIOBUF_KIO_BLOCKS
244 #define KIOBUF_GET_BLOCKS(k) ((k)->kio_blocks)
245 #else
246 #define KIOBUF_GET_BLOCKS(k) ((k)->blocks)
247 #endif
248
249 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
250 #define ll_set_dflags(dentry, flags) do { dentry->d_vfs_flags |= flags; } while(0)
251 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path)
252 #else
253 #define ll_set_dflags(dentry, flags) do { \
254                 spin_lock(&dentry->d_lock); \
255                 dentry->d_flags |= flags; \
256                 spin_unlock(&dentry->d_lock); \
257         } while(0)
258 #ifdef HAVE_SECURITY_PLUG
259 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
260                 vfs_symlink(dir, dentry, mnt, path, mode)
261 #else
262 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
263                 vfs_symlink(dir, dentry, path, mode)
264 #endif
265 #endif
266
267 #ifndef container_of
268 #define container_of(ptr, type, member) ({                      \
269                 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
270                 (type *)( (char *)__mptr - offsetof(type,member) );})
271 #endif
272
273 #ifdef HAVE_I_ALLOC_SEM
274 #define UP_WRITE_I_ALLOC_SEM(i)   do { up_write(&(i)->i_alloc_sem); } while (0)
275 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down_write(&(i)->i_alloc_sem); } while(0)
276 #define LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i) LASSERT(down_read_trylock(&(i)->i_alloc_sem) == 0)
277
278 #define UP_READ_I_ALLOC_SEM(i)    do { up_read(&(i)->i_alloc_sem); } while (0)
279 #define DOWN_READ_I_ALLOC_SEM(i)  do { down_read(&(i)->i_alloc_sem); } while (0)
280 #define LASSERT_I_ALLOC_SEM_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
281 #else
282 #define UP_READ_I_ALLOC_SEM(i)              do { } while (0)
283 #define DOWN_READ_I_ALLOC_SEM(i)            do { } while (0)
284 #define LASSERT_I_ALLOC_SEM_READ_LOCKED(i)  do { } while (0)
285
286 #define UP_WRITE_I_ALLOC_SEM(i)             do { } while (0)
287 #define DOWN_WRITE_I_ALLOC_SEM(i)           do { } while (0)
288 #define LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i) do { } while (0)
289 #endif
290
291 #ifndef HAVE_GRAB_CACHE_PAGE_NOWAIT_GFP
292 #define grab_cache_page_nowait_gfp(x, y, z) grab_cache_page_nowait((x), (y))
293 #endif
294
295 #ifndef HAVE_FILEMAP_FDATAWRITE
296 #define filemap_fdatawrite(mapping)      filemap_fdatasync(mapping)
297 #endif
298
299 #ifdef HAVE_VFS_KERN_MOUNT
300 static inline 
301 struct vfsmount *
302 ll_kern_mount(const char *fstype, int flags, const char *name, void *data)
303 {
304         struct file_system_type *type = get_fs_type(fstype);
305         struct vfsmount *mnt;
306         if (!type)
307                 return ERR_PTR(-ENODEV);
308         mnt = vfs_kern_mount(type, flags, name, data);
309         module_put(type->owner);
310         return mnt;
311 }
312 #else
313 #define ll_kern_mount(fstype, flags, name, data) do_kern_mount((fstype), (flags), (name), (data))
314 #endif
315
316 #ifndef HAVE_GENERIC_FILE_READ
317 static inline
318 ssize_t
319 generic_file_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
320 {
321         struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
322         struct kiocb kiocb;
323         ssize_t ret;
324
325         init_sync_kiocb(&kiocb, filp);
326         kiocb.ki_pos = *ppos;
327         kiocb.ki_left = len;
328
329         ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
330         *ppos = kiocb.ki_pos;
331         return ret;
332 }
333 #endif
334
335 #ifndef HAVE_GENERIC_FILE_WRITE
336 static inline
337 ssize_t
338 generic_file_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
339 {
340         struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
341         struct kiocb kiocb;
342         ssize_t ret;
343
344         init_sync_kiocb(&kiocb, filp);
345         kiocb.ki_pos = *ppos;
346         kiocb.ki_left = len;
347
348         ret = generic_file_aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
349         *ppos = kiocb.ki_pos;
350
351         return ret;
352 }
353 #endif
354
355 #ifdef HAVE_STATFS_DENTRY_PARAM
356 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb)->s_root, (sfs))
357 #else
358 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb), (sfs))
359 #endif
360
361 /* task_struct */
362 #ifndef HAVE_TASK_PPTR
363 #define p_pptr parent
364 #endif
365
366 #ifndef HAVE_SB_TIME_GRAN
367 #ifndef HAVE_S_TIME_GRAN
368 #error Need s_time_gran patch!
369 #endif
370 static inline u32 get_sb_time_gran(struct super_block *sb)
371 {
372         return sb->s_time_gran;
373 }
374 #endif
375
376 #ifdef HAVE_RW_TREE_LOCK
377 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
378 #define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
379 #else
380 #define TREE_READ_LOCK_IRQ(mapping) spin_lock_irq(&(mapping)->tree_lock)
381 #define TREE_READ_UNLOCK_IRQ(mapping) spin_unlock_irq(&(mapping)->tree_lock)
382 #endif
383
384 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
385 #define ll_unregister_blkdev(a,b)       unregister_blkdev((a),(b))
386 #else
387 static inline 
388 int ll_unregister_blkdev(unsigned int dev, const char *name)
389 {
390         unregister_blkdev(dev, name);
391         return 0;
392 }
393 #endif
394
395 #ifdef HAVE_INVALIDATE_BDEV_2ARG
396 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a),(b))
397 #else
398 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a))
399 #endif
400
401 #ifdef HAVE_INODE_BLKSIZE
402 #define ll_inode_blksize(a)     (a)->i_blksize
403 #else
404 #define ll_inode_blksize(a)     (1<<(a)->i_blkbits)
405 #endif
406
407 #ifndef HAVE_EXPORT_NR_FREE_BUFFER_PAGES
408 static inline unsigned int ll_nr_free_buffer_pages(void)
409 {
410         struct sysinfo si;
411
412         si_meminfo(&si);
413         return (unsigned int)(si.freeram - si.freehigh);
414 }
415 #else
416 #define ll_nr_free_buffer_pages()       nr_free_buffer_pages()
417 #endif
418
419 #ifdef HAVE_FS_RENAME_DOES_D_MOVE
420 #define LL_RENAME_DOES_D_MOVE   FS_RENAME_DOES_D_MOVE
421 #else
422 #define LL_RENAME_DOES_D_MOVE   FS_ODD_RENAME
423 #endif
424
425 /* add a lustre compatible layer for crypto API */
426 #include <linux/crypto.h>
427 #ifdef HAVE_ASYNC_BLOCK_CIPHER
428 #define ll_crypto_hash          crypto_hash
429 #define ll_crypto_cipher        crypto_blkcipher
430 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
431 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
432 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
433 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
434 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
435 #define ll_crypto_alloc_blkcipher(name, type, mask) \
436                 crypto_alloc_blkcipher(name ,type, mask)
437 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
438                 crypto_blkcipher_setkey(tfm, key, keylen)
439 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
440                 crypto_blkcipher_set_iv(tfm, src, len)
441 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
442                 crypto_blkcipher_get_iv(tfm, dst, len)
443 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
444                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
445 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
446                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
447 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
448                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
449 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
450                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
451
452 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
453                                  u8 *key, unsigned int *keylen,
454                                  struct scatterlist *sg,
455                                  unsigned int size, u8 *result)
456 {
457         struct hash_desc desc;
458         int              rv;
459         desc.tfm   = tfm;
460         desc.flags = 0;
461         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
462         if (rv) {
463                 CERROR("failed to hash setkey: %d\n", rv);
464                 return rv;
465         }
466         return crypto_hash_digest(&desc, sg, size, result);
467 }
468 static inline
469 unsigned int crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
470 {
471         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
472 }
473 static inline
474 unsigned int crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
475 {
476         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
477 }
478
479 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
480 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
481 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
482 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
483 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
484 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
485 #else /* HAVE_ASYNC_BLOCK_CIPHER */
486 #include <linux/scatterlist.h>
487 #define ll_crypto_hash          crypto_tfm
488 #define ll_crypto_cipher        crypto_tfm
489 struct hash_desc {
490         struct ll_crypto_hash *tfm;
491         u32                    flags;
492 };
493 struct blkcipher_desc {
494         struct ll_crypto_cipher *tfm;
495         void                    *info;
496         u32                      flags;
497 };
498 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
499         crypto_cipher_setkey(tfm, key, keylen)
500 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
501         crypto_cipher_set_iv(tfm, src, len)
502 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
503         crypto_cipher_get_iv(tfm, dst, len)
504 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
505         crypto_cipher_encrypt((desc)->tfm, dst, src, bytes)
506 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
507         crypto_cipher_decrypt((desc)->tfm, dst, src, bytes)
508 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
509         crypto_cipher_decrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
510 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
511         crypto_cipher_encrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
512
513 extern struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(
514                             const char * algname, u32 type, u32 mask);
515 static inline 
516 struct ll_crypto_hash *ll_crypto_alloc_hash(const char *alg, u32 type, u32 mask)
517 {
518         char        buf[CRYPTO_MAX_ALG_NAME + 1];
519         const char *pan = alg;
520
521         if (strncmp("hmac(", alg, 5) == 0) {
522                 char *vp = strnchr(alg, CRYPTO_MAX_ALG_NAME, ')');
523                 if (vp) {
524                         memcpy(buf, alg+ 5, vp - alg- 5);
525                         buf[vp - alg - 5] = 0x00;
526                         pan = buf;
527                 }
528         }
529         return crypto_alloc_tfm(pan, 0);
530 }
531 static inline int ll_crypto_hash_init(struct hash_desc *desc)
532 {
533        crypto_digest_init(desc->tfm); return 0;
534 }
535 static inline int ll_crypto_hash_update(struct hash_desc *desc,
536                                         struct scatterlist *sg,
537                                         unsigned int nbytes)
538 {
539         struct scatterlist *sl = sg;
540         unsigned int        count;
541                 /* 
542                  * This way is very weakness. We must ensure that
543                  * the sum of sg[0..i]->length isn't greater than nbytes.
544                  * In the upstream kernel the crypto_hash_update() also 
545                  * via the nbytes computed the count of sg[...].
546                  * The old style is more safely. but it gone.
547                  */
548         for (count = 0; nbytes > 0; count ++, sl ++) {
549                 nbytes -= sl->length;
550         }
551         crypto_digest_update(desc->tfm, sg, count); return 0;
552 }
553 static inline int ll_crypto_hash_final(struct hash_desc *desc, u8 *out)
554 {
555         crypto_digest_final(desc->tfm, out); return 0;
556 }
557 static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
558                                  u8 *key, unsigned int *keylen,
559                                  struct scatterlist *sg,
560                                  unsigned int nbytes,
561                                  u8 *out)
562 {
563         struct scatterlist *sl = sg;
564         int                 count;
565         for (count = 0; nbytes > 0; count ++, sl ++) {
566                 nbytes -= sl->length;
567         }
568         crypto_hmac(tfm, key, keylen, sg, count, out);
569         return 0;
570 }
571
572 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_digest_setkey(tfm, key, keylen)
573 #define ll_crypto_blkcipher_blocksize(tfm)      crypto_tfm_alg_blocksize(tfm)
574 #define ll_crypto_blkcipher_ivsize(tfm) crypto_tfm_alg_ivsize(tfm)
575 #define ll_crypto_hash_digestsize(tfm)  crypto_tfm_alg_digestsize(tfm)
576 #define ll_crypto_hash_blocksize(tfm)   crypto_tfm_alg_blocksize(tfm)
577 #define ll_crypto_free_hash(tfm)        crypto_free_tfm(tfm)
578 #define ll_crypto_free_blkcipher(tfm)   crypto_free_tfm(tfm)
579 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
580
581 #ifdef HAVE_SECURITY_PLUG
582 #define ll_remove_suid(inode,mnt)               remove_suid(inode,mnt)
583 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
584 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
585 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
586 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
587 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
588                 vfs_mknod(dir,entry,mnt,mode,dev)
589 #define ll_security_inode_unlink(dir,entry,mnt)         \
590                 security_inode_unlink(dir,entry,mnt)     
591 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
592                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
593 #else
594 #define ll_remove_suid(inode,mnt)               remove_suid(inode)
595 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
596 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
597 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
598 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
599 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
600 #define ll_security_inode_unlink(dir,entry,mnt) security_inode_unlink(dir,entry)     
601 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
602                 vfs_rename(old,old_dir,new,new_dir)
603 #endif
604
605 #endif /* __KERNEL__ */
606 #endif /* _COMPAT25_H */