1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2004 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 _LINUX_LUSTRE_FSFILT_H
26 #define _LINUX_LUSTRE_FSFILT_H
28 #ifndef _LUSTRE_FSFILT_H
29 #error Do not #include this file directly. #include <lustre_fsfilt.h> instead
35 #include <obd_class.h>
37 typedef void (*fsfilt_cb_t)(struct obd_device *obd, __u64 last_rcvd,
38 void *data, int error);
40 struct fsfilt_objinfo {
41 struct dentry *fso_dentry;
45 #define XATTR_LUSTRE_MDS_LOV_EA "lov"
48 struct fsfilt_operations {
49 struct list_head fs_list;
50 struct module *fs_owner;
52 char *(* fs_getlabel)(struct super_block *sb);
53 int (* fs_setlabel)(struct super_block *sb, char *label);
54 char *(* fs_uuid)(struct super_block *sb);
55 void *(* fs_start)(struct inode *inode, int op, void *desc_private,
57 void *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
58 int niocount, struct niobuf_local *nb,
59 void *desc_private, int logs);
60 int (* fs_extend)(struct inode *inode, unsigned nblocks, void *h);
61 int (* fs_commit)(struct inode *inode, void *handle,int force_sync);
62 int (* fs_commit_async)(struct inode *inode, void *handle,
64 int (* fs_commit_wait)(struct inode *inode, void *handle);
65 int (* fs_setattr)(struct dentry *dentry, void *handle,
66 struct iattr *iattr, int do_trunc);
67 int (* fs_iocontrol)(struct inode *inode, struct file *file,
68 unsigned int cmd, unsigned long arg);
69 int (* fs_set_md)(struct inode *inode, void *handle, void *md,
70 int size, const char *name);
71 int (* fs_get_md)(struct inode *inode, void *md, int size,
74 * this method is needed to make IO operation fsfilt nature depend.
76 * This operation maybe synchronous or asynchronous.
78 * Return convention: positive number of bytes written (synchronously)
79 * on success. Negative errno value on failure. Zero if asynchronous
80 * IO was submitted successfully.
83 int (* fs_send_bio)(int rw, struct inode *inode,struct kiobuf *bio);
84 ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
86 int (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
87 void *handle, fsfilt_cb_t cb_func,
89 int (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
90 int (* fs_sync)(struct super_block *sb);
91 int (* fs_map_inode_pages)(struct inode *inode, struct page **page,
92 int pages, unsigned long *blocks,
93 int *created, int create,
94 struct semaphore *sem);
95 int (* fs_write_record)(struct file *, void *, int size, loff_t *,
97 int (* fs_read_record)(struct file *, void *, int size, loff_t *);
98 int (* fs_setup)(struct super_block *sb);
99 int (* fs_get_op_len)(int, struct fsfilt_objinfo *, int);
100 int (* fs_quotacheck)(struct super_block *sb,
101 struct obd_quotactl *oqctl);
102 __u64 (* fs_get_version) (struct inode *inode);
103 __u64 (* fs_set_version) (struct inode *inode, __u64 new_version);
104 int (* fs_quotactl)(struct super_block *sb,
105 struct obd_quotactl *oqctl);
106 int (* fs_quotainfo)(struct lustre_quota_info *lqi, int type,
108 int (* fs_qids)(struct file *file, struct inode *inode, int type,
109 struct list_head *list);
110 int (* fs_dquot)(struct lustre_dquot *dquot, int cmd);
111 lvfs_sbdev_type (* fs_journal_sbdev)(struct super_block *sb);
114 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
115 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
116 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
117 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
119 static inline char *fsfilt_get_label(struct obd_device *obd,
120 struct super_block *sb)
122 if (obd->obd_fsops->fs_getlabel == NULL)
124 if (obd->obd_fsops->fs_getlabel(sb)[0] == '\0')
127 return obd->obd_fsops->fs_getlabel(sb);
130 static inline int fsfilt_set_label(struct obd_device *obd,
131 struct super_block *sb, char *label)
133 if (obd->obd_fsops->fs_setlabel == NULL)
135 return (obd->obd_fsops->fs_setlabel(sb, label));
138 static inline __u8 *fsfilt_uuid(struct obd_device *obd, struct super_block *sb)
140 if (obd->obd_fsops->fs_uuid == NULL)
143 return obd->obd_fsops->fs_uuid(sb);
146 static inline lvfs_sbdev_type fsfilt_journal_sbdev(struct obd_device *obd,
147 struct super_block *sb)
149 if (obd && obd->obd_fsops && obd->obd_fsops->fs_journal_sbdev)
150 return obd->obd_fsops->fs_journal_sbdev(sb);
151 return (lvfs_sbdev_type)0;
154 #define FSFILT_OP_UNLINK 1
155 #define FSFILT_OP_RMDIR 2
156 #define FSFILT_OP_RENAME 3
157 #define FSFILT_OP_CREATE 4
158 #define FSFILT_OP_MKDIR 5
159 #define FSFILT_OP_SYMLINK 6
160 #define FSFILT_OP_MKNOD 7
161 #define FSFILT_OP_SETATTR 8
162 #define FSFILT_OP_LINK 9
163 #define FSFILT_OP_CANCEL_UNLINK 10
164 #define FSFILT_OP_JOIN 11
165 #define FSFILT_OP_NOOP 15
167 #define fsfilt_check_slow(obd, start, timeout, msg) \
169 if (time_before(jiffies, start + 15 * HZ)) \
171 else if (time_before(jiffies, start + 30 * HZ)) \
172 CDEBUG(D_VFSTRACE, "%s: slow %s %lus\n", obd->obd_name, \
173 msg, (jiffies-start) / HZ); \
174 else if (time_before(jiffies, start + timeout / 2 * HZ)) \
175 CWARN("%s: slow %s %lus\n", obd->obd_name, msg, \
176 (jiffies - start) / HZ); \
178 CERROR("%s: slow %s %lus\n", obd->obd_name, msg, \
179 (jiffies - start) / HZ); \
182 static inline void *fsfilt_start_log(struct obd_device *obd,
183 struct inode *inode, int op,
184 struct obd_trans_info *oti, int logs)
186 unsigned long now = jiffies;
187 void *parent_handle = oti ? oti->oti_handle : NULL;
191 return ERR_PTR(-EROFS);
193 handle = obd->obd_fsops->fs_start(inode, op, parent_handle, logs);
194 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
197 if (parent_handle == NULL) {
198 oti->oti_handle = handle;
199 } else if (handle != parent_handle) {
200 CERROR("mismatch: parent %p, handle %p, oti %p\n",
201 parent_handle, handle, oti);
205 fsfilt_check_slow(obd, now, obd_timeout, "journal start");
209 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
210 int op, struct obd_trans_info *oti)
212 return fsfilt_start_log(obd, inode, op, oti, 0);
215 static inline void *fsfilt_brw_start_log(struct obd_device *obd, int objcount,
216 struct fsfilt_objinfo *fso,
217 int niocount, struct niobuf_local *nb,
218 struct obd_trans_info *oti, int logs)
220 unsigned long now = jiffies;
221 void *parent_handle = oti ? oti->oti_handle : NULL;
225 return ERR_PTR(-EROFS);
227 handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
228 parent_handle, logs);
229 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
232 if (parent_handle == NULL) {
233 oti->oti_handle = handle;
234 } else if (handle != parent_handle) {
235 CERROR("mismatch: parent %p, handle %p, oti %p\n",
236 parent_handle, handle, oti);
240 fsfilt_check_slow(obd, now, obd_timeout, "journal start");
245 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
246 struct fsfilt_objinfo *fso, int niocount,
247 struct niobuf_local *nb,
248 struct obd_trans_info *oti)
250 return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
253 static inline int fsfilt_extend(struct obd_device *obd, struct inode *inode,
254 unsigned int nblocks, void *handle)
256 unsigned long now = jiffies;
257 int rc = obd->obd_fsops->fs_extend(inode, nblocks, handle);
258 CDEBUG(D_INFO, "extending handle %p with %u blocks\n", handle, nblocks);
260 fsfilt_check_slow(obd, now, obd_timeout, "journal extend");
265 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
266 void *handle, int force_sync)
268 unsigned long now = jiffies;
269 int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
270 CDEBUG(D_INFO, "committing handle %p\n", handle);
272 fsfilt_check_slow(obd, now, obd_timeout, "journal start");
277 static inline int fsfilt_commit_async(struct obd_device *obd,
278 struct inode *inode, void *handle,
281 unsigned long now = jiffies;
282 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
284 CDEBUG(D_INFO, "committing handle %p (async)\n", *wait_handle);
285 fsfilt_check_slow(obd, now, obd_timeout, "journal start");
290 static inline int fsfilt_commit_wait(struct obd_device *obd,
291 struct inode *inode, void *handle)
293 unsigned long now = jiffies;
294 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
295 CDEBUG(D_INFO, "waiting for completion %p\n", handle);
296 fsfilt_check_slow(obd, now, obd_timeout, "journal start");
300 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
301 void *handle, struct iattr *iattr,int do_trunc)
303 unsigned long now = jiffies;
305 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
306 fsfilt_check_slow(obd, now, obd_timeout, "setattr");
310 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
311 struct file *file, unsigned int cmd,
314 return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
317 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
318 void *handle, void *md, int size,
321 return obd->obd_fsops->fs_set_md(inode, handle, md, size, name);
324 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
325 void *md, int size, const char *name)
327 return obd->obd_fsops->fs_get_md(inode, md, size, name);
330 static inline int fsfilt_send_bio(int rw, struct obd_device *obd,
331 struct inode *inode, void *bio)
333 LASSERTF(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ, "%x\n", rw);
335 if (rw == OBD_BRW_READ)
336 return obd->obd_fsops->fs_send_bio(READ, inode, bio);
337 return obd->obd_fsops->fs_send_bio(WRITE, inode, bio);
340 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
341 struct file *file, char *buf,
342 size_t count, loff_t *offset)
344 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
347 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
348 void *handle, fsfilt_cb_t cb_func,
351 return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd,
352 handle, cb_func, cb_data);
355 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
356 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
361 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
362 obd->obd_osfs_age, max_age);
363 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
364 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
365 if (rc == 0) /* N.B. statfs can't really fail */
366 obd->obd_osfs_age = cfs_time_current_64();
368 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
374 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
376 return obd->obd_fsops->fs_sync(sb);
379 static inline int fsfilt_quotacheck(struct obd_device *obd,
380 struct super_block *sb,
381 struct obd_quotactl *oqctl)
383 if (obd->obd_fsops->fs_quotacheck)
384 return obd->obd_fsops->fs_quotacheck(sb, oqctl);
388 static inline int fsfilt_quotactl(struct obd_device *obd,
389 struct super_block *sb,
390 struct obd_quotactl *oqctl)
392 if (obd->obd_fsops->fs_quotactl)
393 return obd->obd_fsops->fs_quotactl(sb, oqctl);
397 static inline int fsfilt_quotainfo(struct obd_device *obd,
398 struct lustre_quota_info *lqi,
401 if (obd->obd_fsops->fs_quotainfo)
402 return obd->obd_fsops->fs_quotainfo(lqi, type, cmd);
406 static inline int fsfilt_qids(struct obd_device *obd, struct file *file,
407 struct inode *inode, int type,
408 struct list_head *list)
410 if (obd->obd_fsops->fs_qids)
411 return obd->obd_fsops->fs_qids(file, inode, type, list);
415 static inline int fsfilt_dquot(struct obd_device *obd,
416 struct lustre_dquot *dquot, int cmd)
418 if (obd->obd_fsops->fs_dquot)
419 return obd->obd_fsops->fs_dquot(dquot, cmd);
423 static inline int fsfilt_map_inode_pages(struct obd_device *obd,
425 struct page **page, int pages,
426 unsigned long *blocks, int *created,
427 int create, struct semaphore *sem)
429 return obd->obd_fsops->fs_map_inode_pages(inode, page, pages, blocks,
430 created, create, sem);
433 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
434 void *buf, loff_t size, loff_t *offs)
436 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
439 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
440 void *buf, loff_t size, loff_t *offs,
443 return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
446 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
448 if (obd->obd_fsops->fs_setup)
449 return obd->obd_fsops->fs_setup(fs);
453 static inline __u64 fsfilt_set_version(struct obd_device *obd,
454 struct inode *inode, __u64 new_version)
456 if (obd->obd_fsops->fs_set_version)
457 return obd->obd_fsops->fs_set_version(inode, new_version);
461 static inline __u64 fsfilt_get_version(struct obd_device *obd,
464 if (obd->obd_fsops->fs_set_version)
465 return obd->obd_fsops->fs_get_version(inode);
469 #endif /* __KERNEL__ */