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