4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lustre/include/linux/lustre_fsfilt.h
36 * Filesystem interface helper.
39 #ifndef _LINUX_LUSTRE_FSFILT_H
40 #define _LINUX_LUSTRE_FSFILT_H
42 #ifndef _LUSTRE_FSFILT_H
43 #error Do not #include this file directly. #include <lustre_fsfilt.h> instead
49 #include <obd_class.h>
51 typedef void (*fsfilt_cb_t)(struct obd_device *obd, __u64 last_rcvd,
52 void *data, int error);
54 struct fsfilt_objinfo {
55 struct dentry *fso_dentry;
65 struct fsfilt_operations {
67 cfs_module_t *fs_owner;
69 char *(* fs_getlabel)(struct super_block *sb);
70 int (* fs_setlabel)(struct super_block *sb, char *label);
71 char *(* fs_uuid)(struct super_block *sb);
72 void *(* fs_start)(struct inode *inode, int op, void *desc_private,
74 void *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
75 int niocount, struct niobuf_local *nb,
76 void *desc_private, int logs);
77 int (* fs_extend)(struct inode *inode, unsigned nblocks, void *h);
78 int (* fs_commit)(struct inode *inode, void *handle,int force_sync);
79 int (* fs_commit_async)(struct inode *inode, void *handle,
81 int (* fs_commit_wait)(struct inode *inode, void *handle);
82 int (* fs_setattr)(struct dentry *dentry, void *handle,
83 struct iattr *iattr, int do_trunc);
84 int (* fs_iocontrol)(struct inode *inode, struct file *file,
85 unsigned int cmd, unsigned long arg);
86 int (* fs_set_md)(struct inode *inode, void *handle, void *md,
87 int size, const char *name);
88 int (* fs_get_md)(struct inode *inode, void *md, int size,
91 * this method is needed to make IO operation fsfilt nature depend.
93 * This operation maybe synchronous or asynchronous.
95 * Return convention: positive number of bytes written (synchronously)
96 * on success. Negative errno value on failure. Zero if asynchronous
97 * IO was submitted successfully.
100 int (* fs_send_bio)(int rw, struct inode *inode, struct bio *bio);
101 ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
103 int (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
104 void *handle, fsfilt_cb_t cb_func,
106 int (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
107 int (* fs_sync)(struct super_block *sb);
108 int (* fs_map_inode_pages)(struct inode *inode, struct page **page,
109 int pages, unsigned long *blocks,
110 int *created, int create,
112 int (* fs_write_record)(struct file *, void *, int size, loff_t *,
114 int (* fs_read_record)(struct file *, void *, int size, loff_t *);
115 int (* fs_setup)(struct super_block *sb);
116 int (* fs_get_op_len)(int, struct fsfilt_objinfo *, int);
117 __u64 (* fs_get_version) (struct inode *inode);
118 __u64 (* fs_set_version) (struct inode *inode, __u64 new_version);
119 lvfs_sbdev_type (* fs_journal_sbdev)(struct super_block *sb);
120 struct dentry *(* fs_fid2dentry)(struct vfsmount *mnt,
121 struct fsfilt_fid *fid,
125 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
126 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
127 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
128 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
130 static inline char *fsfilt_get_label(struct obd_device *obd,
131 struct super_block *sb)
133 if (obd->obd_fsops->fs_getlabel == NULL)
135 if (obd->obd_fsops->fs_getlabel(sb)[0] == '\0')
138 return obd->obd_fsops->fs_getlabel(sb);
141 static inline int fsfilt_set_label(struct obd_device *obd,
142 struct super_block *sb, char *label)
144 if (obd->obd_fsops->fs_setlabel == NULL)
146 return (obd->obd_fsops->fs_setlabel(sb, label));
149 static inline __u8 *fsfilt_uuid(struct obd_device *obd, struct super_block *sb)
151 if (obd->obd_fsops->fs_uuid == NULL)
154 return obd->obd_fsops->fs_uuid(sb);
157 static inline lvfs_sbdev_type fsfilt_journal_sbdev(struct obd_device *obd,
158 struct super_block *sb)
160 if (obd && obd->obd_fsops && obd->obd_fsops->fs_journal_sbdev)
161 return obd->obd_fsops->fs_journal_sbdev(sb);
162 return (lvfs_sbdev_type)0;
165 #define FSFILT_OP_UNLINK 1
166 #define FSFILT_OP_RMDIR 2
167 #define FSFILT_OP_RENAME 3
168 #define FSFILT_OP_CREATE 4
169 #define FSFILT_OP_MKDIR 5
170 #define FSFILT_OP_SYMLINK 6
171 #define FSFILT_OP_MKNOD 7
172 #define FSFILT_OP_SETATTR 8
173 #define FSFILT_OP_LINK 9
174 #define FSFILT_OP_CANCEL_UNLINK 10
175 #define FSFILT_OP_NOOP 15
176 #define FSFILT_OP_UNLINK_PARTIAL_CHILD 21
177 #define FSFILT_OP_UNLINK_PARTIAL_PARENT 22
178 #define FSFILT_OP_CREATE_PARTIAL_CHILD 23
180 #define __fsfilt_check_slow(obd, start, msg) \
182 if (cfs_time_before(jiffies, start + 15 * CFS_HZ)) \
184 else if (cfs_time_before(jiffies, start + 30 * CFS_HZ)) \
185 CDEBUG(D_VFSTRACE, "%s: slow %s %lus\n", obd->obd_name, \
186 msg, (jiffies-start) / CFS_HZ); \
187 else if (cfs_time_before(jiffies, start + DISK_TIMEOUT * CFS_HZ)) \
188 CWARN("%s: slow %s %lus\n", obd->obd_name, msg, \
189 (jiffies - start) / CFS_HZ); \
191 CERROR("%s: slow %s %lus\n", obd->obd_name, msg, \
192 (jiffies - start) / CFS_HZ); \
195 #define fsfilt_check_slow(obd, start, msg) \
197 __fsfilt_check_slow(obd, start, msg); \
201 static inline void *fsfilt_start_log(struct obd_device *obd,
202 struct inode *inode, int op,
203 struct obd_trans_info *oti, int logs)
205 unsigned long now = jiffies;
206 void *parent_handle = oti ? oti->oti_handle : NULL;
209 handle = obd->obd_fsops->fs_start(inode, op, parent_handle, logs);
210 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
213 if (parent_handle == NULL) {
214 oti->oti_handle = handle;
215 } else if (handle != parent_handle) {
216 CERROR("mismatch: parent %p, handle %p, oti %p\n",
217 parent_handle, handle, oti);
221 fsfilt_check_slow(obd, now, "journal start");
225 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
226 int op, struct obd_trans_info *oti)
228 return fsfilt_start_log(obd, inode, op, oti, 0);
231 static inline void *fsfilt_brw_start_log(struct obd_device *obd, int objcount,
232 struct fsfilt_objinfo *fso,
233 int niocount, struct niobuf_local *nb,
234 struct obd_trans_info *oti, int logs)
236 unsigned long now = jiffies;
237 void *parent_handle = oti ? oti->oti_handle : NULL;
240 handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
241 parent_handle, logs);
242 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
245 if (parent_handle == NULL) {
246 oti->oti_handle = handle;
247 } else if (handle != parent_handle) {
248 CERROR("mismatch: parent %p, handle %p, oti %p\n",
249 parent_handle, handle, oti);
253 fsfilt_check_slow(obd, now, "journal start");
258 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
259 struct fsfilt_objinfo *fso, int niocount,
260 struct niobuf_local *nb,
261 struct obd_trans_info *oti)
263 return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
266 static inline int fsfilt_extend(struct obd_device *obd, struct inode *inode,
267 unsigned int nblocks, void *handle)
269 unsigned long now = jiffies;
270 int rc = obd->obd_fsops->fs_extend(inode, nblocks, handle);
271 CDEBUG(D_INFO, "extending handle %p with %u blocks\n", handle, nblocks);
273 fsfilt_check_slow(obd, now, "journal extend");
278 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
279 void *handle, int force_sync)
281 unsigned long now = jiffies;
282 int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
283 CDEBUG(D_INFO, "committing handle %p\n", handle);
285 fsfilt_check_slow(obd, now, "journal start");
290 static inline int fsfilt_commit_async(struct obd_device *obd,
291 struct inode *inode, void *handle,
294 unsigned long now = jiffies;
295 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
297 CDEBUG(D_INFO, "committing handle %p (async)\n", *wait_handle);
298 fsfilt_check_slow(obd, now, "journal start");
303 static inline int fsfilt_commit_wait(struct obd_device *obd,
304 struct inode *inode, void *handle)
306 unsigned long now = jiffies;
307 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
308 CDEBUG(D_INFO, "waiting for completion %p\n", handle);
309 fsfilt_check_slow(obd, now, "journal start");
313 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
314 void *handle, struct iattr *iattr,int do_trunc)
316 unsigned long now = jiffies;
318 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
319 fsfilt_check_slow(obd, now, "setattr");
323 static inline int fsfilt_iocontrol(struct obd_device *obd, struct dentry *dentry,
324 unsigned int cmd, unsigned long arg)
326 struct file *dummy_file = NULL;
329 OBD_ALLOC_PTR(dummy_file);
333 dummy_file->f_dentry = dentry;
334 dummy_file->f_vfsmnt = obd->u.obt.obt_vfsmnt;
336 ret = obd->obd_fsops->fs_iocontrol(dentry->d_inode, dummy_file, cmd,
339 OBD_FREE_PTR(dummy_file);
343 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
344 void *handle, void *md, int size,
347 return obd->obd_fsops->fs_set_md(inode, handle, md, size, name);
350 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
351 void *md, int size, const char *name)
353 return obd->obd_fsops->fs_get_md(inode, md, size, name);
356 static inline int fsfilt_send_bio(int rw, struct obd_device *obd,
357 struct inode *inode, void *bio)
359 LASSERTF(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ, "%x\n", rw);
361 if (rw == OBD_BRW_READ)
362 return obd->obd_fsops->fs_send_bio(READ, inode, bio);
363 return obd->obd_fsops->fs_send_bio(WRITE, inode, bio);
366 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
367 struct file *file, char *buf,
368 size_t count, loff_t *offset)
370 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
373 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
374 void *handle, fsfilt_cb_t cb_func,
377 return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd,
378 handle, cb_func, cb_data);
381 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
382 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
387 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
388 obd->obd_osfs_age, max_age);
389 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
390 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
391 if (rc == 0) /* N.B. statfs can't really fail */
392 obd->obd_osfs_age = cfs_time_current_64();
394 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
400 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
402 return obd->obd_fsops->fs_sync(sb);
405 static inline int fsfilt_map_inode_pages(struct obd_device *obd,
407 struct page **page, int pages,
408 unsigned long *blocks, int *created,
409 int create, cfs_mutex_t *mutex)
411 return obd->obd_fsops->fs_map_inode_pages(inode, page, pages, blocks,
412 created, create, mutex);
415 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
416 void *buf, loff_t size, loff_t *offs)
418 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
421 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
422 void *buf, loff_t size, loff_t *offs,
425 return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
428 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
430 if (obd->obd_fsops->fs_setup)
431 return obd->obd_fsops->fs_setup(fs);
435 static inline __u64 fsfilt_set_version(struct obd_device *obd,
436 struct inode *inode, __u64 new_version)
438 if (obd->obd_fsops->fs_set_version)
439 return obd->obd_fsops->fs_set_version(inode, new_version);
443 static inline __u64 fsfilt_get_version(struct obd_device *obd,
446 if (obd->obd_fsops->fs_get_version)
447 return obd->obd_fsops->fs_get_version(inode);
451 static inline struct dentry *fsfilt_fid2dentry(struct obd_device *obd,
452 struct vfsmount *mnt,
453 struct fsfilt_fid *fid,
456 if (obd->obd_fsops->fs_fid2dentry)
457 return obd->obd_fsops->fs_fid2dentry(mnt, fid, ignore_gen);
458 return ERR_PTR(-EOPNOTSUPP);
461 #endif /* __KERNEL__ */