Whamcloud - gitweb
51e8054025ba9df5a03af4807e8630cab209e4aa
[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 <libcfs/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 set_page_writeback(page)
219 #define end_page_writeback(page)
220
221 static inline int mapping_mapped(struct address_space *mapping)
222 {
223         if (mapping->i_mmap_shared)
224                 return 1;
225         if (mapping->i_mmap)
226                 return 1;
227         return 0;
228 }
229
230 #ifdef ZAP_PAGE_RANGE_VMA
231 #define ll_zap_page_range(vma, addr, len)  zap_page_range(vma, addr, len)
232 #else
233 #define ll_zap_page_range(vma, addr, len)  zap_page_range(vma->vm_mm, addr, len)
234 #endif
235
236 #endif /* end of 2.4 compat macros */
237
238 #ifdef HAVE_PAGE_LIST
239 static inline int mapping_has_pages(struct address_space *mapping)
240 {
241         int rc = 1;
242
243         ll_pgcache_lock(mapping);
244         if (list_empty(&mapping->dirty_pages) &&
245             list_empty(&mapping->clean_pages) &&
246             list_empty(&mapping->locked_pages)) {
247                 rc = 0;
248         }
249         ll_pgcache_unlock(mapping);
250
251         return rc;
252 }
253
254 static inline int clear_page_dirty_for_io(struct page *page)
255 {
256         struct address_space *mapping = page->mapping;
257
258         if (page->mapping && PageDirty(page)) {
259                 ClearPageDirty(page);
260                 ll_pgcache_lock(mapping);
261                 list_del(&page->list);
262                 list_add(&page->list, &mapping->locked_pages);
263                 ll_pgcache_unlock(mapping);
264                 return 1;
265         }
266         return 0;
267 }
268 #else
269 static inline int mapping_has_pages(struct address_space *mapping)
270 {
271         return mapping->nrpages > 0;
272 }
273 #endif
274
275 #ifdef HAVE_KIOBUF_KIO_BLOCKS
276 #define KIOBUF_GET_BLOCKS(k) ((k)->kio_blocks)
277 #else
278 #define KIOBUF_GET_BLOCKS(k) ((k)->blocks)
279 #endif
280
281 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
282 #define ll_set_dflags(dentry, flags) do { dentry->d_vfs_flags |= flags; } while(0)
283 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path)
284 #else
285 #define ll_set_dflags(dentry, flags) do { \
286                 spin_lock(&dentry->d_lock); \
287                 dentry->d_flags |= flags; \
288                 spin_unlock(&dentry->d_lock); \
289         } while(0)
290 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path, mode)
291 #endif
292
293 #ifndef container_of
294 #define container_of(ptr, type, member) ({                      \
295                 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
296                 (type *)( (char *)__mptr - offsetof(type,member) );})
297 #endif
298
299 #ifdef HAVE_I_ALLOC_SEM
300 #define UP_WRITE_I_ALLOC_SEM(i) do { up_write(&(i)->i_alloc_sem); } while (0)
301 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down_write(&(i)->i_alloc_sem); } while(0)
302 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_read_trylock(&(i)->i_alloc_sem) == 0)
303
304 #define UP_READ_I_ALLOC_SEM(i) do { up_read(&(i)->i_alloc_sem); } while (0)
305 #define DOWN_READ_I_ALLOC_SEM(i) do { down_read(&(i)->i_alloc_sem); } while (0)
306 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
307 #define MDS_PACK_MD_LOCK 1
308 #else
309 #define UP_READ_I_ALLOC_SEM(i) do { up(&(i)->i_sem); } while (0)
310 #define DOWN_READ_I_ALLOC_SEM(i) do { down(&(i)->i_sem); } while (0)
311 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem) != 0)
312
313 #define UP_WRITE_I_ALLOC_SEM(i) do { up(&(i)->i_sem); } while (0)
314 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down(&(i)->i_sem); } while (0)
315 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem) != 0)
316 #define MDS_PACK_MD_LOCK 0
317 #endif
318
319 #ifndef HAVE_GRAB_CACHE_PAGE_NOWAIT_GFP
320 #define grab_cache_page_nowait_gfp(x, y, z) grab_cache_page_nowait((x), (y))
321 #endif
322
323 #endif /* __KERNEL__ */
324 #endif /* _COMPAT25_H */