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 [sun.com URL with a
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;
61 #define XATTR_LUSTRE_MDS_LOV_EA "lov"
64 struct fsfilt_operations {
65 struct list_head fs_list;
66 struct module *fs_owner;
68 char *(* fs_getlabel)(struct super_block *sb);
69 int (* fs_setlabel)(struct super_block *sb, char *label);
70 char *(* fs_uuid)(struct super_block *sb);
71 void *(* fs_start)(struct inode *inode, int op, void *desc_private,
73 void *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
74 int niocount, struct niobuf_local *nb,
75 void *desc_private, int logs);
76 int (* fs_extend)(struct inode *inode, unsigned nblocks, void *h);
77 int (* fs_commit)(struct inode *inode, void *handle,int force_sync);
78 int (* fs_commit_async)(struct inode *inode, void *handle,
80 int (* fs_commit_wait)(struct inode *inode, void *handle);
81 int (* fs_setattr)(struct dentry *dentry, void *handle,
82 struct iattr *iattr, int do_trunc);
83 int (* fs_iocontrol)(struct inode *inode, struct file *file,
84 unsigned int cmd, unsigned long arg);
85 int (* fs_set_md)(struct inode *inode, void *handle, void *md,
86 int size, const char *name);
87 int (* fs_get_md)(struct inode *inode, void *md, int size,
90 * this method is needed to make IO operation fsfilt nature depend.
92 * This operation maybe synchronous or asynchronous.
94 * Return convention: positive number of bytes written (synchronously)
95 * on success. Negative errno value on failure. Zero if asynchronous
96 * IO was submitted successfully.
99 int (* fs_send_bio)(int rw, struct inode *inode,struct kiobuf *bio);
100 ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
102 int (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
103 void *handle, fsfilt_cb_t cb_func,
105 int (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
106 int (* fs_sync)(struct super_block *sb);
107 int (* fs_map_inode_pages)(struct inode *inode, struct page **page,
108 int pages, unsigned long *blocks,
109 int *created, int create,
110 struct semaphore *sem);
111 int (* fs_write_record)(struct file *, void *, int size, loff_t *,
113 int (* fs_read_record)(struct file *, void *, int size, loff_t *);
114 int (* fs_setup)(struct super_block *sb);
115 int (* fs_get_op_len)(int, struct fsfilt_objinfo *, int);
116 int (* fs_quotactl)(struct super_block *sb,
117 struct obd_quotactl *oqctl);
118 int (* fs_quotacheck)(struct super_block *sb,
119 struct obd_quotactl *oqctl);
120 __u64 (* fs_get_version) (struct inode *inode);
121 __u64 (* fs_set_version) (struct inode *inode, __u64 new_version);
122 int (* fs_quotainfo)(struct lustre_quota_info *lqi, int type,
124 int (* fs_qids)(struct file *file, struct inode *inode, int type,
125 struct list_head *list);
126 int (* fs_dquot)(struct lustre_dquot *dquot, int cmd);
127 lvfs_sbdev_type (* fs_journal_sbdev)(struct super_block *sb);
130 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
131 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
132 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
133 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
135 static inline char *fsfilt_get_label(struct obd_device *obd,
136 struct super_block *sb)
138 if (obd->obd_fsops->fs_getlabel == NULL)
140 if (obd->obd_fsops->fs_getlabel(sb)[0] == '\0')
143 return obd->obd_fsops->fs_getlabel(sb);
146 static inline int fsfilt_set_label(struct obd_device *obd,
147 struct super_block *sb, char *label)
149 if (obd->obd_fsops->fs_setlabel == NULL)
151 return (obd->obd_fsops->fs_setlabel(sb, label));
154 static inline __u8 *fsfilt_uuid(struct obd_device *obd, struct super_block *sb)
156 if (obd->obd_fsops->fs_uuid == NULL)
159 return obd->obd_fsops->fs_uuid(sb);
162 static inline lvfs_sbdev_type fsfilt_journal_sbdev(struct obd_device *obd,
163 struct super_block *sb)
165 if (obd && obd->obd_fsops && obd->obd_fsops->fs_journal_sbdev)
166 return obd->obd_fsops->fs_journal_sbdev(sb);
167 return (lvfs_sbdev_type)0;
170 #define FSFILT_OP_UNLINK 1
171 #define FSFILT_OP_RMDIR 2
172 #define FSFILT_OP_RENAME 3
173 #define FSFILT_OP_CREATE 4
174 #define FSFILT_OP_MKDIR 5
175 #define FSFILT_OP_SYMLINK 6
176 #define FSFILT_OP_MKNOD 7
177 #define FSFILT_OP_SETATTR 8
178 #define FSFILT_OP_LINK 9
179 #define FSFILT_OP_CANCEL_UNLINK 10
180 #define FSFILT_OP_JOIN 11
181 #define FSFILT_OP_NOOP 15
183 #define __fsfilt_check_slow(obd, start, msg) \
185 if (time_before(jiffies, start + 15 * HZ)) \
187 else if (time_before(jiffies, start + 30 * HZ)) \
188 CDEBUG(D_VFSTRACE, "%s: slow %s %lus\n", obd->obd_name, \
189 msg, (jiffies-start) / HZ); \
190 else if (time_before(jiffies, start + DISK_TIMEOUT * HZ)) \
191 CWARN("%s: slow %s %lus\n", obd->obd_name, msg, \
192 (jiffies - start) / HZ); \
194 CERROR("%s: slow %s %lus\n", obd->obd_name, msg, \
195 (jiffies - start) / HZ); \
198 #define fsfilt_check_slow(obd, start, msg) \
200 __fsfilt_check_slow(obd, start, msg); \
204 static inline void *fsfilt_start_log(struct obd_device *obd,
205 struct inode *inode, int op,
206 struct obd_trans_info *oti, int logs)
208 unsigned long now = jiffies;
209 void *parent_handle = oti ? oti->oti_handle : NULL;
213 return ERR_PTR(-EROFS);
215 handle = obd->obd_fsops->fs_start(inode, op, parent_handle, logs);
216 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
219 if (parent_handle == NULL) {
220 oti->oti_handle = handle;
221 } else if (handle != parent_handle) {
222 CERROR("mismatch: parent %p, handle %p, oti %p\n",
223 parent_handle, handle, oti);
227 fsfilt_check_slow(obd, now, "journal start");
231 static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
232 int op, struct obd_trans_info *oti)
234 return fsfilt_start_log(obd, inode, op, oti, 0);
237 static inline void *fsfilt_brw_start_log(struct obd_device *obd, int objcount,
238 struct fsfilt_objinfo *fso,
239 int niocount, struct niobuf_local *nb,
240 struct obd_trans_info *oti, int logs)
242 unsigned long now = jiffies;
243 void *parent_handle = oti ? oti->oti_handle : NULL;
247 return ERR_PTR(-EROFS);
249 handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
250 parent_handle, logs);
251 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
254 if (parent_handle == NULL) {
255 oti->oti_handle = handle;
256 } else if (handle != parent_handle) {
257 CERROR("mismatch: parent %p, handle %p, oti %p\n",
258 parent_handle, handle, oti);
262 fsfilt_check_slow(obd, now, "journal start");
267 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
268 struct fsfilt_objinfo *fso, int niocount,
269 struct niobuf_local *nb,
270 struct obd_trans_info *oti)
272 return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
275 static inline int fsfilt_extend(struct obd_device *obd, struct inode *inode,
276 unsigned int nblocks, void *handle)
278 unsigned long now = jiffies;
279 int rc = obd->obd_fsops->fs_extend(inode, nblocks, handle);
280 CDEBUG(D_INFO, "extending handle %p with %u blocks\n", handle, nblocks);
282 fsfilt_check_slow(obd, now, "journal extend");
287 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
288 void *handle, int force_sync)
290 unsigned long now = jiffies;
291 int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
292 CDEBUG(D_INFO, "committing handle %p\n", handle);
294 fsfilt_check_slow(obd, now, "journal start");
299 static inline int fsfilt_commit_async(struct obd_device *obd,
300 struct inode *inode, void *handle,
303 unsigned long now = jiffies;
304 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
306 CDEBUG(D_INFO, "committing handle %p (async)\n", *wait_handle);
307 fsfilt_check_slow(obd, now, "journal start");
312 static inline int fsfilt_commit_wait(struct obd_device *obd,
313 struct inode *inode, void *handle)
315 unsigned long now = jiffies;
316 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
317 CDEBUG(D_INFO, "waiting for completion %p\n", handle);
318 fsfilt_check_slow(obd, now, "journal start");
322 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
323 void *handle, struct iattr *iattr,int do_trunc)
325 unsigned long now = jiffies;
327 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
328 fsfilt_check_slow(obd, now, "setattr");
332 static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
333 struct file *file, unsigned int cmd,
336 return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
339 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
340 void *handle, void *md, int size,
343 return obd->obd_fsops->fs_set_md(inode, handle, md, size, name);
346 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
347 void *md, int size, const char *name)
349 return obd->obd_fsops->fs_get_md(inode, md, size, name);
352 static inline int fsfilt_send_bio(int rw, struct obd_device *obd,
353 struct inode *inode, void *bio)
355 LASSERTF(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ, "%x\n", rw);
357 if (rw == OBD_BRW_READ)
358 return obd->obd_fsops->fs_send_bio(READ, inode, bio);
359 return obd->obd_fsops->fs_send_bio(WRITE, inode, bio);
362 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
363 struct file *file, char *buf,
364 size_t count, loff_t *offset)
366 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
369 static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
370 void *handle, fsfilt_cb_t cb_func,
373 return obd->obd_fsops->fs_add_journal_cb(obd, last_rcvd,
374 handle, cb_func, cb_data);
377 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
378 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
383 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
384 obd->obd_osfs_age, max_age);
385 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
386 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
387 if (rc == 0) /* N.B. statfs can't really fail */
388 obd->obd_osfs_age = cfs_time_current_64();
390 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
396 static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
398 return obd->obd_fsops->fs_sync(sb);
401 static inline int fsfilt_quotacheck(struct obd_device *obd,
402 struct super_block *sb,
403 struct obd_quotactl *oqctl)
405 if (obd->obd_fsops->fs_quotacheck)
406 return obd->obd_fsops->fs_quotacheck(sb, oqctl);
410 static inline int fsfilt_quotactl(struct obd_device *obd,
411 struct super_block *sb,
412 struct obd_quotactl *oqctl)
414 if (obd->obd_fsops->fs_quotactl)
415 return obd->obd_fsops->fs_quotactl(sb, oqctl);
419 static inline int fsfilt_quotainfo(struct obd_device *obd,
420 struct lustre_quota_info *lqi,
423 if (obd->obd_fsops->fs_quotainfo)
424 return obd->obd_fsops->fs_quotainfo(lqi, type, cmd);
428 static inline int fsfilt_qids(struct obd_device *obd, struct file *file,
429 struct inode *inode, int type,
430 struct list_head *list)
432 if (obd->obd_fsops->fs_qids)
433 return obd->obd_fsops->fs_qids(file, inode, type, list);
437 static inline int fsfilt_dquot(struct obd_device *obd,
438 struct lustre_dquot *dquot, int cmd)
440 if (obd->obd_fsops->fs_dquot)
441 return obd->obd_fsops->fs_dquot(dquot, cmd);
445 static inline int fsfilt_map_inode_pages(struct obd_device *obd,
447 struct page **page, int pages,
448 unsigned long *blocks, int *created,
449 int create, struct semaphore *sem)
451 return obd->obd_fsops->fs_map_inode_pages(inode, page, pages, blocks,
452 created, create, sem);
455 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
456 void *buf, loff_t size, loff_t *offs)
458 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
461 static inline int fsfilt_write_record(struct obd_device *obd, struct file *file,
462 void *buf, loff_t size, loff_t *offs,
465 return obd->obd_fsops->fs_write_record(file, buf, size,offs,force_sync);
468 static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
470 if (obd->obd_fsops->fs_setup)
471 return obd->obd_fsops->fs_setup(fs);
475 static inline __u64 fsfilt_set_version(struct obd_device *obd,
476 struct inode *inode, __u64 new_version)
478 if (obd->obd_fsops->fs_set_version)
479 return obd->obd_fsops->fs_set_version(inode, new_version);
483 static inline __u64 fsfilt_get_version(struct obd_device *obd,
486 if (obd->obd_fsops->fs_set_version)
487 return obd->obd_fsops->fs_get_version(inode);
491 #endif /* __KERNEL__ */