Whamcloud - gitweb
5de494eca5b3002b2160ce6b57ab18e075ed0255
[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  *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #ifndef LUSTRE_PATCHLESS_COMPAT_H
24 #define LUSTRE_PATCHLESS_COMPAT_H
25
26 #include <linux/lustre_version.h>
27 #ifndef LUSTRE_KERNEL_VERSION
28 #include <linux/fs.h>
29
30 #ifndef HAVE_TRUNCATE_COMPLETE_PAGE
31 #include <linux/list.h>
32 #include <linux/mm.h>
33 #include <linux/hash.h>
34
35 /* XXX copy & paste from 2.6.15 kernel */
36 static inline void ll_remove_from_page_cache(struct page *page)
37 {
38         struct address_space *mapping = page->mapping;
39
40         BUG_ON(!PageLocked(page));
41
42 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
43         write_lock_irq(&mapping->tree_lock);
44 #else
45         spin_lock_irq(&mapping->tree_lock);
46 #endif
47         radix_tree_delete(&mapping->page_tree, page->index);
48         page->mapping = NULL;
49         mapping->nrpages--;
50 #ifdef HAVE_NR_PAGECACHE
51         atomic_add(-1, &nr_pagecache); // XXX pagecache_acct(-1);
52 #else
53         __dec_zone_page_state(page, NR_FILE_PAGES);
54 #endif
55
56 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
57         write_unlock_irq(&mapping->tree_lock);
58 #else
59         spin_unlock_irq(&mapping->tree_lock);
60 #endif
61 }
62
63 static inline void
64 truncate_complete_page(struct address_space *mapping, struct page *page)
65 {
66         if (page->mapping != mapping)
67                 return;
68
69         if (PagePrivate(page))
70                 page->mapping->a_ops->invalidatepage(page, 0);
71
72 #ifdef HAVE_CANCEL_DIRTY_PAGE
73         cancel_dirty_page(page, PAGE_SIZE);
74 #else
75         clear_page_dirty(page);
76 #endif
77         ClearPageUptodate(page);
78         ClearPageMappedToDisk(page);
79         ll_remove_from_page_cache(page);
80         page_cache_release(page);       /* pagecache ref */
81 }
82 #endif
83
84 /* megahack */
85 static inline void d_rehash_cond(struct dentry * entry, int lock)
86 {
87         if (!lock)
88                 spin_unlock(&dcache_lock);
89
90         d_rehash(entry);
91
92         if (!lock)
93                 spin_lock(&dcache_lock);
94 }
95
96 #define __d_rehash(dentry, lock) d_rehash_cond(dentry, lock)
97
98 #define LUSTRE_PATCHLESS
99
100 #ifndef ATTR_FROM_OPEN
101 #define ATTR_FROM_OPEN 0
102 #endif
103 #ifndef ATTR_RAW
104 #define ATTR_RAW 0
105 #endif
106
107 #endif /* LUSTRE_KERNEL_VERSION */
108
109 #endif