Whamcloud - gitweb
82343321a416e2f685176648b6c1adaa22c904e1
[fs/lustre-release.git] / lustre / include / lustre_compat.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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #ifndef _LUSTRE_COMPAT_H
33 #define _LUSTRE_COMPAT_H
34
35 #include <linux/aio.h>
36 #include <linux/fs.h>
37 #include <linux/namei.h>
38 #include <linux/pagemap.h>
39 #include <linux/posix_acl_xattr.h>
40 #include <linux/bio.h>
41 #include <linux/xattr.h>
42 #include <linux/workqueue.h>
43 #include <linux/blkdev.h>
44 #include <linux/slab.h>
45 #include <linux/security.h>
46 #include <libcfs/linux/linux-fs.h>
47 #include <obd_support.h>
48
49 #ifdef HAVE_4ARGS_VFS_SYMLINK
50 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
51                 vfs_symlink(dir, dentry, path, mode)
52 #else
53 #define ll_vfs_symlink(dir, dentry, mnt, path, mode) \
54                        vfs_symlink(dir, dentry, path)
55 #endif
56
57 #ifdef HAVE_BVEC_ITER
58 #define bio_idx(bio)                    (bio->bi_iter.bi_idx)
59 #define bio_set_sector(bio, sector)     (bio->bi_iter.bi_sector = sector)
60 #define bvl_to_page(bvl)                (bvl->bv_page)
61 #else
62 #define bio_idx(bio)                    (bio->bi_idx)
63 #define bio_set_sector(bio, sector)     (bio->bi_sector = sector)
64 #define bio_sectors(bio)                ((bio)->bi_size >> 9)
65 #define bvl_to_page(bvl)                (bvl->bv_page)
66 #endif
67
68 #ifdef HAVE_BVEC_ITER
69 #define bio_start_sector(bio) (bio->bi_iter.bi_sector)
70 #else
71 #define bio_start_sector(bio) (bio->bi_sector)
72 #endif
73
74 #ifdef HAVE_BI_BDEV
75 # define bio_get_dev(bio)       ((bio)->bi_bdev)
76 # define bio_get_disk(bio)      (bio_get_dev(bio)->bd_disk)
77 # define bio_get_queue(bio)     bdev_get_queue(bio_get_dev(bio))
78
79 # ifndef HAVE_BIO_SET_DEV
80 #  define bio_set_dev(bio, bdev) (bio_get_dev(bio) = (bdev))
81 # endif
82 #else
83 # define bio_get_disk(bio)      ((bio)->bi_disk)
84 # define bio_get_queue(bio)     (bio_get_disk(bio)->queue)
85 #endif
86
87 #ifndef HAVE_BI_OPF
88 #define bi_opf bi_rw
89 #endif
90
91 static inline struct bio *cfs_bio_alloc(struct block_device *bdev,
92                                         unsigned short nr_vecs,
93                                         __u32 op, gfp_t gfp_mask)
94 {
95         struct bio *bio;
96 #ifdef HAVE_BIO_ALLOC_WITH_BDEV
97         bio = bio_alloc(bdev, nr_vecs, op, gfp_mask);
98 #else
99         bio = bio_alloc(gfp_mask, nr_vecs);
100         if (bio) {
101                 bio_set_dev(bio, bdev);
102                 bio->bi_opf = op;
103         }
104 #endif /* HAVE_BIO_ALLOC_WITH_BDEV */
105         return bio;
106 }
107
108 #ifndef HAVE_DENTRY_D_CHILD
109 #define d_child                 d_u.d_child
110 #endif
111
112 #ifndef HAVE_D_IN_LOOKUP
113 static inline int d_in_lookup(struct dentry *dentry)
114 {
115         return false;
116 }
117 #endif
118
119 #ifndef HAVE_VM_FAULT_T
120 #define vm_fault_t int
121 #endif
122
123 #ifndef HAVE_FOP_ITERATE_SHARED
124 #define iterate_shared iterate
125 #endif
126
127 #ifdef HAVE_OLDSIZE_TRUNCATE_PAGECACHE
128 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, 0, size)
129 #else
130 #define ll_truncate_pagecache(inode, size) truncate_pagecache(inode, size)
131 #endif
132
133 #ifdef HAVE_VFS_RENAME_5ARGS
134 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d, NULL)
135 #elif defined HAVE_VFS_RENAME_6ARGS
136 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d, NULL, 0)
137 #else
138 #define ll_vfs_rename(a, b, c, d) vfs_rename(a, b, c, d)
139 #endif
140
141 #ifdef HAVE_USER_NAMESPACE_ARG
142 #define vfs_unlink(ns, dir, de) vfs_unlink(ns, dir, de, NULL)
143 #elif defined HAVE_VFS_UNLINK_3ARGS
144 #define vfs_unlink(ns, dir, de) vfs_unlink(dir, de, NULL)
145 #else
146 #define vfs_unlink(ns, dir, de) vfs_unlink(dir, de)
147 #endif
148
149 static inline int ll_vfs_getattr(struct path *path, struct kstat *st,
150                                  u32 request_mask, unsigned int flags)
151 {
152         int rc;
153
154 #if defined(HAVE_USER_NAMESPACE_ARG) || defined(HAVE_INODEOPS_ENHANCED_GETATTR)
155         rc = vfs_getattr(path, st, request_mask, flags);
156 #else
157         rc = vfs_getattr(path, st);
158 #endif
159         return rc;
160 }
161
162 #ifndef HAVE_D_IS_POSITIVE
163 static inline bool d_is_positive(const struct dentry *dentry)
164 {
165         return dentry->d_inode != NULL;
166 }
167 #endif
168
169 #ifndef HAVE_INODE_LOCK
170 # define inode_lock(inode) mutex_lock(&(inode)->i_mutex)
171 # define inode_unlock(inode) mutex_unlock(&(inode)->i_mutex)
172 # define inode_trylock(inode) mutex_trylock(&(inode)->i_mutex)
173 #endif
174
175 #ifndef HAVE_PAGECACHE_GET_PAGE
176 #define pagecache_get_page(mapping, index, fp, gfp) \
177         grab_cache_page_nowait(mapping, index)
178 #endif
179
180 /* Old kernels lacked both Xarray support and the page cache
181  * using Xarrays. Our back ported Xarray support introduces
182  * the real xa_is_value() but we need a wrapper as well for
183  * the page cache interaction. Lets keep xa_is_value() separate
184  * in old kernels for Xarray support and page cache handling.
185  */
186 #ifndef HAVE_XARRAY_SUPPORT
187 static inline bool ll_xa_is_value(void *entry)
188 {
189         return radix_tree_exceptional_entry(entry);
190 }
191 #else
192 #define ll_xa_is_value  xa_is_value
193 #endif
194
195 #ifndef HAVE_TRUNCATE_INODE_PAGES_FINAL
196 static inline void truncate_inode_pages_final(struct address_space *map)
197 {
198         truncate_inode_pages(map, 0);
199 }
200 #endif
201
202 #ifndef HAVE_PTR_ERR_OR_ZERO
203 static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
204 {
205         if (IS_ERR(ptr))
206                 return PTR_ERR(ptr);
207         else
208                 return 0;
209 }
210 #endif
211
212 #ifdef HAVE_PID_NS_FOR_CHILDREN
213 # define ll_task_pid_ns(task) \
214          ((task)->nsproxy ? ((task)->nsproxy->pid_ns_for_children) : NULL)
215 #else
216 # define ll_task_pid_ns(task) \
217          ((task)->nsproxy ? ((task)->nsproxy->pid_ns) : NULL)
218 #endif
219
220 #ifdef HAVE_FULL_NAME_HASH_3ARGS
221 # define ll_full_name_hash(salt, name, len) full_name_hash(salt, name, len)
222 #else
223 # define ll_full_name_hash(salt, name, len) full_name_hash(name, len)
224 #endif
225
226 #ifdef HAVE_STRUCT_POSIX_ACL_XATTR
227 # define posix_acl_xattr_header struct posix_acl_xattr_header
228 # define posix_acl_xattr_entry  struct posix_acl_xattr_entry
229 # define GET_POSIX_ACL_XATTR_ENTRY(head) ((void *)((head) + 1))
230 #else
231 # define GET_POSIX_ACL_XATTR_ENTRY(head) ((head)->a_entries)
232 #endif
233
234 #ifdef HAVE_IOP_XATTR
235 #define ll_setxattr     generic_setxattr
236 #define ll_getxattr     generic_getxattr
237 #define ll_removexattr  generic_removexattr
238 #endif /* HAVE_IOP_XATTR */
239
240 #ifndef HAVE_POSIX_ACL_VALID_USER_NS
241 #define posix_acl_valid(a,b)            posix_acl_valid(b)
242 #endif
243
244 #ifdef HAVE_IOP_SET_ACL
245 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
246 #if !defined(HAVE_USER_NAMESPACE_ARG) && !defined(HAVE_POSIX_ACL_UPDATE_MODE)
247 static inline int posix_acl_update_mode(struct inode *inode, umode_t *mode_p,
248                           struct posix_acl **acl)
249 {
250         umode_t mode = inode->i_mode;
251         int error;
252
253         error = posix_acl_equiv_mode(*acl, &mode);
254         if (error < 0)
255                 return error;
256         if (error == 0)
257                 *acl = NULL;
258         if (!in_group_p(inode->i_gid) &&
259             !capable_wrt_inode_uidgid(inode, CAP_FSETID))
260                 mode &= ~S_ISGID;
261         *mode_p = mode;
262         return 0;
263 }
264 #endif /* HAVE_POSIX_ACL_UPDATE_MODE */
265 #endif
266 #endif
267
268 #ifndef HAVE_IOV_ITER_TRUNCATE
269 static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
270 {
271         if (i->count > count)
272                 i->count = count;
273 }
274 #endif
275
276 /*
277  * mount MS_* flags split from superblock SB_* flags
278  * if the SB_* flags are not available use the MS_* flags
279  */
280 #if !defined(SB_RDONLY) && defined(MS_RDONLY)
281 # define SB_RDONLY MS_RDONLY
282 #endif
283 #if !defined(SB_ACTIVE) && defined(MS_ACTIVE)
284 # define SB_ACTIVE MS_ACTIVE
285 #endif
286 #if !defined(SB_NOSEC) && defined(MS_NOSEC)
287 # define SB_NOSEC MS_NOSEC
288 #endif
289 #if !defined(SB_POSIXACL) && defined(MS_POSIXACL)
290 # define SB_POSIXACL MS_POSIXACL
291 #endif
292 #if !defined(SB_NODIRATIME) && defined(MS_NODIRATIME)
293 # define SB_NODIRATIME MS_NODIRATIME
294 #endif
295
296 #ifndef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
297 static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
298 {
299         i->count = count;
300 }
301
302 static inline struct iovec iov_iter_iovec(const struct iov_iter *iter)
303 {
304         return (struct iovec) {
305                 .iov_base = iter->iov->iov_base + iter->iov_offset,
306                 .iov_len = min(iter->count,
307                                iter->iov->iov_len - iter->iov_offset),
308         };
309 }
310
311 #define iov_for_each(iov, iter, start)                                  \
312         for (iter = (start);                                            \
313              (iter).count && ((iov = iov_iter_iovec(&(iter))), 1);      \
314              iov_iter_advance(&(iter), (iov).iov_len))
315
316 static inline ssize_t
317 generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
318 {
319         struct iovec iov;
320         struct iov_iter i;
321         ssize_t bytes = 0;
322
323         iov_for_each(iov, i, *iter) {
324                 ssize_t res;
325
326                 res = generic_file_aio_read(iocb, &iov, 1, iocb->ki_pos);
327                 if (res <= 0) {
328                         if (bytes == 0)
329                                 bytes = res;
330                         break;
331                 }
332
333                 bytes += res;
334                 if (res < iov.iov_len)
335                         break;
336         }
337
338         if (bytes > 0)
339                 iov_iter_advance(iter, bytes);
340         return bytes;
341 }
342
343 static inline ssize_t
344 __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
345 {
346         struct iovec iov;
347         struct iov_iter i;
348         ssize_t bytes = 0;
349
350         /* Since LLITE updates file size at the end of I/O in
351          * vvp_io_commit_write(), append write has to be done in atomic when
352          * there are multiple segments because otherwise each iteration to
353          * __generic_file_aio_write() will see original file size */
354         if (unlikely(iocb->ki_filp->f_flags & O_APPEND && iter->nr_segs > 1)) {
355                 struct iovec *iov_copy;
356                 int count = 0;
357
358                 OBD_ALLOC_PTR_ARRAY(iov_copy, iter->nr_segs);
359                 if (!iov_copy)
360                         return -ENOMEM;
361
362                 iov_for_each(iov, i, *iter)
363                         iov_copy[count++] = iov;
364
365                 bytes = __generic_file_aio_write(iocb, iov_copy, count,
366                                                  &iocb->ki_pos);
367                 OBD_FREE_PTR_ARRAY(iov_copy, iter->nr_segs);
368
369                 if (bytes > 0)
370                         iov_iter_advance(iter, bytes);
371                 return bytes;
372         }
373
374         iov_for_each(iov, i, *iter) {
375                 ssize_t res;
376
377                 res = __generic_file_aio_write(iocb, &iov, 1, &iocb->ki_pos);
378                 if (res <= 0) {
379                         if (bytes == 0)
380                                 bytes = res;
381                         break;
382                 }
383
384                 bytes += res;
385                 if (res < iov.iov_len)
386                         break;
387         }
388
389         if (bytes > 0)
390                 iov_iter_advance(iter, bytes);
391         return bytes;
392 }
393 #endif /* HAVE_FILE_OPERATIONS_READ_WRITE_ITER */
394
395 static inline void __user *get_vmf_address(struct vm_fault *vmf)
396 {
397 #ifdef HAVE_VM_FAULT_ADDRESS
398         return (void __user *)vmf->address;
399 #else
400         return vmf->virtual_address;
401 #endif
402 }
403
404 #ifdef HAVE_VM_OPS_USE_VM_FAULT_ONLY
405 # define __ll_filemap_fault(vma, vmf) filemap_fault(vmf)
406 #else
407 # define __ll_filemap_fault(vma, vmf) filemap_fault(vma, vmf)
408 #endif
409
410 #ifndef HAVE_CURRENT_TIME
411 static inline struct timespec current_time(struct inode *inode)
412 {
413         return CURRENT_TIME;
414 }
415 #endif
416
417 #ifndef time_after32
418 /**
419  * time_after32 - compare two 32-bit relative times
420  * @a: the time which may be after @b
421  * @b: the time which may be before @a
422  *
423  * Needed for kernels earlier than v4.14-rc1~134^2
424  *
425  * time_after32(a, b) returns true if the time @a is after time @b.
426  * time_before32(b, a) returns true if the time @b is before time @a.
427  *
428  * Similar to time_after(), compare two 32-bit timestamps for relative
429  * times.  This is useful for comparing 32-bit seconds values that can't
430  * be converted to 64-bit values (e.g. due to disk format or wire protocol
431  * issues) when it is known that the times are less than 68 years apart.
432  */
433 #define time_after32(a, b)     ((s32)((u32)(b) - (u32)(a)) < 0)
434 #define time_before32(b, a)    time_after32(a, b)
435
436 #endif
437
438 #ifndef smp_store_mb
439 #define smp_store_mb(var, value)        set_mb(var, value)
440 #endif
441
442 #ifdef HAVE_PAGEVEC_INIT_ONE_PARAM
443 #define ll_pagevec_init(pvec, n) pagevec_init(pvec)
444 #else
445 #define ll_pagevec_init(pvec, n) pagevec_init(pvec, n)
446 #endif
447
448 #ifdef HAVE_D_COUNT
449 #  define ll_d_count(d)         d_count(d)
450 #else
451 #  define ll_d_count(d)         ((d)->d_count)
452 #endif /* HAVE_D_COUNT */
453
454 #ifndef HAVE_IN_COMPAT_SYSCALL
455 #define in_compat_syscall       is_compat_task
456 #endif
457
458 #ifdef HAVE_I_PAGES
459 #define page_tree i_pages
460 #define ll_xa_lock_irqsave(lockp, flags) xa_lock_irqsave(lockp, flags)
461 #define ll_xa_unlock_irqrestore(lockp, flags) xa_unlock_irqrestore(lockp, flags)
462 #else
463 #define i_pages tree_lock
464 #define ll_xa_lock_irqsave(lockp, flags) spin_lock_irqsave(lockp, flags)
465 #define ll_xa_unlock_irqrestore(lockp, flags) spin_unlock_irqrestore(lockp, flags)
466 #endif
467
468 /* Linux commit v5.15-12273-gab2f9d2d3626
469  *   mm: unexport {,un}lock_page_memcg
470  *
471  * Note that the functions are still defined or declared breaking
472  * the simple approach of just defining the missing functions here
473  */
474 #ifdef HAVE_LOCK_PAGE_MEMCG
475 #define vvp_lock_page_memcg(page)       lock_page_memcg((page))
476 #define vvp_unlock_page_memcg(page)     unlock_page_memcg((page))
477 #else
478 #define vvp_lock_page_memcg(page)
479 #define vvp_unlock_page_memcg(page)
480 #endif
481
482 #ifndef KMEM_CACHE_USERCOPY
483 #define kmem_cache_create_usercopy(name, size, align, flags, useroffset, \
484                                    usersize, ctor)                       \
485         kmem_cache_create(name, size, align, flags, ctor)
486 #endif
487
488 static inline bool ll_security_xattr_wanted(struct inode *in)
489 {
490 #ifdef CONFIG_SECURITY
491         return in->i_security && in->i_sb->s_security;
492 #else
493         return false;
494 #endif
495 }
496
497 static inline int ll_vfs_getxattr(struct dentry *dentry, struct inode *inode,
498                                   const char *name,
499                                   void *value, size_t size)
500 {
501 #ifdef HAVE_USER_NAMESPACE_ARG
502         return vfs_getxattr(&init_user_ns, dentry, name, value, size);
503 #elif defined(HAVE_VFS_SETXATTR)
504         return __vfs_getxattr(dentry, inode, name, value, size);
505 #else
506         if (unlikely(!inode->i_op->getxattr))
507                 return -ENODATA;
508
509         return inode->i_op->getxattr(dentry, name, value, size);
510 #endif
511 }
512
513 static inline int ll_vfs_setxattr(struct dentry *dentry, struct inode *inode,
514                                   const char *name,
515                                   const void *value, size_t size, int flags)
516 {
517 #ifdef HAVE_USER_NAMESPACE_ARG
518         return vfs_setxattr(&init_user_ns, dentry, name,
519                             VFS_SETXATTR_VALUE(value), size, flags);
520 #elif defined(HAVE_VFS_SETXATTR)
521         return __vfs_setxattr(dentry, inode, name, value, size, flags);
522 #else
523         if (unlikely(!inode->i_op->setxattr))
524                 return -EOPNOTSUPP;
525
526         return inode->i_op->setxattr(dentry, name, value, size, flags);
527 #endif
528 }
529
530 static inline int ll_vfs_removexattr(struct dentry *dentry, struct inode *inode,
531                                      const char *name)
532 {
533 #ifdef HAVE_USER_NAMESPACE_ARG
534         return vfs_removexattr(&init_user_ns, dentry, name);
535 #elif defined(HAVE_VFS_SETXATTR)
536         return __vfs_removexattr(dentry, name);
537 #else
538         if (unlikely(!inode->i_op->setxattr))
539                 return -EOPNOTSUPP;
540
541         return inode->i_op->removexattr(dentry, name);
542 #endif
543 }
544
545 #ifndef FALLOC_FL_COLLAPSE_RANGE
546 #define FALLOC_FL_COLLAPSE_RANGE 0x08 /* remove a range of a file */
547 #endif
548
549 #ifndef FALLOC_FL_ZERO_RANGE
550 #define FALLOC_FL_ZERO_RANGE 0x10 /* convert range to zeros */
551 #endif
552
553 #ifndef FALLOC_FL_INSERT_RANGE
554 #define FALLOC_FL_INSERT_RANGE 0x20 /* insert space within file */
555 #endif
556
557 #ifndef raw_cpu_ptr
558 #define raw_cpu_ptr(p) __this_cpu_ptr(p)
559 #endif
560
561 #ifndef HAVE_IS_ROOT_INODE
562 static inline bool is_root_inode(struct inode *inode)
563 {
564         return inode == inode->i_sb->s_root->d_inode;
565 }
566 #endif
567
568 #ifndef HAVE_IOV_ITER_GET_PAGES_ALLOC2
569 #define iov_iter_get_pages_alloc2(i, p, m, s) \
570         iov_iter_get_pages_alloc((i), (p), (m), (s))
571 #endif
572
573 #ifdef HAVE_AOPS_MIGRATE_FOLIO
574 #define folio_migr      folio
575 #else
576 #define folio_migr      page
577 #define migrate_folio   migratepage
578 #endif
579
580 #ifdef HAVE_REGISTER_SHRINKER_FORMAT_NAMED
581 #define register_shrinker(_s) register_shrinker((_s), "%ps", (_s))
582 #elif !defined(HAVE_REGISTER_SHRINKER_RET)
583 #define register_shrinker(_s) (register_shrinker(_s), 0)
584 #endif
585
586 #ifndef fallthrough
587 # if defined(__GNUC__) && __GNUC__ >= 7
588 #  define fallthrough  __attribute__((fallthrough)) /* fallthrough */
589 # else
590 #  define fallthrough do {} while (0)  /* fallthrough */
591 # endif
592 #endif
593
594 #ifdef VERIFY_WRITE /* removed in kernel commit v4.20-10979-g96d4f267e40f */
595 #define ll_access_ok(ptr, len) access_ok(VERIFY_WRITE, ptr, len)
596 #else
597 #define ll_access_ok(ptr, len) access_ok(ptr, len)
598 #endif
599
600 static inline void ll_security_release_secctx(char *secdata, u32 seclen)
601 {
602 #ifdef HAVE_SEC_RELEASE_SECCTX_1ARG
603         struct lsmcontext context = { };
604
605         lsmcontext_init(&context, secdata, seclen, 0);
606         return security_release_secctx(&context);
607 #else
608         return security_release_secctx(secdata, seclen);
609 #endif
610 }
611
612 #ifndef HAVE_USER_NAMESPACE_ARG
613 #define posix_acl_update_mode(ns, inode, mode, acl) \
614         posix_acl_update_mode(inode, mode, acl)
615 #define notify_change(ns, de, attr, inode)      notify_change(de, attr, inode)
616 #define inode_owner_or_capable(ns, inode)       inode_owner_or_capable(inode)
617 #define vfs_create(ns, dir, de, mode, ex)       vfs_create(dir, de, mode, ex)
618 #define vfs_mkdir(ns, dir, de, mode)            vfs_mkdir(dir, de, mode)
619 #define ll_set_acl(ns, inode, acl, type)        ll_set_acl(inode, acl, type)
620 #endif
621
622 /**
623  * delete_from_page_cache is not exported anymore
624  */
625 #ifdef HAVE_DELETE_FROM_PAGE_CACHE
626 #define cfs_delete_from_page_cache(page)        delete_from_page_cache((page))
627 #else
628 static inline void cfs_delete_from_page_cache(struct page *page)
629 {
630         if (!page->mapping)
631                 return;
632         LASSERT(PageLocked(page));
633         get_page(page);
634         unlock_page(page);
635         /* on entry page is locked */
636         if (S_ISREG(page->mapping->host->i_mode)) {
637                 generic_error_remove_page(page->mapping, page);
638         } else {
639                 loff_t lstart = page->index << PAGE_SHIFT;
640                 loff_t lend = lstart + PAGE_SIZE - 1;
641
642                 truncate_inode_pages_range(page->mapping, lstart, lend);
643         }
644         lock_page(page);
645         put_page(page);
646 }
647 #endif
648
649 static inline struct page *ll_read_cache_page(struct address_space *mapping,
650                                               pgoff_t index, filler_t *filler,
651                                               void *data)
652 {
653 #ifdef HAVE_READ_CACHE_PAGE_WANTS_FILE
654         struct file dummy_file;
655
656         dummy_file.f_ra.ra_pages = 32; /* unused, modified on ra error */
657         dummy_file.private_data = data;
658         return read_cache_page(mapping, index, filler, &dummy_file);
659 #else
660         return read_cache_page(mapping, index, filler, data);
661 #endif /* HAVE_READ_CACHE_PAGE_WANTS_FILE */
662 }
663
664 #endif /* _LUSTRE_COMPAT_H */