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>
35 * groups_info related staff
37 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4)
39 #define NGROUPS_SMALL NGROUPS
40 #define NGROUPS_PER_BLOCK ((int)(EXEC_PAGESIZE / sizeof(gid_t)))
44 gid_t small_block[NGROUPS_SMALL];
48 #define current_ngroups current->ngroups
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);
54 #define get_group_info(group_info) \
56 atomic_inc(&(group_info)->usage); \
59 #define put_group_info(group_info) \
61 if (atomic_dec_and_test(&(group_info)->usage)) \
62 groups_free(group_info); \
65 #define groups_sort(gi) do {} while (0)
67 #define GROUP_AT(gi, i) ((gi)->small_block[(i)])
69 static inline int cleanup_group_info(void)
71 /* Get rid of unneeded supplementary groups */
73 memset(current->groups, 0, sizeof(current->groups));
79 #define current_ngroups current->group_info->ngroups
81 void groups_sort(struct group_info *ginfo);
82 int groups_search(struct group_info *ginfo, gid_t grp);
84 static inline int cleanup_group_info(void)
86 struct group_info *ginfo;
88 ginfo = groups_alloc(0);
92 set_current_groups(ginfo);
93 put_group_info(ginfo);
97 #endif /* end of groups_info stuff */
100 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
103 * OBD need working random driver, thus all our
104 * initialization routines must be called after device
105 * driver initialization
109 #define module_init(a) late_initcall(a)
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)
117 #define KDEVT_INIT(val) (val)
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)
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)
132 #define ll_vfs_create(a,b,c,d) vfs_create(a,b,c,d)
134 #define ll_dev_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);
141 #include <linux/writeback.h>
143 static inline void lustre_daemonize_helper(void)
145 LASSERT(current->signal != NULL);
146 current->signal->session = 1;
147 if (current->group_leader)
148 current->group_leader->signal->pgrp = 1;
150 CERROR("we aren't group leader\n");
151 current->signal->tty = NULL;
154 #define smp_num_cpus NR_CPUS
156 #include <linux/proc_fs.h>
160 #define ll_vfs_create(a,b,c,d) vfs_create(a,b,c)
161 #define ll_permission(inode,mask,nd) permission(inode,mask)
162 #define ILOOKUP(sb, ino, test, data) ilookup4(sb, ino, test, data);
163 #define DCACHE_DISCONNECTED DCACHE_NFSD_DISCONNECTED
166 static inline void clear_page_dirty(struct page *page)
169 ClearPageDirty(page);
172 /* 2.5 uses hlists for some things, like the d_hash. we'll treat them
173 * as 2.5 and let macros drop back.. */
174 #ifndef HLIST_HEAD /* until we get a kernel newer than l28 */
175 #define hlist_entry list_entry
176 #define hlist_head list_head
177 #define hlist_node list_head
178 #define HLIST_HEAD LIST_HEAD
179 #define INIT_HLIST_HEAD INIT_LIST_HEAD
180 #define hlist_del_init list_del_init
181 #define hlist_add_head list_add
182 #define hlist_for_each_safe list_for_each_safe
184 #define KDEVT_INIT(val) (val)
185 #define ext3_xattr_set_handle ext3_xattr_set
186 #define extN_xattr_set_handle extN_xattr_set
187 #define try_module_get __MOD_INC_USE_COUNT
188 #define module_put __MOD_DEC_USE_COUNT
189 #define LTIME_S(time) (time)
190 #if !defined(CONFIG_RH_2_4_20) && !defined(cpu_online)
191 #define cpu_online(cpu) (cpu_online_map & (1<<cpu))
194 static inline int ll_path_lookup(const char *path, unsigned flags,
195 struct nameidata *nd)
198 if (path_init(path, flags, nd))
199 error = path_walk(path, nd);
202 #define ll_permission(inode,mask,nd) permission(inode,mask)
203 typedef long sector_t;
205 #define ll_pgcache_lock(mapping) spin_lock(&pagecache_lock)
206 #define ll_pgcache_unlock(mapping) spin_unlock(&pagecache_lock)
207 #define ll_call_writepage(inode, page) \
208 (inode)->i_mapping->a_ops->writepage(page)
209 #define ll_invalidate_inode_pages(inode) invalidate_inode_pages(inode)
210 #define ll_truncate_complete_page(page) truncate_complete_page(page)
212 static inline void __d_drop(struct dentry *dentry)
214 list_del(&dentry->d_hash);
215 INIT_LIST_HEAD(&dentry->d_hash);
218 static inline void lustre_daemonize_helper(void)
220 current->session = 1;
225 #ifndef HAVE_COND_RESCHED
226 static inline void cond_resched(void)
228 if (unlikely(need_resched())) {
229 set_curret_state(TASK_RUNNING);
235 /* to find proc_dir_entry from inode. 2.6 has native one -bzzz */
237 #define PDE(ii) ((ii)->u.generic_ip)
240 #endif /* end of 2.4 compat macros */
242 #ifdef HAVE_PAGE_LIST
243 static inline int mapping_has_pages(struct address_space *mapping)
247 ll_pgcache_lock(mapping);
248 if (list_empty(&mapping->dirty_pages) &&
249 list_empty(&mapping->clean_pages) &&
250 list_empty(&mapping->locked_pages)) {
253 ll_pgcache_unlock(mapping);
258 static inline int clear_page_dirty_for_io(struct page *page)
260 struct address_space *mapping = page->mapping;
262 if (page->mapping && PageDirty(page)) {
263 ClearPageDirty(page);
264 ll_pgcache_lock(mapping);
265 list_del(&page->list);
266 list_add(&page->list, &mapping->locked_pages);
267 ll_pgcache_unlock(mapping);
273 static inline int mapping_has_pages(struct address_space *mapping)
275 return mapping->nrpages > 0;
279 #endif /* __KERNEL__ */
280 #endif /* _COMPAT25_H */