Whamcloud - gitweb
Branch HEAD
[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 #include <linux/fs.h>
28
29 #ifndef HAVE_TRUNCATE_COMPLETE_PAGE
30 #include <linux/list.h>
31 #include <linux/mm.h>
32 #include <linux/hash.h>
33
34 /* XXX copy & paste from 2.6.15 kernel */
35 static inline void ll_remove_from_page_cache(struct page *page)
36 {
37         struct address_space *mapping = page->mapping;
38
39         BUG_ON(!PageLocked(page));
40
41 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
42         write_lock_irq(&mapping->tree_lock);
43 #else
44         spin_lock_irq(&mapping->tree_lock);
45 #endif
46         radix_tree_delete(&mapping->page_tree, page->index);
47         page->mapping = NULL;
48         mapping->nrpages--;
49 #ifdef HAVE_NR_PAGECACHE
50         atomic_add(-1, &nr_pagecache); // XXX pagecache_acct(-1);
51 #else
52         __dec_zone_page_state(page, NR_FILE_PAGES);
53 #endif
54
55 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
56         write_unlock_irq(&mapping->tree_lock);
57 #else
58         spin_unlock_irq(&mapping->tree_lock);
59 #endif
60 }
61
62 static inline void
63 truncate_complete_page(struct address_space *mapping, struct page *page)
64 {
65         if (page->mapping != mapping)
66                 return;
67
68         if (PagePrivate(page))
69                 page->mapping->a_ops->invalidatepage(page, 0);
70
71 #ifdef HAVE_CANCEL_DIRTY_PAGE
72         cancel_dirty_page(page, PAGE_SIZE);
73 #else
74         clear_page_dirty(page);
75 #endif
76         ClearPageUptodate(page);
77         ClearPageMappedToDisk(page);
78         ll_remove_from_page_cache(page);
79         page_cache_release(page);       /* pagecache ref */
80 }
81 #endif /* HAVE_TRUNCATE_COMPLETE_PAGE */
82
83 #if !defined(HAVE_D_REHASH_COND) && !defined(HAVE___D_REHASH)
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 #endif /* !HAVE_D_REHASH_COND && !HAVE___D_REHASH*/
98
99 #ifdef ATTR_OPEN
100 # define ATTR_FROM_OPEN ATTR_OPEN
101 #else
102 # ifndef ATTR_FROM_OPEN
103 #  define ATTR_FROM_OPEN 0
104 # endif
105 #endif /* ATTR_OPEN */
106
107 #ifndef ATTR_RAW
108 #define ATTR_RAW 0
109 #endif
110
111 #ifndef ATTR_CTIME_SET
112 /*
113  * set ATTR_CTIME_SET to a high value to avoid any risk of collision with other
114  * ATTR_* attributes (see bug 13828)
115  */
116 #define ATTR_CTIME_SET (1 << 28)
117 #endif
118
119 #endif /* LUSTRE_PATCHLESS_COMPAT_H */