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