1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <info@clusterfs.com>
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.
21 * Filesystem interface helper.
25 #ifndef _LUSTRE_FSFILT_H
26 #define _LUSTRE_FSFILT_H
30 #include <linux/obd.h>
33 typedef void (*fsfilt_cb_t)(struct obd_device *obd, __u64 last_rcvd,
34 void *data, int error);
36 struct fsfilt_objinfo {
37 struct dentry *fso_dentry;
41 struct fsfilt_operations {
42 struct list_head fs_list;
43 struct module *fs_owner;
45 void *(* fs_start)(struct inode *inode, int op, void *desc_private);
46 void *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
47 int niocount, void *desc_private);
48 int (* fs_commit)(struct inode *inode, void *handle,int force_sync);
49 int (* fs_commit_async)(struct inode *inode, void *handle,
51 int (* fs_commit_wait)(struct inode *inode, void *handle);
52 int (* fs_setattr)(struct dentry *dentry, void *handle,
53 struct iattr *iattr, int do_trunc);
54 int (* fs_iocontrol)(struct inode *inode, struct file *file,
55 unsigned int cmd, unsigned long arg);
56 int (* fs_set_md)(struct inode *inode, void *handle, void *md,
58 int (* fs_get_md)(struct inode *inode, void *md, int size);
59 ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
61 int (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
62 void *handle, fsfilt_cb_t cb_func,
64 int (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
65 int (* fs_sync)(struct super_block *sb);
66 int (* fs_map_inode_page)(struct inode *inode, struct page *page,
67 unsigned long *blocks, int *created,
69 int (* fs_prep_san_write)(struct inode *inode, long *blocks,
70 int nblocks, loff_t newsize);
71 int (* fs_write_record)(struct file *, void *, int size, loff_t *,
73 int (* fs_read_record)(struct file *, void *, int size, loff_t *);
74 int (* fs_setup)(struct super_block *sb);
77 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
78 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
79 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
80 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
82 #define FSFILT_OP_UNLINK 1
83 #define FSFILT_OP_RMDIR 2
84 #define FSFILT_OP_RENAME 3
85 #define FSFILT_OP_CREATE 4
86 #define FSFILT_OP_MKDIR 5
87 #define FSFILT_OP_SYMLINK 6
88 #define FSFILT_OP_MKNOD 7
89 #define FSFILT_OP_SETATTR 8
90 #define FSFILT_OP_LINK 9
91 #define FSFILT_OP_CREATE_LOG 10
92 #define FSFILT_OP_UNLINK_LOG 11
94 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
95 int op, struct obd_trans_info *oti)
97 unsigned long now = jiffies;
98 void *parent_handle = oti ? oti->oti_handle : NULL;
99 void *handle = obd->obd_fsops->fs_start(inode, op, parent_handle);
100 CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
103 if (parent_handle == NULL) {
104 oti->oti_handle = handle;
105 } else if (handle != parent_handle) {
106 CERROR("mismatch: parent %p, handle %p, oti %p\n",
107 parent_handle, handle, oti->oti_handle);
111 if (time_after(jiffies, now + 15 * HZ))
112 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
116 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
117 struct fsfilt_objinfo *fso, int niocount,
118 struct obd_trans_info *oti)
120 unsigned long now = jiffies;
121 void *parent_handle = oti ? oti->oti_handle : NULL;
124 handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount,
126 CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
129 if (parent_handle == NULL) {
130 oti->oti_handle = handle;
131 } else if (handle != parent_handle) {
132 CERROR("mismatch: parent %p, handle %p, oti %p\n",
133 parent_handle, handle, oti->oti_handle);
137 if (time_after(jiffies, now + 15 * HZ))
138 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
142 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
143 void *handle, int force_sync)
145 unsigned long now = jiffies;
146 int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
147 CDEBUG(D_HA, "committing handle %p\n", handle);
148 if (time_after(jiffies, now + 15 * HZ))
149 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
153 static inline int fsfilt_commit_async(struct obd_device *obd,
158 unsigned long now = jiffies;
159 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
160 CDEBUG(D_HA, "committing handle %p (async)\n", *wait_handle);
161 if (time_after(jiffies, now + 15 * HZ))
162 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
166 static inline int fsfilt_commit_wait(struct obd_device *obd, struct inode *inode,
169 unsigned long now = jiffies;
170 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
171 CDEBUG(D_HA, "waiting for completion %p\n", handle);
172 if (time_after(jiffies, now + 15 * HZ))
173 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
177 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
178 void *handle, struct iattr *iattr,int do_trunc)
180 unsigned long now = jiffies;
182 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
183 if (time_after(jiffies, now + 15 * HZ))
184 CERROR("long setattr time %lus\n", (jiffies - now) / HZ);
188 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
189 struct file *file, unsigned int cmd,
192 return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
195 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
196 void *handle, void *md, int size)
198 return obd->obd_fsops->fs_set_md(inode, handle, md, size);
201 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
204 return obd->obd_fsops->fs_get_md(inode, md, size);
207 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
208 struct file *file, char *buf,
209 size_t count, loff_t *offset)
211 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
214 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
215 void *handle, fsfilt_cb_t cb_func,
218 return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd, handle,
222 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
223 struct obd_statfs *osfs)
225 return obd->obd_fsops->fs_statfs(sb, osfs);
228 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
230 return obd->obd_fsops->fs_sync(sb);
233 static inline int fsfilt_map_inode_page(struct obd_device *obd,
234 struct inode *inode, struct page *page,
235 unsigned long *blocks, int *created,
238 return obd->obd_fsops->fs_map_inode_page(inode, page, blocks, created,
242 static inline int fs_prep_san_write(struct obd_device *obd,
248 return obd->obd_fsops->fs_prep_san_write(inode, blocks,
252 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
253 void *buf, loff_t size, loff_t *offs)
255 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
258 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
259 void *buf, loff_t size, loff_t *offs,
262 return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
265 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
267 if (obd->obd_fsops->fs_setup)
268 return obd->obd_fsops->fs_setup(fs);
272 #endif /* __KERNEL__ */