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