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>
31 #include <linux/obd_class.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,
47 void *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
48 int niocount, struct niobuf_local *nb,
49 void *desc_private, int logs);
50 int (* fs_commit)(struct inode *inode, void *handle,int force_sync);
51 int (* fs_commit_async)(struct inode *inode, void *handle,
53 int (* fs_commit_wait)(struct inode *inode, void *handle);
54 int (* fs_setattr)(struct dentry *dentry, void *handle,
55 struct iattr *iattr, int do_trunc);
56 int (* fs_iocontrol)(struct inode *inode, struct file *file,
57 unsigned int cmd, unsigned long arg);
58 int (* fs_set_md)(struct inode *inode, void *handle, void *md,
60 int (* fs_get_md)(struct inode *inode, void *md, int size);
61 /* this method is needed to make IO operation fsfilt nature depend. */
62 int (* fs_send_bio)(int rw, struct inode *inode,struct kiobuf *bio);
63 ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
65 int (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
66 void *handle, fsfilt_cb_t cb_func,
68 int (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
69 int (* fs_sync)(struct super_block *sb);
70 int (* fs_map_inode_pages)(struct inode *inode, struct page **page,
71 int pages, unsigned long *blocks,
72 int *created, int create,
73 struct semaphore *sem);
74 int (* fs_prep_san_write)(struct inode *inode, long *blocks,
75 int nblocks, loff_t newsize);
76 int (* fs_write_record)(struct file *, void *, int size, loff_t *,
78 int (* fs_read_record)(struct file *, void *, int size, loff_t *);
79 int (* fs_setup)(struct super_block *sb);
80 int (* fs_get_op_len)(int, struct fsfilt_objinfo *, int);
83 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
84 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
85 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
86 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
88 #define FSFILT_OP_UNLINK 1
89 #define FSFILT_OP_RMDIR 2
90 #define FSFILT_OP_RENAME 3
91 #define FSFILT_OP_CREATE 4
92 #define FSFILT_OP_MKDIR 5
93 #define FSFILT_OP_SYMLINK 6
94 #define FSFILT_OP_MKNOD 7
95 #define FSFILT_OP_SETATTR 8
96 #define FSFILT_OP_LINK 9
97 #define FSFILT_OP_CANCEL_UNLINK 10
99 #define fsfilt_check_slow(start, timeout, msg) \
101 if (time_before(jiffies, start + 15 * HZ)) \
103 else if (time_before(jiffies, start + timeout / 2 * HZ)) \
104 CWARN("slow %s %lus\n", msg, (jiffies - start) / HZ); \
106 CERROR("slow %s %lus\n", msg, (jiffies - start) / HZ); \
109 static inline void *fsfilt_start_log(struct obd_device *obd,
110 struct inode *inode, int op,
111 struct obd_trans_info *oti, int logs)
113 unsigned long now = jiffies;
114 void *parent_handle = oti ? oti->oti_handle : NULL;
115 void *handle = obd->obd_fsops->fs_start(inode, op, parent_handle, logs);
116 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
119 if (parent_handle == NULL) {
120 oti->oti_handle = handle;
121 } else if (handle != parent_handle) {
122 CERROR("mismatch: parent %p, handle %p, oti %p\n",
123 parent_handle, handle, oti);
127 fsfilt_check_slow(now, obd_timeout, "journal start");
131 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
132 int op, struct obd_trans_info *oti)
134 return fsfilt_start_log(obd, inode, op, oti, 0);
137 static inline void *fsfilt_brw_start_log(struct obd_device *obd,
139 struct fsfilt_objinfo *fso,
140 int niocount, struct niobuf_local *nb,
141 struct obd_trans_info *oti, int logs)
143 unsigned long now = jiffies;
144 void *parent_handle = oti ? oti->oti_handle : NULL;
145 void *handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
146 parent_handle, logs);
147 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
150 if (parent_handle == NULL) {
151 oti->oti_handle = handle;
152 } else if (handle != parent_handle) {
153 CERROR("mismatch: parent %p, handle %p, oti %p\n",
154 parent_handle, handle, oti);
158 fsfilt_check_slow(now, obd_timeout, "journal start");
163 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
164 struct fsfilt_objinfo *fso, int niocount,
165 struct niobuf_local *nb,
166 struct obd_trans_info *oti)
168 return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
171 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
172 void *handle, int force_sync)
174 unsigned long now = jiffies;
175 int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
176 CDEBUG(D_INFO, "committing handle %p\n", handle);
178 fsfilt_check_slow(now, obd_timeout, "journal start");
183 static inline int fsfilt_commit_async(struct obd_device *obd,
184 struct inode *inode, void *handle,
187 unsigned long now = jiffies;
188 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
190 CDEBUG(D_INFO, "committing handle %p (async)\n", *wait_handle);
191 fsfilt_check_slow(now, obd_timeout, "journal start");
196 static inline int fsfilt_commit_wait(struct obd_device *obd,
197 struct inode *inode, void *handle)
199 unsigned long now = jiffies;
200 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
201 CDEBUG(D_INFO, "waiting for completion %p\n", handle);
202 fsfilt_check_slow(now, obd_timeout, "journal start");
206 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
207 void *handle, struct iattr *iattr,int do_trunc)
209 unsigned long now = jiffies;
211 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
212 fsfilt_check_slow(now, obd_timeout, "setattr");
216 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
217 struct file *file, unsigned int cmd,
220 return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
223 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
224 void *handle, void *md, int size)
226 return obd->obd_fsops->fs_set_md(inode, handle, md, size);
229 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
232 return obd->obd_fsops->fs_get_md(inode, md, size);
235 static inline int fsfilt_send_bio(int rw, struct obd_device *obd,
236 struct inode *inode, void *bio)
238 LASSERTF(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ, "%x\n", rw);
240 if (rw == OBD_BRW_READ)
241 return obd->obd_fsops->fs_send_bio(READ, inode, bio);
243 return obd->obd_fsops->fs_send_bio(WRITE, inode, bio);
246 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
247 struct file *file, char *buf,
248 size_t count, loff_t *offset)
250 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
253 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
254 void *handle, fsfilt_cb_t cb_func,
257 return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd,
258 handle, cb_func, cb_data);
261 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
262 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
263 unsigned long max_age)
267 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
268 if (time_before(obd->obd_osfs_age, max_age)) {
269 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
270 if (rc == 0) /* N.B. statfs can't really fail */
271 obd->obd_osfs_age = jiffies;
273 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
279 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
281 return obd->obd_fsops->fs_sync(sb);
284 static inline int fsfilt_map_inode_pages(struct obd_device *obd,
286 struct page **page, int pages,
287 unsigned long *blocks, int *created,
288 int create, struct semaphore *sem)
290 return obd->obd_fsops->fs_map_inode_pages(inode, page, pages, blocks,
291 created, create, sem);
294 static inline int fs_prep_san_write(struct obd_device *obd,
300 return obd->obd_fsops->fs_prep_san_write(inode, blocks,
304 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
305 void *buf, loff_t size, loff_t *offs)
307 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
310 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
311 void *buf, loff_t size, loff_t *offs,
314 return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
317 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
319 if (obd->obd_fsops->fs_setup)
320 return obd->obd_fsops->fs_setup(fs);
324 #endif /* __KERNEL__ */