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