Whamcloud - gitweb
9b985d56fc1893f2abb1b98bdb6b3dcb7817a5d9
[fs/lustre-release.git] / lustre / include / linux / lustre_compat25.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 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 _COMPAT25_H
24 #define _COMPAT25_H
25
26 #ifdef __KERNEL__
27
28 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) && LINUX_VERSION_CODE < KERNEL_VERSION(2,5,69)
29 #error sorry, lustre requires at least 2.5.69
30 #endif
31
32 #include <linux/portals_compat25.h>
33
34 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
35
36 /*
37  * OBD need working random driver, thus all our
38  * initialization routines must be called after device
39  * driver initialization
40  */
41 #ifndef MODULE
42 #undef module_init
43 #define module_init(a)     late_initcall(a)
44 #endif
45
46 /* XXX our code should be using the 2.6 calls, not the other way around */
47 #define TryLockPage(page)                TestSetPageLocked(page)
48 #define filemap_fdatasync(mapping)       filemap_fdatawrite(mapping)
49 #define Page_Uptodate(page)              PageUptodate(page)
50
51 #define KDEVT_INIT(val)                 (val)
52
53 #define LTIME_S(time)                   (time.tv_sec)
54 #define ll_path_lookup                  path_lookup
55 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
56
57 #define ll_pgcache_lock(mapping)          spin_lock(&mapping->page_lock)
58 #define ll_pgcache_unlock(mapping)        spin_unlock(&mapping->page_lock)
59 #define ll_call_writepage(inode, page)  \
60                                 (inode)->i_mapping->a_ops->writepage(page, NULL)
61 #define ll_invalidate_inode_pages(inode) \
62                                 invalidate_inode_pages((inode)->i_mapping)
63 #define ll_truncate_complete_page(page) \
64                                 truncate_complete_page(page->mapping, page)
65
66 #define ll_vfs_create(a,b,c,d)              vfs_create(a,b,c,d)
67
68 #define ll_dev_t                        dev_t
69 #define kdev_t                          dev_t
70 #define to_kdev_t(dev)                  (dev)
71 #define kdev_t_to_nr(dev)               (dev)
72 #define val_to_kdev(dev)                (dev)
73 #define ILOOKUP(sb, ino, test, data)    ilookup5(sb, ino, test, data);
74
75 #include <linux/writeback.h>
76
77 static inline void lustre_daemonize_helper(void)
78 {
79         LASSERT(current->signal != NULL);
80         current->signal->session = 1;
81         if (current->group_leader)
82                 current->group_leader->signal->pgrp = 1;
83         else
84                 CERROR("we aren't group leader\n");
85         current->signal->tty = NULL;
86 }
87
88 static inline int cleanup_group_info(void)
89 {
90         struct group_info *ginfo;
91
92         ginfo = groups_alloc(2);
93         if (!ginfo)
94                 return -ENOMEM;
95
96         ginfo->ngroups = 0;
97         set_current_groups(ginfo);
98         put_group_info(ginfo);
99
100         return 0;
101 }
102
103 #define smp_num_cpus    NR_CPUS
104
105 #include <linux/proc_fs.h>
106
107 #else /* 2.4.. */
108
109 #define ll_vfs_create(a,b,c,d)              vfs_create(a,b,c)
110 #define ll_permission(inode,mask,nd)        permission(inode,mask)
111 #define ILOOKUP(sb, ino, test, data)        ilookup4(sb, ino, test, data);
112 #define DCACHE_DISCONNECTED                 DCACHE_NFSD_DISCONNECTED
113 #define ll_dev_t                            int
114
115 static inline void clear_page_dirty(struct page *page)
116 {
117         if (PageDirty(page))
118                 ClearPageDirty(page); 
119 }
120
121 /* 2.5 uses hlists for some things, like the d_hash.  we'll treat them
122  * as 2.5 and let macros drop back.. */
123 #ifndef HLIST_HEAD /* until we get a kernel newer than l28 */
124 #define hlist_entry                     list_entry
125 #define hlist_head                      list_head
126 #define hlist_node                      list_head
127 #define HLIST_HEAD                      LIST_HEAD
128 #define INIT_HLIST_HEAD                 INIT_LIST_HEAD
129 #define hlist_del_init                  list_del_init
130 #define hlist_add_head                  list_add
131 #define hlist_for_each_safe             list_for_each_safe
132 #endif
133 #define KDEVT_INIT(val)                 (val)
134 #define ext3_xattr_set_handle           ext3_xattr_set
135 #define extN_xattr_set_handle           extN_xattr_set
136 #define try_module_get                  __MOD_INC_USE_COUNT
137 #define module_put                      __MOD_DEC_USE_COUNT
138 #define LTIME_S(time)                   (time)
139 #if !defined(CONFIG_RH_2_4_20) && !defined(cpu_online)
140 #define cpu_online(cpu)                 (cpu_online_map & (1<<cpu))
141 #endif
142
143 static inline int ll_path_lookup(const char *path, unsigned flags,
144                                  struct nameidata *nd)
145 {
146         int error = 0;
147         if (path_init(path, flags, nd))
148                 error = path_walk(path, nd);
149         return error;
150 }
151 #define ll_permission(inode,mask,nd)    permission(inode,mask)
152 typedef long sector_t;
153
154 #define ll_pgcache_lock(mapping)        spin_lock(&pagecache_lock)
155 #define ll_pgcache_unlock(mapping)      spin_unlock(&pagecache_lock)
156 #define ll_call_writepage(inode, page)  \
157                                (inode)->i_mapping->a_ops->writepage(page)
158 #define ll_invalidate_inode_pages(inode) invalidate_inode_pages(inode)
159 #define ll_truncate_complete_page(page) truncate_complete_page(page)
160
161 static inline void __d_drop(struct dentry *dentry)
162 {
163         list_del(&dentry->d_hash);
164         INIT_LIST_HEAD(&dentry->d_hash);
165 }
166
167 static inline void lustre_daemonize_helper(void)
168 {
169         current->session = 1;
170         current->pgrp = 1;
171         current->tty = NULL;
172 }
173
174 static inline int cleanup_group_info(void)
175 {
176         /* Get rid of unneeded supplementary groups */
177         current->ngroups = 0;
178         memset(current->groups, 0, sizeof(current->groups));
179         return 0;
180 }
181
182 #ifndef HAVE_COND_RESCHED
183 static inline void cond_resched(void)
184 {
185         if (unlikely(need_resched())) {
186                 set_curret_state(TASK_RUNNING);
187                 schedule();
188         }
189 }
190 #endif
191
192 /* to find proc_dir_entry from inode. 2.6 has native one -bzzz */
193 #ifndef HAVE_PDE
194 #define PDE(ii)         ((ii)->u.generic_ip)
195 #endif
196
197 #endif /* end of 2.4 compat macros */
198
199 #ifdef HAVE_PAGE_LIST
200 static inline int mapping_has_pages(struct address_space *mapping)
201 {
202         int rc = 1;
203
204         ll_pgcache_lock(mapping);
205         if (list_empty(&mapping->dirty_pages) &&
206             list_empty(&mapping->clean_pages) &&
207             list_empty(&mapping->locked_pages)) {
208                 rc = 0;
209         }
210         ll_pgcache_unlock(mapping);
211
212         return rc;
213 }
214
215 static inline int clear_page_dirty_for_io(struct page *page)
216 {
217         struct address_space *mapping = page->mapping;
218
219         if (page->mapping && PageDirty(page)) {
220                 ClearPageDirty(page);
221                 ll_pgcache_lock(mapping);
222                 list_del(&page->list);
223                 list_add(&page->list, &mapping->locked_pages);
224                 ll_pgcache_unlock(mapping);
225                 return 1;
226         }
227         return 0;
228 }
229 #else
230 static inline int mapping_has_pages(struct address_space *mapping)
231 {
232         return mapping->nrpages > 0;
233 }
234 #endif
235
236 #endif /* __KERNEL__ */
237 #endif /* _COMPAT25_H */