Whamcloud - gitweb
LU-812 ldiskfs: super_operations->dirty_inode now takes a flag
[fs/lustre-release.git] / lustre / include / linux / lustre_compat25.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef _LINUX_COMPAT25_H
38 #define _LINUX_COMPAT25_H
39
40 #include <linux/fs_struct.h>
41 #include <linux/namei.h>
42 #include <libcfs/linux/portals_compat25.h>
43
44 #include <linux/lustre_patchless_compat.h>
45
46 #ifdef HAVE_FS_STRUCT_RWLOCK
47 # define LOCK_FS_STRUCT(fs)     write_lock(&(fs)->lock)
48 # define UNLOCK_FS_STRUCT(fs)   write_unlock(&(fs)->lock)
49 #else
50 # define LOCK_FS_STRUCT(fs)     spin_lock(&(fs)->lock)
51 # define UNLOCK_FS_STRUCT(fs)   spin_unlock(&(fs)->lock)
52 #endif
53
54 #ifdef HAVE_FS_STRUCT_USE_PATH
55 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
56                                  struct dentry *dentry)
57 {
58         struct path path;
59         struct path old_pwd;
60
61         path.mnt = mnt;
62         path.dentry = dentry;
63         LOCK_FS_STRUCT(fs);
64         old_pwd = fs->pwd;
65         path_get(&path);
66         fs->pwd = path;
67         UNLOCK_FS_STRUCT(fs);
68
69         if (old_pwd.dentry)
70                 path_put(&old_pwd);
71 }
72
73 #else
74
75 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
76                 struct dentry *dentry)
77 {
78         struct dentry *old_pwd;
79         struct vfsmount *old_pwdmnt;
80
81         LOCK_FS_STRUCT(fs);
82         old_pwd = fs->pwd;
83         old_pwdmnt = fs->pwdmnt;
84         fs->pwdmnt = mntget(mnt);
85         fs->pwd = dget(dentry);
86         UNLOCK_FS_STRUCT(fs);
87
88         if (old_pwd) {
89                 dput(old_pwd);
90                 mntput(old_pwdmnt);
91         }
92 }
93 #endif
94
95 /*
96  * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
97  * ATTR_* attributes (see bug 13828)
98  */
99 #define ATTR_BLOCKS    (1 << 27)
100
101 #define current_ngroups current_cred()->group_info->ngroups
102 #define current_groups current_cred()->group_info->small_block
103
104 /*
105  * OBD need working random driver, thus all our
106  * initialization routines must be called after device
107  * driver initialization
108  */
109 #ifndef MODULE
110 #undef module_init
111 #define module_init(a)     late_initcall(a)
112 #endif
113
114 #ifndef HAVE_TRYLOCK_PAGE
115 #define trylock_page(page)              (!TestSetPageLocked(page))
116 #endif
117
118 #define LTIME_S(time)                   (time.tv_sec)
119
120 #ifdef HAVE_EXPORT_INODE_PERMISSION
121 #define ll_permission(inode,mask,nd)    inode_permission(inode,mask)
122 #else
123 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
124 #endif
125
126 #ifdef HAVE_GENERIC_PERMISSION_2ARGS
127 # define ll_generic_permission(inode, mask, flags, check_acl) \
128          generic_permission(inode, mask)
129 #elif defined HAVE_GENERIC_PERMISSION_4ARGS
130 # define ll_generic_permission(inode, mask, flags, check_acl) \
131          generic_permission(inode, mask, flags, check_acl)
132 #else
133 # define ll_generic_permission(inode, mask, flags, check_acl) \
134          generic_permission(inode, mask, check_acl)
135 #endif
136
137 #ifdef HAVE_BLKDEV_PUT_2ARGS
138 #define ll_blkdev_put(a, b) blkdev_put(a, b)
139 #else
140 #define ll_blkdev_put(a, b) blkdev_put(a)
141 #endif
142
143 #ifdef HAVE_DENTRY_OPEN_USE_PATH
144 #define ll_dentry_open(a,b,c)   dentry_open(a,b,c)
145 #else
146 /*
147  * dentry_open handles its own reference counting since Linux v3.6
148  * (commit 765927b2). Callers should free their own references.
149  *
150  * Prior versions expected the caller to increment the references.
151  * The references are retained on success and freed on error.
152  */
153 static inline struct file *ll_dentry_open(struct path *path, int flags,
154                                           const struct cred *cred)
155 {
156         mntget(path->mnt);
157         dget(path->dentry);
158 # ifdef HAVE_DENTRY_OPEN_4ARGS
159         return dentry_open(path->dentry, path->mnt, flags, cred);
160 # else
161         return dentry_open(path->dentry, path->mnt, flags);
162 # endif
163 }
164 #endif
165
166 #ifdef HAVE_SECURITY_PLUG
167 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
168                 vfs_symlink(dir, dentry, mnt, path, mode)
169 #else
170 #ifdef HAVE_4ARGS_VFS_SYMLINK
171 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
172                 vfs_symlink(dir, dentry, path, mode)
173 #else
174 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
175                        vfs_symlink(dir, dentry, path)
176 #endif
177
178 #endif
179
180 #if !defined(HAVE_FILE_LLSEEK_SIZE) || defined(HAVE_FILE_LLSEEK_SIZE_5ARGS)
181 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
182                 generic_file_llseek_size(file, offset, origin, maxbytes, eof);
183 #else
184 #define ll_generic_file_llseek_size(file, offset, origin, maxbytes, eof) \
185                 generic_file_llseek_size(file, offset, origin, maxbytes);
186 #endif
187
188 #ifdef HAVE_INODE_DIO_WAIT
189 /* inode_dio_wait(i) use as-is for write lock */
190 # define inode_dio_write_done(i)        do {} while (0) /* for write unlock */
191 # define inode_dio_read(i)              atomic_inc(&(i)->i_dio_count)
192 /* inode_dio_done(i) use as-is for read unlock */
193 #else
194 # define inode_dio_wait(i)              down_write(&(i)->i_alloc_sem)
195 # define inode_dio_write_done(i)        up_write(&(i)->i_alloc_sem)
196 # define inode_dio_read(i)              down_read(&(i)->i_alloc_sem)
197 # define inode_dio_done(i)              up_read(&(i)->i_alloc_sem)
198 #endif
199
200 #ifdef HAVE_RW_TREE_LOCK
201 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
202 #define TREE_READ_UNLOCK_IRQ(mapping)   read_unlock_irq(&(mapping)->tree_lock)
203 #else
204 #define TREE_READ_LOCK_IRQ(mapping)     spin_lock_irq(&(mapping)->tree_lock)
205 #define TREE_READ_UNLOCK_IRQ(mapping)   spin_unlock_irq(&(mapping)->tree_lock)
206 #endif
207
208 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
209 #define ll_unregister_blkdev(a,b)       unregister_blkdev((a),(b))
210 #else
211 static inline
212 int ll_unregister_blkdev(unsigned int dev, const char *name)
213 {
214         unregister_blkdev(dev, name);
215         return 0;
216 }
217 #endif
218
219 #ifdef HAVE_INVALIDATE_BDEV_2ARG
220 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a),(b))
221 #else
222 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a))
223 #endif
224
225 #ifndef FS_HAS_FIEMAP
226 #define FS_HAS_FIEMAP                   (0)
227 #endif
228
229 #ifndef HAVE_FS_RENAME_DOES_D_MOVE
230 #define FS_RENAME_DOES_D_MOVE           FS_ODD_RENAME
231 #endif
232
233 #ifndef HAVE_D_OBTAIN_ALIAS
234 /* The old d_alloc_anon() didn't free the inode reference on error
235  * like d_obtain_alias().  Hide that difference/inconvenience here. */
236 static inline struct dentry *d_obtain_alias(struct inode *inode)
237 {
238         struct dentry *anon = d_alloc_anon(inode);
239
240         if (anon == NULL) {
241                 iput(inode);
242                 anon = ERR_PTR(-ENOMEM);
243         }
244
245         return anon;
246 }
247 #endif
248
249 /* add a lustre compatible layer for crypto API */
250 #include <linux/crypto.h>
251 #ifdef HAVE_ASYNC_BLOCK_CIPHER
252 #define ll_crypto_hash          crypto_hash
253 #define ll_crypto_cipher        crypto_blkcipher
254 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
255 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
256 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
257 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
258 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
259 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
260                 crypto_blkcipher_setkey(tfm, key, keylen)
261 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
262                 crypto_blkcipher_set_iv(tfm, src, len)
263 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
264                 crypto_blkcipher_get_iv(tfm, dst, len)
265 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
266                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
267 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
268                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
269 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
270                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
271 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
272                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
273
274 static inline
275 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char *name,
276                                                    u32 type, u32 mask)
277 {
278         struct ll_crypto_cipher *rtn = crypto_alloc_blkcipher(name, type, mask);
279
280         return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
281 }
282
283 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
284                                  u8 *key, unsigned int *keylen,
285                                  struct scatterlist *sg,
286                                  unsigned int size, u8 *result)
287 {
288         struct hash_desc desc;
289         int              rv;
290         desc.tfm   = tfm;
291         desc.flags = 0;
292         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
293         if (rv) {
294                 CERROR("failed to hash setkey: %d\n", rv);
295                 return rv;
296         }
297         return crypto_hash_digest(&desc, sg, size, result);
298 }
299 static inline
300 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
301 {
302         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
303 }
304 static inline
305 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
306 {
307         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
308 }
309
310 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
311 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
312 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
313 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
314 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
315 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
316 #else /* HAVE_ASYNC_BLOCK_CIPHER */
317 #include <linux/scatterlist.h>
318 #define ll_crypto_hash          crypto_tfm
319 #define ll_crypto_cipher        crypto_tfm
320 #ifndef HAVE_STRUCT_HASH_DESC
321 struct hash_desc {
322         struct ll_crypto_hash *tfm;
323         u32                    flags;
324 };
325 #endif
326 #ifndef HAVE_STRUCT_BLKCIPHER_DESC
327 struct blkcipher_desc {
328         struct ll_crypto_cipher *tfm;
329         void                    *info;
330         u32                      flags;
331 };
332 #endif
333 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
334         crypto_cipher_setkey(tfm, key, keylen)
335 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
336         crypto_cipher_set_iv(tfm, src, len)
337 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
338         crypto_cipher_get_iv(tfm, dst, len)
339 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
340         crypto_cipher_encrypt((desc)->tfm, dst, src, bytes)
341 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
342         crypto_cipher_decrypt((desc)->tfm, dst, src, bytes)
343 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
344         crypto_cipher_decrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
345 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
346         crypto_cipher_encrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
347
348 static inline
349 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char * algname,
350                                                    u32 type, u32 mask)
351 {
352         struct ll_crypto_cipher *rtn;
353         char                     buf[CRYPTO_MAX_ALG_NAME + 1];
354         const char              *pan = algname;
355         u32                      flag = 0;
356
357         if (strncmp("cbc(", algname, 4) == 0)
358                 flag |= CRYPTO_TFM_MODE_CBC;
359         else if (strncmp("ecb(", algname, 4) == 0)
360                 flag |= CRYPTO_TFM_MODE_ECB;
361         if (flag) {
362                 char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
363                 if (vp) {
364                         memcpy(buf, algname + 4, vp - algname - 4);
365                         buf[vp - algname - 4] = '\0';
366                         pan = buf;
367                 } else {
368                         flag = 0;
369                 }
370         }
371         rtn = crypto_alloc_tfm(pan, flag);
372         return (rtn == NULL ?  ERR_PTR(-ENOMEM) : rtn);
373 }
374
375 static inline
376 struct ll_crypto_hash *ll_crypto_alloc_hash(const char *alg, u32 type, u32 mask)
377 {
378         char        buf[CRYPTO_MAX_ALG_NAME + 1];
379         const char *pan = alg;
380
381         if (strncmp("hmac(", alg, 5) == 0) {
382                 char *vp = strnchr(alg, CRYPTO_MAX_ALG_NAME, ')');
383                 if (vp) {
384                         memcpy(buf, alg+ 5, vp - alg- 5);
385                         buf[vp - alg - 5] = 0x00;
386                         pan = buf;
387                 }
388         }
389         return crypto_alloc_tfm(pan, 0);
390 }
391 static inline int ll_crypto_hash_init(struct hash_desc *desc)
392 {
393        crypto_digest_init(desc->tfm); return 0;
394 }
395 static inline int ll_crypto_hash_update(struct hash_desc *desc,
396                                         struct scatterlist *sg,
397                                         unsigned int nbytes)
398 {
399         struct scatterlist *sl = sg;
400         unsigned int        count;
401                 /*
402                  * This way is very weakness. We must ensure that
403                  * the sum of sg[0..i]->length isn't greater than nbytes.
404                  * In the upstream kernel the crypto_hash_update() also
405                  * via the nbytes computed the count of sg[...].
406                  * The old style is more safely. but it gone.
407                  */
408         for (count = 0; nbytes > 0; count ++, sl ++) {
409                 nbytes -= sl->length;
410         }
411         crypto_digest_update(desc->tfm, sg, count); return 0;
412 }
413 static inline int ll_crypto_hash_final(struct hash_desc *desc, u8 *out)
414 {
415         crypto_digest_final(desc->tfm, out); return 0;
416 }
417 static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
418                                  u8 *key, unsigned int *keylen,
419                                  struct scatterlist *sg,
420                                  unsigned int nbytes,
421                                  u8 *out)
422 {
423         struct scatterlist *sl = sg;
424         int                 count;
425         for (count = 0; nbytes > 0; count ++, sl ++) {
426                 nbytes -= sl->length;
427         }
428         crypto_hmac(tfm, key, keylen, sg, count, out);
429         return 0;
430 }
431
432 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_digest_setkey(tfm, key, keylen)
433 #define ll_crypto_blkcipher_blocksize(tfm)      crypto_tfm_alg_blocksize(tfm)
434 #define ll_crypto_blkcipher_ivsize(tfm) crypto_tfm_alg_ivsize(tfm)
435 #define ll_crypto_hash_digestsize(tfm)  crypto_tfm_alg_digestsize(tfm)
436 #define ll_crypto_hash_blocksize(tfm)   crypto_tfm_alg_blocksize(tfm)
437 #define ll_crypto_free_hash(tfm)        crypto_free_tfm(tfm)
438 #define ll_crypto_free_blkcipher(tfm)   crypto_free_tfm(tfm)
439 #define ll_crypto_tfm_alg_min_keysize   crypto_tfm_alg_min_keysize
440 #define ll_crypto_tfm_alg_max_keysize   crypto_tfm_alg_max_keysize
441 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
442
443 #ifdef HAVE_SECURITY_PLUG
444 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
445 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
446 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
447 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
448 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
449                 vfs_mknod(dir,entry,mnt,mode,dev)
450 #define ll_security_inode_unlink(dir,entry,mnt)         \
451                 security_inode_unlink(dir,entry,mnt)
452 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
453                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
454 #else
455 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
456 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
457 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
458 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
459 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
460 #define ll_security_inode_unlink(dir,entry,mnt) security_inode_unlink(dir,entry)
461 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
462                 vfs_rename(old,old_dir,new,new_dir)
463 #endif /* HAVE_SECURITY_PLUG */
464
465 #ifdef for_each_possible_cpu
466 #define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
467 #elif defined(for_each_cpu)
468 #define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
469 #endif
470
471 #ifdef HAVE_BIO_ENDIO_2ARG
472 #define cfs_bio_io_error(a,b)   bio_io_error((a))
473 #define cfs_bio_endio(a,b,c)    bio_endio((a),(c))
474 #else
475 #define cfs_bio_io_error(a,b)   bio_io_error((a),(b))
476 #define cfs_bio_endio(a,b,c)    bio_endio((a),(b),(c))
477 #endif
478
479 #ifdef HAVE_FS_STRUCT_USE_PATH
480 #define cfs_fs_pwd(fs)       ((fs)->pwd.dentry)
481 #define cfs_fs_mnt(fs)       ((fs)->pwd.mnt)
482 #define cfs_path_put(nd)     path_put(&(nd)->path)
483 #else
484 #define cfs_fs_pwd(fs)       ((fs)->pwd)
485 #define cfs_fs_mnt(fs)       ((fs)->pwdmnt)
486 #define cfs_path_put(nd)     path_release(nd)
487 #endif
488
489 #ifndef HAVE_SIMPLE_SETATTR
490 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
491 #endif
492
493 #ifndef SLAB_DESTROY_BY_RCU
494 #define SLAB_DESTROY_BY_RCU 0
495 #endif
496
497 #ifndef HAVE_SB_HAS_QUOTA_ACTIVE
498 #define sb_has_quota_active(sb, type) sb_has_quota_enabled(sb, type)
499 #endif
500
501 #ifndef HAVE_SB_ANY_QUOTA_LOADED
502 # ifdef HAVE_SB_ANY_QUOTA_ACTIVE
503 # define sb_any_quota_loaded(sb) sb_any_quota_active(sb)
504 # else
505 # define sb_any_quota_loaded(sb) sb_any_quota_enabled(sb)
506 # endif
507 #endif
508
509 static inline int
510 ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
511 {
512         int rc;
513
514         if (sb->s_qcop->quota_on) {
515 #ifdef HAVE_QUOTA_ON_USE_PATH
516                 struct path path;
517
518                 rc = kern_path(name, LOOKUP_FOLLOW, &path);
519                 if (!rc)
520                         return rc;
521 #endif
522                 rc = sb->s_qcop->quota_on(sb, off, ver
523 #ifdef HAVE_QUOTA_ON_USE_PATH
524                                             , &path
525 #else
526                                             , name
527 #endif
528 #ifdef HAVE_QUOTA_ON_5ARGS
529                                             , remount
530 #endif
531                                            );
532 #ifdef HAVE_QUOTA_ON_USE_PATH
533                 path_put(&path);
534 #endif
535                 return rc;
536         }
537         else
538                 return -ENOSYS;
539 }
540
541 static inline int ll_quota_off(struct super_block *sb, int off, int remount)
542 {
543         if (sb->s_qcop->quota_off) {
544                 return sb->s_qcop->quota_off(sb, off
545 #ifdef HAVE_QUOTA_OFF_3ARGS
546                                              , remount
547 #endif
548                                             );
549         }
550         else
551                 return -ENOSYS;
552 }
553
554 #ifndef HAVE_BLK_QUEUE_LOG_BLK_SIZE /* added in 2.6.31 */
555 #define blk_queue_logical_block_size(q, sz) blk_queue_hardsect_size(q, sz)
556 #endif
557
558 #ifndef HAVE_DQUOT_SUSPEND
559 #ifndef HAVE_VFS_DQ_OFF
560 # define ll_vfs_dq_init             DQUOT_INIT
561 # define ll_vfs_dq_drop             DQUOT_DROP
562 # define ll_vfs_dq_transfer         DQUOT_TRANSFER
563 # define ll_vfs_dq_off(sb, remount) DQUOT_OFF(sb)
564 #else
565 # define ll_vfs_dq_init             vfs_dq_init
566 # define ll_vfs_dq_drop             vfs_dq_drop
567 # define ll_vfs_dq_transfer         vfs_dq_transfer
568 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
569 #endif
570 #else
571 # define ll_vfs_dq_init             dquot_initialize
572 # define ll_vfs_dq_drop             dquot_drop
573 # define ll_vfs_dq_transfer         dquot_transfer
574 # define ll_vfs_dq_off(sb, remount) dquot_suspend(sb, -1)
575 #endif
576
577 #ifndef HAVE_BDI_INIT
578 #define bdi_init(bdi)    0
579 #define bdi_destroy(bdi) do { } while (0)
580 #endif
581
582 #ifdef HAVE_BLK_QUEUE_MAX_SECTORS /* removed in rhel6 */
583 #define blk_queue_max_hw_sectors(q, sect) blk_queue_max_sectors(q, sect)
584 #endif
585
586 #ifndef HAVE_BLKDEV_GET_BY_DEV
587 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
588 #endif
589
590 #ifndef HAVE_REQUEST_QUEUE_LIMITS
591 #define queue_max_sectors(rq)             ((rq)->max_sectors)
592 #define queue_max_hw_sectors(rq)          ((rq)->max_hw_sectors)
593 #define queue_max_phys_segments(rq)       ((rq)->max_phys_segments)
594 #define queue_max_hw_segments(rq)         ((rq)->max_hw_segments)
595 #endif
596
597 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
598 #define blk_queue_max_segments(rq, seg)                      \
599         do { blk_queue_max_phys_segments(rq, seg);           \
600              blk_queue_max_hw_segments(rq, seg); } while (0)
601 #else
602 #define queue_max_phys_segments(rq)       queue_max_segments(rq)
603 #define queue_max_hw_segments(rq)         queue_max_segments(rq)
604 #endif
605
606 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
607 #define ll_kmap_atomic(a, b)    kmap_atomic(a)
608 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a)
609 #else
610 #define ll_kmap_atomic(a, b)    kmap_atomic(a, b)
611 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a, b)
612 #endif
613
614 #ifndef HAVE_CLEAR_INODE
615 #define clear_inode(i)          end_writeback(i)
616 #endif
617
618 #ifdef HAVE_DENTRY_D_ALIAS_HLIST
619 #define ll_d_hlist_node hlist_node
620 #define ll_d_hlist_empty(list) hlist_empty(list)
621 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
622 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
623 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
624         hlist_for_each_entry(dentry, p, i_dentry, alias)
625 #else
626 #define ll_d_hlist_node list_head
627 #define ll_d_hlist_empty(list) list_empty(list)
628 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
629 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
630 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
631         p = NULL; list_for_each_entry(dentry, i_dentry, alias)
632 #endif
633
634
635 #ifndef HAVE_BI_HW_SEGMENTS
636 #define bio_hw_segments(q, bio) 0
637 #endif
638
639 #ifndef HAVE_PAGEVEC_LRU_ADD_FILE
640 #define pagevec_lru_add_file pagevec_lru_add
641 #endif
642
643 #ifdef HAVE_ADD_TO_PAGE_CACHE_LRU
644 #define ll_pagevec_init(pv, cold)       do {} while (0)
645 #define ll_pagevec_add(pv, pg)          (0)
646 #define ll_pagevec_lru_add_file(pv)     do {} while (0)
647 #else
648 #define add_to_page_cache_lru(pg, mapping, off, gfp) \
649         add_to_page_cache(pg, mapping, off, gfp)
650 #define ll_pagevec_init(pv, cold)       pagevec_init(pv, cold);
651 #define ll_pagevec_add(pv, pg)                                  \
652 ({                                                              \
653         int __ret;                                              \
654                                                                 \
655         page_cache_get(pg);                                     \
656         __ret = pagevec_add(pv, pg);                            \
657 })
658 #define ll_pagevec_lru_add_file(pv)     pagevec_lru_add_file(pv)
659 #endif
660
661 #if !defined(HAVE_CPUMASK_OF_NODE) && defined(HAVE_NODE_TO_CPUMASK)
662 # ifdef HAVE_OFED_CPUMASK_OF_NODE
663 # undef cpumask_of_node
664 # define HAVE_CPUMASK_OF_NODE
665 # endif
666 #define cpumask_of_node(i)      (&node_to_cpumask(i))
667 #endif
668
669 #ifndef QUOTA_OK
670 # define QUOTA_OK 0
671 #endif
672 #ifndef NO_QUOTA
673 # define NO_QUOTA (-EDQUOT)
674 #endif
675
676 #ifndef SEEK_DATA
677 #define SEEK_DATA      3       /* seek to the next data */
678 #endif
679 #ifndef SEEK_HOLE
680 #define SEEK_HOLE      4       /* seek to the next hole */
681 #endif
682
683 #ifndef FMODE_UNSIGNED_OFFSET
684 #define FMODE_UNSIGNED_OFFSET   ((__force fmode_t)0x2000)
685 #endif
686
687 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
688 # define ext2_set_bit             __test_and_set_bit_le
689 # define ext2_clear_bit           __test_and_clear_bit_le
690 # define ext2_test_bit            test_bit_le
691 # define ext2_find_first_zero_bit find_first_zero_bit_le
692 # define ext2_find_next_zero_bit  find_next_zero_bit_le
693 #endif
694
695 #ifdef ATTR_TIMES_SET
696 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
697 #else
698 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
699 #endif
700
701 #ifndef HAVE_SELINUX_IS_ENABLED
702 static inline bool selinux_is_enabled(void)
703 {
704         return 0;
705 }
706 #endif
707
708 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
709 # define lm_compare_owner       fl_compare_owner
710 #endif
711
712 /*
713  * After 3.1, kernel's nameidata.intent.open.flags is different
714  * with lustre's lookup_intent.it_flags, as lustre's it_flags'
715  * lower bits equal to FMODE_xxx while kernel doesn't transliterate
716  * lower bits of nameidata.intent.open.flags to FMODE_xxx.
717  * */
718 #include <linux/version.h>
719 static inline int ll_namei_to_lookup_intent_flag(int flag)
720 {
721 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
722         flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
723 #endif
724         return flag;
725 }
726
727 #ifdef HAVE_VOID_MAKE_REQUEST_FN
728 # define ll_mrf_ret void
729 # define LL_MRF_RETURN(rc)
730 #else
731 # define ll_mrf_ret int
732 # define LL_MRF_RETURN(rc) RETURN(rc)
733 #endif
734
735 #include <linux/fs.h>
736 #ifndef HAVE_PROTECT_I_NLINK
737 static inline void set_nlink(struct inode *inode, unsigned int nlink)
738 {
739         inode->i_nlink = nlink;
740 }
741 #endif
742
743 #ifdef HAVE_INODEOPS_USE_UMODE_T
744 # define ll_umode_t     umode_t
745 #else
746 # define ll_umode_t     int
747 #endif
748
749 #include <linux/dcache.h>
750 #ifndef HAVE_D_MAKE_ROOT
751 static inline struct dentry *d_make_root(struct inode *root)
752 {
753         struct dentry *res = d_alloc_root(root);
754
755         if (res == NULL && root)
756                 iput(root);
757
758         return res;
759 }
760 #endif
761
762 #ifdef HAVE_DIRTY_INODE_HAS_FLAG
763 # define ll_dirty_inode(inode, flag)    (inode)->i_sb->s_op->dirty_inode((inode), flag)
764 #else
765 # define ll_dirty_inode(inode, flag)    (inode)->i_sb->s_op->dirty_inode((inode))
766 #endif
767
768 #endif /* _COMPAT25_H */