Whamcloud - gitweb
add 2.6.27 kernel support
[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 #ifdef HAVE_FS_STRUCT_USE_PATH
60 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
61                                  struct dentry *dentry)
62 {
63         struct path path;
64         struct path old_pwd;
65
66         path.mnt = mnt;
67         path.dentry = dentry;
68         write_lock(&fs->lock);
69         old_pwd = fs->pwd;
70         path_get(&path);
71         fs->pwd = path;
72         write_unlock(&fs->lock);
73
74         if (old_pwd.dentry)
75                 path_put(&old_pwd);
76 }
77
78 #else
79
80 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
81                 struct dentry *dentry)
82 {
83         struct dentry *old_pwd;
84         struct vfsmount *old_pwdmnt;
85
86         write_lock(&fs->lock);
87         old_pwd = fs->pwd;
88         old_pwdmnt = fs->pwdmnt;
89         fs->pwdmnt = mntget(mnt);
90         fs->pwd = dget(dentry);
91         write_unlock(&fs->lock);
92
93         if (old_pwd) {
94                 dput(old_pwd);
95                 mntput(old_pwdmnt);
96         }
97 }
98 #endif
99
100 /*
101  * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
102  * ATTR_* attributes (see bug 13828)
103  */
104 #define ATTR_BLOCKS    (1 << 27)
105
106 #if HAVE_INODE_I_MUTEX
107 #define UNLOCK_INODE_MUTEX(inode) do {mutex_unlock(&(inode)->i_mutex); } while(0)
108 #define LOCK_INODE_MUTEX(inode) do {mutex_lock(&(inode)->i_mutex); } while(0)
109 #define LOCK_INODE_MUTEX_PARENT(inode) \
110 do {mutex_lock_nested(&(inode)->i_mutex, I_MUTEX_PARENT); } while(0)
111 #define TRYLOCK_INODE_MUTEX(inode) mutex_trylock(&(inode)->i_mutex)
112 #else
113 #define UNLOCK_INODE_MUTEX(inode) do {up(&(inode)->i_sem); } while(0)
114 #define LOCK_INODE_MUTEX(inode) do {down(&(inode)->i_sem); } while(0)
115 #define TRYLOCK_INODE_MUTEX(inode) (!down_trylock(&(inode)->i_sem))
116 #define LOCK_INODE_MUTEX_PARENT(inode) LOCK_INODE_MUTEX(inode)
117 #endif /* HAVE_INODE_I_MUTEX */
118
119 #ifdef HAVE_SEQ_LOCK
120 #define LL_SEQ_LOCK(seq) mutex_lock(&(seq)->lock)
121 #define LL_SEQ_UNLOCK(seq) mutex_unlock(&(seq)->lock)
122 #else
123 #define LL_SEQ_LOCK(seq) down(&(seq)->sem)
124 #define LL_SEQ_UNLOCK(seq) up(&(seq)->sem)
125 #endif
126
127 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
128 #define d_child d_u.d_child
129 #define d_rcu d_u.d_rcu
130 #endif
131
132 #ifdef HAVE_DQUOTOFF_MUTEX
133 #define UNLOCK_DQONOFF_MUTEX(dqopt) do {mutex_unlock(&(dqopt)->dqonoff_mutex); } while(0)
134 #define LOCK_DQONOFF_MUTEX(dqopt) do {mutex_lock(&(dqopt)->dqonoff_mutex); } while(0)
135 #else
136 #define UNLOCK_DQONOFF_MUTEX(dqopt) do {up(&(dqopt)->dqonoff_sem); } while(0)
137 #define LOCK_DQONOFF_MUTEX(dqopt) do {down(&(dqopt)->dqonoff_sem); } while(0)
138 #endif /* HAVE_DQUOTOFF_MUTEX */
139
140 #define current_ngroups current->group_info->ngroups
141 #define current_groups current->group_info->small_block
142
143 #ifndef page_private
144 #define page_private(page) ((page)->private)
145 #define set_page_private(page, v) ((page)->private = (v))
146 #endif
147
148 #ifndef HAVE_GFP_T
149 #define gfp_t int
150 #endif
151
152 #define lock_dentry(___dentry)          spin_lock(&(___dentry)->d_lock)
153 #define unlock_dentry(___dentry)        spin_unlock(&(___dentry)->d_lock)
154
155 #define ll_kernel_locked()      kernel_locked()
156
157 /*
158  * OBD need working random driver, thus all our
159  * initialization routines must be called after device
160  * driver initialization
161  */
162 #ifndef MODULE
163 #undef module_init
164 #define module_init(a)     late_initcall(a)
165 #endif
166
167 /* XXX our code should be using the 2.6 calls, not the other way around */
168 #ifdef HAVE_TRYLOCK_PAGE
169 #define TestSetPageLocked(page)         (!trylock_page(page))
170 #endif
171
172 #define Page_Uptodate(page)             PageUptodate(page)
173 #define ll_redirty_page(page)           set_page_dirty(page)
174
175 #define KDEVT_INIT(val)                 (val)
176
177 #define LTIME_S(time)                   (time.tv_sec)
178 #define ll_path_lookup                  path_lookup
179 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
180
181 #define ll_pgcache_lock(mapping)          spin_lock(&mapping->page_lock)
182 #define ll_pgcache_unlock(mapping)        spin_unlock(&mapping->page_lock)
183 #define ll_call_writepage(inode, page)  \
184                                 (inode)->i_mapping->a_ops->writepage(page, NULL)
185 #define ll_invalidate_inode_pages(inode) \
186                                 invalidate_inode_pages((inode)->i_mapping)
187 #define ll_truncate_complete_page(page) \
188                                 truncate_complete_page(page->mapping, page)
189
190 #define ll_vfs_create(a,b,c,d)          vfs_create(a,b,c,d)
191 #define ll_dev_t                        dev_t
192 #define kdev_t                          dev_t
193 #define to_kdev_t(dev)                  (dev)
194 #define kdev_t_to_nr(dev)               (dev)
195 #define val_to_kdev(dev)                (dev)
196 #define ILOOKUP(sb, ino, test, data)    ilookup5(sb, ino, test, (void *)(data));
197
198 #include <linux/writeback.h>
199
200 static inline int cleanup_group_info(void)
201 {
202         struct group_info *ginfo;
203
204         ginfo = groups_alloc(0);
205         if (!ginfo)
206                 return -ENOMEM;
207
208         set_current_groups(ginfo);
209         put_group_info(ginfo);
210
211         return 0;
212 }
213
214 #define __set_page_ll_data(page, llap) \
215         do {       \
216                 page_cache_get(page); \
217                 SetPagePrivate(page); \
218                 set_page_private(page, (unsigned long)llap); \
219         } while (0)
220 #define __clear_page_ll_data(page) \
221         do {       \
222                 ClearPagePrivate(page); \
223                 set_page_private(page, 0); \
224                 page_cache_release(page); \
225         } while(0)
226
227 #define kiobuf bio
228
229 #include <linux/proc_fs.h>
230
231 #if !defined(HAVE_D_REHASH_COND) && defined(HAVE___D_REHASH)
232 #define d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
233 extern void __d_rehash(struct dentry *dentry, int lock);
234 #endif
235
236 #if !defined(HAVE_D_MOVE_LOCKED) && defined(HAVE___D_MOVE)
237 #define d_move_locked(dentry, target) __d_move(dentry, target)
238 extern void __d_move(struct dentry *dentry, struct dentry *target);
239 #endif
240
241 #ifdef HAVE_CAN_SLEEP_ARG
242 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
243         flock_lock_file_wait(file, lock, can_sleep)
244 #else
245 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
246         flock_lock_file_wait(file, lock)
247 #endif
248
249 #define CheckWriteback(page, cmd) \
250         ((!PageWriteback(page) && (cmd & OBD_BRW_READ)) || \
251          (PageWriteback(page) && (cmd & OBD_BRW_WRITE)))
252
253 #ifdef HAVE_PAGE_LIST
254 static inline int mapping_has_pages(struct address_space *mapping)
255 {
256         int rc = 1;
257
258         ll_pgcache_lock(mapping);
259         if (list_empty(&mapping->dirty_pages) &&
260             list_empty(&mapping->clean_pages) &&
261             list_empty(&mapping->locked_pages)) {
262                 rc = 0;
263         }
264         ll_pgcache_unlock(mapping);
265
266         return rc;
267 }
268 #else
269 static inline int mapping_has_pages(struct address_space *mapping)
270 {
271         return mapping->nrpages > 0;
272 }
273 #endif
274
275 #ifdef HAVE_KIOBUF_KIO_BLOCKS
276 #define KIOBUF_GET_BLOCKS(k) ((k)->kio_blocks)
277 #else
278 #define KIOBUF_GET_BLOCKS(k) ((k)->blocks)
279 #endif
280
281 #ifdef HAVE_SECURITY_PLUG
282 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
283                 vfs_symlink(dir, dentry, mnt, path, mode)
284 #else
285 #ifdef HAVE_4ARGS_VFS_SYMLINK
286 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
287                 vfs_symlink(dir, dentry, path, mode)
288 #else
289 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
290                        vfs_symlink(dir, dentry, path)
291 #endif
292 #endif
293
294 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
295 #define ll_set_dflags(dentry, flags) do { dentry->d_vfs_flags |= flags; } while(0)
296 #else
297 #define ll_set_dflags(dentry, flags) do { \
298                 spin_lock(&dentry->d_lock); \
299                 dentry->d_flags |= flags; \
300                 spin_unlock(&dentry->d_lock); \
301         } while(0)
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 #ifndef HAVE_GRAB_CACHE_PAGE_NOWAIT_GFP
319 #define grab_cache_page_nowait_gfp(x, y, z) grab_cache_page_nowait((x), (y))
320 #endif
321
322 #include <linux/mpage.h>        /* for generic_writepages */
323 #ifndef HAVE_FILEMAP_FDATAWRITE_RANGE
324 #include <linux/backing-dev.h>  /* for mapping->backing_dev_info */
325 static inline int filemap_fdatawrite_range(struct address_space *mapping,
326                                            loff_t start, loff_t end)
327 {
328         int rc;
329         struct writeback_control wbc = {
330                 .sync_mode = WB_SYNC_ALL,
331                 .nr_to_write = (end - start + PAGE_SIZE - 1) >> PAGE_SHIFT,
332         };
333
334 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
335         wbc.range_start = start;
336         wbc.range_end = end;
337 #else
338         wbc.start = start;
339         wbc.end = end;
340 #endif
341
342 #ifdef HAVE_MAPPING_CAP_WRITEBACK_DIRTY
343         if (!mapping_cap_writeback_dirty(mapping))
344                 rc = 0;
345 #else
346         if (mapping->backing_dev_info->memory_backed)
347                 rc = 0;
348 #endif
349         /* do_writepages() */
350         else if (mapping->a_ops->writepages)
351                 rc = mapping->a_ops->writepages(mapping, &wbc);
352         else
353                 rc = generic_writepages(mapping, &wbc);
354         return rc;
355 }
356 #else
357 int filemap_fdatawrite_range(struct address_space *mapping,
358                              loff_t start, loff_t end);
359 #endif /* HAVE_FILEMAP_FDATAWRITE_RANGE */
360
361 #ifdef HAVE_VFS_KERN_MOUNT
362 static inline struct vfsmount *
363 ll_kern_mount(const char *fstype, int flags, const char *name, void *data)
364 {
365         struct file_system_type *type = get_fs_type(fstype);
366         struct vfsmount *mnt;
367         if (!type)
368                 return ERR_PTR(-ENODEV);
369         mnt = vfs_kern_mount(type, flags, name, data);
370         module_put(type->owner);
371         return mnt;
372 }
373 #else
374 #define ll_kern_mount(fstype, flags, name, data) do_kern_mount((fstype), (flags), (name), (data))
375 #endif
376
377 #ifdef HAVE_STATFS_DENTRY_PARAM
378 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb)->s_root, (sfs))
379 #else
380 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb), (sfs))
381 #endif
382
383 #ifndef HAVE_SB_TIME_GRAN
384 #ifndef HAVE_S_TIME_GRAN
385 #error Need s_time_gran patch!
386 #endif
387 static inline u32 get_sb_time_gran(struct super_block *sb)
388 {
389         return sb->s_time_gran;
390 }
391 #endif
392
393 #ifdef HAVE_RW_TREE_LOCK
394 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
395 #define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
396 #else
397 #define TREE_READ_LOCK_IRQ(mapping) spin_lock_irq(&(mapping)->tree_lock)
398 #define TREE_READ_UNLOCK_IRQ(mapping) spin_unlock_irq(&(mapping)->tree_lock)
399 #endif
400
401 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
402 #define ll_unregister_blkdev(a,b)       unregister_blkdev((a),(b))
403 #else
404 static inline
405 int ll_unregister_blkdev(unsigned int dev, const char *name)
406 {
407         unregister_blkdev(dev, name);
408         return 0;
409 }
410 #endif
411
412 #ifdef HAVE_INVALIDATE_BDEV_2ARG
413 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a),(b))
414 #else
415 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a))
416 #endif
417
418 #ifdef HAVE_INODE_BLKSIZE
419 #define ll_inode_blksize(a)     (a)->i_blksize
420 #else
421 #define ll_inode_blksize(a)     (1<<(a)->i_blkbits)
422 #endif
423
424 #ifdef HAVE_FS_RENAME_DOES_D_MOVE
425 #define LL_RENAME_DOES_D_MOVE   FS_RENAME_DOES_D_MOVE
426 #else
427 #define LL_RENAME_DOES_D_MOVE   FS_ODD_RENAME
428 #endif
429
430 /* add a lustre compatible layer for crypto API */
431 #include <linux/crypto.h>
432 #ifdef HAVE_ASYNC_BLOCK_CIPHER
433 #define ll_crypto_hash          crypto_hash
434 #define ll_crypto_cipher        crypto_blkcipher
435 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
436 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
437 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
438 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
439 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
440 #define ll_crypto_alloc_blkcipher(name, type, mask) \
441                 crypto_alloc_blkcipher(name ,type, mask)
442 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
443                 crypto_blkcipher_setkey(tfm, key, keylen)
444 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
445                 crypto_blkcipher_set_iv(tfm, src, len)
446 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
447                 crypto_blkcipher_get_iv(tfm, dst, len)
448 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
449                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
450 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
451                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
452 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
453                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
454 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
455                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
456
457 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
458                                  u8 *key, unsigned int *keylen,
459                                  struct scatterlist *sg,
460                                  unsigned int size, u8 *result)
461 {
462         struct hash_desc desc;
463         int              rv;
464         desc.tfm   = tfm;
465         desc.flags = 0;
466         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
467         if (rv) {
468                 CERROR("failed to hash setkey: %d\n", rv);
469                 return rv;
470         }
471         return crypto_hash_digest(&desc, sg, size, result);
472 }
473 static inline
474 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
475 {
476         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
477 }
478 static inline
479 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
480 {
481         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
482 }
483
484 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
485 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
486 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
487 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
488 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
489 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
490 #else /* HAVE_ASYNC_BLOCK_CIPHER */
491 #include <linux/scatterlist.h>
492 #define ll_crypto_hash          crypto_tfm
493 #define ll_crypto_cipher        crypto_tfm
494 #ifndef HAVE_STRUCT_HASH_DESC
495 struct hash_desc {
496         struct ll_crypto_hash *tfm;
497         u32                    flags;
498 };
499 #endif
500 #ifndef HAVE_STRUCT_BLKCIPHER_DESC
501 struct blkcipher_desc {
502         struct ll_crypto_cipher *tfm;
503         void                    *info;
504         u32                      flags;
505 };
506 #endif
507 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
508         crypto_cipher_setkey(tfm, key, keylen)
509 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
510         crypto_cipher_set_iv(tfm, src, len)
511 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
512         crypto_cipher_get_iv(tfm, dst, len)
513 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
514         crypto_cipher_encrypt((desc)->tfm, dst, src, bytes)
515 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
516         crypto_cipher_decrypt((desc)->tfm, dst, src, bytes)
517 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
518         crypto_cipher_decrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
519 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
520         crypto_cipher_encrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
521
522 static inline
523 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char * algname,
524                                                    u32 type, u32 mask)
525 {
526         char        buf[CRYPTO_MAX_ALG_NAME + 1];
527         const char *pan = algname;
528         u32         flag = 0;
529
530         if (strncmp("cbc(", algname, 4) == 0)
531                 flag |= CRYPTO_TFM_MODE_CBC;
532         else if (strncmp("ecb(", algname, 4) == 0)
533                 flag |= CRYPTO_TFM_MODE_ECB;
534         if (flag) {
535                 char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
536                 if (vp) {
537                         memcpy(buf, algname + 4, vp - algname - 4);
538                         buf[vp - algname - 4] = '\0';
539                         pan = buf;
540                 } else {
541                         flag = 0;
542                 }
543         }
544         return crypto_alloc_tfm(pan, flag);
545 }
546
547 static inline
548 struct ll_crypto_hash *ll_crypto_alloc_hash(const char *alg, u32 type, u32 mask)
549 {
550         char        buf[CRYPTO_MAX_ALG_NAME + 1];
551         const char *pan = alg;
552
553         if (strncmp("hmac(", alg, 5) == 0) {
554                 char *vp = strnchr(alg, CRYPTO_MAX_ALG_NAME, ')');
555                 if (vp) {
556                         memcpy(buf, alg+ 5, vp - alg- 5);
557                         buf[vp - alg - 5] = 0x00;
558                         pan = buf;
559                 }
560         }
561         return crypto_alloc_tfm(pan, 0);
562 }
563 static inline int ll_crypto_hash_init(struct hash_desc *desc)
564 {
565        crypto_digest_init(desc->tfm); return 0;
566 }
567 static inline int ll_crypto_hash_update(struct hash_desc *desc,
568                                         struct scatterlist *sg,
569                                         unsigned int nbytes)
570 {
571         struct scatterlist *sl = sg;
572         unsigned int        count;
573                 /*
574                  * This way is very weakness. We must ensure that
575                  * the sum of sg[0..i]->length isn't greater than nbytes.
576                  * In the upstream kernel the crypto_hash_update() also
577                  * via the nbytes computed the count of sg[...].
578                  * The old style is more safely. but it gone.
579                  */
580         for (count = 0; nbytes > 0; count ++, sl ++) {
581                 nbytes -= sl->length;
582         }
583         crypto_digest_update(desc->tfm, sg, count); return 0;
584 }
585 static inline int ll_crypto_hash_final(struct hash_desc *desc, u8 *out)
586 {
587         crypto_digest_final(desc->tfm, out); return 0;
588 }
589 static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
590                                  u8 *key, unsigned int *keylen,
591                                  struct scatterlist *sg,
592                                  unsigned int nbytes,
593                                  u8 *out)
594 {
595         struct scatterlist *sl = sg;
596         int                 count;
597         for (count = 0; nbytes > 0; count ++, sl ++) {
598                 nbytes -= sl->length;
599         }
600         crypto_hmac(tfm, key, keylen, sg, count, out);
601         return 0;
602 }
603
604 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_digest_setkey(tfm, key, keylen)
605 #define ll_crypto_blkcipher_blocksize(tfm)      crypto_tfm_alg_blocksize(tfm)
606 #define ll_crypto_blkcipher_ivsize(tfm) crypto_tfm_alg_ivsize(tfm)
607 #define ll_crypto_hash_digestsize(tfm)  crypto_tfm_alg_digestsize(tfm)
608 #define ll_crypto_hash_blocksize(tfm)   crypto_tfm_alg_blocksize(tfm)
609 #define ll_crypto_free_hash(tfm)        crypto_free_tfm(tfm)
610 #define ll_crypto_free_blkcipher(tfm)   crypto_free_tfm(tfm)
611 #define ll_crypto_tfm_alg_min_keysize   crypto_tfm_alg_min_keysize
612 #define ll_crypto_tfm_alg_max_keysize   crypto_tfm_alg_max_keysize
613 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
614
615 #ifndef HAVE_SYNCHRONIZE_RCU
616 #define synchronize_rcu() synchronize_kernel()
617 #endif
618
619 #ifdef HAVE_FILE_REMOVE_SUID
620 # define ll_remove_suid(file, mnt)       file_remove_suid(file)
621 #else
622 # ifdef HAVE_SECURITY_PLUG
623 #  define ll_remove_suid(file,mnt)      remove_suid(file->f_dentry,mnt)
624 # else
625 #  define ll_remove_suid(file,mnt)      remove_suid(file->f_dentry)
626 # endif
627 #endif
628
629 #ifdef HAVE_SECURITY_PLUG
630 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
631 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
632 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
633 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
634 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
635                 vfs_mknod(dir,entry,mnt,mode,dev)
636 #define ll_security_inode_unlink(dir,entry,mnt)         \
637                 security_inode_unlink(dir,entry,mnt)
638 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
639                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
640 #else
641 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
642 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
643 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
644 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
645 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
646 #define ll_security_inode_unlink(dir,entry,mnt) security_inode_unlink(dir,entry)
647 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
648                 vfs_rename(old,old_dir,new,new_dir)
649 #endif /* HAVE_SECURITY_PLUG */
650
651 #ifndef for_each_possible_cpu
652 #define for_each_possible_cpu(i) for_each_cpu(i)
653 #endif
654
655 #ifndef cpu_to_node
656 #define cpu_to_node(cpu)         0
657 #endif
658
659 #ifdef HAVE_REGISTER_SHRINKER
660 typedef int (*shrinker_t)(int nr_to_scan, gfp_t gfp_mask);
661
662 static inline
663 struct shrinker *set_shrinker(int seek, shrinker_t func)
664 {
665         struct shrinker *s;
666
667         s = kmalloc(sizeof(*s), GFP_KERNEL);
668         if (s == NULL)
669                 return (NULL);
670
671         s->shrink = func;
672         s->seeks = seek;
673
674         register_shrinker(s);
675
676         return s;
677 }
678
679 static inline
680 void remove_shrinker(struct shrinker *shrinker) 
681 {
682         if (shrinker == NULL)
683                 return;
684
685         unregister_shrinker(shrinker);
686         kfree(shrinker);
687 }
688 #endif
689
690 #ifdef HAVE_BIO_ENDIO_2ARG
691 #define cfs_bio_io_error(a,b)   bio_io_error((a))
692 #define cfs_bio_endio(a,b,c)    bio_endio((a),(c))
693 #else
694 #define cfs_bio_io_error(a,b)   bio_io_error((a),(b))
695 #define cfs_bio_endio(a,b,c)    bio_endio((a),(b),(c))
696 #endif
697
698 #ifdef HAVE_FS_STRUCT_USE_PATH
699 #define cfs_fs_pwd(fs)       ((fs)->pwd.dentry)
700 #define cfs_fs_mnt(fs)       ((fs)->pwd.mnt)
701 #define cfs_path_put(nd)     path_put(&(nd)->path)
702 #else
703 #define cfs_fs_pwd(fs)       ((fs)->pwd)
704 #define cfs_fs_mnt(fs)       ((fs)->pwdmnt)
705 #define cfs_path_put(nd)     path_release(nd)
706 #endif
707
708 #ifndef abs
709 static inline int abs(int x)
710 {
711         return (x < 0) ? -x : x;
712 }
713 #endif
714
715 #ifndef labs
716 static inline long labs(long x)
717 {
718         return (x < 0) ? -x : x;
719 }
720 #endif /* HAVE_REGISTER_SHRINKER */
721
722 /* Using kernel fls(). Userspace will use one defined in user-bitops.h. */
723 #ifndef __fls
724 #define __fls fls
725 #endif
726
727 #ifdef HAVE_INVALIDATE_INODE_PAGES
728 #define invalidate_mapping_pages(mapping,s,e) invalidate_inode_pages(mapping)
729 #endif
730
731 #ifdef HAVE_INODE_IPRIVATE
732 #define INODE_PRIVATE_DATA(inode)       ((inode)->i_private)
733 #else
734 #define INODE_PRIVATE_DATA(inode)       ((inode)->u.generic_ip)
735 #endif
736
737 #ifndef SLAB_DESTROY_BY_RCU
738 #define SLAB_DESTROY_BY_RCU 0
739 #endif
740
741 #ifdef HAVE_SB_HAS_QUOTA_ACTIVE
742 #define ll_sb_has_quota_active(sb, type) sb_has_quota_active(sb, type)
743 #else
744 #define ll_sb_has_quota_active(sb, type) sb_has_quota_enabled(sb, type)
745 #endif
746
747 #ifdef HAVE_SB_ANY_QUOTA_ACTIVE
748 #define ll_sb_any_quota_active(sb) sb_any_quota_active(sb)
749 #else
750 #define ll_sb_any_quota_active(sb) sb_any_quota_enabled(sb)
751 #endif
752
753 static inline int
754 ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
755 {
756         if (sb->s_qcop->quota_on) {
757                 return sb->s_qcop->quota_on(sb, off, ver, name
758 #ifdef HAVE_QUOTA_ON_5ARGS
759                                             , remount
760 #endif
761                                            );
762         }
763         else
764                 return -ENOSYS;
765 }
766
767 static inline int ll_quota_off(struct super_block *sb, int off, int remount)
768 {
769         if (sb->s_qcop->quota_off) {
770                 return sb->s_qcop->quota_off(sb, off
771 #ifdef HAVE_QUOTA_OFF_3ARGS
772                                              , remount
773 #endif
774                                             );
775         }
776         else
777                 return -ENOSYS;
778 }
779
780
781 #ifdef HAVE_VFS_RENAME_MUTEX
782 #define VFS_RENAME_LOCK(inode) mutex_lock(&((inode)->i_sb->s_vfs_rename_mutex))
783 #define VFS_RENAME_UNLOCK(inode) mutex_unlock(&((inode)->i_sb->s_vfs_rename_mutex))
784 #else
785 #define VFS_RENAME_LOCK(inode) down(&((inode)->i_sb->s_vfs_rename_sem))
786 #define VFS_RENAME_UNLOCK(inode) up(&((inode)->i_sb->s_vfs_rename_sem))
787 #endif
788
789 #endif /* __KERNEL__ */
790 #endif /* _COMPAT25_H */