Whamcloud - gitweb
- include mm_inline on 2.4 kernels (required for page_count)
[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 __set_page_ll_data(page, llap) \
104         do {       \
105                 page_cache_get(page); \
106                 SetPagePrivate(page); \
107                 page->private = (unsigned long)llap; \
108         } while (0)
109 #define __clear_page_ll_data(page) \
110         do {       \
111                 ClearPagePrivate(page); \
112                 page_cache_release(page); \
113                 page->private = 0; \
114         } while(0)
115
116 #define smp_num_cpus    NR_CPUS
117
118 #include <linux/proc_fs.h>
119
120 #else /* 2.4.. */
121
122 #ifdef HAVE_MM_INLINE 
123 #include <linux/mm_inline.h> 
124 #endif
125
126 #define ll_vfs_create(a,b,c,d)              vfs_create(a,b,c)
127 #define ll_permission(inode,mask,nd)        permission(inode,mask)
128 #define ILOOKUP(sb, ino, test, data)        ilookup4(sb, ino, test, data);
129 #define DCACHE_DISCONNECTED                 DCACHE_NFSD_DISCONNECTED
130 #define ll_dev_t                            int
131
132 static inline void clear_page_dirty(struct page *page)
133 {
134         if (PageDirty(page))
135                 ClearPageDirty(page); 
136 }
137
138 /* 2.5 uses hlists for some things, like the d_hash.  we'll treat them
139  * as 2.5 and let macros drop back.. */
140 #ifndef HLIST_HEAD /* until we get a kernel newer than l28 */
141 #define hlist_entry                     list_entry
142 #define hlist_head                      list_head
143 #define hlist_node                      list_head
144 #define HLIST_HEAD                      LIST_HEAD
145 #define INIT_HLIST_HEAD                 INIT_LIST_HEAD
146 #define hlist_del_init                  list_del_init
147 #define hlist_add_head                  list_add
148 #define hlist_for_each_safe             list_for_each_safe
149 #endif
150 #define KDEVT_INIT(val)                 (val)
151 #define ext3_xattr_set_handle           ext3_xattr_set
152 #define extN_xattr_set_handle           extN_xattr_set
153 #define try_module_get                  __MOD_INC_USE_COUNT
154 #define module_put                      __MOD_DEC_USE_COUNT
155 #define LTIME_S(time)                   (time)
156 #if !defined(CONFIG_RH_2_4_20) && !defined(cpu_online)
157 #define cpu_online(cpu)                 (cpu_online_map & (1<<cpu))
158 #endif
159
160 static inline int ll_path_lookup(const char *path, unsigned flags,
161                                  struct nameidata *nd)
162 {
163         int error = 0;
164         if (path_init(path, flags, nd))
165                 error = path_walk(path, nd);
166         return error;
167 }
168 #define ll_permission(inode,mask,nd)    permission(inode,mask)
169 typedef long sector_t;
170
171 #define ll_pgcache_lock(mapping)        spin_lock(&pagecache_lock)
172 #define ll_pgcache_unlock(mapping)      spin_unlock(&pagecache_lock)
173 #define ll_call_writepage(inode, page)  \
174                                (inode)->i_mapping->a_ops->writepage(page)
175 #define ll_invalidate_inode_pages(inode) invalidate_inode_pages(inode)
176 #define ll_truncate_complete_page(page) truncate_complete_page(page)
177
178 static inline void __d_drop(struct dentry *dentry)
179 {
180         list_del(&dentry->d_hash);
181         INIT_LIST_HEAD(&dentry->d_hash);
182 }
183
184 static inline void lustre_daemonize_helper(void)
185 {
186         current->session = 1;
187         current->pgrp = 1;
188         current->tty = NULL;
189 }
190
191 static inline int cleanup_group_info(void)
192 {
193         /* Get rid of unneeded supplementary groups */
194         current->ngroups = 0;
195         memset(current->groups, 0, sizeof(current->groups));
196         return 0;
197 }
198
199 #ifndef HAVE_COND_RESCHED
200 static inline void cond_resched(void)
201 {
202         if (unlikely(need_resched())) {
203                 set_current_state(TASK_RUNNING);
204                 schedule();
205         }
206 }
207 #endif
208
209 /* to find proc_dir_entry from inode. 2.6 has native one -bzzz */
210 #ifndef HAVE_PDE
211 #define PDE(ii)         ((ii)->u.generic_ip)
212 #endif
213
214 #define __set_page_ll_data(page, llap) page->private = (unsigned long)llap
215 #define __clear_page_ll_data(page) page->private = 0
216 #define PageWriteback(page) 0
217 #define end_page_writeback(page)
218
219 static inline int mapping_mapped(struct address_space *mapping)
220 {
221         return mapping->i_mmap_shared ? 1 : 0;
222 }
223
224 #ifdef ZAP_PAGE_RANGE_VMA
225 #define ll_zap_page_range(vma, addr, len)  zap_page_range(vma, addr, len)
226 #else
227 #define ll_zap_page_range(vma, addr, len)  zap_page_range(vma->vm_mm, addr, len)
228 #endif
229
230 #endif /* end of 2.4 compat macros */
231
232 #ifdef HAVE_PAGE_LIST
233 static inline int mapping_has_pages(struct address_space *mapping)
234 {
235         int rc = 1;
236
237         ll_pgcache_lock(mapping);
238         if (list_empty(&mapping->dirty_pages) &&
239             list_empty(&mapping->clean_pages) &&
240             list_empty(&mapping->locked_pages)) {
241                 rc = 0;
242         }
243         ll_pgcache_unlock(mapping);
244
245         return rc;
246 }
247
248 static inline int clear_page_dirty_for_io(struct page *page)
249 {
250         struct address_space *mapping = page->mapping;
251
252         if (page->mapping && PageDirty(page)) {
253                 ClearPageDirty(page);
254                 ll_pgcache_lock(mapping);
255                 list_del(&page->list);
256                 list_add(&page->list, &mapping->locked_pages);
257                 ll_pgcache_unlock(mapping);
258                 return 1;
259         }
260         return 0;
261 }
262 #else
263 static inline int mapping_has_pages(struct address_space *mapping)
264 {
265         return mapping->nrpages > 0;
266 }
267 #endif
268
269 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
270 #define ll_set_dflags(dentry, flags) do { dentry->d_vfs_flags |= flags; } while(0)
271 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path)
272 #else
273 #define ll_set_dflags(dentry, flags) do { \
274                 spin_lock(&dentry->d_lock); \
275                 dentry->d_flags |= flags; \
276                 spin_unlock(&dentry->d_lock); \
277         } while(0)
278 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path, mode)
279 #endif
280
281 #ifndef container_of
282 #define container_of(ptr, type, member) ({                      \
283                 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
284                 (type *)( (char *)__mptr - offsetof(type,member) );})
285 #endif
286
287 #ifdef HAVE_I_ALLOC_SEM
288 #define UP_WRITE_I_ALLOC_SEM(i) do { up_write(&(i)->i_alloc_sem); } while (0)
289 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down_write(&(i)->i_alloc_sem); } while(0)
290 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_read_trylock(&(i)->i_alloc_sem) == 0)
291
292 #define UP_READ_I_ALLOC_SEM(i) do { up_read(&(i)->i_alloc_sem); } while (0)
293 #define DOWN_READ_I_ALLOC_SEM(i) do { down_read(&(i)->i_alloc_sem); } while (0)
294 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
295 #define MDS_PACK_MD_LOCK 1
296 #else
297 #define UP_READ_I_ALLOC_SEM(i) do { up(&(i)->i_sem); } while (0)
298 #define DOWN_READ_I_ALLOC_SEM(i) do { down(&(i)->i_sem); } while (0)
299 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem) != 0)
300
301 #define UP_WRITE_I_ALLOC_SEM(i) do { up(&(i)->i_sem); } while (0)
302 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down(&(i)->i_sem); } while (0)
303 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem) != 0)
304 #define MDS_PACK_MD_LOCK 0
305 #endif
306
307 #endif /* __KERNEL__ */
308 #endif /* _COMPAT25_H */