Whamcloud - gitweb
41d589b2c915c7be63e099d9463d97fd63474ffe
[fs/lustre-release.git] / lustre / include / lustre_patchless_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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2014, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #ifndef LUSTRE_PATCHLESS_COMPAT_H
34 #define LUSTRE_PATCHLESS_COMPAT_H
35
36 #include <linux/fs.h>
37 #include <linux/mm.h>
38 #ifndef HAVE_TRUNCATE_COMPLETE_PAGE
39 #include <linux/list.h>
40 #include <linux/hash.h>
41
42 #ifndef HAVE_DELETE_FROM_PAGE_CACHE /* 2.6.39 */
43 #ifndef HAVE_REMOVE_FROM_PAGE_CACHE /* 2.6.35 - 2.6.38 */
44
45 /* XXX copy & paste from 2.6.15 kernel */
46 static inline void ll_remove_from_page_cache(struct page *page)
47 {
48         struct address_space *mapping = page->mapping;
49
50         BUG_ON(!PageLocked(page));
51
52         spin_lock_irq(&mapping->tree_lock);
53         radix_tree_delete(&mapping->page_tree, page->index);
54         page->mapping = NULL;
55         mapping->nrpages--;
56         __dec_zone_page_state(page, NR_FILE_PAGES);
57
58         spin_unlock_irq(&mapping->tree_lock);
59 }
60 #else /* HAVE_REMOVE_FROM_PAGE_CACHE */
61 #define ll_remove_from_page_cache(page) remove_from_page_cache(page)
62 #endif /* !HAVE_REMOVE_FROM_PAGE_CACHE */
63
64 static inline void ll_delete_from_page_cache(struct page *page)
65 {
66         ll_remove_from_page_cache(page);
67         put_page(page);
68 }
69 #else /* HAVE_DELETE_FROM_PAGE_CACHE */
70 #define ll_delete_from_page_cache(page) delete_from_page_cache(page)
71 #endif /* !HAVE_DELETE_FROM_PAGE_CACHE */
72
73 static inline void
74 ll_cancel_dirty_page(struct address_space *mapping, struct page *page)
75 {
76 #ifdef HAVE_NEW_CANCEL_DIRTY_PAGE
77         cancel_dirty_page(page);
78 #elif defined(HAVE_CANCEL_DIRTY_PAGE)
79         cancel_dirty_page(page, PAGE_SIZE);
80 #else
81         if (TestClearPageDirty(page))
82                 account_page_cleaned(page, mapping);
83 #endif  /* HAVE_NEW_CANCEL_DIRTY_PAGE */
84 }
85
86 static inline void
87 truncate_complete_page(struct address_space *mapping, struct page *page)
88 {
89         if (page->mapping != mapping)
90                 return;
91
92         if (PagePrivate(page))
93 #ifdef HAVE_INVALIDATE_RANGE
94                 page->mapping->a_ops->invalidatepage(page, 0, PAGE_SIZE);
95 #else
96                 page->mapping->a_ops->invalidatepage(page, 0);
97 #endif
98
99         ll_cancel_dirty_page(mapping, page);
100         ClearPageMappedToDisk(page);
101         ll_delete_from_page_cache(page);
102 }
103 #endif /* !HAVE_TRUNCATE_COMPLETE_PAGE */
104
105 #ifdef HAVE_D_COUNT
106 #  define ll_d_count(d)                 d_count(d)
107 #else
108 #  define ll_d_count(d)                 ((d)->d_count)
109 #endif /* HAVE_D_COUNT */
110
111 #ifndef HAVE_IN_COMPAT_SYSCALL
112 #define in_compat_syscall       is_compat_task
113 #endif
114
115 #endif /* LUSTRE_PATCHLESS_COMPAT_H */