Whamcloud - gitweb
- changed name convention in cobd, thus all MD related methods have _md_ prefix like...
[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 /*
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 #define GROUP_AT(gi, i) ((gi)->small_block[(i)])
67
68 static inline int cleanup_group_info(void)
69 {
70         /* Get rid of unneeded supplementary groups */
71         current->ngroups = 0;
72         memset(current->groups, 0, sizeof(current->groups));
73         return 0;
74 }
75
76 #else /* >= 2.6.4 */
77
78 #define current_ngroups current->group_info->ngroups
79
80 void groups_sort(struct group_info *ginfo);
81 int groups_search(struct group_info *ginfo, gid_t grp);
82
83 static inline int cleanup_group_info(void)
84 {
85         struct group_info *ginfo;
86
87         ginfo = groups_alloc(0);
88         if (!ginfo)
89                 return -ENOMEM;
90
91         set_current_groups(ginfo);
92         put_group_info(ginfo);
93
94         return 0;
95 }
96 #endif /* end of groups_info stuff */
97
98 /*
99  * this define is from the same namespace as other lookup flags in linux, will
100  * be gone when COBD medium switching will be done more correct manner.
101  * Currently this is dirty hack and this flag is needed to let MDC layer know
102  * that it does not have to check if requested id is the same as receviced from
103  * MDS in mdc_intent_lock() --umka
104  */
105 #define LOOKUP_COBD 4096
106
107 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
108
109 /* New (actually old) intent naming */
110 #define lookup_intent open_intent
111
112 /* And internals */
113 #define it_flags flags
114 #define it_op op
115 #define it_magic magic
116 #define it_op_release op_release
117 #define it_create_mode create_mode
118
119 /*
120  * OBD need working random driver, thus all our
121  * initialization routines must be called after device
122  * driver initialization
123  */
124 #ifndef MODULE
125 #undef module_init
126 #define module_init(a)     late_initcall(a)
127 #endif
128
129 /* XXX our code should be using the 2.6 calls, not the other way around */
130 #define TryLockPage(page)                TestSetPageLocked(page)
131 #define Page_Uptodate(page)              PageUptodate(page)
132
133 #define KDEVT_INIT(val)                 (val)
134
135 #define LTIME_S(time)                   (time.tv_sec)
136 #define ll_path_lookup                  path_lookup
137 #define ll_permission(inode,mask,nd)    permission(inode,mask,nd)
138
139 #define ll_pgcache_lock(mapping)          spin_lock(&mapping->page_lock)
140 #define ll_pgcache_unlock(mapping)        spin_unlock(&mapping->page_lock)
141 #define ll_call_writepage(inode, page)  \
142                                 (inode)->i_mapping->a_ops->writepage(page, NULL)
143 #define ll_invalidate_inode_pages(inode) \
144                                 invalidate_inode_pages((inode)->i_mapping)
145 #define ll_truncate_complete_page(page) \
146                                 truncate_complete_page(page->mapping, page)
147
148 #define ll_vfs_create(a,b,c,d)              vfs_create(a,b,c,d)
149
150 #define ll_dev_t                        dev_t
151 #define kdev_t                          dev_t
152 #define to_kdev_t(dev)                  (dev)
153 #define kdev_t_to_nr(dev)               (dev)
154 #define val_to_kdev(dev)                (dev)
155 #define ILOOKUP(sb, ino, test, data)    ilookup5(sb, ino, test, data);
156
157 #include <linux/writeback.h>
158
159 static inline void lustre_daemonize_helper(void)
160 {
161         LASSERT(current->signal != NULL);
162         current->signal->session = 1;
163         if (current->group_leader)
164                 current->group_leader->signal->pgrp = 1;
165         else
166                 CERROR("we aren't group leader\n");
167         current->signal->tty = NULL;
168 }
169
170 #define __set_page_ll_data(page, llap) \
171         do {       \
172                 page_cache_get(page); \
173                 SetPagePrivate(page); \
174                 page->private = (unsigned long)llap; \
175         } while (0)
176 #define __clear_page_ll_data(page) \
177         do {       \
178                 ClearPagePrivate(page); \
179                 page_cache_release(page); \
180                 page->private = 0; \
181         } while(0)
182
183 #ifndef smp_num_cpus
184 #define smp_num_cpus    num_online_cpus()
185 #endif
186
187 #define kiobuf bio
188
189 #include <linux/proc_fs.h>
190
191 #else /* 2.4.. */
192
193 #define ll_vfs_create(a,b,c,d)              vfs_create(a,b,c)
194 #define ll_permission(inode,mask,nd)        permission(inode,mask)
195 #define ILOOKUP(sb, ino, test, data)        ilookup4(sb, ino, test, data);
196 #define DCACHE_DISCONNECTED                 DCACHE_NFSD_DISCONNECTED
197 #define ll_dev_t                            int
198
199 static inline void clear_page_dirty(struct page *page)
200 {
201         if (PageDirty(page))
202                 ClearPageDirty(page); 
203 }
204
205 /* 2.5 uses hlists for some things, like the d_hash.  we'll treat them
206  * as 2.5 and let macros drop back.. */
207 #ifndef HLIST_HEAD /* until we get a kernel newer than l28 */
208 #define hlist_entry                     list_entry
209 #define hlist_head                      list_head
210 #define hlist_node                      list_head
211 #define HLIST_HEAD                      LIST_HEAD
212 #define INIT_HLIST_HEAD                 INIT_LIST_HEAD
213 #define hlist_del_init                  list_del_init
214 #define hlist_add_head                  list_add
215 #define hlist_for_each_safe             list_for_each_safe
216 #endif
217 #define KDEVT_INIT(val)                 (val)
218 #define ext3_xattr_set_handle           ext3_xattr_set
219 #define extN_xattr_set_handle           extN_xattr_set
220 #define try_module_get                  __MOD_INC_USE_COUNT
221 #define module_put                      __MOD_DEC_USE_COUNT
222 #define LTIME_S(time)                   (time)
223 #if !defined(CONFIG_RH_2_4_20) && !defined(cpu_online)
224 #define cpu_online(cpu)                 (cpu_online_map & (1<<cpu))
225 #endif
226
227 static inline int ll_path_lookup(const char *path, unsigned flags,
228                                  struct nameidata *nd)
229 {
230         int error = 0;
231         if (path_init(path, flags, nd))
232                 error = path_walk(path, nd);
233         return error;
234 }
235 #define ll_permission(inode,mask,nd)    permission(inode,mask)
236 typedef long sector_t;
237
238 #define ll_pgcache_lock(mapping)        spin_lock(&pagecache_lock)
239 #define ll_pgcache_unlock(mapping)      spin_unlock(&pagecache_lock)
240 #define ll_call_writepage(inode, page)  \
241                                (inode)->i_mapping->a_ops->writepage(page)
242 #define filemap_fdatawrite(mapping)      filemap_fdatasync(mapping)
243 #define ll_invalidate_inode_pages(inode) invalidate_inode_pages(inode)
244 #define ll_truncate_complete_page(page) truncate_complete_page(page)
245
246 static inline void __d_drop(struct dentry *dentry)
247 {
248         list_del(&dentry->d_hash);
249         INIT_LIST_HEAD(&dentry->d_hash);
250 }
251
252 static inline void lustre_daemonize_helper(void)
253 {
254         current->session = 1;
255         current->pgrp = 1;
256         current->tty = NULL;
257 }
258
259 #ifndef HAVE_COND_RESCHED
260 static inline void cond_resched(void)
261 {
262         if (unlikely(need_resched())) {
263                 set_current_state(TASK_RUNNING);
264                 schedule();
265         }
266 }
267 #endif
268
269 static inline int mapping_mapped(struct address_space *mapping)
270 {
271         if (mapping->i_mmap_shared)
272                 return 1;
273         if (mapping->i_mmap)
274                 return 1;
275         return 0;
276 }
277
278 /* to find proc_dir_entry from inode. 2.6 has native one -bzzz */
279 #ifndef HAVE_PDE
280 #define PDE(ii)         ((ii)->u.generic_ip)
281 #endif
282
283 #define __set_page_ll_data(page, llap) page->private = (unsigned long)llap
284 #define __clear_page_ll_data(page) page->private = 0
285 #define PageWriteback(page) 0
286 #define set_page_writeback(page) do {} while (0)
287 #define end_page_writeback(page) do {} while (0)
288   
289 #define end_page_writeback(page)
290
291 #ifdef ZAP_PAGE_RANGE_VMA
292 #define ll_zap_page_range(vma, addr, len)  zap_page_range(vma, addr, len)
293 #else
294 #define ll_zap_page_range(vma, addr, len)  zap_page_range(vma->vm_mm, addr, len)
295 #endif
296
297 #endif /* end of 2.4 compat macros */
298
299 #ifdef HAVE_PAGE_LIST
300 static inline int mapping_has_pages(struct address_space *mapping)
301 {
302         int rc = 1;
303
304         ll_pgcache_lock(mapping);
305         if (list_empty(&mapping->dirty_pages) &&
306             list_empty(&mapping->clean_pages) &&
307             list_empty(&mapping->locked_pages)) {
308                 rc = 0;
309         }
310         ll_pgcache_unlock(mapping);
311
312         return rc;
313 }
314
315 static inline int clear_page_dirty_for_io(struct page *page)
316 {
317         struct address_space *mapping = page->mapping;
318
319         if (page->mapping && PageDirty(page)) {
320                 ClearPageDirty(page);
321                 ll_pgcache_lock(mapping);
322                 list_del(&page->list);
323                 list_add(&page->list, &mapping->locked_pages);
324                 ll_pgcache_unlock(mapping);
325                 return 1;
326         }
327         return 0;
328 }
329 #else
330 static inline int mapping_has_pages(struct address_space *mapping)
331 {
332         return mapping->nrpages > 0;
333 }
334 #endif
335
336 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
337 #define ll_set_dflags(dentry, flags) do { dentry->d_vfs_flags |= flags; } while(0)
338 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path)
339 #else
340 #define ll_set_dflags(dentry, flags) do { \
341                 spin_lock(&dentry->d_lock); \
342                 dentry->d_flags |= flags; \
343                 spin_unlock(&dentry->d_lock); \
344         } while(0)
345 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path, mode)
346 #endif
347
348 #ifndef container_of
349 #define container_of(ptr, type, member) ({                      \
350                 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
351                 (type *)( (char *)__mptr - offsetof(type,member) );})
352 #endif
353
354 #ifdef HAVE_I_ALLOC_SEM
355 #define UP_WRITE_I_ALLOC_SEM(i) do { up_write(&(i)->i_alloc_sem); } while (0)
356 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down_write(&(i)->i_alloc_sem); } while(0)
357 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_read_trylock(&(i)->i_alloc_sem) == 0)
358
359 #define UP_READ_I_ALLOC_SEM(i) do { up_read(&(i)->i_alloc_sem); } while (0)
360 #define DOWN_READ_I_ALLOC_SEM(i) do { down_read(&(i)->i_alloc_sem); } while (0)
361 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
362 #define MDS_PACK_MD_LOCK 1
363 #else
364 #define UP_READ_I_ALLOC_SEM(i) do { up(&(i)->i_sem); } while (0)
365 #define DOWN_READ_I_ALLOC_SEM(i) do { down(&(i)->i_sem); } while (0)
366 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem) != 0)
367
368 #define UP_WRITE_I_ALLOC_SEM(i) do { up(&(i)->i_sem); } while (0)
369 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down(&(i)->i_sem); } while (0)
370 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem) != 0)
371 #define MDS_PACK_MD_LOCK 0
372 #endif
373
374 #endif /* __KERNEL__ */
375 #endif /* _COMPAT25_H */