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_quotactl)(struct super_block *sb,
101 struct obd_quotactl *oqctl);
102 int (* fs_quotacheck)(struct super_block *sb,
103 struct obd_quotactl *oqctl);
104 __u64 (* fs_get_version) (struct inode *inode);
105 __u64 (* fs_set_version) (struct inode *inode, __u64 new_version);
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 #define fsfilt_check_slow(obd, start, timeout, msg) \
184 __fsfilt_check_slow(obd, start, timeout, msg); \
188 static inline void *fsfilt_start_log(struct obd_device *obd,
189 struct inode *inode, int op,
190 struct obd_trans_info *oti, int logs)
192 unsigned long now = jiffies;
193 void *parent_handle = oti ? oti->oti_handle : NULL;
197 return ERR_PTR(-EROFS);
199 handle = obd->obd_fsops->fs_start(inode, op, parent_handle, logs);
200 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
203 if (parent_handle == NULL) {
204 oti->oti_handle = handle;
205 } else if (handle != parent_handle) {
206 CERROR("mismatch: parent %p, handle %p, oti %p\n",
207 parent_handle, handle, oti);
211 fsfilt_check_slow(obd, now, obd_timeout, "journal start");
215 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
216 int op, struct obd_trans_info *oti)
218 return fsfilt_start_log(obd, inode, op, oti, 0);
221 static inline void *fsfilt_brw_start_log(struct obd_device *obd, int objcount,
222 struct fsfilt_objinfo *fso,
223 int niocount, struct niobuf_local *nb,
224 struct obd_trans_info *oti, int logs)
226 unsigned long now = jiffies;
227 void *parent_handle = oti ? oti->oti_handle : NULL;
231 return ERR_PTR(-EROFS);
233 handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
234 parent_handle, logs);
235 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
238 if (parent_handle == NULL) {
239 oti->oti_handle = handle;
240 } else if (handle != parent_handle) {
241 CERROR("mismatch: parent %p, handle %p, oti %p\n",
242 parent_handle, handle, oti);
246 fsfilt_check_slow(obd, now, obd_timeout, "journal start");
251 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
252 struct fsfilt_objinfo *fso, int niocount,
253 struct niobuf_local *nb,
254 struct obd_trans_info *oti)
256 return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
259 static inline int fsfilt_extend(struct obd_device *obd, struct inode *inode,
260 unsigned int nblocks, void *handle)
262 unsigned long now = jiffies;
263 int rc = obd->obd_fsops->fs_extend(inode, nblocks, handle);
264 CDEBUG(D_INFO, "extending handle %p with %u blocks\n", handle, nblocks);
266 fsfilt_check_slow(obd, now, obd_timeout, "journal extend");
271 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
272 void *handle, int force_sync)
274 unsigned long now = jiffies;
275 int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
276 CDEBUG(D_INFO, "committing handle %p\n", handle);
278 fsfilt_check_slow(obd, now, obd_timeout, "journal start");
283 static inline int fsfilt_commit_async(struct obd_device *obd,
284 struct inode *inode, void *handle,
287 unsigned long now = jiffies;
288 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
290 CDEBUG(D_INFO, "committing handle %p (async)\n", *wait_handle);
291 fsfilt_check_slow(obd, now, obd_timeout, "journal start");
296 static inline int fsfilt_commit_wait(struct obd_device *obd,
297 struct inode *inode, void *handle)
299 unsigned long now = jiffies;
300 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
301 CDEBUG(D_INFO, "waiting for completion %p\n", handle);
302 fsfilt_check_slow(obd, now, obd_timeout, "journal start");
306 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
307 void *handle, struct iattr *iattr,int do_trunc)
309 unsigned long now = jiffies;
311 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
312 fsfilt_check_slow(obd, now, obd_timeout, "setattr");
316 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
317 struct file *file, unsigned int cmd,
320 return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
323 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
324 void *handle, void *md, int size,
327 return obd->obd_fsops->fs_set_md(inode, handle, md, size, name);
330 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
331 void *md, int size, const char *name)
333 return obd->obd_fsops->fs_get_md(inode, md, size, name);
336 static inline int fsfilt_send_bio(int rw, struct obd_device *obd,
337 struct inode *inode, void *bio)
339 LASSERTF(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ, "%x\n", rw);
341 if (rw == OBD_BRW_READ)
342 return obd->obd_fsops->fs_send_bio(READ, inode, bio);
343 return obd->obd_fsops->fs_send_bio(WRITE, inode, bio);
346 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
347 struct file *file, char *buf,
348 size_t count, loff_t *offset)
350 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
353 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
354 void *handle, fsfilt_cb_t cb_func,
357 return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd,
358 handle, cb_func, cb_data);
361 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
362 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
367 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
368 obd->obd_osfs_age, max_age);
369 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
370 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
371 if (rc == 0) /* N.B. statfs can't really fail */
372 obd->obd_osfs_age = cfs_time_current_64();
374 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
380 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
382 return obd->obd_fsops->fs_sync(sb);
385 static inline int fsfilt_quotacheck(struct obd_device *obd,
386 struct super_block *sb,
387 struct obd_quotactl *oqctl)
389 if (obd->obd_fsops->fs_quotacheck)
390 return obd->obd_fsops->fs_quotacheck(sb, oqctl);
394 static inline int fsfilt_quotactl(struct obd_device *obd,
395 struct super_block *sb,
396 struct obd_quotactl *oqctl)
398 if (obd->obd_fsops->fs_quotactl)
399 return obd->obd_fsops->fs_quotactl(sb, oqctl);
403 static inline int fsfilt_quotainfo(struct obd_device *obd,
404 struct lustre_quota_info *lqi,
407 if (obd->obd_fsops->fs_quotainfo)
408 return obd->obd_fsops->fs_quotainfo(lqi, type, cmd);
412 static inline int fsfilt_qids(struct obd_device *obd, struct file *file,
413 struct inode *inode, int type,
414 struct list_head *list)
416 if (obd->obd_fsops->fs_qids)
417 return obd->obd_fsops->fs_qids(file, inode, type, list);
421 static inline int fsfilt_dquot(struct obd_device *obd,
422 struct lustre_dquot *dquot, int cmd)
424 if (obd->obd_fsops->fs_dquot)
425 return obd->obd_fsops->fs_dquot(dquot, cmd);
429 static inline int fsfilt_map_inode_pages(struct obd_device *obd,
431 struct page **page, int pages,
432 unsigned long *blocks, int *created,
433 int create, struct semaphore *sem)
435 return obd->obd_fsops->fs_map_inode_pages(inode, page, pages, blocks,
436 created, create, sem);
439 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
440 void *buf, loff_t size, loff_t *offs)
442 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
445 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
446 void *buf, loff_t size, loff_t *offs,
449 return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
452 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
454 if (obd->obd_fsops->fs_setup)
455 return obd->obd_fsops->fs_setup(fs);
459 static inline __u64 fsfilt_set_version(struct obd_device *obd,
460 struct inode *inode, __u64 new_version)
462 if (obd->obd_fsops->fs_set_version)
463 return obd->obd_fsops->fs_set_version(inode, new_version);
467 static inline __u64 fsfilt_get_version(struct obd_device *obd,
470 if (obd->obd_fsops->fs_set_version)
471 return obd->obd_fsops->fs_get_version(inode);
475 #endif /* __KERNEL__ */