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