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