1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/include/linux/lustre_fsfilt.h
38 * Filesystem interface helper.
41 #ifndef _LINUX_LUSTRE_FSFILT_H
42 #define _LINUX_LUSTRE_FSFILT_H
44 #ifndef _LUSTRE_FSFILT_H
45 #error Do not #include this file directly. #include <lustre_fsfilt.h> instead
51 #include <obd_class.h>
53 typedef void (*fsfilt_cb_t)(struct obd_device *obd, __u64 last_rcvd,
54 void *data, int error);
56 struct fsfilt_objinfo {
57 struct dentry *fso_dentry;
62 struct fsfilt_operations {
63 struct list_head fs_list;
64 struct module *fs_owner;
66 char *(* fs_getlabel)(struct super_block *sb);
67 int (* fs_setlabel)(struct super_block *sb, char *label);
68 char *(* fs_uuid)(struct super_block *sb);
69 void *(* fs_start)(struct inode *inode, int op, void *desc_private,
71 void *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
72 int niocount, struct niobuf_local *nb,
73 void *desc_private, int logs);
74 int (* fs_extend)(struct inode *inode, unsigned nblocks, void *h);
75 int (* fs_commit)(struct inode *inode, void *handle,int force_sync);
76 int (* fs_commit_async)(struct inode *inode, void *handle,
78 int (* fs_commit_wait)(struct inode *inode, void *handle);
79 int (* fs_setattr)(struct dentry *dentry, void *handle,
80 struct iattr *iattr, int do_trunc);
81 int (* fs_iocontrol)(struct inode *inode, struct file *file,
82 unsigned int cmd, unsigned long arg);
83 int (* fs_set_md)(struct inode *inode, void *handle, void *md,
84 int size, const char *name);
85 int (* fs_get_md)(struct inode *inode, void *md, int size,
88 * this method is needed to make IO operation fsfilt nature depend.
90 * This operation maybe synchronous or asynchronous.
92 * Return convention: positive number of bytes written (synchronously)
93 * on success. Negative errno value on failure. Zero if asynchronous
94 * IO was submitted successfully.
97 int (* fs_send_bio)(int rw, struct inode *inode,struct kiobuf *bio);
98 ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
100 int (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
101 void *handle, fsfilt_cb_t cb_func,
103 int (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
104 int (* fs_sync)(struct super_block *sb);
105 int (* fs_map_inode_pages)(struct inode *inode, struct page **page,
106 int pages, unsigned long *blocks,
107 int *created, int create,
108 struct semaphore *sem);
109 int (* fs_write_record)(struct file *, void *, int size, loff_t *,
111 int (* fs_read_record)(struct file *, void *, int size, loff_t *);
112 int (* fs_setup)(struct super_block *sb);
113 int (* fs_get_op_len)(int, struct fsfilt_objinfo *, int);
114 int (* fs_quotacheck)(struct super_block *sb,
115 struct obd_quotactl *oqctl);
116 __u64 (* fs_get_version) (struct inode *inode);
117 __u64 (* fs_set_version) (struct inode *inode, __u64 new_version);
118 int (* fs_quotactl)(struct super_block *sb,
119 struct obd_quotactl *oqctl);
120 int (* fs_quotainfo)(struct lustre_quota_info *lqi, int type,
122 int (* fs_qids)(struct file *file, struct inode *inode, int type,
123 struct list_head *list);
124 int (* fs_dquot)(struct lustre_dquot *dquot, int cmd);
125 lvfs_sbdev_type (* fs_journal_sbdev)(struct super_block *sb);
128 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
129 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
130 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
131 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
133 static inline char *fsfilt_get_label(struct obd_device *obd,
134 struct super_block *sb)
136 if (obd->obd_fsops->fs_getlabel == NULL)
138 if (obd->obd_fsops->fs_getlabel(sb)[0] == '\0')
141 return obd->obd_fsops->fs_getlabel(sb);
144 static inline int fsfilt_set_label(struct obd_device *obd,
145 struct super_block *sb, char *label)
147 if (obd->obd_fsops->fs_setlabel == NULL)
149 return (obd->obd_fsops->fs_setlabel(sb, label));
152 static inline __u8 *fsfilt_uuid(struct obd_device *obd, struct super_block *sb)
154 if (obd->obd_fsops->fs_uuid == NULL)
157 return obd->obd_fsops->fs_uuid(sb);
160 static inline lvfs_sbdev_type fsfilt_journal_sbdev(struct obd_device *obd,
161 struct super_block *sb)
163 if (obd && obd->obd_fsops && obd->obd_fsops->fs_journal_sbdev)
164 return obd->obd_fsops->fs_journal_sbdev(sb);
165 return (lvfs_sbdev_type)0;
168 #define FSFILT_OP_UNLINK 1
169 #define FSFILT_OP_RMDIR 2
170 #define FSFILT_OP_RENAME 3
171 #define FSFILT_OP_CREATE 4
172 #define FSFILT_OP_MKDIR 5
173 #define FSFILT_OP_SYMLINK 6
174 #define FSFILT_OP_MKNOD 7
175 #define FSFILT_OP_SETATTR 8
176 #define FSFILT_OP_LINK 9
177 #define FSFILT_OP_CANCEL_UNLINK 10
178 #define FSFILT_OP_JOIN 11
179 #define FSFILT_OP_NOOP 15
180 #define FSFILT_OP_UNLINK_PARTIAL_CHILD 21
181 #define FSFILT_OP_UNLINK_PARTIAL_PARENT 22
182 #define FSFILT_OP_CREATE_PARTIAL_CHILD 23
184 #define __fsfilt_check_slow(obd, start, msg) \
186 if (time_before(jiffies, start + 15 * HZ)) \
188 else if (time_before(jiffies, start + 30 * HZ)) \
189 CDEBUG(D_VFSTRACE, "%s: slow %s %lus\n", obd->obd_name, \
190 msg, (jiffies-start) / HZ); \
191 else if (time_before(jiffies, start + DISK_TIMEOUT * HZ)) \
192 CWARN("%s: slow %s %lus\n", obd->obd_name, msg, \
193 (jiffies - start) / HZ); \
195 CERROR("%s: slow %s %lus\n", obd->obd_name, msg, \
196 (jiffies - start) / HZ); \
199 #define fsfilt_check_slow(obd, start, msg) \
201 __fsfilt_check_slow(obd, start, msg); \
205 static inline void *fsfilt_start_log(struct obd_device *obd,
206 struct inode *inode, int op,
207 struct obd_trans_info *oti, int logs)
209 unsigned long now = jiffies;
210 void *parent_handle = oti ? oti->oti_handle : NULL;
214 return ERR_PTR(-EROFS);
216 handle = obd->obd_fsops->fs_start(inode, op, parent_handle, logs);
217 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
220 if (parent_handle == NULL) {
221 oti->oti_handle = handle;
222 } else if (handle != parent_handle) {
223 CERROR("mismatch: parent %p, handle %p, oti %p\n",
224 parent_handle, handle, oti);
228 fsfilt_check_slow(obd, now, "journal start");
232 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
233 int op, struct obd_trans_info *oti)
235 return fsfilt_start_log(obd, inode, op, oti, 0);
238 static inline void *fsfilt_brw_start_log(struct obd_device *obd, int objcount,
239 struct fsfilt_objinfo *fso,
240 int niocount, struct niobuf_local *nb,
241 struct obd_trans_info *oti, int logs)
243 unsigned long now = jiffies;
244 void *parent_handle = oti ? oti->oti_handle : NULL;
248 return ERR_PTR(-EROFS);
250 handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
251 parent_handle, logs);
252 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
255 if (parent_handle == NULL) {
256 oti->oti_handle = handle;
257 } else if (handle != parent_handle) {
258 CERROR("mismatch: parent %p, handle %p, oti %p\n",
259 parent_handle, handle, oti);
263 fsfilt_check_slow(obd, now, "journal start");
268 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
269 struct fsfilt_objinfo *fso, int niocount,
270 struct niobuf_local *nb,
271 struct obd_trans_info *oti)
273 return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
276 static inline int fsfilt_extend(struct obd_device *obd, struct inode *inode,
277 unsigned int nblocks, void *handle)
279 unsigned long now = jiffies;
280 int rc = obd->obd_fsops->fs_extend(inode, nblocks, handle);
281 CDEBUG(D_INFO, "extending handle %p with %u blocks\n", handle, nblocks);
283 fsfilt_check_slow(obd, now, "journal extend");
288 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
289 void *handle, int force_sync)
291 unsigned long now = jiffies;
292 int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
293 CDEBUG(D_INFO, "committing handle %p\n", handle);
295 fsfilt_check_slow(obd, now, "journal start");
300 static inline int fsfilt_commit_async(struct obd_device *obd,
301 struct inode *inode, void *handle,
304 unsigned long now = jiffies;
305 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
307 CDEBUG(D_INFO, "committing handle %p (async)\n", *wait_handle);
308 fsfilt_check_slow(obd, now, "journal start");
313 static inline int fsfilt_commit_wait(struct obd_device *obd,
314 struct inode *inode, void *handle)
316 unsigned long now = jiffies;
317 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
318 CDEBUG(D_INFO, "waiting for completion %p\n", handle);
319 fsfilt_check_slow(obd, now, "journal start");
323 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
324 void *handle, struct iattr *iattr,int do_trunc)
326 unsigned long now = jiffies;
328 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
329 fsfilt_check_slow(obd, now, "setattr");
333 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
334 struct file *file, unsigned int cmd,
337 return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
340 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
341 void *handle, void *md, int size,
344 return obd->obd_fsops->fs_set_md(inode, handle, md, size, name);
347 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
348 void *md, int size, const char *name)
350 return obd->obd_fsops->fs_get_md(inode, md, size, name);
353 static inline int fsfilt_send_bio(int rw, struct obd_device *obd,
354 struct inode *inode, void *bio)
356 LASSERTF(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ, "%x\n", rw);
358 if (rw == OBD_BRW_READ)
359 return obd->obd_fsops->fs_send_bio(READ, inode, bio);
360 return obd->obd_fsops->fs_send_bio(WRITE, inode, bio);
363 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
364 struct file *file, char *buf,
365 size_t count, loff_t *offset)
367 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
370 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
371 void *handle, fsfilt_cb_t cb_func,
374 return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd,
375 handle, cb_func, cb_data);
378 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
379 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
384 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
385 obd->obd_osfs_age, max_age);
386 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
387 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
388 if (rc == 0) /* N.B. statfs can't really fail */
389 obd->obd_osfs_age = cfs_time_current_64();
391 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
397 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
399 return obd->obd_fsops->fs_sync(sb);
402 static inline int fsfilt_quotacheck(struct obd_device *obd,
403 struct super_block *sb,
404 struct obd_quotactl *oqctl)
406 if (obd->obd_fsops->fs_quotacheck)
407 return obd->obd_fsops->fs_quotacheck(sb, oqctl);
411 static inline int fsfilt_quotactl(struct obd_device *obd,
412 struct super_block *sb,
413 struct obd_quotactl *oqctl)
415 if (obd->obd_fsops->fs_quotactl)
416 return obd->obd_fsops->fs_quotactl(sb, oqctl);
420 static inline int fsfilt_quotainfo(struct obd_device *obd,
421 struct lustre_quota_info *lqi,
424 if (obd->obd_fsops->fs_quotainfo)
425 return obd->obd_fsops->fs_quotainfo(lqi, type, cmd);
429 static inline int fsfilt_qids(struct obd_device *obd, struct file *file,
430 struct inode *inode, int type,
431 struct list_head *list)
433 if (obd->obd_fsops->fs_qids)
434 return obd->obd_fsops->fs_qids(file, inode, type, list);
438 static inline int fsfilt_dquot(struct obd_device *obd,
439 struct lustre_dquot *dquot, int cmd)
441 if (obd->obd_fsops->fs_dquot)
442 return obd->obd_fsops->fs_dquot(dquot, cmd);
446 static inline int fsfilt_map_inode_pages(struct obd_device *obd,
448 struct page **page, int pages,
449 unsigned long *blocks, int *created,
450 int create, struct semaphore *sem)
452 return obd->obd_fsops->fs_map_inode_pages(inode, page, pages, blocks,
453 created, create, sem);
456 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
457 void *buf, loff_t size, loff_t *offs)
459 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
462 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
463 void *buf, loff_t size, loff_t *offs,
466 return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
469 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
471 if (obd->obd_fsops->fs_setup)
472 return obd->obd_fsops->fs_setup(fs);
476 static inline __u64 fsfilt_set_version(struct obd_device *obd,
477 struct inode *inode, __u64 new_version)
479 if (obd->obd_fsops->fs_set_version)
480 return obd->obd_fsops->fs_set_version(inode, new_version);
484 static inline __u64 fsfilt_get_version(struct obd_device *obd,
487 if (obd->obd_fsops->fs_set_version)
488 return obd->obd_fsops->fs_get_version(inode);
492 #endif /* __KERNEL__ */