Whamcloud - gitweb
land b1_5 onto HEAD
[fs/lustre-release.git] / lustre / include / linux / lustre_patchless_compat.h
1 #ifndef LUSTRE_PATCHLESS_COMPAT_H
2 #define LUSTRE_PATCHLESS_COMPAT_H
3
4 #include <linux/lustre_version.h>
5 #ifndef LUSTRE_KERNEL_VERSION
6 #include <linux/fs.h>
7
8 #ifndef HAVE_TRUNCATE_COMPLETE_PAGE
9 #include <linux/list.h>
10 #include <linux/mm.h>
11 #include <linux/hash.h>
12
13 /* XXX copy & paste from 2.6.15 kernel */
14 static inline void ll_remove_from_page_cache(struct page *page)
15 {
16         struct address_space *mapping = page->mapping;
17
18         BUG_ON(!PageLocked(page));
19
20 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
21         write_lock_irq(&mapping->tree_lock);
22 #else
23         spin_lock_irq(&mapping->tree_lock);
24 #endif
25         radix_tree_delete(&mapping->page_tree, page->index);
26         page->mapping = NULL;
27         mapping->nrpages--;
28 #ifdef HAVE_NR_PAGECACHE
29         atomic_add(-1, &nr_pagecache); // XXX pagecache_acct(-1);
30 #else
31         __dec_zone_page_state(page, NR_FILE_PAGES);
32 #endif
33 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
34         write_unlock_irq(&mapping->tree_lock);
35 #else
36         spin_unlock_irq(&mapping->tree_lock);
37 #endif
38 }
39
40 static inline void
41 truncate_complete_page(struct address_space *mapping, struct page *page)
42 {
43         if (page->mapping != mapping)
44                 return;
45
46         if (PagePrivate(page))
47                 page->mapping->a_ops->invalidatepage(page, 0);
48
49         clear_page_dirty(page);
50         ClearPageUptodate(page);
51         ClearPageMappedToDisk(page);
52         ll_remove_from_page_cache(page);
53         page_cache_release(page);       /* pagecache ref */
54 }
55 #endif
56
57 /* megahack */
58 static inline void d_rehash_cond(struct dentry * entry, int lock)
59 {
60         if (!lock)
61                 spin_unlock(&dcache_lock);
62
63         d_rehash(entry);
64
65         if (!lock)
66                 spin_lock(&dcache_lock);
67 }
68
69 #define __d_rehash(dentry, lock) d_rehash_cond(dentry, lock)
70         
71 #define LUSTRE_PATCHLESS
72
73 #ifndef ATTR_FROM_OPEN
74 #define ATTR_FROM_OPEN 0
75 #endif
76 #ifndef ATTR_RAW
77 #define ATTR_RAW 0
78 #endif
79
80 #endif /* LUSTRE_KERNEL_VERSION */
81
82 #endif