Whamcloud - gitweb
b=15699
[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 #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 LOCK_INODE_MUTEX_PARENT(inode) \
92 do {mutex_lock_nested(&(inode)->i_mutex, I_MUTEX_PARENT); } while(0)
93 #define TRYLOCK_INODE_MUTEX(inode) mutex_trylock(&(inode)->i_mutex)
94 #else
95 #define UNLOCK_INODE_MUTEX(inode) do {up(&(inode)->i_sem); } while(0)
96 #define LOCK_INODE_MUTEX(inode) do {down(&(inode)->i_sem); } while(0)
97 #define TRYLOCK_INODE_MUTEX(inode) (!down_trylock(&(inode)->i_sem))
98 #define LOCK_INODE_MUTEX_PARENT(inode) LOCK_INODE_MUTEX(inode)
99 #endif /* HAVE_INODE_I_MUTEX */
100
101 #ifdef HAVE_SEQ_LOCK
102 #define LL_SEQ_LOCK(seq) mutex_lock(&(seq)->lock)
103 #define LL_SEQ_UNLOCK(seq) mutex_unlock(&(seq)->lock)
104 #else
105 #define LL_SEQ_LOCK(seq) down(&(seq)->sem)
106 #define LL_SEQ_UNLOCK(seq) up(&(seq)->sem)
107 #endif
108
109 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
110 #define d_child d_u.d_child
111 #define d_rcu d_u.d_rcu
112 #endif
113
114 #ifdef HAVE_DQUOTOFF_MUTEX
115 #define UNLOCK_DQONOFF_MUTEX(dqopt) do {mutex_unlock(&(dqopt)->dqonoff_mutex); } while(0)
116 #define LOCK_DQONOFF_MUTEX(dqopt) do {mutex_lock(&(dqopt)->dqonoff_mutex); } while(0)
117 #else
118 #define UNLOCK_DQONOFF_MUTEX(dqopt) do {up(&(dqopt)->dqonoff_sem); } while(0)
119 #define LOCK_DQONOFF_MUTEX(dqopt) do {down(&(dqopt)->dqonoff_sem); } while(0)
120 #endif /* HAVE_DQUOTOFF_MUTEX */
121
122 #define current_ngroups current->group_info->ngroups
123 #define current_groups current->group_info->small_block
124
125 #ifndef page_private
126 #define page_private(page) ((page)->private)
127 #define set_page_private(page, v) ((page)->private = (v))
128 #endif
129
130 #ifndef HAVE_GFP_T
131 #define gfp_t int
132 #endif
133
134 #define lock_dentry(___dentry)          spin_lock(&(___dentry)->d_lock)
135 #define unlock_dentry(___dentry)        spin_unlock(&(___dentry)->d_lock)
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 #define TryLockPage(page)               TestSetPageLocked(page)
151 #define Page_Uptodate(page)             PageUptodate(page)
152 #define ll_redirty_page(page)           set_page_dirty(page)
153
154 #define KDEVT_INIT(val)                 (val)
155
156 #define LTIME_S(time)                   (time.tv_sec)
157 #define ll_path_lookup                  path_lookup
158 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
159
160 #define ll_pgcache_lock(mapping)          spin_lock(&mapping->page_lock)
161 #define ll_pgcache_unlock(mapping)        spin_unlock(&mapping->page_lock)
162 #define ll_call_writepage(inode, page)  \
163                                 (inode)->i_mapping->a_ops->writepage(page, NULL)
164 #define ll_invalidate_inode_pages(inode) \
165                                 invalidate_inode_pages((inode)->i_mapping)
166 #define ll_truncate_complete_page(page) \
167                                 truncate_complete_page(page->mapping, page)
168
169 #define ll_vfs_create(a,b,c,d)          vfs_create(a,b,c,d)
170 #define ll_dev_t                        dev_t
171 #define kdev_t                          dev_t
172 #define to_kdev_t(dev)                  (dev)
173 #define kdev_t_to_nr(dev)               (dev)
174 #define val_to_kdev(dev)                (dev)
175 #define ILOOKUP(sb, ino, test, data)    ilookup5(sb, ino, test, data);
176
177 #include <linux/writeback.h>
178
179 static inline int cleanup_group_info(void)
180 {
181         struct group_info *ginfo;
182
183         ginfo = groups_alloc(0);
184         if (!ginfo)
185                 return -ENOMEM;
186
187         set_current_groups(ginfo);
188         put_group_info(ginfo);
189
190         return 0;
191 }
192
193 #define __set_page_ll_data(page, llap) \
194         do {       \
195                 page_cache_get(page); \
196                 SetPagePrivate(page); \
197                 set_page_private(page, (unsigned long)llap); \
198         } while (0)
199 #define __clear_page_ll_data(page) \
200         do {       \
201                 ClearPagePrivate(page); \
202                 set_page_private(page, 0); \
203                 page_cache_release(page); \
204         } while(0)
205
206 #define kiobuf bio
207
208 #include <linux/proc_fs.h>
209
210 #if !defined(HAVE_D_REHASH_COND) && defined(HAVE___D_REHASH)
211 #define d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
212 extern void __d_rehash(struct dentry *dentry, int lock);
213 #endif
214
215 #if !defined(HAVE_D_MOVE_LOCKED) && defined(HAVE___D_MOVE)
216 #define d_move_locked(dentry, target) __d_move(dentry, target)
217 extern void __d_move(struct dentry *dentry, struct dentry *target);
218 #endif
219
220 #ifdef HAVE_CAN_SLEEP_ARG
221 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
222         flock_lock_file_wait(file, lock, can_sleep)
223 #else
224 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
225         flock_lock_file_wait(file, lock)
226 #endif
227
228 #define CheckWriteback(page, cmd) \
229         ((!PageWriteback(page) && (cmd & OBD_BRW_READ)) || \
230          (PageWriteback(page) && (cmd & OBD_BRW_WRITE)))
231
232 #ifdef HAVE_PAGE_LIST
233 static inline int mapping_has_pages(struct address_space *mapping)
234 {
235         int rc = 1;
236
237         ll_pgcache_lock(mapping);
238         if (list_empty(&mapping->dirty_pages) &&
239             list_empty(&mapping->clean_pages) &&
240             list_empty(&mapping->locked_pages)) {
241                 rc = 0;
242         }
243         ll_pgcache_unlock(mapping);
244
245         return rc;
246 }
247 #else
248 static inline int mapping_has_pages(struct address_space *mapping)
249 {
250         return mapping->nrpages > 0;
251 }
252 #endif
253
254 #ifdef HAVE_KIOBUF_KIO_BLOCKS
255 #define KIOBUF_GET_BLOCKS(k) ((k)->kio_blocks)
256 #else
257 #define KIOBUF_GET_BLOCKS(k) ((k)->blocks)
258 #endif
259
260 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
261 #define ll_set_dflags(dentry, flags) do { dentry->d_vfs_flags |= flags; } while(0)
262 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path)
263 #else
264 #define ll_set_dflags(dentry, flags) do { \
265                 spin_lock(&dentry->d_lock); \
266                 dentry->d_flags |= flags; \
267                 spin_unlock(&dentry->d_lock); \
268         } while(0)
269 #ifdef HAVE_SECURITY_PLUG
270 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
271                 vfs_symlink(dir, dentry, mnt, path, mode)
272 #else
273 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
274                 vfs_symlink(dir, dentry, path, mode)
275 #endif
276 #endif
277
278 #ifndef container_of
279 #define container_of(ptr, type, member) ({                      \
280                 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
281                 (type *)( (char *)__mptr - offsetof(type,member) );})
282 #endif
283
284 #ifdef HAVE_I_ALLOC_SEM
285 #define UP_WRITE_I_ALLOC_SEM(i)   do { up_write(&(i)->i_alloc_sem); } while (0)
286 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down_write(&(i)->i_alloc_sem); } while(0)
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)    do { up_read(&(i)->i_alloc_sem); } while (0)
290 #define DOWN_READ_I_ALLOC_SEM(i)  do { down_read(&(i)->i_alloc_sem); } while (0)
291 #define LASSERT_I_ALLOC_SEM_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
292 #else
293 #define UP_READ_I_ALLOC_SEM(i)              do { } while (0)
294 #define DOWN_READ_I_ALLOC_SEM(i)            do { } while (0)
295 #define LASSERT_I_ALLOC_SEM_READ_LOCKED(i)  do { } while (0)
296
297 #define UP_WRITE_I_ALLOC_SEM(i)             do { } while (0)
298 #define DOWN_WRITE_I_ALLOC_SEM(i)           do { } while (0)
299 #define LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i) do { } while (0)
300 #endif
301
302 #ifndef HAVE_GRAB_CACHE_PAGE_NOWAIT_GFP
303 #define grab_cache_page_nowait_gfp(x, y, z) grab_cache_page_nowait((x), (y))
304 #endif
305
306 #ifndef HAVE_FILEMAP_FDATAWRITE
307 #define filemap_fdatawrite(mapping)      filemap_fdatasync(mapping)
308 #endif
309
310 #include <linux/mpage.h>        /* for generic_writepages */
311 #ifndef HAVE_FILEMAP_FDATAWRITE_RANGE
312 #include <linux/backing-dev.h>  /* for mapping->backing_dev_info */
313 static inline int filemap_fdatawrite_range(struct address_space *mapping,
314                                            loff_t start, loff_t end)
315 {
316         int rc;
317         struct writeback_control wbc = {
318                 .sync_mode = WB_SYNC_ALL,
319                 .nr_to_write = (end - start + PAGE_SIZE - 1) >> PAGE_SHIFT,
320         };
321
322 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
323         wbc.range_start = start;
324         wbc.range_end = end;
325 #else
326         wbc.start = start;
327         wbc.end = end;
328 #endif
329
330 #ifdef mapping_cap_writeback_dirty
331         if (!mapping_cap_writeback_dirty(mapping))
332                 rc = 0;
333 #else
334         if (mapping->backing_dev_info->memory_backed)
335                 rc = 0;
336 #endif
337         /* do_writepages() */
338         else if (mapping->a_ops->writepages)
339                 rc = mapping->a_ops->writepages(mapping, &wbc);
340         else
341                 rc = generic_writepages(mapping, &wbc);
342         return rc;
343 }
344 #else
345 int filemap_fdatawrite_range(struct address_space *mapping,
346                              loff_t start, loff_t end);
347 #endif
348
349 #ifdef HAVE_VFS_KERN_MOUNT
350 static inline
351 struct vfsmount *
352 ll_kern_mount(const char *fstype, int flags, const char *name, void *data)
353 {
354         struct file_system_type *type = get_fs_type(fstype);
355         struct vfsmount *mnt;
356         if (!type)
357                 return ERR_PTR(-ENODEV);
358         mnt = vfs_kern_mount(type, flags, name, data);
359         module_put(type->owner);
360         return mnt;
361 }
362 #else
363 #define ll_kern_mount(fstype, flags, name, data) do_kern_mount((fstype), (flags), (name), (data))
364 #endif
365
366 #ifdef HAVE_STATFS_DENTRY_PARAM
367 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb)->s_root, (sfs))
368 #else
369 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb), (sfs))
370 #endif
371
372 /* task_struct */
373 #ifndef HAVE_TASK_PPTR
374 #define p_pptr parent
375 #endif
376
377 #ifndef HAVE_SB_TIME_GRAN
378 #ifndef HAVE_S_TIME_GRAN
379 #error Need s_time_gran patch!
380 #endif
381 static inline u32 get_sb_time_gran(struct super_block *sb)
382 {
383         return sb->s_time_gran;
384 }
385 #endif
386
387 #ifdef HAVE_RW_TREE_LOCK
388 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
389 #define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
390 #else
391 #define TREE_READ_LOCK_IRQ(mapping) spin_lock_irq(&(mapping)->tree_lock)
392 #define TREE_READ_UNLOCK_IRQ(mapping) spin_unlock_irq(&(mapping)->tree_lock)
393 #endif
394
395 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
396 #define ll_unregister_blkdev(a,b)       unregister_blkdev((a),(b))
397 #else
398 static inline
399 int ll_unregister_blkdev(unsigned int dev, const char *name)
400 {
401         unregister_blkdev(dev, name);
402         return 0;
403 }
404 #endif
405
406 #ifdef HAVE_INVALIDATE_BDEV_2ARG
407 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a),(b))
408 #else
409 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a))
410 #endif
411
412 #ifdef HAVE_INODE_BLKSIZE
413 #define ll_inode_blksize(a)     (a)->i_blksize
414 #else
415 #define ll_inode_blksize(a)     (1<<(a)->i_blkbits)
416 #endif
417
418 #ifdef HAVE_FS_RENAME_DOES_D_MOVE
419 #define LL_RENAME_DOES_D_MOVE   FS_RENAME_DOES_D_MOVE
420 #else
421 #define LL_RENAME_DOES_D_MOVE   FS_ODD_RENAME
422 #endif
423
424 /* add a lustre compatible layer for crypto API */
425 #include <linux/crypto.h>
426 #ifdef HAVE_ASYNC_BLOCK_CIPHER
427 #define ll_crypto_hash          crypto_hash
428 #define ll_crypto_cipher        crypto_blkcipher
429 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
430 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
431 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
432 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
433 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
434 #define ll_crypto_alloc_blkcipher(name, type, mask) \
435                 crypto_alloc_blkcipher(name ,type, mask)
436 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
437                 crypto_blkcipher_setkey(tfm, key, keylen)
438 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
439                 crypto_blkcipher_set_iv(tfm, src, len)
440 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
441                 crypto_blkcipher_get_iv(tfm, dst, len)
442 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
443                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
444 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
445                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
446 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
447                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
448 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
449                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
450
451 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
452                                  u8 *key, unsigned int *keylen,
453                                  struct scatterlist *sg,
454                                  unsigned int size, u8 *result)
455 {
456         struct hash_desc desc;
457         int              rv;
458         desc.tfm   = tfm;
459         desc.flags = 0;
460         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
461         if (rv) {
462                 CERROR("failed to hash setkey: %d\n", rv);
463                 return rv;
464         }
465         return crypto_hash_digest(&desc, sg, size, result);
466 }
467 static inline
468 unsigned int crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
469 {
470         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
471 }
472 static inline
473 unsigned int crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
474 {
475         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
476 }
477
478 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
479 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
480 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
481 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
482 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
483 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
484 #else /* HAVE_ASYNC_BLOCK_CIPHER */
485 #include <linux/scatterlist.h>
486 #define ll_crypto_hash          crypto_tfm
487 #define ll_crypto_cipher        crypto_tfm
488 struct hash_desc {
489         struct ll_crypto_hash *tfm;
490         u32                    flags;
491 };
492 struct blkcipher_desc {
493         struct ll_crypto_cipher *tfm;
494         void                    *info;
495         u32                      flags;
496 };
497 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
498         crypto_cipher_setkey(tfm, key, keylen)
499 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
500         crypto_cipher_set_iv(tfm, src, len)
501 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
502         crypto_cipher_get_iv(tfm, dst, len)
503 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
504         crypto_cipher_encrypt((desc)->tfm, dst, src, bytes)
505 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
506         crypto_cipher_decrypt((desc)->tfm, dst, src, bytes)
507 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
508         crypto_cipher_decrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
509 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
510         crypto_cipher_encrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
511
512 static inline
513 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char * algname,
514                                                    u32 type, u32 mask)
515 {
516         char        buf[CRYPTO_MAX_ALG_NAME + 1];
517         const char *pan = algname;
518         u32         flag = 0;
519
520         if (strncmp("cbc(", algname, 4) == 0)
521                 flag |= CRYPTO_TFM_MODE_CBC;
522         else if (strncmp("ecb(", algname, 4) == 0)
523                 flag |= CRYPTO_TFM_MODE_ECB;
524         if (flag) {
525                 char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
526                 if (vp) {
527                         memcpy(buf, algname + 4, vp - algname - 4);
528                         buf[vp - algname - 4] = '\0';
529                         pan = buf;
530                 } else {
531                         flag = 0;
532                 }
533         }
534         return crypto_alloc_tfm(pan, flag);
535 }
536
537 static inline
538 struct ll_crypto_hash *ll_crypto_alloc_hash(const char *alg, u32 type, u32 mask)
539 {
540         char        buf[CRYPTO_MAX_ALG_NAME + 1];
541         const char *pan = alg;
542
543         if (strncmp("hmac(", alg, 5) == 0) {
544                 char *vp = strnchr(alg, CRYPTO_MAX_ALG_NAME, ')');
545                 if (vp) {
546                         memcpy(buf, alg+ 5, vp - alg- 5);
547                         buf[vp - alg - 5] = 0x00;
548                         pan = buf;
549                 }
550         }
551         return crypto_alloc_tfm(pan, 0);
552 }
553 static inline int ll_crypto_hash_init(struct hash_desc *desc)
554 {
555        crypto_digest_init(desc->tfm); return 0;
556 }
557 static inline int ll_crypto_hash_update(struct hash_desc *desc,
558                                         struct scatterlist *sg,
559                                         unsigned int nbytes)
560 {
561         struct scatterlist *sl = sg;
562         unsigned int        count;
563                 /*
564                  * This way is very weakness. We must ensure that
565                  * the sum of sg[0..i]->length isn't greater than nbytes.
566                  * In the upstream kernel the crypto_hash_update() also
567                  * via the nbytes computed the count of sg[...].
568                  * The old style is more safely. but it gone.
569                  */
570         for (count = 0; nbytes > 0; count ++, sl ++) {
571                 nbytes -= sl->length;
572         }
573         crypto_digest_update(desc->tfm, sg, count); return 0;
574 }
575 static inline int ll_crypto_hash_final(struct hash_desc *desc, u8 *out)
576 {
577         crypto_digest_final(desc->tfm, out); return 0;
578 }
579 static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
580                                  u8 *key, unsigned int *keylen,
581                                  struct scatterlist *sg,
582                                  unsigned int nbytes,
583                                  u8 *out)
584 {
585         struct scatterlist *sl = sg;
586         int                 count;
587         for (count = 0; nbytes > 0; count ++, sl ++) {
588                 nbytes -= sl->length;
589         }
590         crypto_hmac(tfm, key, keylen, sg, count, out);
591         return 0;
592 }
593
594 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_digest_setkey(tfm, key, keylen)
595 #define ll_crypto_blkcipher_blocksize(tfm)      crypto_tfm_alg_blocksize(tfm)
596 #define ll_crypto_blkcipher_ivsize(tfm) crypto_tfm_alg_ivsize(tfm)
597 #define ll_crypto_hash_digestsize(tfm)  crypto_tfm_alg_digestsize(tfm)
598 #define ll_crypto_hash_blocksize(tfm)   crypto_tfm_alg_blocksize(tfm)
599 #define ll_crypto_free_hash(tfm)        crypto_free_tfm(tfm)
600 #define ll_crypto_free_blkcipher(tfm)   crypto_free_tfm(tfm)
601 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
602
603 #ifdef HAVE_SECURITY_PLUG
604 #define ll_remove_suid(inode,mnt)               remove_suid(inode,mnt)
605 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
606 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
607 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
608 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
609 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
610                 vfs_mknod(dir,entry,mnt,mode,dev)
611 #define ll_security_inode_unlink(dir,entry,mnt)         \
612                 security_inode_unlink(dir,entry,mnt)
613 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
614                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
615 #else
616 #define ll_remove_suid(inode,mnt)               remove_suid(inode)
617 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
618 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
619 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
620 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
621 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
622 #define ll_security_inode_unlink(dir,entry,mnt) security_inode_unlink(dir,entry)
623 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
624                 vfs_rename(old,old_dir,new,new_dir)
625 #endif
626
627 #ifndef get_cpu
628 #ifdef CONFIG_PREEMPT
629 #define get_cpu()       ({ preempt_disable(); smp_processor_id(); })
630 #define put_cpu()       preempt_enable()
631 #else
632 #define get_cpu()       smp_processor_id()
633 #define put_cpu()
634 #endif
635 #endif /* get_cpu & put_cpu */
636
637 #ifndef for_each_possible_cpu
638 #define for_each_possible_cpu(i) for_each_cpu(i)
639 #endif
640
641 #ifndef cpu_to_node
642 #define cpu_to_node(cpu)         0
643 #endif
644
645 #ifndef abs
646 static inline int abs(int x)
647 {
648         return (x < 0) ? -x : x;
649 }
650 #endif
651
652 #ifndef labs
653 static inline long labs(long x)
654 {
655         return (x < 0) ? -x : x;
656 }
657 #endif
658
659 /* Using kernel fls(). Userspace will use one defined in user-bitops.h. */
660 #ifndef __fls
661 #define __fls fls
662 #endif
663
664 #ifdef HAVE_INVALIDATE_INODE_PAGES
665 #define invalidate_mapping_pages(mapping,s,e) invalidate_inode_pages(mapping)
666 #endif
667
668 #endif /* __KERNEL__ */
669 #endif /* _COMPAT25_H */