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, struct niobuf_local *nb,
49 int (* fs_commit)(struct inode *inode, void *handle,int force_sync);
50 int (* fs_commit_async)(struct inode *inode, void *handle,
52 int (* fs_commit_wait)(struct inode *inode, void *handle);
53 int (* fs_setattr)(struct dentry *dentry, void *handle,
54 struct iattr *iattr, int do_trunc);
55 int (* fs_iocontrol)(struct inode *inode, struct file *file,
56 unsigned int cmd, unsigned long arg);
57 int (* fs_set_md)(struct inode *inode, void *handle, void *md,
59 int (* fs_get_md)(struct inode *inode, void *md, int size);
60 ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
62 int (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
63 void *handle, fsfilt_cb_t cb_func,
65 int (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
66 int (* fs_sync)(struct super_block *sb);
67 int (* fs_map_inode_page)(struct inode *inode, struct page *page,
68 unsigned long *blocks, int *created,
70 int (* fs_prep_san_write)(struct inode *inode, long *blocks,
71 int nblocks, loff_t newsize);
72 int (* fs_write_record)(struct file *, void *, int size, loff_t *,
74 int (* fs_read_record)(struct file *, void *, int size, loff_t *);
75 int (* fs_setup)(struct super_block *sb);
78 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
79 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
80 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
81 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
83 #define FSFILT_OP_UNLINK 1
84 #define FSFILT_OP_RMDIR 2
85 #define FSFILT_OP_RENAME 3
86 #define FSFILT_OP_CREATE 4
87 #define FSFILT_OP_MKDIR 5
88 #define FSFILT_OP_SYMLINK 6
89 #define FSFILT_OP_MKNOD 7
90 #define FSFILT_OP_SETATTR 8
91 #define FSFILT_OP_LINK 9
92 #define FSFILT_OP_CREATE_LOG 10
93 #define FSFILT_OP_UNLINK_LOG 11
94 #define FSFILT_OP_CANCEL_UNLINK_LOG 12
96 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
97 int op, struct obd_trans_info *oti)
99 unsigned long now = jiffies;
100 void *parent_handle = oti ? oti->oti_handle : NULL;
101 void *handle = obd->obd_fsops->fs_start(inode, op, parent_handle);
102 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
105 if (parent_handle == NULL) {
106 oti->oti_handle = handle;
107 } else if (handle != parent_handle) {
108 CERROR("mismatch: parent %p, handle %p, oti %p\n",
109 parent_handle, handle, oti->oti_handle);
113 if (time_after(jiffies, now + 15 * HZ))
114 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
118 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
119 struct fsfilt_objinfo *fso, int niocount,
120 struct niobuf_local *nb,
121 struct obd_trans_info *oti)
123 unsigned long now = jiffies;
124 void *parent_handle = oti ? oti->oti_handle : NULL;
127 handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
129 CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
132 if (parent_handle == NULL) {
133 oti->oti_handle = handle;
134 } else if (handle != parent_handle) {
135 CERROR("mismatch: parent %p, handle %p, oti %p\n",
136 parent_handle, handle, oti->oti_handle);
140 if (time_after(jiffies, now + 15 * HZ))
141 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
145 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
146 void *handle, int force_sync)
148 unsigned long now = jiffies;
149 int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
150 CDEBUG(D_INFO, "committing handle %p\n", handle);
151 if (time_after(jiffies, now + 15 * HZ))
152 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
156 static inline int fsfilt_commit_async(struct obd_device *obd,
161 unsigned long now = jiffies;
162 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
163 CDEBUG(D_HA, "committing handle %p (async)\n", *wait_handle);
164 if (time_after(jiffies, now + 15 * HZ))
165 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
169 static inline int fsfilt_commit_wait(struct obd_device *obd, struct inode *inode,
172 unsigned long now = jiffies;
173 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
174 CDEBUG(D_HA, "waiting for completion %p\n", handle);
175 if (time_after(jiffies, now + 15 * HZ))
176 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
180 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
181 void *handle, struct iattr *iattr,int do_trunc)
183 unsigned long now = jiffies;
185 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
186 if (time_after(jiffies, now + 15 * HZ))
187 CERROR("long setattr time %lus\n", (jiffies - now) / HZ);
191 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
192 struct file *file, unsigned int cmd,
195 return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
198 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
199 void *handle, void *md, int size)
201 return obd->obd_fsops->fs_set_md(inode, handle, md, size);
204 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
207 return obd->obd_fsops->fs_get_md(inode, md, size);
210 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
211 struct file *file, char *buf,
212 size_t count, loff_t *offset)
214 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
217 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
218 void *handle, fsfilt_cb_t cb_func,
221 return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd, handle,
225 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
226 struct obd_statfs *osfs)
228 return obd->obd_fsops->fs_statfs(sb, osfs);
231 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
233 return obd->obd_fsops->fs_sync(sb);
236 static inline int fsfilt_map_inode_page(struct obd_device *obd,
237 struct inode *inode, struct page *page,
238 unsigned long *blocks, int *created,
241 return obd->obd_fsops->fs_map_inode_page(inode, page, blocks, created,
245 static inline int fs_prep_san_write(struct obd_device *obd,
251 return obd->obd_fsops->fs_prep_san_write(inode, blocks,
255 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
256 void *buf, loff_t size, loff_t *offs)
258 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
261 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
262 void *buf, loff_t size, loff_t *offs,
265 return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
268 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
270 if (obd->obd_fsops->fs_setup)
271 return obd->obd_fsops->fs_setup(fs);
275 #endif /* __KERNEL__ */