1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/lib/fsfilt_smfs.c
5 * Lustre filesystem abstraction routines
7 * Copyright (C) 2004 Cluster File Systems, Inc.
8 * Author: Wang Di <wangdi@clusterfs.com>
10 * This file is part of Lustre, http://www.lustre.org.
12 * Lustre is free software; you can redistribute it and/or
13 * modify it under the terms of version 2 of the GNU General Public
14 * License as published by the Free Software Foundation.
16 * Lustre is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Lustre; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define DEBUG_SUBSYSTEM S_SM
29 #include <linux/jbd.h>
30 #include <linux/slab.h>
31 #include <linux/pagemap.h>
32 #include <linux/quotaops.h>
33 #include <linux/version.h>
34 #include <libcfs/kp30.h>
35 #include <linux/obd.h>
36 #include <linux/obd_class.h>
38 #include <linux/lustre_fsfilt.h>
39 #include <linux/lustre_smfs.h>
40 #include <linux/lustre_snap.h>
42 #include "smfs_internal.h"
44 static void *fsfilt_smfs_start(struct inode *inode, int op,
45 void *desc_private, int logs)
48 struct inode *cache_inode = I2CI(inode);
49 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
53 if (cache_fsfilt == NULL)
56 if (!cache_fsfilt->fs_start)
57 return ERR_PTR(-ENOSYS);
59 //opcode can be changed here.
60 //For example, unlink is rename in nature for undo plugin
61 extra = SMFS_PLG_HELP(inode->i_sb, PLG_TRANS_SIZE, &opcode);
63 handle = cache_fsfilt->fs_start(cache_inode, op, desc_private,
69 static void *fsfilt_smfs_brw_start(int objcount, struct fsfilt_objinfo *fso,
70 int niocount, struct niobuf_local *nb,
71 void *desc_private, int logs)
73 struct fsfilt_operations *cache_fsfilt;
74 struct dentry *cache_dentry = NULL;
75 struct inode *cache_inode = NULL;
76 struct fsfilt_objinfo cache_fso;
81 cache_fsfilt = I2FOPS(fso->fso_dentry->d_inode);
82 if (cache_fsfilt == NULL)
85 cache_inode = I2CI(fso->fso_dentry->d_inode);
86 cache_dentry = pre_smfs_dentry(NULL, cache_inode, fso->fso_dentry);
88 RETURN(ERR_PTR(-ENOMEM));
90 cache_fso.fso_dentry = cache_dentry;
91 cache_fso.fso_bufcnt = fso->fso_bufcnt;
93 if (!cache_fsfilt->fs_brw_start) {
94 rc = ERR_PTR(-ENOSYS);
98 rc = cache_fsfilt->fs_brw_start(objcount, &cache_fso, niocount, nb,
101 post_smfs_dentry(cache_dentry);
105 /* FIXME-WANGDI: here we can easily have inode == NULL due to
106 mds_open() behavior. It passes NULL inode to mds_finish_transno()
107 sometimes. Probably we should have spare way to get cache fsfilt
109 static int fsfilt_smfs_commit(struct super_block *sb, struct inode *inode,
110 void *h, int force_sync)
112 struct fsfilt_operations *cache_fsfilt = S2SMI(sb)->sm_cache_fsfilt;
113 struct super_block *csb = S2CSB(sb);
114 struct inode *cache_inode = NULL;
120 cache_inode = I2CI(inode);
122 if (cache_fsfilt == NULL)
125 if (!cache_fsfilt->fs_commit)
128 rc = cache_fsfilt->fs_commit(csb, cache_inode, h, force_sync);
133 static int fsfilt_smfs_commit_async(struct inode *inode, void *h,
136 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
137 struct inode *cache_inode = NULL;
140 cache_inode = I2CI(inode);
141 if (cache_fsfilt == NULL)
144 if (!cache_fsfilt->fs_commit_async)
147 rc = cache_fsfilt->fs_commit_async(cache_inode, h, wait_handle);
152 static int fsfilt_smfs_commit_wait(struct inode *inode, void *h)
154 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
155 struct inode *cache_inode = NULL;
158 cache_inode = I2CI(inode);
159 if (cache_fsfilt == NULL)
162 if (!cache_fsfilt->fs_commit_wait)
165 rc = cache_fsfilt->fs_commit_wait(cache_inode, h);
170 static int fsfilt_smfs_iocontrol(struct inode *inode, struct file *file,
171 unsigned int cmd, unsigned long arg)
173 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
174 struct inode *cache_inode = I2CI(inode);
175 struct smfs_file_info *sfi = NULL;
176 struct file * cache_file = NULL;
180 if (!cache_fsfilt || !cache_inode)
183 if (!cache_fsfilt->fs_iocontrol)
189 if (sfi->magic != SMFS_FILE_MAGIC)
191 cache_file = sfi->c_file;
194 pre_smfs_inode(inode, cache_inode);
196 rc = cache_fsfilt->fs_iocontrol(cache_inode, cache_file, cmd, arg);
198 post_smfs_inode(inode, cache_inode);
203 static int fsfilt_smfs_send_bio(int rw, struct inode *inode, void *bio)
205 struct inode *cache_inode;
206 struct fsfilt_operations *cache_fsfilt;
210 cache_fsfilt = I2FOPS(inode);
214 cache_inode = I2CI(inode);
218 if (!cache_fsfilt->fs_send_bio)
221 return cache_fsfilt->fs_send_bio(rw, cache_inode, bio);
224 static struct page * fsfilt_smfs_getpage(struct inode *inode, long int index)
226 struct fsfilt_operations *cache_fsfilt;
227 struct inode *cache_inode;
229 cache_fsfilt = I2FOPS(inode);
231 RETURN(ERR_PTR(-EINVAL));
233 cache_inode = I2CI(inode);
235 RETURN(ERR_PTR(-EINVAL));
237 if (!cache_fsfilt->fs_getpage)
238 RETURN(ERR_PTR(-ENOSYS));
240 if (SMFS_DO_COW(S2SMI(inode->i_sb))) {
241 struct address_space_operations *aops =
242 cache_inode->i_mapping->a_ops;
243 if (aops->bmap(cache_inode->i_mapping, index)) {
244 struct inode *ind_inode = NULL;
245 struct inode *cache_ind = NULL;
246 struct page *page = NULL;
248 ind_inode = smfs_cow_get_ind(inode, index);
250 RETURN(ERR_PTR(-EIO));
252 cache_ind = I2CI(ind_inode);
253 /*FIXME cow inode should be bottom fs inode */
254 page = cache_fsfilt->fs_getpage(cache_ind, index);
260 return cache_fsfilt->fs_getpage(cache_inode, index);
263 static ssize_t fsfilt_smfs_readpage(struct file *file, char *buf,
264 size_t count, loff_t *off)
266 struct fsfilt_operations *cache_fsfilt;
267 struct smfs_file_info *sfi;
268 struct inode *cache_inode;
271 struct hook_msg msg = {
272 .dentry = file->f_dentry,
277 cache_fsfilt = I2FOPS(file->f_dentry->d_inode);
281 cache_inode = I2CI(file->f_dentry->d_inode);
286 if (sfi->magic != SMFS_FILE_MAGIC)
289 pre_smfs_file(file, off, &cache_ppos);
290 SMFS_PRE_HOOK(file->f_dentry->d_inode, HOOK_READDIR, &msg);
294 if (smfs_dotsnap_inode(file->f_dentry->d_inode)) {
295 struct fsfilt_operations *snapops =
296 I2SNAPOPS(file->f_dentry->d_inode);
298 LASSERT(S_ISDIR(file->f_dentry->d_inode->i_mode));
300 rc = snapops->fs_read_dotsnap_dir_page(sfi->c_file, buf, count,
303 if (cache_fsfilt->fs_readpage)
304 rc = cache_fsfilt->fs_readpage(sfi->c_file, buf, count,
308 if (cache_fsfilt->fs_readpage)
309 rc = cache_fsfilt->fs_readpage(sfi->c_file, buf, count,
313 SMFS_POST_HOOK(file->f_dentry->d_inode, HOOK_READDIR, &msg, rc);
314 post_smfs_file(file);
320 static int fsfilt_smfs_add_journal_cb(struct obd_device *obd,
321 struct super_block *sb, __u64 last_rcvd,
322 void *handle, fsfilt_cb_t cb_func,
325 struct fsfilt_operations *cache_fsfilt = S2SMI(sb)->sm_cache_fsfilt;
326 struct super_block *csb = S2CSB(sb);
333 if (cache_fsfilt->fs_add_journal_cb)
334 rc = cache_fsfilt->fs_add_journal_cb(obd, csb, last_rcvd,
335 handle, cb_func, cb_data);
339 static int fsfilt_smfs_statfs(struct super_block *sb, struct obd_statfs *osfs)
341 struct fsfilt_operations *cache_fsfilt = S2SMI(sb)->sm_cache_fsfilt;
342 struct super_block *csb = S2CSB(sb);
350 if (!cache_fsfilt->fs_statfs)
353 rc = cache_fsfilt->fs_statfs(csb, osfs);
354 duplicate_sb(csb, sb);
359 static int fsfilt_smfs_sync(struct super_block *sb)
361 struct fsfilt_operations *cache_fsfilt = S2SMI(sb)->sm_cache_fsfilt;
362 struct super_block *csb = S2CSB(sb);
368 if (cache_fsfilt->fs_sync)
369 rc = cache_fsfilt->fs_sync(csb);
374 int fsfilt_smfs_map_inode_pages(struct inode *inode, struct page **page,
375 int pages, unsigned long *blocks, int *created,
376 int create, struct semaphore *sem)
378 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
379 struct inode *cache_inode = NULL;
381 struct hook_rw_msg msg = {
384 hook_op hook = create ? HOOK_WRITE : HOOK_READ;
391 cache_inode = I2CI(inode);
396 if (!cache_fsfilt->fs_map_inode_pages)
399 SMFS_PRE_HOOK(inode, hook, &msg);
400 down(&cache_inode->i_sem);
402 rc = cache_fsfilt->fs_map_inode_pages(cache_inode, page, pages, blocks,
403 created, create, sem);
404 up(&cache_inode->i_sem);
405 SMFS_POST_HOOK(inode, hook, &msg, rc);
410 static int fsfilt_smfs_prep_san_write(struct inode *inode, long *blocks,
411 int nblocks, loff_t newsize)
413 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
414 struct inode *cache_inode = NULL;
420 cache_inode = I2CI(inode);
425 if (!cache_fsfilt->fs_prep_san_write)
428 down(&cache_inode->i_sem);
429 rc = cache_fsfilt->fs_prep_san_write(cache_inode, blocks, nblocks,
431 up(&cache_inode->i_sem);
436 static int fsfilt_smfs_read_record(struct file * file, void *buf,
437 int size, loff_t *offs)
439 struct fsfilt_operations *cache_fsfilt;
440 struct inode *cache_inode;
441 struct smfs_file_info *sfi;
446 cache_fsfilt = I2FOPS(file->f_dentry->d_inode);
450 cache_inode = I2CI(file->f_dentry->d_inode);
455 LASSERT(sfi->magic == SMFS_FILE_MAGIC);
457 if (!cache_fsfilt->fs_read_record)
460 pre_smfs_file(file, offs, &cache_ppos);
461 rc = cache_fsfilt->fs_read_record(sfi->c_file, buf, size, cache_ppos);
462 post_smfs_file(file);
467 static int fsfilt_smfs_write_record(struct file *file, void *buf, int bufsize,
468 loff_t *offs, int force_sync)
470 struct fsfilt_operations *cache_fsfilt;
471 struct inode *cache_inode;
472 struct smfs_file_info *sfi;
478 cache_fsfilt = I2FOPS(file->f_dentry->d_inode);
482 cache_inode = I2CI(file->f_dentry->d_inode);
487 LASSERT(sfi->magic == SMFS_FILE_MAGIC);
489 if (!cache_fsfilt->fs_write_record)
492 pre_smfs_file(file, offs, &cache_ppos);
493 rc = cache_fsfilt->fs_write_record(sfi->c_file, buf,
494 bufsize, cache_ppos, force_sync);
496 post_smfs_file(file);
501 static int fsfilt_smfs_post_setup(struct obd_device *obd, struct vfsmount *mnt,
502 struct dentry *root_dentry)//, void *data)
504 struct super_block *sb = NULL;
513 S2SMI(sb)->smsi_exp = obd->obd_self_export;
515 rc = smfs_post_setup(obd, mnt, root_dentry);//, data);
517 CERROR("post_setup fails in obd %p rc=%d", obd, rc);
524 static int fsfilt_smfs_post_cleanup(struct obd_device *obd,
525 struct vfsmount *mnt)
527 struct super_block *sb = NULL;
533 smfs_post_cleanup(sb);
539 static int fsfilt_smfs_set_fs_flags(struct inode *inode, int flags)
544 if (flags & SM_ALL_PLG) /* enable all plugins */
545 SMFS_SET(I2SMI(inode)->smi_flags, SMFS_PLG_ALL);
547 if (SMFS_DO_COW(S2SMI(inode->i_sb)) && (flags & SM_DO_COW))
548 SMFS_SET_INODE_COW(inode);
553 static int fsfilt_smfs_clear_fs_flags(struct inode *inode, int flags)
558 if (SMFS_DO_REC(S2SMI(inode->i_sb)) && (flags & SM_DO_REC))
559 SMFS_CLEAN_INODE_REC(inode);
560 if (SMFS_DO_COW(S2SMI(inode->i_sb)) && (flags & SM_DO_COW))
561 SMFS_CLEAN_INODE_COW(inode);
563 if(flags & SM_ALL_PLG) /* disable all plugins */
564 SMFS_CLEAR(I2SMI(inode)->smi_flags, SMFS_PLG_ALL);
568 static int fsfilt_smfs_get_fs_flags(struct dentry *de)
570 struct inode *inode = de->d_inode;
576 flags = I2SMI(inode)->smi_flags & S2SMI(inode->i_sb)->plg_flags;
581 static int fsfilt_smfs_set_ost_flags(struct super_block *sb)
586 static int fsfilt_smfs_set_mds_flags(struct super_block *sb)
592 static int fsfilt_smfs_get_reint_log_ctxt(struct super_block *sb,
593 struct llog_ctxt **ctxt)
595 struct smfs_super_info *smfs_info = S2SMI(sb);
598 *ctxt = smfs_info->smsi_kml_log;
603 static int fsfilt_smfs_setup(struct obd_device *obd, struct super_block *sb)
605 struct smfs_super_info *smfs_info = S2SMI(sb);
606 struct fsfilt_operations *cache_fsfilt;
607 struct super_block *csb;
612 /* It should be initialized olready by smfs_read_super(). */
613 if (!(cache_fsfilt = smfs_info->sm_cache_fsfilt))
614 cache_fsfilt = fsfilt_get_ops(smfs_info->smsi_cache_ftype);
620 if (cache_fsfilt->fs_setup)
621 rc = cache_fsfilt->fs_setup(obd, csb);
623 duplicate_sb(sb, csb);
628 static int fsfilt_smfs_setattr(struct dentry *dentry, void *handle,
629 struct iattr *iattr, int do_trunc)
631 struct fsfilt_operations *cache_fsfilt = I2FOPS(dentry->d_inode);
632 struct dentry *cache_dentry = NULL;
633 struct inode *cache_inode = I2CI(dentry->d_inode);
634 struct smfs_super_info *sbi = S2SMI(dentry->d_inode->i_sb);
635 struct hook_attr_msg msg = {
644 if (!cache_fsfilt->fs_setattr)
647 cache_dentry = pre_smfs_dentry(NULL, cache_inode, dentry);
651 pre_smfs_inode(dentry->d_inode, cache_inode);
653 SMFS_PRE_HOOK(dentry->d_inode, HOOK_F_SETATTR, &msg);
655 if (SMFS_DO_HND_IBLOCKS(sbi)) {
656 /* size-on-mds changes i_blocks directly to reflect
657 * aggregated i_blocks from all OSTs -bzzz */
658 cache_inode->i_blocks = dentry->d_inode->i_blocks;
661 rc = cache_fsfilt->fs_setattr(cache_dentry, handle, iattr, do_trunc);
663 SMFS_POST_HOOK(dentry->d_inode, HOOK_F_SETATTR, &msg, rc);
664 post_smfs_inode(dentry->d_inode, cache_inode);
666 post_smfs_dentry(cache_dentry);
670 static int fsfilt_smfs_set_xattr(struct inode *inode, void *handle, char *name,
671 void *buffer, int buffer_size)
673 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
674 struct inode *cache_inode = NULL;
675 struct hook_xattr_msg msg = {
678 .buffer_size = buffer_size
688 cache_inode = I2CI(inode);
692 lov = (!strcmp(name, XATTR_LUSTRE_MDS_LOV_EA));
693 pre_smfs_inode(inode, cache_inode);
694 SMFS_PRE_HOOK(inode, HOOK_F_SETXATTR, &msg);
695 if (cache_fsfilt->fs_set_xattr)
696 rc = cache_fsfilt->fs_set_xattr(cache_inode, handle, name,
697 buffer, buffer_size);
699 SMFS_POST_HOOK(inode, HOOK_F_SETXATTR, &msg, rc);
700 post_smfs_inode(inode, cache_inode);
705 static int fsfilt_smfs_get_xattr(struct inode *inode, char *name,
706 void *buffer, int buffer_size)
708 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
709 struct inode *cache_inode = NULL;
715 cache_inode = I2CI(inode);
719 pre_smfs_inode(inode, cache_inode);
720 if (cache_fsfilt->fs_get_xattr)
721 rc = cache_fsfilt->fs_get_xattr(cache_inode, name,
722 buffer, buffer_size);
723 post_smfs_inode(inode, cache_inode);
727 static int fsfilt_smfs_set_md(struct inode *inode, void *handle,
728 void *lmm, int lmm_size, enum ea_type type)
734 rc = fsfilt_smfs_set_xattr(inode, handle,
735 XATTR_LUSTRE_MDS_LOV_EA,
739 rc = fsfilt_smfs_set_xattr(inode, handle,
740 XATTR_LUSTRE_MDS_MEA_EA,
744 rc = fsfilt_smfs_set_xattr(inode, handle,
745 XATTR_LUSTRE_MDS_SID_EA,
749 rc = fsfilt_smfs_set_xattr(inode, handle,
750 XATTR_LUSTRE_MDS_PID_EA,
754 rc = fsfilt_smfs_set_xattr(inode, handle,
755 XATTR_LUSTRE_MDS_KEY_EA,
765 static int fsfilt_smfs_get_md(struct inode *inode, void *lmm,
766 int lmm_size, enum ea_type type)
772 rc = fsfilt_smfs_get_xattr(inode,
773 XATTR_LUSTRE_MDS_LOV_EA,
777 rc = fsfilt_smfs_get_xattr(inode,
778 XATTR_LUSTRE_MDS_MEA_EA,
782 rc = fsfilt_smfs_get_xattr(inode,
783 XATTR_LUSTRE_MDS_SID_EA,
787 rc = fsfilt_smfs_get_xattr(inode,
788 XATTR_LUSTRE_MDS_PID_EA,
792 rc = fsfilt_smfs_get_xattr(inode,
793 XATTR_LUSTRE_MDS_KEY_EA,
803 static int fsfilt_smfs_insert_extents_ea(struct inode *inode,
804 unsigned long from, unsigned long num)
806 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
807 struct inode *cache_inode = NULL;
813 cache_inode = I2CI(inode);
817 pre_smfs_inode(inode, cache_inode);
819 if (cache_fsfilt->fs_insert_extents_ea)
820 rc = cache_fsfilt->fs_insert_extents_ea(cache_inode, from, num);
822 post_smfs_inode(inode, cache_inode);
826 static int fsfilt_smfs_remove_extents_ea(struct inode *inode,
827 unsigned long from, unsigned long num)
829 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
830 struct inode *cache_inode = NULL;
836 cache_inode = I2CI(inode);
840 pre_smfs_inode(inode, cache_inode);
842 if (cache_fsfilt->fs_remove_extents_ea)
843 rc = cache_fsfilt->fs_remove_extents_ea(cache_inode, from, num);
845 post_smfs_inode(inode, cache_inode);
849 static int fsfilt_smfs_init_extents_ea(struct inode *inode)
851 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
852 struct inode *cache_inode = NULL;
859 cache_inode = I2CI(inode);
863 pre_smfs_inode(inode, cache_inode);
865 if (cache_fsfilt->fs_init_extents_ea)
866 rc = cache_fsfilt->fs_init_extents_ea(cache_inode);
868 post_smfs_inode(inode, cache_inode);
872 static int fsfilt_smfs_free_extents(struct super_block *sb, ino_t ino,
873 char *pbuf, int size)
875 OBD_FREE(pbuf, size * (sizeof(struct ldlm_extent)));
879 static int fsfilt_smfs_write_extents(struct dentry *dentry,
880 unsigned long from, unsigned long num)
882 /* TODO: fix this later */
885 struct inode * cache_inode = I2CI(dentry->d_inode);
886 struct hook_write_msg msg = {
894 pre_smfs_inode(dentry->d_inode, cache_inode);
896 SMFS_PRE_HOOK(dentry->d_inode, HOOK_WRITE, &msg);
898 rc = smfs_write_extents(dentry->d_inode, dentry, from, num);
899 SMFS_POST_HOOK(dentry->d_inode, HOOK_WRITE, &msg, rc);
900 post_smfs_inode(dentry->d_inode, cache_inode);
908 static int fsfilt_smfs_precreate_rec(struct dentry *dentry, int *count,
912 /* Why to log precreate?? MDS will do this in any case
913 if (SMFS_DO_REC(S2SMI(dentry->d_inode->i_sb)))
914 rc = smfs_rec_precreate(dentry, count, oa);
919 // should be rewrote when needed
920 static int fsfilt_smfs_get_ino_write_extents(struct super_block *sb, ino_t ino,
921 char **pbuf, int *size)
925 struct fs_extent *fs_extents;
926 struct ldlm_extent *extents = NULL;
928 struct inode *cache_inode;
929 struct fsfilt_operations *cache_fsfilt = NULL;
930 struct lvfs_run_ctxt saved;
931 int fs_ex_size, ex_num, flags;
932 char *buf = NULL, *ex_buf = NULL;
935 push_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
937 inode = iget(sb, ino);
939 if (!inode || is_bad_inode(inode)) {
940 CWARN("Can not get inode %lu ino\n", ino);
943 cache_inode = I2CI(inode);
944 cache_fsfilt = I2FOPS(inode);
946 rc = cache_fsfilt->fs_get_xattr(cache_inode, REINT_EXTENTS_FLAGS,
947 &flags, sizeof(int));
948 if (!(flags & SMFS_OVER_WRITE) && !(flags & SMFS_DIRTY_WRITE)) {
950 } else if (flags & SMFS_OVER_WRITE) {
952 OBD_ALLOC(ex_buf, sizeof(struct ldlm_extent));
954 GOTO(out, rc=-ENOMEM);
955 extents = (struct ldlm_extent*)(ex_buf);
957 extents->end = 0xffffffff;
961 rc = cache_fsfilt->fs_get_write_extents_num(cache_inode, &fs_ex_size);
964 OBD_ALLOC(buf, fs_ex_size);
966 GOTO(out, rc=-ENOMEM);
968 rc = cache_fsfilt->fs_get_inode_write_extents(cache_inode, &buf,
973 ex_num = fs_ex_size / sizeof(struct fs_extent);
975 OBD_ALLOC(ex_buf, ex_num* sizeof(struct ldlm_extent));
977 GOTO(out, rc=-ENOMEM);
979 fs_extents = (struct fs_extent*)(buf);
980 extents = (struct ldlm_extent*)(ex_buf);
982 int blk_size = I2CI(inode)->i_blksize;
984 extents->start = fs_extents->e_block * blk_size;
985 extents->end = extents->start + fs_extents->e_num * blk_size;
994 OBD_FREE(buf, fs_ex_size);
996 OBD_FREE(ex_buf, (*size) * (sizeof(struct ldlm_extent)));
997 pop_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
1002 static int fsfilt_smfs_set_snap_item(struct super_block *sb, char *name)
1008 #warning "still not implement for add snap item -wangdi"
1012 static int fsfilt_smfs_do_write_cow(struct dentry *de, void *extents,
1017 struct write_extents *w_ext = (struct write_extents *)extents;
1020 for (i = 0; i < num_extents; i++) {
1021 size_t count = w_ext->w_count;
1022 loff_t off = w_ext->w_pos;
1023 rc = smfs_cow_write_pre(de->d_inode, de, &count, &off);
1032 static int fsfilt_smfs_add_dir_entry(struct obd_device * obd,
1033 struct dentry * parent, char* name,
1034 int namelen, unsigned long ino,
1035 unsigned long generation,
1039 struct fsfilt_operations *cache_fsfilt = I2FOPS(parent->d_inode);
1040 struct dentry *cache_dentry = NULL, *dentry = NULL;
1041 struct inode *cache_parent = I2CI(parent->d_inode);
1049 if (!cache_fsfilt->fs_add_dir_entry)
1052 dentry = ll_lookup_one_len(name, parent, namelen);
1053 if (IS_ERR(dentry)) {
1054 CERROR("can't lookup %*s in %lu/%lu: %d\n", namelen,
1055 name, parent->d_inode->i_ino,
1056 (unsigned long) parent->d_inode->i_generation,
1057 (int) PTR_ERR(dentry));
1058 RETURN(PTR_ERR(dentry));
1060 if (dentry->d_inode != NULL || dentry->d_flags & DCACHE_CROSS_REF) {
1061 CERROR("dentry %*s(0x%p) found\n", dentry->d_name.len,
1062 dentry->d_name.name, dentry);
1066 /* mds_reint_rename() may use this method to add dir entry
1067 * that points onto local inode. and we don't want to find
1068 * it cross-ref by subsequent lookups */
1071 dentry->d_flags |= DCACHE_CROSS_REF;
1072 dentry->d_inum = ino;
1073 dentry->d_mdsnum = mds;
1074 dentry->d_generation = generation;
1075 dentry->d_fid = fid;
1078 cache_dentry = pre_smfs_dentry(NULL, cache_parent, parent);
1079 if (!cache_dentry) {
1083 pre_smfs_inode(parent->d_inode, cache_parent);
1085 rc = cache_fsfilt->fs_add_dir_entry(obd, cache_dentry, name, namelen,
1086 ino, generation, mds, fid);
1088 post_smfs_inode(parent->d_inode, cache_parent);
1090 post_smfs_dentry(cache_dentry);
1096 static int fsfilt_smfs_del_dir_entry(struct obd_device * obd,
1097 struct dentry * dentry)
1099 struct fsfilt_operations *cache_fsfilt = I2FOPS(dentry->d_parent->d_inode);
1100 struct dentry *cache_dentry = NULL, *cache_parent = NULL;
1101 struct inode * cache_dir = I2CI(dentry->d_parent->d_inode);
1102 struct inode * cache_inode = NULL;
1110 if (!cache_fsfilt->fs_del_dir_entry)
1113 if (dentry->d_inode)
1114 cache_inode = I2CI(dentry->d_inode);
1116 cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent);
1117 cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
1118 if (!cache_parent || !cache_dentry) {
1123 pre_smfs_inode(dentry->d_parent->d_inode, cache_dir);
1124 pre_smfs_inode(dentry->d_inode, cache_inode);
1126 rc = cache_fsfilt->fs_del_dir_entry(obd, cache_dentry);
1131 post_smfs_inode(dentry->d_inode, cache_inode);
1132 if (S_ISDIR(dentry->d_inode->i_mode))
1133 dentry->d_parent->d_inode->i_nlink--;
1135 post_smfs_inode(dentry->d_parent->d_inode, cache_dir);
1138 post_smfs_dentry(cache_dentry);
1139 post_smfs_dentry(cache_parent);
1144 static int fsfilt_smfs_set_info (struct super_block *sb, struct inode * inode,
1145 __u32 keylen, void *key,
1146 __u32 valsize, void *val)
1149 struct plg_info_msg msg = {
1155 if (keylen >= 9 && memcmp(key, "file_read", 9) == 0) {
1157 * this key used to inform smfs on OST about incoming r/w
1159 struct lustre_id * id = val;
1160 struct hook_rw_msg msg = {
1165 SMFS_POST_HOOK(inode, HOOK_SI_READ, &msg, rc);
1167 else if (keylen >= 10 && memcmp(key, "file_write", 10) == 0) {
1169 * this key used to inform smfs on OST about incoming r/w
1171 struct lustre_id * id = val;
1172 struct hook_rw_msg msg = {
1177 SMFS_POST_HOOK(inode, HOOK_SI_WRITE, &msg, rc);
1179 else if (keylen >= 10 && memcmp(key, "audit_info", 10) == 0) {
1180 /* this key used to pass audit data on MDS */
1181 struct audit_info * info = val;
1183 SMFS_POST_HOOK(inode, HOOK_SPECIAL, info, info->m.result);
1185 else if (keylen >= 8 && memcmp(key, "auditlog", 8) == 0) {
1187 * this key used to inform smfs on OST about client audit data
1190 audit_client_log(sb, val);
1192 else if (keylen == 5 && memcmp(key, "audit", 5) == 0) {
1193 smfs_set_audit(sb, inode, (__u64 *)val);
1195 else if (keylen == 7 && memcmp(key, "id2name", 7) == 0) {
1196 rc = SMFS_PLG_HELP(sb, PLG_SET_INFO, &msg);
1204 static int fsfilt_smfs_get_info (struct super_block *sb, struct inode * inode,
1205 __u32 keylen, void *key,
1206 __u32 *valsize, void *val)
1212 if (keylen == 5 && strcmp(key, "audit") == 0) {
1214 rc = smfs_get_audit(sb, inode, NULL, mask);
1220 static struct fsfilt_operations fsfilt_smfs_ops = {
1222 .fs_owner = THIS_MODULE,
1223 .fs_start = fsfilt_smfs_start,
1224 .fs_brw_start = fsfilt_smfs_brw_start,
1225 .fs_commit = fsfilt_smfs_commit,
1226 .fs_commit_async = fsfilt_smfs_commit_async,
1227 .fs_commit_wait = fsfilt_smfs_commit_wait,
1228 .fs_setattr = fsfilt_smfs_setattr,
1229 .fs_iocontrol = fsfilt_smfs_iocontrol,
1230 .fs_set_md = fsfilt_smfs_set_md,
1231 .fs_get_md = fsfilt_smfs_get_md,
1232 .fs_readpage = fsfilt_smfs_readpage,
1233 .fs_getpage = fsfilt_smfs_getpage,
1234 .fs_add_journal_cb = fsfilt_smfs_add_journal_cb,
1235 .fs_statfs = fsfilt_smfs_statfs,
1236 .fs_sync = fsfilt_smfs_sync,
1237 .fs_map_inode_pages = fsfilt_smfs_map_inode_pages,
1238 .fs_prep_san_write = fsfilt_smfs_prep_san_write,
1239 .fs_write_record = fsfilt_smfs_write_record,
1240 .fs_read_record = fsfilt_smfs_read_record,
1241 .fs_setup = fsfilt_smfs_setup,
1242 .fs_send_bio = fsfilt_smfs_send_bio,
1243 .fs_set_xattr = fsfilt_smfs_set_xattr,
1244 .fs_get_xattr = fsfilt_smfs_get_xattr,
1245 .fs_get_op_len = NULL,
1246 .fs_del_dir_entry = fsfilt_smfs_del_dir_entry,
1247 .fs_add_dir_entry = fsfilt_smfs_add_dir_entry,
1248 .fs_insert_extents_ea = fsfilt_smfs_insert_extents_ea,
1249 .fs_remove_extents_ea = fsfilt_smfs_remove_extents_ea,
1250 .fs_init_extents_ea = fsfilt_smfs_init_extents_ea,
1251 .fs_get_ino_write_extents = fsfilt_smfs_get_ino_write_extents,
1252 .fs_get_write_extents_num = NULL,
1254 .fs_free_write_extents = fsfilt_smfs_free_extents,
1255 .fs_write_extents = fsfilt_smfs_write_extents,
1256 .fs_post_setup = fsfilt_smfs_post_setup,
1257 .fs_post_cleanup = fsfilt_smfs_post_cleanup,
1258 .fs_set_fs_flags = fsfilt_smfs_set_fs_flags,
1259 .fs_clear_fs_flags = fsfilt_smfs_clear_fs_flags,
1260 .fs_get_fs_flags = fsfilt_smfs_get_fs_flags,
1261 .fs_set_ost_flags = fsfilt_smfs_set_ost_flags,
1262 .fs_set_mds_flags = fsfilt_smfs_set_mds_flags,
1263 .fs_precreate_rec = fsfilt_smfs_precreate_rec,
1264 .fs_set_info = fsfilt_smfs_set_info,
1265 .fs_get_info = fsfilt_smfs_get_info,
1266 .fs_set_snap_item = fsfilt_smfs_set_snap_item,
1267 .fs_do_write_cow = fsfilt_smfs_do_write_cow,
1270 struct fsfilt_operations *get_smfs_fs_ops(void)
1272 return (&fsfilt_smfs_ops);
1274 EXPORT_SYMBOL(get_smfs_fs_ops);