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