Whamcloud - gitweb
- landing of b_hd_cleanup_merge to HEAD.
[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 /*
35  * groups_info related staff
36  */
37 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4)
38
39 #define NGROUPS_SMALL           NGROUPS
40 #define NGROUPS_PER_BLOCK       ((int)(EXEC_PAGESIZE / sizeof(gid_t)))
41 struct group_info {
42         int        ngroups;
43         atomic_t   usage;
44         gid_t      small_block[NGROUPS_SMALL];
45         int        nblocks;
46         gid_t     *blocks[0];
47 };
48 #define current_ngroups current->ngroups
49                                                                            
50 struct group_info *groups_alloc(int gidsetsize);
51 void groups_free(struct group_info *ginfo);
52 int groups_search(struct group_info *ginfo, gid_t grp);
53
54 #define get_group_info(group_info)                              \
55         do {                                                    \
56                 atomic_inc(&(group_info)->usage);               \
57         } while (0)
58
59 #define put_group_info(group_info)                              \
60         do {                                                    \
61                 if (atomic_dec_and_test(&(group_info)->usage))  \
62                         groups_free(group_info);                \
63         } while (0)
64
65 #define groups_sort(gi) do {} while (0)
66
67 #define GROUP_AT(gi, i) ((gi)->small_block[(i)])
68
69 static inline int cleanup_group_info(void)
70 {
71         /* Get rid of unneeded supplementary groups */
72         current->ngroups = 0;
73         memset(current->groups, 0, sizeof(current->groups));
74         return 0;
75 }
76
77 #else /* >= 2.6.4 */
78
79 #define current_ngroups current->group_info->ngroups
80
81 void groups_sort(struct group_info *ginfo);
82 int groups_search(struct group_info *ginfo, gid_t grp);
83
84 static inline int cleanup_group_info(void)
85 {
86         struct group_info *ginfo;
87
88         ginfo = groups_alloc(0);
89         if (!ginfo)
90                 return -ENOMEM;
91
92         set_current_groups(ginfo);
93         put_group_info(ginfo);
94
95         return 0;
96 }
97 #endif /* end of groups_info stuff */
98
99
100 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
101
102 /*
103  * OBD need working random driver, thus all our
104  * initialization routines must be called after device
105  * driver initialization
106  */
107 #ifndef MODULE
108 #undef module_init
109 #define module_init(a)     late_initcall(a)
110 #endif
111
112 /* XXX our code should be using the 2.6 calls, not the other way around */
113 #define TryLockPage(page)                TestSetPageLocked(page)
114 #define filemap_fdatasync(mapping)       filemap_fdatawrite(mapping)
115 #define Page_Uptodate(page)              PageUptodate(page)
116
117 #define KDEVT_INIT(val)                 (val)
118
119 #define LTIME_S(time)                   (time.tv_sec)
120 #define ll_path_lookup                  path_lookup
121 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
122
123 #define ll_pgcache_lock(mapping)          spin_lock(&mapping->page_lock)
124 #define ll_pgcache_unlock(mapping)        spin_unlock(&mapping->page_lock)
125 #define ll_call_writepage(inode, page)  \
126                                 (inode)->i_mapping->a_ops->writepage(page, NULL)
127 #define ll_invalidate_inode_pages(inode) \
128                                 invalidate_inode_pages((inode)->i_mapping)
129 #define ll_truncate_complete_page(page) \
130                                 truncate_complete_page(page->mapping, page)
131
132 #define ll_vfs_create(a,b,c,d)              vfs_create(a,b,c,d)
133
134 #define ll_dev_t                        dev_t
135 #define kdev_t                          dev_t
136 #define to_kdev_t(dev)                  (dev)
137 #define kdev_t_to_nr(dev)               (dev)
138 #define val_to_kdev(dev)                (dev)
139 #define ILOOKUP(sb, ino, test, data)    ilookup5(sb, ino, test, data);
140
141 #include <linux/writeback.h>
142
143 static inline void lustre_daemonize_helper(void)
144 {
145         LASSERT(current->signal != NULL);
146         current->signal->session = 1;
147         if (current->group_leader)
148                 current->group_leader->signal->pgrp = 1;
149         else
150                 CERROR("we aren't group leader\n");
151         current->signal->tty = NULL;
152 }
153
154 #define __set_page_ll_data(page, llap) \
155         do {       \
156                 page_cache_get(page); \
157                 SetPagePrivate(page); \
158                 page->private = (unsigned long)llap; \
159         } while (0)
160 #define __clear_page_ll_data(page) \
161         do {       \
162                 ClearPagePrivate(page); \
163                 page_cache_release(page); \
164                 page->private = 0; \
165         } while(0)
166
167 #define smp_num_cpus    NR_CPUS
168
169 #define kiobuf bio
170
171 #include <linux/proc_fs.h>
172
173 #else /* 2.4.. */
174
175 #define ll_vfs_create(a,b,c,d)              vfs_create(a,b,c)
176 #define ll_permission(inode,mask,nd)        permission(inode,mask)
177 #define ILOOKUP(sb, ino, test, data)        ilookup4(sb, ino, test, data);
178 #define DCACHE_DISCONNECTED                 DCACHE_NFSD_DISCONNECTED
179 #define ll_dev_t                            int
180
181 static inline void clear_page_dirty(struct page *page)
182 {
183         if (PageDirty(page))
184                 ClearPageDirty(page); 
185 }
186
187 /* 2.5 uses hlists for some things, like the d_hash.  we'll treat them
188  * as 2.5 and let macros drop back.. */
189 #ifndef HLIST_HEAD /* until we get a kernel newer than l28 */
190 #define hlist_entry                     list_entry
191 #define hlist_head                      list_head
192 #define hlist_node                      list_head
193 #define HLIST_HEAD                      LIST_HEAD
194 #define INIT_HLIST_HEAD                 INIT_LIST_HEAD
195 #define hlist_del_init                  list_del_init
196 #define hlist_add_head                  list_add
197 #define hlist_for_each_safe             list_for_each_safe
198 #endif
199 #define KDEVT_INIT(val)                 (val)
200 #define ext3_xattr_set_handle           ext3_xattr_set
201 #define extN_xattr_set_handle           extN_xattr_set
202 #define try_module_get                  __MOD_INC_USE_COUNT
203 #define module_put                      __MOD_DEC_USE_COUNT
204 #define LTIME_S(time)                   (time)
205 #if !defined(CONFIG_RH_2_4_20) && !defined(cpu_online)
206 #define cpu_online(cpu)                 (cpu_online_map & (1<<cpu))
207 #endif
208
209 static inline int ll_path_lookup(const char *path, unsigned flags,
210                                  struct nameidata *nd)
211 {
212         int error = 0;
213         if (path_init(path, flags, nd))
214                 error = path_walk(path, nd);
215         return error;
216 }
217 #define ll_permission(inode,mask,nd)    permission(inode,mask)
218 typedef long sector_t;
219
220 #define ll_pgcache_lock(mapping)        spin_lock(&pagecache_lock)
221 #define ll_pgcache_unlock(mapping)      spin_unlock(&pagecache_lock)
222 #define ll_call_writepage(inode, page)  \
223                                (inode)->i_mapping->a_ops->writepage(page)
224 #define ll_invalidate_inode_pages(inode) invalidate_inode_pages(inode)
225 #define ll_truncate_complete_page(page) truncate_complete_page(page)
226
227 static inline void __d_drop(struct dentry *dentry)
228 {
229         list_del(&dentry->d_hash);
230         INIT_LIST_HEAD(&dentry->d_hash);
231 }
232
233 static inline void lustre_daemonize_helper(void)
234 {
235         current->session = 1;
236         current->pgrp = 1;
237         current->tty = NULL;
238 }
239
240 #ifndef HAVE_COND_RESCHED
241 static inline void cond_resched(void)
242 {
243         if (unlikely(need_resched())) {
244                 set_current_state(TASK_RUNNING);
245                 schedule();
246         }
247 }
248 #endif
249
250 static inline int mapping_mapped(struct address_space *mapping)
251 {
252         return mapping->i_mmap_shared ? 1 : 0;
253 }
254
255 /* to find proc_dir_entry from inode. 2.6 has native one -bzzz */
256 #ifndef HAVE_PDE
257 #define PDE(ii)         ((ii)->u.generic_ip)
258 #endif
259
260 #define __set_page_ll_data(page, llap) page->private = (unsigned long)llap
261 #define __clear_page_ll_data(page) page->private = 0
262 #define PageWriteback(page) 0
263 #define end_page_writeback(page)
264
265 #ifdef ZAP_PAGE_RANGE_VMA
266 #define ll_zap_page_range(vma, addr, len)  zap_page_range(vma, addr, len)
267 #else
268 #define ll_zap_page_range(vma, addr, len)  zap_page_range(vma->vm_mm, addr, len)
269 #endif
270
271 #endif /* end of 2.4 compat macros */
272
273 #ifdef HAVE_PAGE_LIST
274 static inline int mapping_has_pages(struct address_space *mapping)
275 {
276         int rc = 1;
277
278         ll_pgcache_lock(mapping);
279         if (list_empty(&mapping->dirty_pages) &&
280             list_empty(&mapping->clean_pages) &&
281             list_empty(&mapping->locked_pages)) {
282                 rc = 0;
283         }
284         ll_pgcache_unlock(mapping);
285
286         return rc;
287 }
288
289 static inline int clear_page_dirty_for_io(struct page *page)
290 {
291         struct address_space *mapping = page->mapping;
292
293         if (page->mapping && PageDirty(page)) {
294                 ClearPageDirty(page);
295                 ll_pgcache_lock(mapping);
296                 list_del(&page->list);
297                 list_add(&page->list, &mapping->locked_pages);
298                 ll_pgcache_unlock(mapping);
299                 return 1;
300         }
301         return 0;
302 }
303 #else
304 static inline int mapping_has_pages(struct address_space *mapping)
305 {
306         return mapping->nrpages > 0;
307 }
308 #endif
309
310 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
311 #define ll_set_dflags(dentry, flags) do { dentry->d_vfs_flags |= flags; } while(0)
312 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path)
313 #else
314 #define ll_set_dflags(dentry, flags) do { \
315                 spin_lock(&dentry->d_lock); \
316                 dentry->d_flags |= flags; \
317                 spin_unlock(&dentry->d_lock); \
318         } while(0)
319 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path, mode)
320 #endif
321
322 #ifdef HAVE_I_ALLOC_SEM
323 #define UP_WRITE_I_ALLOC_SEM(i) do { up_write(&(i)->i_alloc_sem); } while (0)
324 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down_write(&(i)->i_alloc_sem); } while(0)
325 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_read_trylock(&(i)->i_alloc_sem) == 0)
326
327 #define UP_READ_I_ALLOC_SEM(i) do { up_read(&(i)->i_alloc_sem); } while (0)
328 #define DOWN_READ_I_ALLOC_SEM(i) do { down_read(&(i)->i_alloc_sem); } while (0)
329 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
330 #define MDS_PACK_MD_LOCK 1
331 #else
332 #define UP_READ_I_ALLOC_SEM(i) do { up(&(i)->i_sem); } while (0)
333 #define DOWN_READ_I_ALLOC_SEM(i) do { down(&(i)->i_sem); } while (0)
334 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem) != 0)
335
336 #define UP_WRITE_I_ALLOC_SEM(i) do { up(&(i)->i_sem); } while (0)
337 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down(&(i)->i_sem); } while (0)
338 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem) != 0)
339 #define MDS_PACK_MD_LOCK 0
340 #endif
341
342 #endif /* __KERNEL__ */
343 #endif /* _COMPAT25_H */