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 struct fsfilt_operations {
43 struct list_head fs_list;
44 struct module *fs_owner;
46 void *(* fs_start)(struct inode *inode, int op, void *desc_private,
48 void *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
49 int niocount, struct niobuf_local *nb,
50 void *desc_private, int logs);
51 int (* fs_commit)(struct super_block *sb, struct inode *inode,
52 void *handle,int force_sync);
53 int (* fs_commit_async)(struct inode *inode, void *handle,
55 int (* fs_commit_wait)(struct inode *inode, void *handle);
56 int (* fs_setattr)(struct dentry *dentry, void *handle,
57 struct iattr *iattr, int do_trunc);
58 int (* fs_iocontrol)(struct inode *inode, struct file *file,
59 unsigned int cmd, unsigned long arg);
61 /* two methods for getting lov EA and setting it back to inode xattr. */
62 int (* fs_set_md)(struct inode *inode, void *handle, void *md,
64 int (* fs_get_md)(struct inode *inode, void *md, int size);
66 /* two methods for getting MID (master id) EA and setting it back to
68 int (* fs_set_mid)(struct inode *inode, void *handle, void *fid,
70 int (* fs_get_mid)(struct inode *inode, void *fid, int size);
72 /* two methods for getting self id EA and setting it back to inode
74 int (* fs_set_sid)(struct inode *inode, void *handle, void *sid,
76 int (* fs_get_sid)(struct inode *inode, void *sid, int size);
78 /* this method is needed to make IO operation fsfilt nature depend. */
79 int (* fs_send_bio)(int rw, struct inode *inode,struct kiobuf *bio);
81 /* methods for getting page from backing fs and putting page there
82 * during IO. Used on OST. */
83 int (* fs_putpage)(struct inode *inode, struct page *page);
84 struct page *(* fs_getpage)(struct inode *inode, long int index);
86 ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
88 int (* fs_add_journal_cb)(struct obd_device *obd,
89 struct super_block *sb,
90 __u64 last_rcvd, void *handle,
93 int (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
94 int (* fs_sync)(struct super_block *sb);
95 int (* fs_map_inode_pages)(struct inode *inode, struct page **page,
96 int pages, unsigned long *blocks,
97 int *created, int create,
98 struct semaphore *sem);
99 int (* fs_prep_san_write)(struct inode *inode, long *blocks,
100 int nblocks, loff_t newsize);
101 int (* fs_write_record)(struct file *, void *, int size, loff_t *,
103 int (* fs_read_record)(struct file *, void *, int size, loff_t *);
104 int (* fs_setup)(struct obd_device *, struct super_block *);
106 int (* fs_post_setup)(struct obd_device *obd, struct vfsmount *mnt,
107 struct dentry *dentry);
108 int (* fs_post_cleanup)(struct obd_device *obd, struct vfsmount *mnt);
109 int (* fs_get_reint_log_ctxt)(struct super_block *sb,
110 struct llog_ctxt **ctxt);
111 int (* fs_set_fs_flags)(struct inode *inode, int flags);
112 int (* fs_clear_fs_flags)(struct inode *inode, int flags);
113 int (* fs_set_ost_flags)(struct super_block *sb);
114 int (* fs_set_mds_flags)(struct super_block *sb);
115 int (* fs_precreate_rec)(struct dentry *dentry, int *num,
117 int (* fs_set_xattr)(struct inode *inode, void *handle, char *name,
118 void *buffer, int buffer_size);
119 int (* fs_get_xattr)(struct inode *inode, char *name,
120 void *buffer, int buffer_size);
122 int (* fs_init_extents_ea)(struct inode *inode);
123 int (* fs_insert_extents_ea)(struct inode *inode, unsigned long from,
125 int (* fs_do_write_cow)(struct dentry *dentry, void *extents, int nexts);
126 int (* fs_write_extents)(struct dentry *dentry,
127 unsigned long offset, unsigned long blks);
128 int (* fs_get_fs_flags)(struct dentry *dentry);
129 int (* fs_remove_extents_ea)(struct inode *inode, unsigned long from,
131 int (* fs_get_ino_write_extents)(struct super_block *sb, ino_t ino,
132 char **pbuf, int *size);
133 int (* fs_free_write_extents)(struct super_block *sb, ino_t ino,
134 char *pbuf, int size);
135 int (* fs_get_inode_write_extents)(struct inode *inode, char **pbuf,
137 int (* fs_get_write_extents_num)(struct inode *inode, int* size);
139 int (* fs_get_op_len)(int, struct fsfilt_objinfo *, int);
140 int (* fs_add_dir_entry)(struct obd_device *, struct dentry *,
141 char *, int, unsigned long, unsigned long,
142 unsigned long, unsigned long);
143 int (* fs_del_dir_entry)(struct obd_device *, struct dentry *);
145 int (* fs_is_redirector)(struct inode *inode);
146 int (* fs_is_indirect)(struct inode *inode);
148 struct inode * (* fs_create_indirect)(struct inode *pri, int index,
150 struct inode *parent,
152 struct inode * (* fs_get_indirect)(struct inode *pri, int *table,
154 ino_t (* fs_get_indirect_ino)(struct super_block *sb, ino_t pri,
156 int (* fs_destroy_indirect)(struct inode *pri, int index,
157 struct inode *next_ind);
158 int (* fs_restore_indirect)(struct inode *pri, int index);
159 int (* fs_iterate)(struct super_block *sb,
160 int (*repeat)(struct inode *inode, void *priv),
161 struct inode **start, void *priv, int flag);
162 int (* fs_copy_block)(struct inode *dst, struct inode *src,
164 int (* fs_set_indirect)(struct inode *pri, int index,
165 ino_t ind_ino, ino_t parent_ino);
166 int (* fs_snap_feature)(struct super_block *sb, int feature,
168 int (* fs_set_snap_info)(struct inode *inode, void* key,
169 __u32 keylen, void *val, __u32 *vallen);
170 int (* fs_get_snap_info)(struct inode *inode, void* key,
171 __u32 keylen, void *val, __u32 *vallen);
172 int (* fs_set_snap_item)(struct super_block *sb, char *name);
173 int (* fs_read_dotsnap_dir_page)(struct file *file, char *buf,
174 size_t count, loff_t *ppos);
175 int (* fs_dir_ent_size)(char *name);
176 int (* fs_set_dir_ent)(struct super_block *sb, char *name,
177 char *buf, int buf_off, int nlen,
181 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
182 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
183 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
184 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
186 #define FSFILT_OP_UNLINK 1
187 #define FSFILT_OP_RMDIR 2
188 #define FSFILT_OP_RENAME 3
189 #define FSFILT_OP_CREATE 4
190 #define FSFILT_OP_MKDIR 5
191 #define FSFILT_OP_SYMLINK 6
192 #define FSFILT_OP_MKNOD 7
193 #define FSFILT_OP_SETATTR 8
194 #define FSFILT_OP_LINK 9
195 #define FSFILT_OP_CANCEL_UNLINK 10
196 #define FSFILT_OP_NOOP 15
198 /* XXX BUG 3188 -- must return to one set of opcodes */
199 #define KML_UNLINK 0x11
200 #define KML_RMDIR 0x12
201 #define KML_RENAME 0x13
202 #define KML_CREATE 0x14
203 #define KML_MKDIR 0x15
204 #define KML_SYMLINK 0x16
205 #define KML_MKNOD 0x17
206 #define KML_LINK 0x19
208 #define CACHE_UNLINK 0x21
209 #define CACHE_RMDIR 0x22
210 #define CACHE_RENAME 0x23
211 #define CACHE_CREATE 0x24
212 #define CACHE_MKDIR 0x25
213 #define CACHE_SYMLINK 0x26
214 #define CACHE_MKNOD 0x27
215 #define CACHE_LINK 0x29
216 #define CACHE_NOOP 0x2f
218 #define KML_CACHE_UNLINK 0x31
219 #define KML_CACHE_RMDIR 0x32
220 #define KML_CACHE_RENAME 0x33
221 #define KML_CACHE_CREATE 0x34
222 #define KML_CACHE_MKDIR 0x35
223 #define KML_CACHE_SYMLINK 0x36
224 #define KML_CACHE_MKNOD 0x37
225 #define KML_CACHE_LINK 0x39
226 #define KML_CACHE_NOOP 0x3f
228 /*for fsfilt set md ea*/
233 fsfilt_start_ops(struct fsfilt_operations *ops, struct inode *inode,
234 int op, struct obd_trans_info *oti, int logs)
236 unsigned long now = jiffies;
237 void *parent_handle = oti ? oti->oti_handle : NULL;
238 void *handle = ops->fs_start(inode, op, parent_handle, logs);
239 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
242 if (parent_handle == NULL) {
243 oti->oti_handle = handle;
244 } else if (handle != parent_handle) {
245 CERROR("mismatch: parent %p, handle %p, oti %p\n",
246 parent_handle, handle, oti);
250 if (time_after(jiffies, now + 15 * HZ))
251 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
256 fsfilt_start_log(struct obd_device *obd, struct inode *inode,
257 int op, struct obd_trans_info *oti, int logs)
259 return fsfilt_start_ops(obd->obd_fsops, inode, op, oti, logs);
263 fsfilt_start(struct obd_device *obd, struct inode *inode,
264 int op, struct obd_trans_info *oti)
266 return fsfilt_start_ops(obd->obd_fsops, inode, op, oti, 0);
270 llog_fsfilt_start(struct llog_ctxt *ctxt, struct inode *inode,
271 int op, struct obd_trans_info *oti)
273 return fsfilt_start_ops(ctxt->loc_fsops, inode, op, oti, 1);
277 fsfilt_commit_ops(struct fsfilt_operations *ops, struct super_block *sb,
278 struct inode *inode, void *handle, int force_sync)
280 unsigned long now = jiffies;
281 int rc = ops->fs_commit(sb, inode, handle, force_sync);
282 CDEBUG(D_INFO, "committing handle %p\n", handle);
284 if (time_after(jiffies, now + 15 * HZ))
285 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
291 fsfilt_commit(struct obd_device *obd, struct super_block *sb,
292 struct inode *inode, void *handle, int force_sync)
294 return fsfilt_commit_ops(obd->obd_fsops, sb, inode, handle, force_sync);
298 llog_fsfilt_commit(struct llog_ctxt *ctxt, struct inode *inode,
299 void *handle, int force_sync)
301 return fsfilt_commit_ops(ctxt->loc_fsops, inode->i_sb, inode, handle,
306 fsfilt_brw_start_log(struct obd_device *obd, int objcount,
307 struct fsfilt_objinfo *fso, int niocount,
308 struct niobuf_local *nb, struct obd_trans_info *oti,
311 unsigned long now = jiffies;
312 void *parent_handle = oti ? oti->oti_handle : NULL;
313 void *handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
314 parent_handle, logs);
315 CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
318 if (parent_handle == NULL) {
319 oti->oti_handle = handle;
320 } else if (handle != parent_handle) {
321 CERROR("mismatch: parent %p, handle %p, oti %p\n",
322 parent_handle, handle, oti);
326 if (time_after(jiffies, now + 15 * HZ))
327 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
333 fsfilt_brw_start(struct obd_device *obd, int objcount,
334 struct fsfilt_objinfo *fso, int niocount,
335 struct niobuf_local *nb, struct obd_trans_info *oti)
337 return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
341 fsfilt_commit_async(struct obd_device *obd, struct inode *inode,
342 void *handle, void **wait_handle)
344 unsigned long now = jiffies;
345 int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
347 CDEBUG(D_INFO, "committing handle %p (async)\n", *wait_handle);
348 if (time_after(jiffies, now + 15 * HZ))
349 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
355 fsfilt_commit_wait(struct obd_device *obd, struct inode *inode, void *handle)
357 unsigned long now = jiffies;
358 int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
359 CDEBUG(D_INFO, "waiting for completion %p\n", handle);
360 if (time_after(jiffies, now + 15 * HZ))
361 CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
366 fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
367 void *handle, struct iattr *iattr, int do_trunc)
369 unsigned long now = jiffies;
371 rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
372 if (time_after(jiffies, now + 15 * HZ))
373 CERROR("long setattr time %lus\n", (jiffies - now) / HZ);
378 fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
379 struct file *file, unsigned int cmd,
382 return obd->obd_fsops->fs_iocontrol(inode, file, cmd, arg);
385 static inline int fsfilt_setup(struct obd_device *obd,
386 struct super_block *fs)
388 if (obd->obd_fsops->fs_setup)
389 return obd->obd_fsops->fs_setup(obd, fs);
394 fsfilt_set_md(struct obd_device *obd, struct inode *inode,
395 void *handle, void *md, int size)
397 return obd->obd_fsops->fs_set_md(inode, handle, md, size);
401 fsfilt_get_md(struct obd_device *obd, struct inode *inode,
404 return obd->obd_fsops->fs_get_md(inode, md, size);
408 fsfilt_set_mid(struct obd_device *obd, struct inode *inode,
409 void *handle, void *mid, int size)
411 return obd->obd_fsops->fs_set_mid(inode, handle, mid, size);
415 fsfilt_get_mid(struct obd_device *obd, struct inode *inode,
418 return obd->obd_fsops->fs_get_mid(inode, mid, size);
422 fsfilt_set_sid(struct obd_device *obd, struct inode *inode,
423 void *handle, void *sid, int size)
425 return obd->obd_fsops->fs_set_sid(inode, handle, sid, size);
429 fsfilt_get_sid(struct obd_device *obd, struct inode *inode,
432 return obd->obd_fsops->fs_get_sid(inode, sid, size);
435 static inline int fsfilt_send_bio(int rw, struct obd_device *obd,
436 struct inode *inode, void *bio)
438 LASSERTF(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ, "%x\n", rw);
440 if (rw == OBD_BRW_READ)
441 return obd->obd_fsops->fs_send_bio(READ, inode, bio);
443 return obd->obd_fsops->fs_send_bio(WRITE, inode, bio);
447 fsfilt_putpage(struct obd_device *obd, struct inode *inode,
451 struct filter_obd *filter;
452 unsigned long now = jiffies;
454 LASSERT(obd != NULL);
455 LASSERT(inode != NULL);
456 LASSERT(page != NULL);
458 filter = &obd->u.filter;
460 if (!obd->obd_fsops->fs_putpage)
463 CDEBUG(D_INFO, "putpage %lx\n", page->index);
465 rc = obd->obd_fsops->fs_putpage(inode, page);
467 if (time_after(jiffies, now + 15 * HZ))
468 CERROR("long putpage time %lus\n", (jiffies - now) / HZ);
473 static inline struct page *
474 fsfilt_getpage(struct obd_device *obd, struct inode *inode,
478 unsigned long now = jiffies;
480 LASSERT(obd != NULL);
481 LASSERT(inode != NULL);
483 if (!obd->obd_fsops->fs_getpage)
484 return ERR_PTR(-ENOSYS);
486 CDEBUG(D_INFO, "getpage %lx\n", index);
488 page = obd->obd_fsops->fs_getpage(inode, index);
490 if (time_after(jiffies, now + 15 * HZ))
491 CERROR("long getpage time %lus\n", (jiffies - now) / HZ);
496 static inline ssize_t
497 fsfilt_readpage(struct obd_device *obd, struct file *file, char *buf,
498 size_t count, loff_t *offset)
500 return obd->obd_fsops->fs_readpage(file, buf, count, offset);
504 fsfilt_add_journal_cb(struct obd_device *obd, struct super_block *sb,
505 __u64 last_num, void *handle, fsfilt_cb_t cb_func,
508 return obd->obd_fsops->fs_add_journal_cb(obd, sb, last_num, handle,
512 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
514 fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
515 unsigned long max_age)
519 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
520 if (time_before(obd->obd_osfs_age, max_age)) {
521 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
522 if (rc == 0) /* N.B. statfs can't really fail */
523 obd->obd_osfs_age = jiffies;
525 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
532 fsfilt_sync(struct obd_device *obd, struct super_block *sb)
534 return obd->obd_fsops->fs_sync(sb);
537 static inline int fsfilt_map_inode_pages(struct obd_device *obd,
539 struct page **page, int pages,
540 unsigned long *blocks, int *created,
541 int create, struct semaphore *sem)
543 return obd->obd_fsops->fs_map_inode_pages(inode, page, pages, blocks,
544 created, create, sem);
546 static inline int fsfilt_get_fs_flags(struct obd_device *obd,
547 struct dentry *dentry)
549 if (obd->obd_fsops->fs_get_fs_flags)
550 return obd->obd_fsops->fs_get_fs_flags(dentry);
555 fsfilt_write_extents(struct obd_device *obd, struct dentry *dentry,
556 unsigned long offset, unsigned long blks)
558 if (obd->obd_fsops->fs_write_extents)
559 return obd->obd_fsops->fs_write_extents(dentry,
564 fsfilt_do_write_cow(struct obd_device *obd, struct dentry *dentry,
565 void *extents, int num_extents)
567 if (obd->obd_fsops->fs_do_write_cow)
568 return obd->obd_fsops->fs_do_write_cow(dentry, extents,
573 fs_prep_san_write(struct obd_device *obd, struct inode *inode,
574 long *blocks, int nblocks, loff_t newsize)
576 return obd->obd_fsops->fs_prep_san_write(inode, blocks,
581 fsfilt_read_record(struct obd_device *obd, struct file *file,
582 void *buf, loff_t size, loff_t *offs)
584 return obd->obd_fsops->fs_read_record(file, buf, size, offs);
588 llog_fsfilt_read_record(struct llog_ctxt *ctxt, struct file *file,
589 void *buf, loff_t size, loff_t *offs)
591 return ctxt->loc_fsops->fs_read_record(file, buf, size, offs);
595 fsfilt_write_record(struct obd_device *obd, struct file *file,
596 void *buf, loff_t size, loff_t *offs, int force_sync)
598 return obd->obd_fsops->fs_write_record(file, buf, size, offs,
603 llog_fsfilt_write_record(struct llog_ctxt *ctxt, struct file *file,
604 void *buf, loff_t size, loff_t *offs,
607 return ctxt->loc_fsops->fs_write_record(file, buf, size, offs,
612 fsfilt_set_fs_flags(struct obd_device *obd, struct inode *inode, int flags)
614 if (obd->obd_fsops->fs_set_fs_flags)
615 return obd->obd_fsops->fs_set_fs_flags(inode, flags);
620 fsfilt_clear_fs_flags(struct obd_device *obd, struct inode *inode, int flags)
622 if (obd->obd_fsops->fs_clear_fs_flags)
623 return obd->obd_fsops->fs_clear_fs_flags(inode, flags);
627 fsfilt_precreate_rec(struct obd_device *obd, struct dentry *dentry,
628 int *num, struct obdo *oa)
630 if (obd->obd_fsops->fs_precreate_rec)
631 return obd->obd_fsops->fs_precreate_rec(dentry, num, oa);
636 fsfilt_post_setup(struct obd_device *obd, struct dentry *de)
638 if (obd->obd_fsops->fs_post_setup)
639 return obd->obd_fsops->fs_post_setup(obd,
640 obd->obd_lvfs_ctxt.pwdmnt, de);
645 fsfilt_post_cleanup(struct obd_device *obd)
647 if (obd->obd_fsops->fs_post_cleanup)
648 return obd->obd_fsops->fs_post_cleanup(obd,
649 obd->obd_lvfs_ctxt.pwdmnt);
654 fsfilt_get_ino_write_extents(struct obd_device *obd,
655 struct super_block *sb,
656 int ino, char **buf, int *size)
658 if (obd->obd_fsops->fs_get_ino_write_extents)
659 return obd->obd_fsops->fs_get_ino_write_extents(sb, ino,
665 fsfilt_free_write_extents(struct obd_device *obd,
666 struct super_block *sb,
667 int ino, char *buf, int size)
669 if (obd->obd_fsops->fs_free_write_extents)
670 return obd->obd_fsops->fs_free_write_extents(sb, ino,
676 fsfilt_get_reint_log_ctxt(struct obd_device *obd,
677 struct super_block *sb,
678 struct llog_ctxt **ctxt)
680 if (obd->obd_fsops->fs_get_reint_log_ctxt)
681 return obd->obd_fsops->fs_get_reint_log_ctxt(sb, ctxt);
686 fsfilt_set_ost_flags(struct obd_device *obd, struct super_block *sb)
688 if (obd->obd_fsops->fs_set_ost_flags)
689 return obd->obd_fsops->fs_set_ost_flags(sb);
694 fsfilt_set_mds_flags(struct obd_device *obd, struct super_block *sb)
696 if (obd->obd_fsops->fs_set_mds_flags)
697 return obd->obd_fsops->fs_set_mds_flags(sb);
702 fsfilt_add_dir_entry(struct obd_device *obd, struct dentry *dir,
703 char *name, int namelen, unsigned long ino,
704 unsigned long generation, unsigned long mds,
707 LASSERT(obd->obd_fsops->fs_add_dir_entry);
709 return obd->obd_fsops->fs_add_dir_entry(obd, dir, name,
716 fsfilt_del_dir_entry(struct obd_device *obd, struct dentry *dentry)
718 LASSERT(obd->obd_fsops->fs_del_dir_entry);
719 return obd->obd_fsops->fs_del_dir_entry(obd, dentry);
723 fsfilt_set_snap_item(struct obd_device *obd, struct super_block *sb,
726 if (obd->obd_fsops->fs_set_snap_item)
727 return obd->obd_fsops->fs_set_snap_item(sb, name);
730 #endif /* __KERNEL__ */