Whamcloud - gitweb
LU-73 Make register_shrinker argument more visible.
[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
183 #ifdef HAVE_EXPORT_INODE_PERMISSION
184 #define ll_permission(inode,mask,nd)    inode_permission(inode,mask)
185 #else
186 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
187 #endif
188
189 #define ll_pgcache_lock(mapping)          cfs_spin_lock(&mapping->page_lock)
190 #define ll_pgcache_unlock(mapping)        cfs_spin_unlock(&mapping->page_lock)
191 #define ll_call_writepage(inode, page)  \
192                                 (inode)->i_mapping->a_ops->writepage(page, NULL)
193 #define ll_invalidate_inode_pages(inode) \
194                                 invalidate_inode_pages((inode)->i_mapping)
195 #define ll_truncate_complete_page(page) \
196                                 truncate_complete_page(page->mapping, page)
197
198 #define ll_vfs_create(a,b,c,d)          vfs_create(a,b,c,d)
199 #define ll_dev_t                        dev_t
200 #define kdev_t                          dev_t
201 #define to_kdev_t(dev)                  (dev)
202 #define kdev_t_to_nr(dev)               (dev)
203 #define val_to_kdev(dev)                (dev)
204
205 #ifdef HAVE_BLKDEV_PUT_2ARGS
206 #define ll_blkdev_put(a, b) blkdev_put(a, b)
207 #else
208 #define ll_blkdev_put(a, b) blkdev_put(a)
209 #endif
210
211 #ifdef HAVE_DENTRY_OPEN_4ARGS
212 #define ll_dentry_open(a, b, c, d) dentry_open(a, b, c, d)
213 #else
214 #define ll_dentry_open(a, b, c, d) dentry_open(a, b, c)
215 #endif
216
217 #include <linux/writeback.h>
218
219 static inline int cfs_cleanup_group_info(void)
220 {
221         struct group_info *ginfo;
222
223         ginfo = groups_alloc(0);
224         if (!ginfo)
225                 return -ENOMEM;
226
227         set_current_groups(ginfo);
228         put_group_info(ginfo);
229
230         return 0;
231 }
232
233 #define __set_page_ll_data(page, llap) \
234         do {       \
235                 page_cache_get(page); \
236                 SetPagePrivate(page); \
237                 set_page_private(page, (unsigned long)llap); \
238         } while (0)
239 #define __clear_page_ll_data(page) \
240         do {       \
241                 ClearPagePrivate(page); \
242                 set_page_private(page, 0); \
243                 page_cache_release(page); \
244         } while(0)
245
246 #define kiobuf bio
247
248 #include <linux/proc_fs.h>
249
250 #if !defined(HAVE_D_REHASH_COND) && defined(HAVE___D_REHASH)
251 #define d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
252 extern void __d_rehash(struct dentry *dentry, int lock);
253 #endif
254
255 #if !defined(HAVE_D_MOVE_LOCKED) && defined(HAVE___D_MOVE)
256 #define d_move_locked(dentry, target) __d_move(dentry, target)
257 extern void __d_move(struct dentry *dentry, struct dentry *target);
258 #endif
259
260 #ifdef HAVE_CAN_SLEEP_ARG
261 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
262         flock_lock_file_wait(file, lock, can_sleep)
263 #else
264 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
265         flock_lock_file_wait(file, lock)
266 #endif
267
268 #define CheckWriteback(page, cmd) \
269         ((!PageWriteback(page) && (cmd & OBD_BRW_READ)) || \
270          (PageWriteback(page) && (cmd & OBD_BRW_WRITE)))
271
272 #ifdef HAVE_PAGE_LIST
273 static inline int mapping_has_pages(struct address_space *mapping)
274 {
275         int rc = 1;
276
277         ll_pgcache_lock(mapping);
278         if (cfs_list_empty(&mapping->dirty_pages) &&
279             cfs_list_empty(&mapping->clean_pages) &&
280             cfs_list_empty(&mapping->locked_pages)) {
281                 rc = 0;
282         }
283         ll_pgcache_unlock(mapping);
284
285         return rc;
286 }
287 #else
288 static inline int mapping_has_pages(struct address_space *mapping)
289 {
290         return mapping->nrpages > 0;
291 }
292 #endif
293
294 #ifdef HAVE_KIOBUF_KIO_BLOCKS
295 #define KIOBUF_GET_BLOCKS(k) ((k)->kio_blocks)
296 #else
297 #define KIOBUF_GET_BLOCKS(k) ((k)->blocks)
298 #endif
299
300 #ifdef HAVE_SECURITY_PLUG
301 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
302                 vfs_symlink(dir, dentry, mnt, path, mode)
303 #else
304 #ifdef HAVE_4ARGS_VFS_SYMLINK
305 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
306                 vfs_symlink(dir, dentry, path, mode)
307 #else
308 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
309                        vfs_symlink(dir, dentry, path)
310 #endif
311
312 #define ll_set_dflags(dentry, flags) do { \
313                 cfs_spin_lock(&dentry->d_lock); \
314                 dentry->d_flags |= flags; \
315                 cfs_spin_unlock(&dentry->d_lock); \
316         } while(0)
317 #endif
318
319 #ifndef container_of
320 #define container_of(ptr, type, member) ({                      \
321                 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
322                 (type *)( (char *)__mptr - offsetof(type,member) );})
323 #endif
324
325 #define UP_WRITE_I_ALLOC_SEM(i)   up_write(&(i)->i_alloc_sem)
326 #define DOWN_WRITE_I_ALLOC_SEM(i) down_write(&(i)->i_alloc_sem)
327 #define LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i) LASSERT(down_read_trylock(&(i)->i_alloc_sem) == 0)
328
329 #define UP_READ_I_ALLOC_SEM(i)    up_read(&(i)->i_alloc_sem)
330 #define DOWN_READ_I_ALLOC_SEM(i)  down_read(&(i)->i_alloc_sem)
331 #define LASSERT_I_ALLOC_SEM_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
332
333 #ifndef HAVE_GRAB_CACHE_PAGE_NOWAIT_GFP
334 #define grab_cache_page_nowait_gfp(x, y, z) grab_cache_page_nowait((x), (y))
335 #endif
336
337 #include <linux/mpage.h>        /* for generic_writepages */
338 #ifndef HAVE_FILEMAP_FDATAWRITE_RANGE
339 #include <linux/backing-dev.h>  /* for mapping->backing_dev_info */
340 static inline int filemap_fdatawrite_range(struct address_space *mapping,
341                                            loff_t start, loff_t end)
342 {
343         int rc;
344         struct writeback_control wbc = {
345                 .sync_mode = WB_SYNC_ALL,
346                 .nr_to_write = (end - start + PAGE_SIZE - 1) >> PAGE_SHIFT,
347         };
348
349 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
350         wbc.range_start = start;
351         wbc.range_end = end;
352 #else
353         wbc.start = start;
354         wbc.end = end;
355 #endif
356
357 #ifdef HAVE_MAPPING_CAP_WRITEBACK_DIRTY
358         if (!mapping_cap_writeback_dirty(mapping))
359                 rc = 0;
360 #else
361         if (mapping->backing_dev_info->memory_backed)
362                 rc = 0;
363 #endif
364         /* do_writepages() */
365         else if (mapping->a_ops->writepages)
366                 rc = mapping->a_ops->writepages(mapping, &wbc);
367         else
368                 rc = generic_writepages(mapping, &wbc);
369         return rc;
370 }
371 #else
372 int filemap_fdatawrite_range(struct address_space *mapping,
373                              loff_t start, loff_t end);
374 #endif /* HAVE_FILEMAP_FDATAWRITE_RANGE */
375
376 #ifdef HAVE_VFS_KERN_MOUNT
377 static inline struct vfsmount *
378 ll_kern_mount(const char *fstype, int flags, const char *name, void *data)
379 {
380         struct file_system_type *type = get_fs_type(fstype);
381         struct vfsmount *mnt;
382         if (!type)
383                 return ERR_PTR(-ENODEV);
384         mnt = vfs_kern_mount(type, flags, name, data);
385         cfs_module_put(type->owner);
386         return mnt;
387 }
388 #else
389 #define ll_kern_mount(fstype, flags, name, data) do_kern_mount((fstype), (flags), (name), (data))
390 #endif
391
392 #ifdef HAVE_STATFS_DENTRY_PARAM
393 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb)->s_root, (sfs))
394 #else
395 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb), (sfs))
396 #endif
397
398 #ifndef HAVE_SB_TIME_GRAN
399 #ifndef HAVE_S_TIME_GRAN
400 #error Need s_time_gran patch!
401 #endif
402 static inline u32 get_sb_time_gran(struct super_block *sb)
403 {
404         return sb->s_time_gran;
405 }
406 #endif
407
408 #ifdef HAVE_RW_TREE_LOCK
409 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
410 #define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
411 #else
412 #define TREE_READ_LOCK_IRQ(mapping) cfs_spin_lock_irq(&(mapping)->tree_lock)
413 #define TREE_READ_UNLOCK_IRQ(mapping) cfs_spin_unlock_irq(&(mapping)->tree_lock)
414 #endif
415
416 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
417 #define ll_unregister_blkdev(a,b)       unregister_blkdev((a),(b))
418 #else
419 static inline
420 int ll_unregister_blkdev(unsigned int dev, const char *name)
421 {
422         unregister_blkdev(dev, name);
423         return 0;
424 }
425 #endif
426
427 #ifdef HAVE_INVALIDATE_BDEV_2ARG
428 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a),(b))
429 #else
430 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a))
431 #endif
432
433 #ifdef HAVE_INODE_BLKSIZE
434 #define ll_inode_blksize(a)     (a)->i_blksize
435 #else
436 #define ll_inode_blksize(a)     (1<<(a)->i_blkbits)
437 #endif
438
439 #ifdef HAVE_FS_RENAME_DOES_D_MOVE
440 #define LL_RENAME_DOES_D_MOVE   FS_RENAME_DOES_D_MOVE
441 #else
442 #define LL_RENAME_DOES_D_MOVE   FS_ODD_RENAME
443 #endif
444
445 #ifndef HAVE_D_OBTAIN_ALIAS
446 /* The old d_alloc_anon() didn't free the inode reference on error
447  * like d_obtain_alias().  Hide that difference/inconvenience here. */
448 static inline struct dentry *d_obtain_alias(struct inode *inode)
449 {
450         struct dentry *anon = d_alloc_anon(inode);
451
452         if (anon == NULL)
453                 iput(inode);
454
455         return anon;
456 }
457 #endif
458
459 /* add a lustre compatible layer for crypto API */
460 #include <linux/crypto.h>
461 #ifdef HAVE_ASYNC_BLOCK_CIPHER
462 #define ll_crypto_hash          crypto_hash
463 #define ll_crypto_cipher        crypto_blkcipher
464 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
465 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
466 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
467 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
468 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
469 #define ll_crypto_alloc_blkcipher(name, type, mask) \
470                 crypto_alloc_blkcipher(name ,type, mask)
471 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
472                 crypto_blkcipher_setkey(tfm, key, keylen)
473 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
474                 crypto_blkcipher_set_iv(tfm, src, len)
475 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
476                 crypto_blkcipher_get_iv(tfm, dst, len)
477 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
478                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
479 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
480                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
481 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
482                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
483 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
484                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
485
486 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
487                                  u8 *key, unsigned int *keylen,
488                                  struct scatterlist *sg,
489                                  unsigned int size, u8 *result)
490 {
491         struct hash_desc desc;
492         int              rv;
493         desc.tfm   = tfm;
494         desc.flags = 0;
495         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
496         if (rv) {
497                 CERROR("failed to hash setkey: %d\n", rv);
498                 return rv;
499         }
500         return crypto_hash_digest(&desc, sg, size, result);
501 }
502 static inline
503 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
504 {
505         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
506 }
507 static inline
508 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
509 {
510         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
511 }
512
513 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
514 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
515 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
516 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
517 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
518 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
519 #else /* HAVE_ASYNC_BLOCK_CIPHER */
520 #include <linux/scatterlist.h>
521 #define ll_crypto_hash          crypto_tfm
522 #define ll_crypto_cipher        crypto_tfm
523 #ifndef HAVE_STRUCT_HASH_DESC
524 struct hash_desc {
525         struct ll_crypto_hash *tfm;
526         u32                    flags;
527 };
528 #endif
529 #ifndef HAVE_STRUCT_BLKCIPHER_DESC
530 struct blkcipher_desc {
531         struct ll_crypto_cipher *tfm;
532         void                    *info;
533         u32                      flags;
534 };
535 #endif
536 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
537         crypto_cipher_setkey(tfm, key, keylen)
538 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
539         crypto_cipher_set_iv(tfm, src, len)
540 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
541         crypto_cipher_get_iv(tfm, dst, len)
542 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
543         crypto_cipher_encrypt((desc)->tfm, dst, src, bytes)
544 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
545         crypto_cipher_decrypt((desc)->tfm, dst, src, bytes)
546 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
547         crypto_cipher_decrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
548 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
549         crypto_cipher_encrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
550
551 static inline
552 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char * algname,
553                                                    u32 type, u32 mask)
554 {
555         char        buf[CRYPTO_MAX_ALG_NAME + 1];
556         const char *pan = algname;
557         u32         flag = 0;
558
559         if (strncmp("cbc(", algname, 4) == 0)
560                 flag |= CRYPTO_TFM_MODE_CBC;
561         else if (strncmp("ecb(", algname, 4) == 0)
562                 flag |= CRYPTO_TFM_MODE_ECB;
563         if (flag) {
564                 char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
565                 if (vp) {
566                         memcpy(buf, algname + 4, vp - algname - 4);
567                         buf[vp - algname - 4] = '\0';
568                         pan = buf;
569                 } else {
570                         flag = 0;
571                 }
572         }
573         return crypto_alloc_tfm(pan, flag);
574 }
575
576 static inline
577 struct ll_crypto_hash *ll_crypto_alloc_hash(const char *alg, u32 type, u32 mask)
578 {
579         char        buf[CRYPTO_MAX_ALG_NAME + 1];
580         const char *pan = alg;
581
582         if (strncmp("hmac(", alg, 5) == 0) {
583                 char *vp = strnchr(alg, CRYPTO_MAX_ALG_NAME, ')');
584                 if (vp) {
585                         memcpy(buf, alg+ 5, vp - alg- 5);
586                         buf[vp - alg - 5] = 0x00;
587                         pan = buf;
588                 }
589         }
590         return crypto_alloc_tfm(pan, 0);
591 }
592 static inline int ll_crypto_hash_init(struct hash_desc *desc)
593 {
594        crypto_digest_init(desc->tfm); return 0;
595 }
596 static inline int ll_crypto_hash_update(struct hash_desc *desc,
597                                         struct scatterlist *sg,
598                                         unsigned int nbytes)
599 {
600         struct scatterlist *sl = sg;
601         unsigned int        count;
602                 /*
603                  * This way is very weakness. We must ensure that
604                  * the sum of sg[0..i]->length isn't greater than nbytes.
605                  * In the upstream kernel the crypto_hash_update() also
606                  * via the nbytes computed the count of sg[...].
607                  * The old style is more safely. but it gone.
608                  */
609         for (count = 0; nbytes > 0; count ++, sl ++) {
610                 nbytes -= sl->length;
611         }
612         crypto_digest_update(desc->tfm, sg, count); return 0;
613 }
614 static inline int ll_crypto_hash_final(struct hash_desc *desc, u8 *out)
615 {
616         crypto_digest_final(desc->tfm, out); return 0;
617 }
618 static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
619                                  u8 *key, unsigned int *keylen,
620                                  struct scatterlist *sg,
621                                  unsigned int nbytes,
622                                  u8 *out)
623 {
624         struct scatterlist *sl = sg;
625         int                 count;
626         for (count = 0; nbytes > 0; count ++, sl ++) {
627                 nbytes -= sl->length;
628         }
629         crypto_hmac(tfm, key, keylen, sg, count, out);
630         return 0;
631 }
632
633 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_digest_setkey(tfm, key, keylen)
634 #define ll_crypto_blkcipher_blocksize(tfm)      crypto_tfm_alg_blocksize(tfm)
635 #define ll_crypto_blkcipher_ivsize(tfm) crypto_tfm_alg_ivsize(tfm)
636 #define ll_crypto_hash_digestsize(tfm)  crypto_tfm_alg_digestsize(tfm)
637 #define ll_crypto_hash_blocksize(tfm)   crypto_tfm_alg_blocksize(tfm)
638 #define ll_crypto_free_hash(tfm)        crypto_free_tfm(tfm)
639 #define ll_crypto_free_blkcipher(tfm)   crypto_free_tfm(tfm)
640 #define ll_crypto_tfm_alg_min_keysize   crypto_tfm_alg_min_keysize
641 #define ll_crypto_tfm_alg_max_keysize   crypto_tfm_alg_max_keysize
642 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
643
644 #ifndef HAVE_SYNCHRONIZE_RCU
645 /* Linux 2.6.32 provides define when !CONFIG_TREE_PREEMPT_RCU */
646 #ifndef synchronize_rcu
647 #define synchronize_rcu() synchronize_kernel()
648 #endif
649 #endif
650
651 #ifdef HAVE_FILE_REMOVE_SUID
652 # define ll_remove_suid(file, mnt)       file_remove_suid(file)
653 #else
654 # ifdef HAVE_SECURITY_PLUG
655 #  define ll_remove_suid(file,mnt)      remove_suid(file->f_dentry,mnt)
656 # else
657 #  define ll_remove_suid(file,mnt)      remove_suid(file->f_dentry)
658 # endif
659 #endif
660
661 #ifdef HAVE_SECURITY_PLUG
662 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
663 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
664 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
665 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
666 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
667                 vfs_mknod(dir,entry,mnt,mode,dev)
668 #define ll_security_inode_unlink(dir,entry,mnt)         \
669                 security_inode_unlink(dir,entry,mnt)
670 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
671                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
672 #else
673 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
674 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
675 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
676 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
677 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
678 #define ll_security_inode_unlink(dir,entry,mnt) security_inode_unlink(dir,entry)
679 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
680                 vfs_rename(old,old_dir,new,new_dir)
681 #endif /* HAVE_SECURITY_PLUG */
682
683 #ifdef for_each_possible_cpu
684 #define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
685 #elif defined(for_each_cpu)
686 #define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
687 #endif
688
689 #ifndef cpu_to_node
690 #define cpu_to_node(cpu)         0
691 #endif
692
693 #ifdef HAVE_REGISTER_SHRINKER
694 typedef int (*cfs_shrinker_t)(SHRINKER_FIRST_ARG int nr_to_scan, gfp_t gfp_mask);
695
696 static inline
697 struct shrinker *cfs_set_shrinker(int seek, cfs_shrinker_t func)
698 {
699         struct shrinker *s;
700
701         s = kmalloc(sizeof(*s), GFP_KERNEL);
702         if (s == NULL)
703                 return (NULL);
704
705         s->shrink = func;
706         s->seeks = seek;
707
708         register_shrinker(s);
709
710         return s;
711 }
712
713 static inline
714 void cfs_remove_shrinker(struct shrinker *shrinker)
715 {
716         if (shrinker == NULL)
717                 return;
718
719         unregister_shrinker(shrinker);
720         kfree(shrinker);
721 }
722 #endif
723
724 #ifdef HAVE_BIO_ENDIO_2ARG
725 #define cfs_bio_io_error(a,b)   bio_io_error((a))
726 #define cfs_bio_endio(a,b,c)    bio_endio((a),(c))
727 #else
728 #define cfs_bio_io_error(a,b)   bio_io_error((a),(b))
729 #define cfs_bio_endio(a,b,c)    bio_endio((a),(b),(c))
730 #endif
731
732 #ifdef HAVE_FS_STRUCT_USE_PATH
733 #define cfs_fs_pwd(fs)       ((fs)->pwd.dentry)
734 #define cfs_fs_mnt(fs)       ((fs)->pwd.mnt)
735 #define cfs_path_put(nd)     path_put(&(nd)->path)
736 #else
737 #define cfs_fs_pwd(fs)       ((fs)->pwd)
738 #define cfs_fs_mnt(fs)       ((fs)->pwdmnt)
739 #define cfs_path_put(nd)     path_release(nd)
740 #endif
741
742 #ifndef abs
743 static inline int abs(int x)
744 {
745         return (x < 0) ? -x : x;
746 }
747 #endif
748
749 #ifndef labs
750 static inline long labs(long x)
751 {
752         return (x < 0) ? -x : x;
753 }
754 #endif /* HAVE_REGISTER_SHRINKER */
755
756 #ifdef HAVE_INVALIDATE_INODE_PAGES
757 #define invalidate_mapping_pages(mapping,s,e) invalidate_inode_pages(mapping)
758 #endif
759
760 #ifdef HAVE_INODE_IPRIVATE
761 #define INODE_PRIVATE_DATA(inode)       ((inode)->i_private)
762 #else
763 #define INODE_PRIVATE_DATA(inode)       ((inode)->u.generic_ip)
764 #endif
765
766 #ifndef SLAB_DESTROY_BY_RCU
767 #define CFS_SLAB_DESTROY_BY_RCU 0
768 #else
769 #define CFS_SLAB_DESTROY_BY_RCU SLAB_DESTROY_BY_RCU
770 #endif
771
772 #ifdef HAVE_SB_HAS_QUOTA_ACTIVE
773 #define ll_sb_has_quota_active(sb, type) sb_has_quota_active(sb, type)
774 #else
775 #define ll_sb_has_quota_active(sb, type) sb_has_quota_enabled(sb, type)
776 #endif
777
778 #ifdef HAVE_SB_ANY_QUOTA_ACTIVE
779 #define ll_sb_any_quota_active(sb) sb_any_quota_active(sb)
780 #else
781 #define ll_sb_any_quota_active(sb) sb_any_quota_enabled(sb)
782 #endif
783
784 static inline int
785 ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
786 {
787         if (sb->s_qcop->quota_on) {
788                 return sb->s_qcop->quota_on(sb, off, ver, name
789 #ifdef HAVE_QUOTA_ON_5ARGS
790                                             , remount
791 #endif
792                                            );
793         }
794         else
795                 return -ENOSYS;
796 }
797
798 static inline int ll_quota_off(struct super_block *sb, int off, int remount)
799 {
800         if (sb->s_qcop->quota_off) {
801                 return sb->s_qcop->quota_off(sb, off
802 #ifdef HAVE_QUOTA_OFF_3ARGS
803                                              , remount
804 #endif
805                                             );
806         }
807         else
808                 return -ENOSYS;
809 }
810
811 #ifndef HAVE_BLK_QUEUE_LOG_BLK_SIZE /* added in 2.6.31 */
812 #define blk_queue_logical_block_size(q, sz) blk_queue_hardsect_size(q, sz)
813 #endif
814
815 #ifndef HAVE_VFS_DQ_OFF
816 # define ll_vfs_dq_init             DQUOT_INIT
817 # define ll_vfs_dq_drop             DQUOT_DROP
818 # define ll_vfs_dq_transfer         DQUOT_TRANSFER
819 # define ll_vfs_dq_off(sb, remount) DQUOT_OFF(sb)
820 #else
821 # define ll_vfs_dq_init             vfs_dq_init
822 # define ll_vfs_dq_drop             vfs_dq_drop
823 # define ll_vfs_dq_transfer         vfs_dq_transfer
824 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
825 #endif
826
827 #ifdef HAVE_BDI_INIT
828 #define ll_bdi_init(bdi)    bdi_init(bdi)
829 #define ll_bdi_destroy(bdi) bdi_destroy(bdi)
830 #else
831 #define ll_bdi_init(bdi)    0
832 #define ll_bdi_destroy(bdi) do { } while(0)
833 #endif
834
835 #ifdef HAVE_NEW_BACKING_DEV_INFO
836 # define ll_bdi_wb_cnt(bdi) ((bdi).wb_cnt)
837 #else
838 # define ll_bdi_wb_cnt(bdi) 1
839 #endif
840
841 #ifdef HAVE_BLK_QUEUE_MAX_SECTORS /* removed in rhel6 */
842 #define blk_queue_max_hw_sectors(q, sect) blk_queue_max_sectors(q, sect)
843 #endif
844
845 #ifndef HAVE_REQUEST_QUEUE_LIMITS
846 #define queue_max_sectors(rq)             ((rq)->max_sectors)
847 #define queue_max_hw_sectors(rq)          ((rq)->max_hw_sectors)
848 #define queue_max_phys_segments(rq)       ((rq)->max_phys_segments)
849 #define queue_max_hw_segments(rq)         ((rq)->max_hw_segments)
850 #endif
851
852 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
853 #define blk_queue_max_segments(rq, seg)                      \
854         do { blk_queue_max_phys_segments(rq, seg);           \
855              blk_queue_max_hw_segments(rq, seg); } while (0)
856 #else
857 #define queue_max_phys_segments(rq)       queue_max_segments(rq)
858 #define queue_max_hw_segments(rq)         queue_max_segments(rq)
859 #endif
860
861
862 #ifndef HAVE_BI_HW_SEGMENTS
863 #define bio_hw_segments(q, bio) 0
864 #endif
865
866 #endif /* __KERNEL__ */
867 #endif /* _COMPAT25_H */