Whamcloud - gitweb
LU-1337 llite: support SEEK_HOLE and SEEK_DATA
[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, Whamcloud, Inc.
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 static inline struct file *ll_dentry_open(struct dentry *dentry,
144                                           struct vfsmount *mnt, int flags,
145                                           const struct cred *cred)
146 {
147 #ifdef HAVE_DENTRY_OPEN_USE_PATH
148         struct path path = { .mnt = mnt, .dentry = dentry };
149         return dentry_open(&path, flags, cred);
150 #elif defined HAVE_DENTRY_OPEN_4ARGS
151         return dentry_open(dentry, mnt, flags, cred);
152 #else
153         return dentry_open(dentry, mnt, flags);
154 #endif
155 }
156
157 #ifdef HAVE_SECURITY_PLUG
158 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
159                 vfs_symlink(dir, dentry, mnt, path, mode)
160 #else
161 #ifdef HAVE_4ARGS_VFS_SYMLINK
162 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
163                 vfs_symlink(dir, dentry, path, mode)
164 #else
165 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
166                        vfs_symlink(dir, dentry, path)
167 #endif
168
169 #endif
170
171 #ifdef HAVE_INODE_DIO_WAIT
172 /* inode_dio_wait(i) use as-is for write lock */
173 # define inode_dio_write_done(i)        do {} while (0) /* for write unlock */
174 # define inode_dio_read(i)              atomic_inc(&(i)->i_dio_count)
175 /* inode_dio_done(i) use as-is for read unlock */
176 #else
177 # define inode_dio_wait(i)              down_write(&(i)->i_alloc_sem)
178 # define inode_dio_write_done(i)        up_write(&(i)->i_alloc_sem)
179 # define inode_dio_read(i)              down_read(&(i)->i_alloc_sem)
180 # define inode_dio_done(i)              up_read(&(i)->i_alloc_sem)
181 #endif
182
183 #ifdef HAVE_HIDE_VFSMOUNT_GUTS
184 # include <../fs/mount.h>
185 #else
186 # define real_mount(mnt)        (mnt)
187 #endif
188
189 static inline const char *mnt_get_devname(struct vfsmount *mnt)
190 {
191         return real_mount(mnt)->mnt_devname;
192 }
193
194 #ifndef HAVE_ATOMIC_MNT_COUNT
195 static inline unsigned int mnt_get_count(struct vfsmount *mnt)
196 {
197 #ifdef CONFIG_SMP
198         unsigned int count = 0;
199         int cpu;
200
201         for_each_possible_cpu(cpu) {
202                 count += per_cpu_ptr(real_mount(mnt)->mnt_pcp, cpu)->mnt_count;
203         }
204
205         return count;
206 #else
207         return real_mount(mnt)->mnt_count;
208 #endif
209 }
210 #else
211 # define mnt_get_count(mnt)      cfs_atomic_read(&(real_mount(mnt)->mnt_count))
212 #endif
213
214 #ifdef HAVE_RW_TREE_LOCK
215 #define TREE_READ_LOCK_IRQ(mapping)     read_lock_irq(&(mapping)->tree_lock)
216 #define TREE_READ_UNLOCK_IRQ(mapping)   read_unlock_irq(&(mapping)->tree_lock)
217 #else
218 #define TREE_READ_LOCK_IRQ(mapping)     spin_lock_irq(&(mapping)->tree_lock)
219 #define TREE_READ_UNLOCK_IRQ(mapping)   spin_unlock_irq(&(mapping)->tree_lock)
220 #endif
221
222 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
223 #define ll_unregister_blkdev(a,b)       unregister_blkdev((a),(b))
224 #else
225 static inline
226 int ll_unregister_blkdev(unsigned int dev, const char *name)
227 {
228         unregister_blkdev(dev, name);
229         return 0;
230 }
231 #endif
232
233 #ifdef HAVE_INVALIDATE_BDEV_2ARG
234 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a),(b))
235 #else
236 #define ll_invalidate_bdev(a,b)         invalidate_bdev((a))
237 #endif
238
239 #ifndef FS_HAS_FIEMAP
240 #define FS_HAS_FIEMAP                   (0)
241 #endif
242
243 #ifndef HAVE_FS_RENAME_DOES_D_MOVE
244 #define FS_RENAME_DOES_D_MOVE           FS_ODD_RENAME
245 #endif
246
247 #ifndef HAVE_D_OBTAIN_ALIAS
248 /* The old d_alloc_anon() didn't free the inode reference on error
249  * like d_obtain_alias().  Hide that difference/inconvenience here. */
250 static inline struct dentry *d_obtain_alias(struct inode *inode)
251 {
252         struct dentry *anon = d_alloc_anon(inode);
253
254         if (anon == NULL) {
255                 iput(inode);
256                 anon = ERR_PTR(-ENOMEM);
257         }
258
259         return anon;
260 }
261 #endif
262
263 /* add a lustre compatible layer for crypto API */
264 #include <linux/crypto.h>
265 #ifdef HAVE_ASYNC_BLOCK_CIPHER
266 #define ll_crypto_hash          crypto_hash
267 #define ll_crypto_cipher        crypto_blkcipher
268 #define ll_crypto_alloc_hash(name, type, mask)  crypto_alloc_hash(name, type, mask)
269 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
270 #define ll_crypto_hash_init(desc)               crypto_hash_init(desc)
271 #define ll_crypto_hash_update(desc, sl, bytes)  crypto_hash_update(desc, sl, bytes)
272 #define ll_crypto_hash_final(desc, out)         crypto_hash_final(desc, out)
273 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
274                 crypto_blkcipher_setkey(tfm, key, keylen)
275 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
276                 crypto_blkcipher_set_iv(tfm, src, len)
277 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
278                 crypto_blkcipher_get_iv(tfm, dst, len)
279 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
280                 crypto_blkcipher_encrypt(desc, dst, src, bytes)
281 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
282                 crypto_blkcipher_decrypt(desc, dst, src, bytes)
283 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
284                 crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
285 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
286                 crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
287
288 static inline
289 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char *name,
290                                                    u32 type, u32 mask)
291 {
292         struct ll_crypto_cipher *rtn = crypto_alloc_blkcipher(name, type, mask);
293
294         return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
295 }
296
297 static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
298                                  u8 *key, unsigned int *keylen,
299                                  struct scatterlist *sg,
300                                  unsigned int size, u8 *result)
301 {
302         struct hash_desc desc;
303         int              rv;
304         desc.tfm   = tfm;
305         desc.flags = 0;
306         rv = crypto_hash_setkey(desc.tfm, key, *keylen);
307         if (rv) {
308                 CERROR("failed to hash setkey: %d\n", rv);
309                 return rv;
310         }
311         return crypto_hash_digest(&desc, sg, size, result);
312 }
313 static inline
314 unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
315 {
316         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
317 }
318 static inline
319 unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
320 {
321         return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
322 }
323
324 #define ll_crypto_hash_blocksize(tfm)       crypto_hash_blocksize(tfm)
325 #define ll_crypto_hash_digestsize(tfm)      crypto_hash_digestsize(tfm)
326 #define ll_crypto_blkcipher_ivsize(tfm)     crypto_blkcipher_ivsize(tfm)
327 #define ll_crypto_blkcipher_blocksize(tfm)  crypto_blkcipher_blocksize(tfm)
328 #define ll_crypto_free_hash(tfm)            crypto_free_hash(tfm)
329 #define ll_crypto_free_blkcipher(tfm)       crypto_free_blkcipher(tfm)
330 #else /* HAVE_ASYNC_BLOCK_CIPHER */
331 #include <linux/scatterlist.h>
332 #define ll_crypto_hash          crypto_tfm
333 #define ll_crypto_cipher        crypto_tfm
334 #ifndef HAVE_STRUCT_HASH_DESC
335 struct hash_desc {
336         struct ll_crypto_hash *tfm;
337         u32                    flags;
338 };
339 #endif
340 #ifndef HAVE_STRUCT_BLKCIPHER_DESC
341 struct blkcipher_desc {
342         struct ll_crypto_cipher *tfm;
343         void                    *info;
344         u32                      flags;
345 };
346 #endif
347 #define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
348         crypto_cipher_setkey(tfm, key, keylen)
349 #define ll_crypto_blkcipher_set_iv(tfm, src, len) \
350         crypto_cipher_set_iv(tfm, src, len)
351 #define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
352         crypto_cipher_get_iv(tfm, dst, len)
353 #define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
354         crypto_cipher_encrypt((desc)->tfm, dst, src, bytes)
355 #define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
356         crypto_cipher_decrypt((desc)->tfm, dst, src, bytes)
357 #define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
358         crypto_cipher_decrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
359 #define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
360         crypto_cipher_encrypt_iv((desc)->tfm, dst, src, bytes, (desc)->info)
361
362 static inline
363 struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char * algname,
364                                                    u32 type, u32 mask)
365 {
366         struct ll_crypto_cipher *rtn;
367         char                     buf[CRYPTO_MAX_ALG_NAME + 1];
368         const char              *pan = algname;
369         u32                      flag = 0;
370
371         if (strncmp("cbc(", algname, 4) == 0)
372                 flag |= CRYPTO_TFM_MODE_CBC;
373         else if (strncmp("ecb(", algname, 4) == 0)
374                 flag |= CRYPTO_TFM_MODE_ECB;
375         if (flag) {
376                 char *vp = strnchr(algname, CRYPTO_MAX_ALG_NAME, ')');
377                 if (vp) {
378                         memcpy(buf, algname + 4, vp - algname - 4);
379                         buf[vp - algname - 4] = '\0';
380                         pan = buf;
381                 } else {
382                         flag = 0;
383                 }
384         }
385         rtn = crypto_alloc_tfm(pan, flag);
386         return (rtn == NULL ?  ERR_PTR(-ENOMEM) : rtn);
387 }
388
389 static inline
390 struct ll_crypto_hash *ll_crypto_alloc_hash(const char *alg, u32 type, u32 mask)
391 {
392         char        buf[CRYPTO_MAX_ALG_NAME + 1];
393         const char *pan = alg;
394
395         if (strncmp("hmac(", alg, 5) == 0) {
396                 char *vp = strnchr(alg, CRYPTO_MAX_ALG_NAME, ')');
397                 if (vp) {
398                         memcpy(buf, alg+ 5, vp - alg- 5);
399                         buf[vp - alg - 5] = 0x00;
400                         pan = buf;
401                 }
402         }
403         return crypto_alloc_tfm(pan, 0);
404 }
405 static inline int ll_crypto_hash_init(struct hash_desc *desc)
406 {
407        crypto_digest_init(desc->tfm); return 0;
408 }
409 static inline int ll_crypto_hash_update(struct hash_desc *desc,
410                                         struct scatterlist *sg,
411                                         unsigned int nbytes)
412 {
413         struct scatterlist *sl = sg;
414         unsigned int        count;
415                 /*
416                  * This way is very weakness. We must ensure that
417                  * the sum of sg[0..i]->length isn't greater than nbytes.
418                  * In the upstream kernel the crypto_hash_update() also
419                  * via the nbytes computed the count of sg[...].
420                  * The old style is more safely. but it gone.
421                  */
422         for (count = 0; nbytes > 0; count ++, sl ++) {
423                 nbytes -= sl->length;
424         }
425         crypto_digest_update(desc->tfm, sg, count); return 0;
426 }
427 static inline int ll_crypto_hash_final(struct hash_desc *desc, u8 *out)
428 {
429         crypto_digest_final(desc->tfm, out); return 0;
430 }
431 static inline int ll_crypto_hmac(struct crypto_tfm *tfm,
432                                  u8 *key, unsigned int *keylen,
433                                  struct scatterlist *sg,
434                                  unsigned int nbytes,
435                                  u8 *out)
436 {
437         struct scatterlist *sl = sg;
438         int                 count;
439         for (count = 0; nbytes > 0; count ++, sl ++) {
440                 nbytes -= sl->length;
441         }
442         crypto_hmac(tfm, key, keylen, sg, count, out);
443         return 0;
444 }
445
446 #define ll_crypto_hash_setkey(tfm, key, keylen) crypto_digest_setkey(tfm, key, keylen)
447 #define ll_crypto_blkcipher_blocksize(tfm)      crypto_tfm_alg_blocksize(tfm)
448 #define ll_crypto_blkcipher_ivsize(tfm) crypto_tfm_alg_ivsize(tfm)
449 #define ll_crypto_hash_digestsize(tfm)  crypto_tfm_alg_digestsize(tfm)
450 #define ll_crypto_hash_blocksize(tfm)   crypto_tfm_alg_blocksize(tfm)
451 #define ll_crypto_free_hash(tfm)        crypto_free_tfm(tfm)
452 #define ll_crypto_free_blkcipher(tfm)   crypto_free_tfm(tfm)
453 #define ll_crypto_tfm_alg_min_keysize   crypto_tfm_alg_min_keysize
454 #define ll_crypto_tfm_alg_max_keysize   crypto_tfm_alg_max_keysize
455 #endif /* HAVE_ASYNC_BLOCK_CIPHER */
456
457 #ifdef HAVE_SECURITY_PLUG
458 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry,mnt)
459 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mnt,mode)
460 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,mnt,dir,new,mnt1)
461 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry,mnt)
462 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)            \
463                 vfs_mknod(dir,entry,mnt,mode,dev)
464 #define ll_security_inode_unlink(dir,entry,mnt)         \
465                 security_inode_unlink(dir,entry,mnt)
466 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
467                 vfs_rename(old,old_dir,mnt,new,new_dir,mnt1)
468 #else
469 #define ll_vfs_rmdir(dir,entry,mnt)             vfs_rmdir(dir,entry)
470 #define ll_vfs_mkdir(inode,dir,mnt,mode)        vfs_mkdir(inode,dir,mode)
471 #define ll_vfs_link(old,mnt,dir,new,mnt1)       vfs_link(old,dir,new)
472 #define ll_vfs_unlink(inode,entry,mnt)          vfs_unlink(inode,entry)
473 #define ll_vfs_mknod(dir,entry,mnt,mode,dev)    vfs_mknod(dir,entry,mode,dev)
474 #define ll_security_inode_unlink(dir,entry,mnt) security_inode_unlink(dir,entry)
475 #define ll_vfs_rename(old,old_dir,mnt,new,new_dir,mnt1) \
476                 vfs_rename(old,old_dir,new,new_dir)
477 #endif /* HAVE_SECURITY_PLUG */
478
479 #ifdef for_each_possible_cpu
480 #define cfs_for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
481 #elif defined(for_each_cpu)
482 #define cfs_for_each_possible_cpu(cpu) for_each_cpu(cpu)
483 #endif
484
485 #ifdef HAVE_BIO_ENDIO_2ARG
486 #define cfs_bio_io_error(a,b)   bio_io_error((a))
487 #define cfs_bio_endio(a,b,c)    bio_endio((a),(c))
488 #else
489 #define cfs_bio_io_error(a,b)   bio_io_error((a),(b))
490 #define cfs_bio_endio(a,b,c)    bio_endio((a),(b),(c))
491 #endif
492
493 #ifdef HAVE_FS_STRUCT_USE_PATH
494 #define cfs_fs_pwd(fs)       ((fs)->pwd.dentry)
495 #define cfs_fs_mnt(fs)       ((fs)->pwd.mnt)
496 #define cfs_path_put(nd)     path_put(&(nd)->path)
497 #else
498 #define cfs_fs_pwd(fs)       ((fs)->pwd)
499 #define cfs_fs_mnt(fs)       ((fs)->pwdmnt)
500 #define cfs_path_put(nd)     path_release(nd)
501 #endif
502
503 #ifndef HAVE_SIMPLE_SETATTR
504 #define simple_setattr(dentry, ops) inode_setattr((dentry)->d_inode, ops)
505 #endif
506
507 #ifndef SLAB_DESTROY_BY_RCU
508 #define SLAB_DESTROY_BY_RCU 0
509 #endif
510
511 #ifndef HAVE_SB_HAS_QUOTA_ACTIVE
512 #define sb_has_quota_active(sb, type) sb_has_quota_enabled(sb, type)
513 #endif
514
515 #ifndef HAVE_SB_ANY_QUOTA_LOADED
516 # ifdef HAVE_SB_ANY_QUOTA_ACTIVE
517 # define sb_any_quota_loaded(sb) sb_any_quota_active(sb)
518 # else
519 # define sb_any_quota_loaded(sb) sb_any_quota_enabled(sb)
520 # endif
521 #endif
522
523 static inline int
524 ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
525 {
526         int rc;
527
528         if (sb->s_qcop->quota_on) {
529 #ifdef HAVE_QUOTA_ON_USE_PATH
530                 struct path path;
531
532                 rc = kern_path(name, LOOKUP_FOLLOW, &path);
533                 if (!rc)
534                         return rc;
535 #endif
536                 rc = sb->s_qcop->quota_on(sb, off, ver
537 #ifdef HAVE_QUOTA_ON_USE_PATH
538                                             , &path
539 #else
540                                             , name
541 #endif
542 #ifdef HAVE_QUOTA_ON_5ARGS
543                                             , remount
544 #endif
545                                            );
546 #ifdef HAVE_QUOTA_ON_USE_PATH
547                 path_put(&path);
548 #endif
549                 return rc;
550         }
551         else
552                 return -ENOSYS;
553 }
554
555 static inline int ll_quota_off(struct super_block *sb, int off, int remount)
556 {
557         if (sb->s_qcop->quota_off) {
558                 return sb->s_qcop->quota_off(sb, off
559 #ifdef HAVE_QUOTA_OFF_3ARGS
560                                              , remount
561 #endif
562                                             );
563         }
564         else
565                 return -ENOSYS;
566 }
567
568 #ifndef HAVE_BLK_QUEUE_LOG_BLK_SIZE /* added in 2.6.31 */
569 #define blk_queue_logical_block_size(q, sz) blk_queue_hardsect_size(q, sz)
570 #endif
571
572 #ifndef HAVE_VFS_DQ_OFF
573 # define ll_vfs_dq_init             DQUOT_INIT
574 # define ll_vfs_dq_drop             DQUOT_DROP
575 # define ll_vfs_dq_transfer         DQUOT_TRANSFER
576 # define ll_vfs_dq_off(sb, remount) DQUOT_OFF(sb)
577 #else
578 # define ll_vfs_dq_init             vfs_dq_init
579 # define ll_vfs_dq_drop             vfs_dq_drop
580 # define ll_vfs_dq_transfer         vfs_dq_transfer
581 # define ll_vfs_dq_off(sb, remount) vfs_dq_off(sb, remount)
582 #endif
583
584 #ifdef HAVE_BDI_INIT
585 #define ll_bdi_init(bdi)    bdi_init(bdi)
586 #define ll_bdi_destroy(bdi) bdi_destroy(bdi)
587 #else
588 #define ll_bdi_init(bdi)    0
589 #define ll_bdi_destroy(bdi) do { } while(0)
590 #endif
591
592 #ifdef HAVE_NEW_BACKING_DEV_INFO
593 # define ll_bdi_wb_cnt(bdi) ((bdi).wb_cnt)
594 #else
595 # define ll_bdi_wb_cnt(bdi) 1
596 #endif
597
598 #ifdef HAVE_BLK_QUEUE_MAX_SECTORS /* removed in rhel6 */
599 #define blk_queue_max_hw_sectors(q, sect) blk_queue_max_sectors(q, sect)
600 #endif
601
602 #ifndef HAVE_BLKDEV_GET_BY_DEV
603 # define blkdev_get_by_dev(dev, mode, holder) open_by_devnum(dev, mode)
604 #endif
605
606 #ifndef HAVE_REQUEST_QUEUE_LIMITS
607 #define queue_max_sectors(rq)             ((rq)->max_sectors)
608 #define queue_max_hw_sectors(rq)          ((rq)->max_hw_sectors)
609 #define queue_max_phys_segments(rq)       ((rq)->max_phys_segments)
610 #define queue_max_hw_segments(rq)         ((rq)->max_hw_segments)
611 #endif
612
613 #ifndef HAVE_BLK_QUEUE_MAX_SEGMENTS
614 #define blk_queue_max_segments(rq, seg)                      \
615         do { blk_queue_max_phys_segments(rq, seg);           \
616              blk_queue_max_hw_segments(rq, seg); } while (0)
617 #else
618 #define queue_max_phys_segments(rq)       queue_max_segments(rq)
619 #define queue_max_hw_segments(rq)         queue_max_segments(rq)
620 #endif
621
622 #ifdef HAVE_KMAP_ATOMIC_HAS_1ARG
623 #define ll_kmap_atomic(a, b)    kmap_atomic(a)
624 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a)
625 #else
626 #define ll_kmap_atomic(a, b)    kmap_atomic(a, b)
627 #define ll_kunmap_atomic(a, b)  kunmap_atomic(a, b)
628 #endif
629
630 #ifndef HAVE_CLEAR_INODE
631 #define clear_inode(i)          end_writeback(i)
632 #endif
633
634 #ifdef HAVE_DENTRY_D_ALIAS_HLIST
635 #define ll_d_hlist_node hlist_node
636 #define ll_d_hlist_empty(list) hlist_empty(list)
637 #define ll_d_hlist_entry(ptr, type, name) hlist_entry(ptr.first, type, name)
638 #define ll_d_hlist_for_each(tmp, i_dentry) hlist_for_each(tmp, i_dentry)
639 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
640         hlist_for_each_entry(dentry, p, i_dentry, alias)
641 #else
642 #define ll_d_hlist_node list_head
643 #define ll_d_hlist_empty(list) list_empty(list)
644 #define ll_d_hlist_entry(ptr, type, name) list_entry(ptr.next, type, name)
645 #define ll_d_hlist_for_each(tmp, i_dentry) list_for_each(tmp, i_dentry)
646 #define ll_d_hlist_for_each_entry(dentry, p, i_dentry, alias) \
647         p = NULL; list_for_each_entry(dentry, i_dentry, alias)
648 #endif
649
650
651 #ifndef HAVE_BI_HW_SEGMENTS
652 #define bio_hw_segments(q, bio) 0
653 #endif
654
655 #ifndef HAVE_PAGEVEC_LRU_ADD_FILE
656 #define pagevec_lru_add_file pagevec_lru_add
657 #endif
658
659 #ifdef HAVE_ADD_TO_PAGE_CACHE_LRU
660 #define ll_add_to_page_cache_lru(pg, mapping, off, gfp) \
661         add_to_page_cache_lru(pg, mapping, off, gfp)
662 #define ll_pagevec_init(pv, cold)       do {} while (0)
663 #define ll_pagevec_add(pv, pg)          (0)
664 #define ll_pagevec_lru_add_file(pv)     do {} while (0)
665 #else
666 #define ll_add_to_page_cache_lru(pg, mapping, off, gfp) \
667         add_to_page_cache(pg, mapping, off, gfp)
668 #define ll_pagevec_init(pv, cold)       pagevec_init(&lru_pvec, cold);
669 #define ll_pagevec_add(pv, pg)                                  \
670 ({                                                              \
671         int __ret;                                              \
672                                                                 \
673         page_cache_get(pg);                                     \
674         __ret = pagevec_add(pv, pg);                            \
675 })
676 #define ll_pagevec_lru_add_file(pv)     pagevec_lru_add_file(pv)
677 #endif
678
679 #if !defined(HAVE_NODE_TO_CPUMASK) && defined(HAVE_CPUMASK_OF_NODE)
680 #define node_to_cpumask(i)         (*(cpumask_of_node(i)))
681 #define HAVE_NODE_TO_CPUMASK
682 #endif
683
684 #ifndef QUOTA_OK
685 # define QUOTA_OK 0
686 #endif
687 #ifndef NO_QUOTA
688 # define NO_QUOTA (-EDQUOT)
689 #endif
690
691 #ifndef SEEK_DATA
692 #define SEEK_DATA      3       /* seek to the next data */
693 #endif
694 #ifndef SEEK_HOLE
695 #define SEEK_HOLE      4       /* seek to the next hole */
696 #endif
697
698 #ifndef FMODE_UNSIGNED_OFFSET
699 #define FMODE_UNSIGNED_OFFSET   ((__force fmode_t)0x2000)
700 #endif
701
702 #if !defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_) && !defined(ext2_set_bit)
703 # define ext2_set_bit             __test_and_set_bit_le
704 # define ext2_clear_bit           __test_and_clear_bit_le
705 # define ext2_test_bit            test_bit_le
706 # define ext2_find_first_zero_bit find_first_zero_bit_le
707 # define ext2_find_next_zero_bit  find_next_zero_bit_le
708 #endif
709
710 #ifdef ATTR_TIMES_SET
711 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
712 #else
713 # define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET)
714 #endif
715
716 #ifndef HAVE_SELINUX_IS_ENABLED
717 static inline bool selinux_is_enabled(void)
718 {
719         return 0;
720 }
721 #endif
722
723 #ifndef HAVE_LM_XXX_LOCK_MANAGER_OPS
724 # define lm_compare_owner       fl_compare_owner
725 #endif
726
727 /*
728  * After 3.1, kernel's nameidata.intent.open.flags is different
729  * with lustre's lookup_intent.it_flags, as lustre's it_flags'
730  * lower bits equal to FMODE_xxx while kernel doesn't transliterate
731  * lower bits of nameidata.intent.open.flags to FMODE_xxx.
732  * */
733 #include <linux/version.h>
734 static inline int ll_namei_to_lookup_intent_flag(int flag)
735 {
736 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
737         flag = (flag & ~O_ACCMODE) | OPEN_FMODE(flag);
738 #endif
739         return flag;
740 }
741
742 #ifdef HAVE_VOID_MAKE_REQUEST_FN
743 # define ll_mrf_ret void
744 # define LL_MRF_RETURN(rc)
745 #else
746 # define ll_mrf_ret int
747 # define LL_MRF_RETURN(rc) RETURN(rc)
748 #endif
749
750 #include <linux/fs.h>
751 #ifndef HAVE_PROTECT_I_NLINK
752 static inline void set_nlink(struct inode *inode, unsigned int nlink)
753 {
754         inode->i_nlink = nlink;
755 }
756 #endif
757
758 #ifdef HAVE_INODEOPS_USE_UMODE_T
759 # define ll_umode_t     umode_t
760 #else
761 # define ll_umode_t     int
762 #endif
763
764 #include <linux/dcache.h>
765 #ifndef HAVE_D_MAKE_ROOT
766 static inline struct dentry *d_make_root(struct inode *root)
767 {
768         struct dentry *res = d_alloc_root(root);
769
770         if (res == NULL && root)
771                 iput(root);
772
773         return res;
774 }
775 #endif
776
777 #endif /* _COMPAT25_H */