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 _LUSTRE_FSFILT_H
26 #define _LUSTRE_FSFILT_H
30 #include <linux/obd.h>
31 #include <linux/lustre_log.h>
32 #include <linux/obd_class.h>
34 typedef void (*fsfilt_cb_t)(struct obd_device *obd, __u64 last_rcvd,
35 void *data, int error);
37 struct fsfilt_objinfo {
38 struct dentry *fso_dentry;
42 /* lustre EA type (MEA, LOV, etc.) */
51 #define XATTR_LUSTRE_MDS_LOV_EA "lov"
52 #define XATTR_LUSTRE_MDS_MEA_EA "mea"
53 #define XATTR_LUSTRE_MDS_SID_EA "sid"
54 #define XATTR_LUSTRE_MDS_KEY_EA "key"
55 #define XATTR_LUSTRE_MDS_PID_EA "pid"
57 struct fsfilt_operations {
58 struct list_head fs_list;
59 struct module *fs_owner;
62 void *(* fs_start)(struct inode *inode, int op, void *desc_private,
64 void *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
65 int niocount, struct niobuf_local *nb,
66 void *desc_private, int logs);
67 int (* fs_commit)(struct super_block *sb, struct inode *inode,
68 void *handle,int force_sync);
69 int (* fs_commit_async)(struct inode *inode, void *handle,
71 int (* fs_commit_wait)(struct inode *inode, void *handle);
72 int (* fs_setattr)(struct dentry *dentry, void *handle,
73 struct iattr *iattr, int do_trunc);
74 int (* fs_iocontrol)(struct inode *inode, struct file *file,
75 unsigned int cmd, unsigned long arg);
77 /* two methods for setting getting diff. kind of EAs from inode. */
78 int (* fs_set_md)(struct inode *inode, void *handle, void *md,
79 int size, enum ea_type type);
80 int (* fs_get_md)(struct inode *inode, void *md, int size,
83 int (* fs_send_bio)(int rw, struct inode *inode, void *bio);
85 /* methods for getting page from backing fs and putting page there
86 * during IO. Used on OST. */
87 int (* fs_putpage)(struct inode *inode, struct page *page);
88 struct page *(* fs_getpage)(struct inode *inode, long int index);
90 ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
92 int (* fs_add_journal_cb)(struct obd_device *obd,
93 struct super_block *sb,
94 __u64 last_rcvd, void *handle,
95 fsfilt_cb_t cb_func, void *cb_data);
96 int (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
97 int (* fs_sync)(struct super_block *sb);
98 int (* fs_map_inode_pages)(struct inode *inode, struct page **page,
99 int pages, unsigned long *blocks,
100 int *created, int create,
101 struct semaphore *sem);
102 int (* fs_prep_san_write)(struct inode *inode, long *blocks,
103 int nblocks, loff_t newsize);
104 int (* fs_write_record)(struct file *, void *, int size, loff_t *,
106 int (* fs_read_record)(struct file *, void *, int size, loff_t *);
107 int (* fs_setup)(struct obd_device *, struct super_block *);
109 int (* fs_post_setup)(struct obd_device *obd, struct vfsmount *mnt,
110 struct dentry *dentry);
111 int (* fs_post_cleanup)(struct obd_device *obd, struct vfsmount *mnt);
112 int (* fs_set_info)(struct super_block *, struct inode *,
113 __u32, void *, __u32, void *);
114 int (* fs_get_info)(struct super_block *, struct inode *,
115 __u32, void *, __u32 *, void *);
116 int (* fs_set_fs_flags)(struct inode *inode, int flags);
117 int (* fs_clear_fs_flags)(struct inode *inode, int flags);
118 int (* fs_set_ost_flags)(struct super_block *sb);
119 int (* fs_set_mds_flags)(struct super_block *sb);
120 int (* fs_precreate_rec)(struct dentry *dentry, int *num,
122 int (* fs_set_xattr)(struct inode *inode, void *handle, char *name,
123 void *buffer, int buffer_size);
124 int (* fs_get_xattr)(struct inode *inode, char *name,
125 void *buffer, int buffer_size);
127 int (* fs_init_extents_ea)(struct inode *inode);
128 int (* fs_insert_extents_ea)(struct inode *inode, unsigned long from,
130 int (* fs_do_write_cow)(struct dentry *dentry, void *extents, int nexts);
131 int (* fs_write_extents)(struct dentry *dentry,
132 unsigned long offset, unsigned long blks);
133 int (* fs_get_fs_flags)(struct dentry *dentry);
134 int (* fs_remove_extents_ea)(struct inode *inode, unsigned long from,
136 int (* fs_get_ino_write_extents)(struct super_block *sb, ino_t ino,
137 char **pbuf, int *size);
138 int (* fs_free_write_extents)(struct super_block *sb, ino_t ino,
139 char *pbuf, int size);
140 int (* fs_get_inode_write_extents)(struct inode *inode, char **pbuf,
142 int (* fs_get_write_extents_num)(struct inode *inode, int* size);
144 int (* fs_get_op_len)(int, struct fsfilt_objinfo *, int);
145 int (* fs_add_dir_entry)(struct obd_device *, struct dentry *,
146 char *, int, unsigned long, unsigned long,
147 unsigned long, unsigned long);
148 int (* fs_del_dir_entry)(struct obd_device *, struct dentry *);
150 int (* fs_is_redirector)(struct inode *inode);
151 int (* fs_is_indirect)(struct inode *inode);
153 struct inode * (* fs_create_indirect)(struct inode *pri, int index,
155 struct inode *parent,
157 struct inode * (* fs_get_indirect)(struct inode *pri, int *table,
159 ino_t (* fs_get_indirect_ino)(struct super_block *sb, ino_t pri,
161 int (* fs_destroy_indirect)(struct inode *pri, int index,
162 struct inode *next_ind);
163 int (* fs_restore_indirect)(struct inode *pri, int index);
164 int (* fs_iterate)(struct super_block *sb,
165 int (*repeat)(struct inode *inode, void *priv),
166 struct inode **start, void *priv, int flag);
167 int (* fs_copy_block)(struct inode *dst, struct inode *src,
169 int (* fs_set_indirect)(struct inode *pri, int index,
170 ino_t ind_ino, ino_t parent_ino);
171 int (* fs_snap_feature)(struct super_block *sb, int feature,
173 int (* fs_set_snap_info)(struct inode *inode, void* key,
174 __u32 keylen, void *val, __u32 *vallen);
175 int (* fs_get_snap_info)(struct inode *inode, void* key,
176 __u32 keylen, void *val, __u32 *vallen);
177 int (* fs_set_snap_item)(struct super_block *sb, char *name);
178 int (* fs_read_dotsnap_dir_page)(struct file *file, char *buf,
179 size_t count, loff_t *ppos);
180 int (* fs_dir_ent_size)(char *name);
181 int (* fs_set_dir_ent)(struct super_block *sb, char *name,
182 char *buf, int buf_off, int nlen,
186 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
187 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
188 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
189 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
191 #define FSFILT_OP_UNLINK 1
192 #define FSFILT_OP_RMDIR 2
193 #define FSFILT_OP_RENAME 3
194 #define FSFILT_OP_CREATE 4
195 #define FSFILT_OP_MKDIR 5
196 #define FSFILT_OP_SYMLINK 6
197 #define FSFILT_OP_MKNOD 7
198 #define FSFILT_OP_SETATTR 8
199 #define FSFILT_OP_LINK 9
200 #define FSFILT_OP_CANCEL_UNLINK 10
201 #define FSFILT_OP_NOOP 15
203 /* XXX BUG 3188 -- must return to one set of opcodes */
204 #define KML_UNLINK 0x11
205 #define KML_RMDIR 0x12
206 #define KML_RENAME 0x13
207 #define KML_CREATE 0x14
208 #define KML_MKDIR 0x15
209 #define KML_SYMLINK 0x16
210 #define KML_MKNOD 0x17
211 #define KML_LINK 0x19
213 #define CACHE_UNLINK 0x21
214 #define CACHE_RMDIR 0x22
215 #define CACHE_RENAME 0x23
216 #define CACHE_CREATE 0x24
217 #define CACHE_MKDIR 0x25
218 #define CACHE_SYMLINK 0x26
219 #define CACHE_MKNOD 0x27
220 #define CACHE_LINK 0x29
221 #define CACHE_NOOP 0x2f
223 #define KML_CACHE_UNLINK 0x31
224 #define KML_CACHE_RMDIR 0x32
225 #define KML_CACHE_RENAME 0x33
226 #define KML_CACHE_CREATE 0x34
227 #define KML_CACHE_MKDIR 0x35
228 #define KML_CACHE_SYMLINK 0x36
229 #define KML_CACHE_MKNOD 0x37
230 #define KML_CACHE_LINK 0x39
231 #define KML_CACHE_NOOP 0x3f
233 /*for fsfilt set md ea*/
237 #define fsfilt_check_slow(start, timeout, msg) \
239 if (time_before(jiffies, start + 15 * HZ)) \
241 else if (time_before(jiffies, start + timeout / 2 * HZ)) \
242 CWARN("slow %s %lus\n", msg, (jiffies - start) / HZ); \
244 CERROR("slow %s %lus\n", msg, (jiffies - start) / HZ); \
248 fsfilt_start_ops(struct fsfilt_operations *ops, struct inode *inode,
249 int op, struct obd_trans_info *oti, int logs)
251 unsigned long now = jiffies;
252 void *parent_handle = oti ? oti->oti_handle : NULL;
253 void *handle = ops->fs_start(inode, op, parent_handle, logs);
254 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
257 if (parent_handle == NULL) {
258 oti->oti_handle = handle;
259 } else if (handle != parent_handle) {
260 CERROR("mismatch: parent %p, handle %p, oti %p\n",
261 parent_handle, handle, oti);
265 fsfilt_check_slow(now, 60, "journal start");
270 fsfilt_start_log(struct obd_device *obd, struct inode *inode,
271 int op, struct obd_trans_info *oti, int logs)
273 return fsfilt_start_ops(obd->obd_fsops, inode, op, oti, logs);
277 fsfilt_start(struct obd_device *obd, struct inode *inode,
278 int op, struct obd_trans_info *oti)
280 return fsfilt_start_ops(obd->obd_fsops, inode, op, oti, 0);
284 llog_fsfilt_start(struct llog_ctxt *ctxt, struct inode *inode,
285 int op, struct obd_trans_info *oti)
287 return fsfilt_start_ops(ctxt->loc_fsops, inode, op, oti, 1);
291 fsfilt_commit_ops(struct fsfilt_operations *ops, struct super_block *sb,
292 struct inode *inode, void *handle, int force_sync)
294 unsigned long now = jiffies;
295 int rc = ops->fs_commit(sb, inode, handle, force_sync);
296 CDEBUG(D_INFO, "committing handle %p\n", handle);
298 fsfilt_check_slow(now, 60, "journal start");
304 fsfilt_commit(struct obd_device *obd, struct super_block *sb,
305 struct inode *inode, void *handle, int force_sync)
307 return fsfilt_commit_ops(obd->obd_fsops, sb, inode, handle, force_sync);
311 llog_fsfilt_commit(struct llog_ctxt *ctxt, struct inode *inode,
312 void *handle, int force_sync)
314 return fsfilt_commit_ops(ctxt->loc_fsops, inode->i_sb, inode, handle,
319 fsfilt_brw_start_log(struct obd_device *obd, int objcount,
320 struct fsfilt_objinfo *fso, int niocount,
321 struct niobuf_local *nb, struct obd_trans_info *oti,
324 unsigned long now = jiffies;
325 void *parent_handle = oti ? oti->oti_handle : NULL;
326 void *handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
327 parent_handle, logs);
328 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
331 if (parent_handle == NULL) {
332 oti->oti_handle = handle;
333 } else if (handle != parent_handle) {
334 CERROR("mismatch: parent %p, handle %p, oti %p\n",
335 parent_handle, handle, oti);
339 fsfilt_check_slow(now, obd_timeout, "journal start");
345 fsfilt_brw_start(struct obd_device *obd, int objcount,
346 struct fsfilt_objinfo *fso, int niocount,
347 struct niobuf_local *nb, struct obd_trans_info *oti)
349 return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
353 fsfilt_commit_async(struct obd_device *obd, struct inode *inode,
354 void *handle, void **wait_handle)
356 unsigned long now = jiffies;
357 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
359 CDEBUG(D_INFO, "committing handle %p (async)\n", *wait_handle);
360 fsfilt_check_slow(now, obd_timeout, "journal start");
366 fsfilt_commit_wait(struct obd_device *obd, struct inode *inode, void *handle)
368 unsigned long now = jiffies;
369 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
370 CDEBUG(D_INFO, "waiting for completion %p\n", handle);
371 fsfilt_check_slow(now, obd_timeout, "journal start");
376 fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
377 void *handle, struct iattr *iattr, int do_trunc)
379 unsigned long now = jiffies;
381 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
382 fsfilt_check_slow(now, obd_timeout, "setattr");
387 fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
388 struct file *file, unsigned int cmd,
391 return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
394 static inline int fsfilt_setup(struct obd_device *obd,
395 struct super_block *fs)
397 if (obd->obd_fsops->fs_setup)
398 return obd->obd_fsops->fs_setup(obd, fs);
403 fsfilt_set_md(struct obd_device *obd, struct inode *inode,
404 void *handle, void *md, int size, enum ea_type type)
406 if (!obd->obd_fsops->fs_set_md)
409 return obd->obd_fsops->fs_set_md(inode, handle, md,
414 fsfilt_get_md(struct obd_device *obd, struct inode *inode,
415 void *md, int size, enum ea_type type)
417 if (!obd->obd_fsops->fs_get_md)
420 return obd->obd_fsops->fs_get_md(inode, md, size,
424 static inline int fsfilt_send_bio(int rw, struct obd_device *obd,
425 struct inode *inode, void *bio)
427 LASSERTF(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ, "%x\n", rw);
429 if (rw == OBD_BRW_READ)
430 return obd->obd_fsops->fs_send_bio(READ, inode, bio);
432 return obd->obd_fsops->fs_send_bio(WRITE, inode, bio);
436 fsfilt_putpage(struct obd_device *obd, struct inode *inode,
440 struct filter_obd *filter;
441 unsigned long now = jiffies;
443 LASSERT(obd != NULL);
444 LASSERT(inode != NULL);
445 LASSERT(page != NULL);
447 filter = &obd->u.filter;
449 if (!obd->obd_fsops->fs_putpage)
452 CDEBUG(D_INFO, "putpage %lx\n", page->index);
454 rc = obd->obd_fsops->fs_putpage(inode, page);
456 fsfilt_check_slow(now, obd_timeout, "putpage");
461 static inline struct page *
462 fsfilt_getpage(struct obd_device *obd, struct inode *inode,
466 unsigned long now = jiffies;
468 LASSERT(obd != NULL);
469 LASSERT(inode != NULL);
471 if (!obd->obd_fsops->fs_getpage)
472 return ERR_PTR(-ENOSYS);
474 CDEBUG(D_INFO, "getpage %lx\n", index);
476 page = obd->obd_fsops->fs_getpage(inode, index);
478 fsfilt_check_slow(now, obd_timeout, "getpage");
483 static inline ssize_t
484 fsfilt_readpage(struct obd_device *obd, struct file *file, char *buf,
485 size_t count, loff_t *offset)
487 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
491 fsfilt_add_journal_cb(struct obd_device *obd, struct super_block *sb,
492 __u64 last_num, void *handle, fsfilt_cb_t cb_func,
495 return obd->obd_fsops->fs_add_journal_cb(obd, sb, last_num, handle,
499 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
501 fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
502 unsigned long max_age)
506 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
507 if (time_before(obd->obd_osfs_age, max_age)) {
508 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
509 if (rc == 0) /* N.B. statfs can't really fail */
510 obd->obd_osfs_age = jiffies;
512 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
519 fsfilt_sync(struct obd_device *obd, struct super_block *sb)
521 return obd->obd_fsops->fs_sync(sb);
524 static inline int fsfilt_map_inode_pages(struct obd_device *obd,
526 struct page **page, int pages,
527 unsigned long *blocks, int *created,
528 int create, struct semaphore *sem)
530 return obd->obd_fsops->fs_map_inode_pages(inode, page, pages, blocks,
531 created, create, sem);
533 static inline int fsfilt_get_fs_flags(struct obd_device *obd,
534 struct dentry *dentry)
536 if (obd->obd_fsops->fs_get_fs_flags)
537 return obd->obd_fsops->fs_get_fs_flags(dentry);
542 fsfilt_write_extents(struct obd_device *obd, struct dentry *dentry,
543 unsigned long offset, unsigned long blks)
545 if (obd->obd_fsops->fs_write_extents)
546 return obd->obd_fsops->fs_write_extents(dentry,
551 fsfilt_do_write_cow(struct obd_device *obd, struct dentry *dentry,
552 void *extents, int num_extents)
554 if (obd->obd_fsops->fs_do_write_cow)
555 return obd->obd_fsops->fs_do_write_cow(dentry, extents,
560 fs_prep_san_write(struct obd_device *obd, struct inode *inode,
561 long *blocks, int nblocks, loff_t newsize)
563 return obd->obd_fsops->fs_prep_san_write(inode, blocks,
568 fsfilt_read_record(struct obd_device *obd, struct file *file,
569 void *buf, loff_t size, loff_t *offs)
571 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
575 llog_fsfilt_read_record(struct llog_ctxt *ctxt, struct file *file,
576 void *buf, loff_t size, loff_t *offs)
578 return ctxt->loc_fsops->fs_read_record(file, buf, size, offs);
582 fsfilt_write_record(struct obd_device *obd, struct file *file,
583 void *buf, loff_t size, loff_t *offs, int force_sync)
585 return obd->obd_fsops->fs_write_record(file, buf, size, offs,
590 llog_fsfilt_write_record(struct llog_ctxt *ctxt, struct file *file,
591 void *buf, loff_t size, loff_t *offs,
594 return ctxt->loc_fsops->fs_write_record(file, buf, size, offs,
599 fsfilt_set_fs_flags(struct obd_device *obd, struct inode *inode, int flags)
601 if (obd->obd_fsops->fs_set_fs_flags)
602 return obd->obd_fsops->fs_set_fs_flags(inode, flags);
607 fsfilt_clear_fs_flags(struct obd_device *obd, struct inode *inode, int flags)
609 if (obd->obd_fsops->fs_clear_fs_flags)
610 return obd->obd_fsops->fs_clear_fs_flags(inode, flags);
615 fsfilt_precreate_rec(struct obd_device *obd, struct dentry *dentry,
616 int *num, struct obdo *oa)
618 if (obd->obd_fsops->fs_precreate_rec)
619 return obd->obd_fsops->fs_precreate_rec(dentry, num, oa);
624 fsfilt_post_setup(struct obd_device *obd, struct dentry *de)
626 if (obd->obd_fsops->fs_post_setup)
627 return obd->obd_fsops->fs_post_setup(obd,
628 obd->obd_lvfs_ctxt.pwdmnt, de);
633 fsfilt_post_cleanup(struct obd_device *obd)
635 if (obd->obd_fsops->fs_post_cleanup)
636 return obd->obd_fsops->fs_post_cleanup(obd,
637 obd->obd_lvfs_ctxt.pwdmnt);
642 fsfilt_get_ino_write_extents(struct obd_device *obd,
643 struct super_block *sb,
644 int ino, char **buf, int *size)
646 if (obd->obd_fsops->fs_get_ino_write_extents)
647 return obd->obd_fsops->fs_get_ino_write_extents(sb, ino,
653 fsfilt_free_write_extents(struct obd_device *obd,
654 struct super_block *sb,
655 int ino, char *buf, int size)
657 if (obd->obd_fsops->fs_free_write_extents)
658 return obd->obd_fsops->fs_free_write_extents(sb, ino,
664 fsfilt_set_info(struct obd_device *obd, struct super_block *sb,
665 struct inode * inode, __u32 keylen, void * key,
666 __u32 valsize, void * val)
668 if (obd->obd_fsops->fs_set_info)
669 return obd->obd_fsops->fs_set_info(sb, inode,
676 fsfilt_get_info(struct obd_device *obd, struct super_block *sb,
677 struct inode * inode, __u32 keylen, void * key,
678 __u32 * valsize, void * val)
680 if (obd->obd_fsops->fs_get_info)
681 return obd->obd_fsops->fs_get_info(sb, inode, keylen, key,
687 fsfilt_set_ost_flags(struct obd_device *obd, struct super_block *sb)
689 if (obd->obd_fsops->fs_set_ost_flags)
690 return obd->obd_fsops->fs_set_ost_flags(sb);
695 fsfilt_set_mds_flags(struct obd_device *obd, struct super_block *sb)
697 if (obd->obd_fsops->fs_set_mds_flags)
698 return obd->obd_fsops->fs_set_mds_flags(sb);
703 fsfilt_add_dir_entry(struct obd_device *obd, struct dentry *dir,
704 char *name, int namelen, unsigned long ino,
705 unsigned long generation, unsigned long mds,
708 LASSERT(obd->obd_fsops->fs_add_dir_entry);
710 return obd->obd_fsops->fs_add_dir_entry(obd, dir, name,
717 fsfilt_del_dir_entry(struct obd_device *obd, struct dentry *dentry)
719 LASSERT(obd->obd_fsops->fs_del_dir_entry);
720 return obd->obd_fsops->fs_del_dir_entry(obd, dentry);
724 fsfilt_set_snap_item(struct obd_device *obd, struct super_block *sb,
727 if (obd->obd_fsops->fs_set_snap_item)
728 return obd->obd_fsops->fs_set_snap_item(sb, name);
731 #endif /* __KERNEL__ */