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.
23 #ifndef _LINUX_COMPAT25_H
24 #define _LINUX_COMPAT25_H
28 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5)
29 #error Sorry, Lustre requires at Linux kernel version 2.6.5 or later
32 #include <libcfs/linux/portals_compat25.h>
34 #include <linux/lustre_patchless_compat.h>
36 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
39 unsigned int ia_attr_flags;
42 #define ll_iattr iattr
43 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14) */
45 #ifndef HAVE_SET_FS_PWD
46 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
47 struct dentry *dentry)
49 struct dentry *old_pwd;
50 struct vfsmount *old_pwdmnt;
52 write_lock(&fs->lock);
54 old_pwdmnt = fs->pwdmnt;
55 fs->pwdmnt = mntget(mnt);
56 fs->pwd = dget(dentry);
57 write_unlock(&fs->lock);
65 #define ll_set_fs_pwd set_fs_pwd
66 #endif /* HAVE_SET_FS_PWD */
69 * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
70 * ATTR_* attributes (see bug 13828)
72 #define ATTR_BLOCKS (1 << 27)
74 #if HAVE_INODE_I_MUTEX
75 #define UNLOCK_INODE_MUTEX(inode) do {mutex_unlock(&(inode)->i_mutex); } while(0)
76 #define LOCK_INODE_MUTEX(inode) do {mutex_lock(&(inode)->i_mutex); } while(0)
77 #define TRYLOCK_INODE_MUTEX(inode) mutex_trylock(&(inode)->i_mutex)
79 #define UNLOCK_INODE_MUTEX(inode) do {up(&(inode)->i_sem); } while(0)
80 #define LOCK_INODE_MUTEX(inode) do {down(&(inode)->i_sem); } while(0)
81 #define TRYLOCK_INODE_MUTEX(inode) (!down_trylock(&(inode)->i_sem))
82 #endif /* HAVE_INODE_I_MUTEX */
84 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
85 #define d_child d_u.d_child
86 #define d_rcu d_u.d_rcu
89 #ifdef HAVE_DQUOTOFF_MUTEX
90 #define UNLOCK_DQONOFF_MUTEX(dqopt) do {mutex_unlock(&(dqopt)->dqonoff_mutex); } while(0)
91 #define LOCK_DQONOFF_MUTEX(dqopt) do {mutex_lock(&(dqopt)->dqonoff_mutex); } while(0)
93 #define UNLOCK_DQONOFF_MUTEX(dqopt) do {up(&(dqopt)->dqonoff_sem); } while(0)
94 #define LOCK_DQONOFF_MUTEX(dqopt) do {down(&(dqopt)->dqonoff_sem); } while(0)
95 #endif /* HAVE_DQUOTOFF_MUTEX */
97 #define current_ngroups current->group_info->ngroups
98 #define current_groups current->group_info->small_block
101 #define page_private(page) ((page)->private)
102 #define set_page_private(page, v) ((page)->private = (v))
109 #define lock_dentry(___dentry) spin_lock(&(___dentry)->d_lock)
110 #define unlock_dentry(___dentry) spin_unlock(&(___dentry)->d_lock)
112 #define ll_kernel_locked() kernel_locked()
115 * OBD need working random driver, thus all our
116 * initialization routines must be called after device
117 * driver initialization
121 #define module_init(a) late_initcall(a)
124 /* XXX our code should be using the 2.6 calls, not the other way around */
125 #define TryLockPage(page) TestSetPageLocked(page)
126 #define Page_Uptodate(page) PageUptodate(page)
127 #define ll_redirty_page(page) set_page_dirty(page)
129 #define KDEVT_INIT(val) (val)
131 #define LTIME_S(time) (time.tv_sec)
132 #define ll_path_lookup path_lookup
133 #define ll_permission(inode,mask,nd) permission(inode,mask,nd)
135 #define ll_pgcache_lock(mapping) spin_lock(&mapping->page_lock)
136 #define ll_pgcache_unlock(mapping) spin_unlock(&mapping->page_lock)
137 #define ll_call_writepage(inode, page) \
138 (inode)->i_mapping->a_ops->writepage(page, NULL)
139 #define ll_invalidate_inode_pages(inode) \
140 invalidate_inode_pages((inode)->i_mapping)
141 #define ll_truncate_complete_page(page) \
142 truncate_complete_page(page->mapping, page)
144 #define ll_vfs_create(a,b,c,d) vfs_create(a,b,c,d)
145 #define ll_dev_t dev_t
147 #define to_kdev_t(dev) (dev)
148 #define kdev_t_to_nr(dev) (dev)
149 #define val_to_kdev(dev) (dev)
150 #define ILOOKUP(sb, ino, test, data) ilookup5(sb, ino, test, data);
152 #include <linux/writeback.h>
154 static inline int cleanup_group_info(void)
156 struct group_info *ginfo;
158 ginfo = groups_alloc(0);
162 set_current_groups(ginfo);
163 put_group_info(ginfo);
168 #define __set_page_ll_data(page, llap) \
170 page_cache_get(page); \
171 SetPagePrivate(page); \
172 set_page_private(page, (unsigned long)llap); \
174 #define __clear_page_ll_data(page) \
176 ClearPagePrivate(page); \
177 set_page_private(page, 0); \
178 page_cache_release(page); \
183 #include <linux/proc_fs.h>
185 #ifndef HAVE___D_REHASH
186 #define __d_rehash(dentry, lock) d_rehash_cond(dentry, lock)
189 #ifdef HAVE_CAN_SLEEP_ARG
190 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
191 flock_lock_file_wait(file, lock, can_sleep)
193 #define ll_flock_lock_file_wait(file, lock, can_sleep) \
194 flock_lock_file_wait(file, lock)
197 #define CheckWriteback(page, cmd) \
198 (!(!PageWriteback(page) && cmd == OBD_BRW_WRITE))
200 #ifdef HAVE_PAGE_LIST
201 static inline int mapping_has_pages(struct address_space *mapping)
205 ll_pgcache_lock(mapping);
206 if (list_empty(&mapping->dirty_pages) &&
207 list_empty(&mapping->clean_pages) &&
208 list_empty(&mapping->locked_pages)) {
211 ll_pgcache_unlock(mapping);
216 static inline int mapping_has_pages(struct address_space *mapping)
218 return mapping->nrpages > 0;
222 #ifdef HAVE_KIOBUF_KIO_BLOCKS
223 #define KIOBUF_GET_BLOCKS(k) ((k)->kio_blocks)
225 #define KIOBUF_GET_BLOCKS(k) ((k)->blocks)
228 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
229 #define ll_set_dflags(dentry, flags) do { dentry->d_vfs_flags |= flags; } while(0)
230 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path)
232 #define ll_set_dflags(dentry, flags) do { \
233 spin_lock(&dentry->d_lock); \
234 dentry->d_flags |= flags; \
235 spin_unlock(&dentry->d_lock); \
237 #define ll_vfs_symlink(dir, dentry, path, mode) vfs_symlink(dir, dentry, path, mode)
241 #define container_of(ptr, type, member) ({ \
242 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
243 (type *)( (char *)__mptr - offsetof(type,member) );})
246 #ifdef HAVE_I_ALLOC_SEM
247 #define UP_WRITE_I_ALLOC_SEM(i) do { up_write(&(i)->i_alloc_sem); } while (0)
248 #define DOWN_WRITE_I_ALLOC_SEM(i) do { down_write(&(i)->i_alloc_sem); } while(0)
249 #define LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i) LASSERT(down_read_trylock(&(i)->i_alloc_sem) == 0)
251 #define UP_READ_I_ALLOC_SEM(i) do { up_read(&(i)->i_alloc_sem); } while (0)
252 #define DOWN_READ_I_ALLOC_SEM(i) do { down_read(&(i)->i_alloc_sem); } while (0)
253 #define LASSERT_I_ALLOC_SEM_READ_LOCKED(i) LASSERT(down_write_trylock(&(i)->i_alloc_sem) == 0)
255 #define UP_READ_I_ALLOC_SEM(i) do { } while (0)
256 #define DOWN_READ_I_ALLOC_SEM(i) do { } while (0)
257 #define LASSERT_I_ALLOC_SEM_READ_LOCKED(i) do { } while (0)
259 #define UP_WRITE_I_ALLOC_SEM(i) do { } while (0)
260 #define DOWN_WRITE_I_ALLOC_SEM(i) do { } while (0)
261 #define LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i) do { } while (0)
264 #ifndef HAVE_GRAB_CACHE_PAGE_NOWAIT_GFP
265 #define grab_cache_page_nowait_gfp(x, y, z) grab_cache_page_nowait((x), (y))
268 #ifndef HAVE_FILEMAP_FDATAWRITE
269 #define filemap_fdatawrite(mapping) filemap_fdatasync(mapping)
272 #ifdef HAVE_VFS_KERN_MOUNT
275 ll_kern_mount(const char *fstype, int flags, const char *name, void *data)
277 struct file_system_type *type = get_fs_type(fstype);
278 struct vfsmount *mnt;
280 return ERR_PTR(-ENODEV);
281 mnt = vfs_kern_mount(type, flags, name, data);
282 module_put(type->owner);
286 #define ll_kern_mount(fstype, flags, name, data) do_kern_mount((fstype), (flags), (name), (data))
289 #ifndef HAVE_GENERIC_FILE_READ
292 generic_file_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
294 struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
298 init_sync_kiocb(&kiocb, filp);
299 kiocb.ki_pos = *ppos;
302 ret = generic_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
303 *ppos = kiocb.ki_pos;
308 #ifndef HAVE_GENERIC_FILE_WRITE
311 generic_file_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
313 struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
317 init_sync_kiocb(&kiocb, filp);
318 kiocb.ki_pos = *ppos;
321 ret = generic_file_aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
322 *ppos = kiocb.ki_pos;
328 #ifdef HAVE_STATFS_DENTRY_PARAM
329 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb)->s_root, (sfs))
331 #define ll_do_statfs(sb, sfs) (sb)->s_op->statfs((sb), (sfs))
335 #ifndef HAVE_TASK_PPTR
336 #define p_pptr parent
339 #ifndef HAVE_SB_TIME_GRAN
340 #ifndef HAVE_S_TIME_GRAN
341 #error Need s_time_gran patch!
343 static inline u32 get_sb_time_gran(struct super_block *sb)
345 return sb->s_time_gran;
349 #ifdef HAVE_RW_TREE_LOCK
350 #define TREE_READ_LOCK_IRQ(mapping) read_lock_irq(&(mapping)->tree_lock)
351 #define TREE_READ_UNLOCK_IRQ(mapping) read_unlock_irq(&(mapping)->tree_lock)
353 #define TREE_READ_LOCK_IRQ(mapping) spin_lock_irq(&(mapping)->tree_lock)
354 #define TREE_READ_UNLOCK_IRQ(mapping) spin_unlock_irq(&(mapping)->tree_lock)
357 #ifdef HAVE_UNREGISTER_BLKDEV_RETURN_INT
358 #define ll_unregister_blkdev(a,b) unregister_blkdev((a),(b))
361 int ll_unregister_blkdev(unsigned int dev, const char *name)
363 unregister_blkdev(dev, name);
368 #ifdef HAVE_INVALIDATE_BDEV_2ARG
369 #define ll_invalidate_bdev(a,b) invalidate_bdev((a),(b))
371 #define ll_invalidate_bdev(a,b) invalidate_bdev((a))
374 #ifdef HAVE_INODE_BLKSIZE
375 #define ll_inode_blksize(a) (a)->i_blksize
377 #define ll_inode_blksize(a) (1<<(a)->i_blkbits)
382 #define FS_RENAME_DOES_D_MOVE FS_ODD_RENAME
385 #endif /* __KERNEL__ */
386 #endif /* _COMPAT25_H */