1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
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
32 #include <linux/portals_compat25.h>
34 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
37 * OBD need working random driver, thus all our
38 * initialization routines must be called after device
39 * driver initialization
43 #define module_init(a) late_initcall(a)
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)
51 #define KDEVT_INIT(val) (val)
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)
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)
66 #define ll_vfs_create(a,b,c,d) vfs_create(a,b,c,d)
68 #define ll_dev_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);
75 #include <linux/writeback.h>
77 static inline void lustre_daemonize_helper(void)
79 LASSERT(current->signal != NULL);
80 current->signal->session = 1;
81 if (current->group_leader)
82 current->group_leader->signal->pgrp = 1;
84 CERROR("we aren't group leader\n");
85 current->signal->tty = NULL;
88 static inline int cleanup_group_info(void)
90 struct group_info *ginfo;
92 ginfo = groups_alloc(2);
97 set_current_groups(ginfo);
98 put_group_info(ginfo);
103 #define __set_page_ll_data(page, llap) \
105 page_cache_get(page); \
106 SetPagePrivate(page); \
107 page->private = (unsigned long)llap; \
109 #define __clear_page_ll_data(page) \
111 ClearPagePrivate(page); \
112 page_cache_release(page); \
116 #define smp_num_cpus NR_CPUS
118 #include <linux/proc_fs.h>
122 #ifdef HAVE_MM_INLINE
123 #include <linux/mm_inline.h>
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
132 static inline void clear_page_dirty(struct page *page)
135 ClearPageDirty(page);
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
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))
160 static inline int ll_path_lookup(const char *path, unsigned flags,
161 struct nameidata *nd)
164 if (path_init(path, flags, nd))
165 error = path_walk(path, nd);
168 #define ll_permission(inode,mask,nd) permission(inode,mask)
169 typedef long sector_t;
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)
178 static inline void __d_drop(struct dentry *dentry)
180 list_del(&dentry->d_hash);
181 INIT_LIST_HEAD(&dentry->d_hash);
184 static inline void lustre_daemonize_helper(void)
186 current->session = 1;
191 static inline int cleanup_group_info(void)
193 /* Get rid of unneeded supplementary groups */
194 current->ngroups = 0;
195 memset(current->groups, 0, sizeof(current->groups));
199 #ifndef HAVE_COND_RESCHED
200 static inline void cond_resched(void)
202 if (unlikely(need_resched())) {
203 set_current_state(TASK_RUNNING);
209 /* to find proc_dir_entry from inode. 2.6 has native one -bzzz */
211 #define PDE(ii) ((ii)->u.generic_ip)
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)
219 static inline int mapping_mapped(struct address_space *mapping)
221 return mapping->i_mmap_shared ? 1 : 0;
224 #ifdef ZAP_PAGE_RANGE_VMA
225 #define ll_zap_page_range(vma, addr, len) zap_page_range(vma, addr, len)
227 #define ll_zap_page_range(vma, addr, len) zap_page_range(vma->vm_mm, addr, len)
230 #endif /* end of 2.4 compat macros */
232 #ifdef HAVE_PAGE_LIST
233 static inline int mapping_has_pages(struct address_space *mapping)
237 ll_pgcache_lock(mapping);
238 if (list_empty(&mapping->dirty_pages) &&
239 list_empty(&mapping->clean_pages) &&
240 list_empty(&mapping->locked_pages)) {
243 ll_pgcache_unlock(mapping);
248 static inline int clear_page_dirty_for_io(struct page *page)
250 struct address_space *mapping = page->mapping;
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);
263 static inline int mapping_has_pages(struct address_space *mapping)
265 return mapping->nrpages > 0;
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)
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); \
278 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path, mode)
282 #define container_of(ptr, type, member) ({ \
283 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
284 (type *)( (char *)__mptr - offsetof(type,member) );})
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)
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
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)
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
307 #endif /* __KERNEL__ */
308 #endif /* _COMPAT25_H */