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 ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
63 int (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
64 void *handle, fsfilt_cb_t cb_func,
66 int (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
67 int (* fs_sync)(struct super_block *sb);
68 int (* fs_map_inode_page)(struct inode *inode, struct page *page,
69 unsigned long *blocks, int *created,
71 int (* fs_prep_san_write)(struct inode *inode, long *blocks,
72 int nblocks, loff_t newsize);
73 int (* fs_write_record)(struct file *, void *, int size, loff_t *,
75 int (* fs_read_record)(struct file *, void *, int size, loff_t *);
76 int (* fs_setup)(struct super_block *sb);
77 int (* fs_get_op_len)(int, struct fsfilt_objinfo *, int);
80 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
81 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
82 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
83 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
85 #define FSFILT_OP_UNLINK 1
86 #define FSFILT_OP_RMDIR 2
87 #define FSFILT_OP_RENAME 3
88 #define FSFILT_OP_CREATE 4
89 #define FSFILT_OP_MKDIR 5
90 #define FSFILT_OP_SYMLINK 6
91 #define FSFILT_OP_MKNOD 7
92 #define FSFILT_OP_SETATTR 8
93 #define FSFILT_OP_LINK 9
94 #define FSFILT_OP_CANCEL_UNLINK 10
96 static inline void *fsfilt_start_log(struct obd_device *obd,
97 struct inode *inode, int op,
98 struct obd_trans_info *oti, int logs)
100 unsigned long now = jiffies;
101 void *parent_handle = oti ? oti->oti_handle : NULL;
102 void *handle = obd->obd_fsops->fs_start(inode, op, parent_handle, logs);
103 CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
106 if (parent_handle == NULL) {
107 oti->oti_handle = handle;
108 } else if (handle != parent_handle) {
109 CERROR("mismatch: parent %p, handle %p, oti %p\n",
110 parent_handle, handle, oti);
114 if (time_after(jiffies, now + 15 * HZ))
115 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
119 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
120 int op, struct obd_trans_info *oti)
122 return fsfilt_start_log(obd, inode, op, oti, 0);
125 static inline void *fsfilt_brw_start_log(struct obd_device *obd,
127 struct fsfilt_objinfo *fso,
128 int niocount, struct niobuf_local *nb,
129 struct obd_trans_info *oti, int logs)
131 unsigned long now = jiffies;
132 void *parent_handle = oti ? oti->oti_handle : NULL;
133 void *handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
134 parent_handle, logs);
135 CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
138 if (parent_handle == NULL) {
139 oti->oti_handle = handle;
140 } else if (handle != parent_handle) {
141 CERROR("mismatch: parent %p, handle %p, oti %p\n",
142 parent_handle, handle, oti);
146 if (time_after(jiffies, now + 15 * HZ))
147 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
152 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
153 struct fsfilt_objinfo *fso, int niocount,
154 struct niobuf_local *nb,
155 struct obd_trans_info *oti)
157 return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
160 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
161 void *handle, int force_sync)
163 unsigned long now = jiffies;
164 int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
165 CDEBUG(D_HA, "committing handle %p\n", handle);
167 if (time_after(jiffies, now + 15 * HZ))
168 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
173 static inline int fsfilt_commit_async(struct obd_device *obd,
174 struct inode *inode, void *handle,
177 unsigned long now = jiffies;
178 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
180 CDEBUG(D_HA, "committing handle %p (async)\n", *wait_handle);
181 if (time_after(jiffies, now + 15 * HZ))
182 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
187 static inline int fsfilt_commit_wait(struct obd_device *obd,
188 struct inode *inode, void *handle)
190 unsigned long now = jiffies;
191 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
192 CDEBUG(D_HA, "waiting for completion %p\n", handle);
193 if (time_after(jiffies, now + 15 * HZ))
194 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
198 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
199 void *handle, struct iattr *iattr,int do_trunc)
201 unsigned long now = jiffies;
203 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
204 if (time_after(jiffies, now + 15 * HZ))
205 CERROR("long setattr time %lus\n", (jiffies - now) / HZ);
209 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
210 struct file *file, unsigned int cmd,
213 return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
216 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
217 void *handle, void *md, int size)
219 return obd->obd_fsops->fs_set_md(inode, handle, md, size);
222 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
225 return obd->obd_fsops->fs_get_md(inode, md, size);
228 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
229 struct file *file, char *buf,
230 size_t count, loff_t *offset)
232 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
235 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
236 void *handle, fsfilt_cb_t cb_func,
239 return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd,
240 handle, cb_func, cb_data);
243 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
244 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
245 unsigned long max_age)
249 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
250 if (time_before(obd->obd_osfs_age, max_age)) {
251 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
252 if (rc == 0) /* N.B. statfs can't really fail */
253 obd->obd_osfs_age = jiffies;
255 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
261 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
263 return obd->obd_fsops->fs_sync(sb);
266 static inline int fsfilt_map_inode_page(struct obd_device *obd,
267 struct inode *inode, struct page *page,
268 unsigned long *blocks, int *created,
271 return obd->obd_fsops->fs_map_inode_page(inode, page, blocks, created,
275 static inline int fs_prep_san_write(struct obd_device *obd,
281 return obd->obd_fsops->fs_prep_san_write(inode, blocks,
285 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
286 void *buf, loff_t size, loff_t *offs)
288 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
291 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
292 void *buf, loff_t size, loff_t *offs,
295 return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
298 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
300 if (obd->obd_fsops->fs_setup)
301 return obd->obd_fsops->fs_setup(fs);
305 #endif /* __KERNEL__ */