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