Whamcloud - gitweb
add 2.6.27 kernel support
[fs/lustre-release.git] / lustre / include / linux / lustre_patchless_compat.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
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 LUSTRE_PATCHLESS_COMPAT_H
38 #define LUSTRE_PATCHLESS_COMPAT_H
39
40 #include <linux/lustre_version.h>
41 #include <linux/fs.h>
42
43 #ifndef HAVE_TRUNCATE_COMPLETE_PAGE
44 #include <linux/list.h>
45 #include <linux/mm.h>
46 #include <linux/hash.h>
47
48 /* XXX copy & paste from 2.6.15 kernel */
49 static inline void ll_remove_from_page_cache(struct page *page)
50 {
51         struct address_space *mapping = page->mapping;
52
53         BUG_ON(!PageLocked(page));
54
55 #ifdef HAVE_RW_TREE_LOCK
56         write_lock_irq(&mapping->tree_lock);
57 #else
58         spin_lock_irq(&mapping->tree_lock);
59 #endif
60         radix_tree_delete(&mapping->page_tree, page->index);
61         page->mapping = NULL;
62         mapping->nrpages--;
63 #ifdef HAVE_NR_PAGECACHE
64         atomic_add(-1, &nr_pagecache); // XXX pagecache_acct(-1);
65 #else
66         __dec_zone_page_state(page, NR_FILE_PAGES);
67 #endif
68
69 #ifdef HAVE_RW_TREE_LOCK
70         write_unlock_irq(&mapping->tree_lock);
71 #else
72         spin_unlock_irq(&mapping->tree_lock);
73 #endif
74 }
75
76 static inline void
77 truncate_complete_page(struct address_space *mapping, struct page *page)
78 {
79         if (page->mapping != mapping)
80                 return;
81
82         if (PagePrivate(page))
83                 page->mapping->a_ops->invalidatepage(page, 0);
84
85 #ifdef HAVE_CANCEL_DIRTY_PAGE
86         cancel_dirty_page(page, PAGE_SIZE);
87 #else
88         clear_page_dirty(page);
89 #endif
90         ClearPageUptodate(page);
91         ClearPageMappedToDisk(page);
92         ll_remove_from_page_cache(page);
93         page_cache_release(page);       /* pagecache ref */
94 }
95 #endif /* HAVE_TRUNCATE_COMPLETE_PAGE */
96
97 #if !defined(HAVE_D_REHASH_COND) && !defined(HAVE___D_REHASH)
98 /* megahack */
99 static inline void d_rehash_cond(struct dentry * entry, int lock)
100 {
101         if (!lock)
102                 spin_unlock(&dcache_lock);
103
104         d_rehash(entry);
105
106         if (!lock)
107                 spin_lock(&dcache_lock);
108 }
109
110 #define __d_rehash(dentry, lock) d_rehash_cond(dentry, lock)
111 #endif /* !HAVE_D_REHASH_COND && !HAVE___D_REHASH*/
112
113 #ifdef ATTR_OPEN
114 # define ATTR_FROM_OPEN ATTR_OPEN
115 #else
116 # ifndef ATTR_FROM_OPEN
117 #  define ATTR_FROM_OPEN 0
118 # endif
119 #endif /* ATTR_OPEN */
120
121 #ifndef ATTR_RAW
122 #define ATTR_RAW 0
123 #endif
124
125 #ifndef ATTR_CTIME_SET
126 /*
127  * set ATTR_CTIME_SET to a high value to avoid any risk of collision with other
128  * ATTR_* attributes (see bug 13828)
129  */
130 #define ATTR_CTIME_SET (1 << 28)
131 #endif
132
133 #endif /* LUSTRE_PATCHLESS_COMPAT_H */