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;
275 cache_fsfilt = I2FOPS(file->f_dentry->d_inode);
279 cache_inode = I2CI(file->f_dentry->d_inode);
284 if (sfi->magic != SMFS_FILE_MAGIC)
287 if (off != &(file->f_pos))
288 cache_ppos = &tmp_ppos;
290 cache_ppos = &sfi->c_file->f_pos;
293 pre_smfs_inode(file->f_dentry->d_inode, cache_inode);
296 if (smfs_dotsnap_inode(file->f_dentry->d_inode)) {
297 struct fsfilt_operations *snapops =
298 I2SNAPOPS(file->f_dentry->d_inode);
300 LASSERT(S_ISDIR(file->f_dentry->d_inode->i_mode));
302 rc = snapops->fs_read_dotsnap_dir_page(sfi->c_file, buf, count,
305 if (cache_fsfilt->fs_readpage)
306 rc = cache_fsfilt->fs_readpage(sfi->c_file, buf, count,
310 if (cache_fsfilt->fs_readpage)
311 rc = cache_fsfilt->fs_readpage(sfi->c_file, buf, count,
316 post_smfs_inode(file->f_dentry->d_inode, cache_inode);
317 duplicate_file(file, sfi->c_file);
323 static int fsfilt_smfs_add_journal_cb(struct obd_device *obd,
324 struct super_block *sb, __u64 last_rcvd,
325 void *handle, fsfilt_cb_t cb_func,
328 struct fsfilt_operations *cache_fsfilt = S2SMI(sb)->sm_cache_fsfilt;
329 struct super_block *csb = S2CSB(sb);
336 if (cache_fsfilt->fs_add_journal_cb)
337 rc = cache_fsfilt->fs_add_journal_cb(obd, csb, last_rcvd,
338 handle, cb_func, cb_data);
342 static int fsfilt_smfs_statfs(struct super_block *sb, struct obd_statfs *osfs)
344 struct fsfilt_operations *cache_fsfilt = S2SMI(sb)->sm_cache_fsfilt;
345 struct super_block *csb = S2CSB(sb);
353 if (!cache_fsfilt->fs_statfs)
356 rc = cache_fsfilt->fs_statfs(csb, osfs);
357 duplicate_sb(csb, sb);
362 static int fsfilt_smfs_sync(struct super_block *sb)
364 struct fsfilt_operations *cache_fsfilt = S2SMI(sb)->sm_cache_fsfilt;
365 struct super_block *csb = S2CSB(sb);
371 if (cache_fsfilt->fs_sync)
372 rc = cache_fsfilt->fs_sync(csb);
377 int fsfilt_smfs_map_inode_pages(struct inode *inode, struct page **page,
378 int pages, unsigned long *blocks, int *created,
379 int create, struct semaphore *sem)
381 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
382 struct inode *cache_inode = NULL;
390 cache_inode = I2CI(inode);
395 if (!cache_fsfilt->fs_map_inode_pages)
398 down(&cache_inode->i_sem);
400 rc = cache_fsfilt->fs_map_inode_pages(cache_inode, page, pages, blocks,
401 created, create, sem);
402 up(&cache_inode->i_sem);
407 static int fsfilt_smfs_prep_san_write(struct inode *inode, long *blocks,
408 int nblocks, loff_t newsize)
410 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
411 struct inode *cache_inode = NULL;
417 cache_inode = I2CI(inode);
422 if (!cache_fsfilt->fs_prep_san_write)
425 down(&cache_inode->i_sem);
426 rc = cache_fsfilt->fs_prep_san_write(cache_inode, blocks, nblocks,
428 up(&cache_inode->i_sem);
433 static int fsfilt_smfs_read_record(struct file * file, void *buf,
434 int size, loff_t *offs)
436 struct fsfilt_operations *cache_fsfilt;
437 struct inode *cache_inode;
438 struct smfs_file_info *sfi;
444 cache_fsfilt = I2FOPS(file->f_dentry->d_inode);
448 cache_inode = I2CI(file->f_dentry->d_inode);
454 if (sfi->magic != SMFS_FILE_MAGIC) BUG();
456 if (offs != &(file->f_pos))
457 cache_ppos = &tmp_ppos;
459 cache_ppos = &sfi->c_file->f_pos;
462 pre_smfs_inode(file->f_dentry->d_inode, cache_inode);
464 if (!cache_fsfilt->fs_read_record)
467 rc = cache_fsfilt->fs_read_record(sfi->c_file, buf, size, cache_ppos);
470 post_smfs_inode(file->f_dentry->d_inode, cache_inode);
471 duplicate_file(file, sfi->c_file);
476 static int fsfilt_smfs_write_record(struct file *file, void *buf, int bufsize,
477 loff_t *offs, int force_sync)
479 struct fsfilt_operations *cache_fsfilt;
480 struct inode *cache_inode;
481 struct smfs_file_info *sfi;
488 cache_fsfilt = I2FOPS(file->f_dentry->d_inode);
492 cache_inode = I2CI(file->f_dentry->d_inode);
498 if (sfi->magic != SMFS_FILE_MAGIC)
501 if (offs != &(file->f_pos))
502 cache_ppos = &tmp_ppos;
504 cache_ppos = &sfi->c_file->f_pos;
507 pre_smfs_inode(file->f_dentry->d_inode, cache_inode);
509 if (!cache_fsfilt->fs_write_record)
512 rc = cache_fsfilt->fs_write_record(sfi->c_file, buf,
513 bufsize, cache_ppos, force_sync);
515 post_smfs_inode(file->f_dentry->d_inode, cache_inode);
516 duplicate_file(file, sfi->c_file);
521 static int fsfilt_smfs_post_setup(struct obd_device *obd, struct vfsmount *mnt,
522 struct dentry *root_dentry)
524 struct super_block *sb = NULL;
533 S2SMI(sb)->smsi_exp = obd->obd_self_export;
535 rc = smfs_post_setup(obd, mnt, root_dentry);
537 CERROR("post_setup fails in obd %p rc=%d", obd, rc);
546 static int fsfilt_smfs_post_cleanup(struct obd_device *obd,
547 struct vfsmount *mnt)
549 struct super_block *sb = NULL;
555 smfs_post_cleanup(sb);
561 static int fsfilt_smfs_set_fs_flags(struct inode *inode, int flags)
566 if (flags & SM_ALL_PLG) /* enable all plugins */
567 SMFS_SET(I2SMI(inode)->smi_flags, SMFS_PLG_ALL);
569 if (SMFS_DO_COW(S2SMI(inode->i_sb)) && (flags & SM_DO_COW))
570 SMFS_SET_INODE_COW(inode);
575 static int fsfilt_smfs_clear_fs_flags(struct inode *inode, int flags)
580 if (SMFS_DO_REC(S2SMI(inode->i_sb)) && (flags & SM_DO_REC))
581 SMFS_CLEAN_INODE_REC(inode);
582 if (SMFS_DO_COW(S2SMI(inode->i_sb)) && (flags & SM_DO_COW))
583 SMFS_CLEAN_INODE_COW(inode);
585 if(flags & SM_ALL_PLG) /* disable all plugins */
586 SMFS_CLEAR(I2SMI(inode)->smi_flags, SMFS_PLG_ALL);
590 static int fsfilt_smfs_get_fs_flags(struct dentry *de)
592 struct inode *inode = de->d_inode;
598 flags = I2SMI(inode)->smi_flags & S2SMI(inode->i_sb)->plg_flags;
603 static int fsfilt_smfs_set_ost_flags(struct super_block *sb)
608 static int fsfilt_smfs_set_mds_flags(struct super_block *sb)
614 static int fsfilt_smfs_get_reint_log_ctxt(struct super_block *sb,
615 struct llog_ctxt **ctxt)
617 struct smfs_super_info *smfs_info = S2SMI(sb);
620 *ctxt = smfs_info->smsi_kml_log;
625 static int fsfilt_smfs_setup(struct obd_device *obd, struct super_block *sb)
627 struct smfs_super_info *smfs_info = S2SMI(sb);
628 struct fsfilt_operations *cache_fsfilt;
629 struct super_block *csb;
634 /* It should be initialized olready by smfs_read_super(). */
635 if (!(cache_fsfilt = smfs_info->sm_cache_fsfilt))
636 cache_fsfilt = fsfilt_get_ops(smfs_info->smsi_cache_ftype);
642 if (cache_fsfilt->fs_setup)
643 rc = cache_fsfilt->fs_setup(obd, csb);
645 duplicate_sb(sb, csb);
650 static int fsfilt_smfs_setattr(struct dentry *dentry, void *handle,
651 struct iattr *iattr, int do_trunc)
653 struct fsfilt_operations *cache_fsfilt = I2FOPS(dentry->d_inode);
654 struct dentry *cache_dentry = NULL;
655 struct inode *cache_inode = I2CI(dentry->d_inode);
656 struct hook_setattr_msg msg = {
665 if (!cache_fsfilt->fs_setattr)
668 cache_dentry = pre_smfs_dentry(NULL, cache_inode, dentry);
672 pre_smfs_inode(dentry->d_inode, cache_inode);
674 SMFS_PRE_HOOK(dentry->d_inode, HOOK_F_SETATTR, &msg);
676 rc = cache_fsfilt->fs_setattr(cache_dentry, handle, iattr, do_trunc);
678 SMFS_POST_HOOK(dentry->d_inode, HOOK_F_SETATTR, &msg, rc);
679 post_smfs_inode(dentry->d_inode, cache_inode);
681 post_smfs_dentry(cache_dentry);
684 static int fsfilt_smfs_set_xattr(struct inode *inode, void *handle, char *name,
685 void *buffer, int buffer_size)
687 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
688 struct inode *cache_inode = NULL;
689 struct hook_setxattr_msg msg = {
693 .buffer_size = buffer_size
702 cache_inode = I2CI(inode);
706 pre_smfs_inode(inode, cache_inode);
708 SMFS_PRE_HOOK(inode, HOOK_F_SETXATTR, &msg);
709 if (cache_fsfilt->fs_set_xattr)
710 rc = cache_fsfilt->fs_set_xattr(cache_inode, handle, name,
711 buffer, buffer_size);
713 SMFS_POST_HOOK(inode, HOOK_F_SETXATTR, &msg, rc);
714 post_smfs_inode(inode, cache_inode);
719 static int fsfilt_smfs_get_xattr(struct inode *inode, char *name,
720 void *buffer, int buffer_size)
722 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
723 struct inode *cache_inode = NULL;
729 cache_inode = I2CI(inode);
733 pre_smfs_inode(inode, cache_inode);
735 if (cache_fsfilt->fs_get_xattr)
736 rc = cache_fsfilt->fs_get_xattr(cache_inode, name,
737 buffer, buffer_size);
738 post_smfs_inode(inode, cache_inode);
743 #define XATTR_LUSTRE_MDS_LOV_EA "lov"
744 #define XATTR_LUSTRE_MDS_MEA_EA "mea"
745 #define XATTR_LUSTRE_MDS_MID_EA "mid"
746 #define XATTR_LUSTRE_MDS_SID_EA "sid"
748 static int fsfilt_smfs_set_md(struct inode *inode, void *handle,
749 void *lmm, int lmm_size, enum ea_type type)
755 rc = fsfilt_smfs_set_xattr(inode, handle,
756 XATTR_LUSTRE_MDS_LOV_EA,
760 rc = fsfilt_smfs_set_xattr(inode, handle,
761 XATTR_LUSTRE_MDS_MEA_EA,
765 rc = fsfilt_smfs_set_xattr(inode, handle,
766 XATTR_LUSTRE_MDS_SID_EA,
770 rc = fsfilt_smfs_set_xattr(inode, handle,
771 XATTR_LUSTRE_MDS_MID_EA,
781 static int fsfilt_smfs_get_md(struct inode *inode, void *lmm,
782 int lmm_size, enum ea_type type)
788 rc = fsfilt_smfs_get_xattr(inode,
789 XATTR_LUSTRE_MDS_LOV_EA,
793 rc = fsfilt_smfs_get_xattr(inode,
794 XATTR_LUSTRE_MDS_MEA_EA,
798 rc = fsfilt_smfs_get_xattr(inode,
799 XATTR_LUSTRE_MDS_SID_EA,
803 rc = fsfilt_smfs_get_xattr(inode,
804 XATTR_LUSTRE_MDS_MID_EA,
814 static int fsfilt_smfs_insert_extents_ea(struct inode *inode,
815 unsigned long from, unsigned long num)
817 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
818 struct inode *cache_inode = NULL;
824 cache_inode = I2CI(inode);
828 pre_smfs_inode(inode, cache_inode);
830 if (cache_fsfilt->fs_insert_extents_ea)
831 rc = cache_fsfilt->fs_insert_extents_ea(cache_inode, from, num);
833 post_smfs_inode(inode, cache_inode);
837 static int fsfilt_smfs_remove_extents_ea(struct inode *inode,
838 unsigned long from, unsigned long num)
840 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
841 struct inode *cache_inode = NULL;
847 cache_inode = I2CI(inode);
851 pre_smfs_inode(inode, cache_inode);
853 if (cache_fsfilt->fs_remove_extents_ea)
854 rc = cache_fsfilt->fs_remove_extents_ea(cache_inode, from, num);
856 post_smfs_inode(inode, cache_inode);
860 static int fsfilt_smfs_init_extents_ea(struct inode *inode)
862 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
863 struct inode *cache_inode = NULL;
870 cache_inode = I2CI(inode);
874 pre_smfs_inode(inode, cache_inode);
876 if (cache_fsfilt->fs_init_extents_ea)
877 rc = cache_fsfilt->fs_init_extents_ea(cache_inode);
879 post_smfs_inode(inode, cache_inode);
883 static int fsfilt_smfs_free_extents(struct super_block *sb, ino_t ino,
884 char *pbuf, int size)
886 OBD_FREE(pbuf, size * (sizeof(struct ldlm_extent)));
890 static int fsfilt_smfs_write_extents(struct dentry *dentry,
891 unsigned long from, unsigned long num)
893 /* TODO: fix this later */
896 struct inode * cache_inode = I2CI(dentry->d_inode);
897 struct hook_write_msg msg = {
905 pre_smfs_inode(dentry->d_inode, cache_inode);
907 SMFS_PRE_HOOK(dentry->d_inode, HOOK_WRITE, &msg);
909 rc = smfs_write_extents(dentry->d_inode, dentry, from, num);
910 SMFS_POST_HOOK(dentry->d_inode, HOOK_WRITE, &msg, rc);
911 post_smfs_inode(dentry->d_inode, cache_inode);
919 static int fsfilt_smfs_precreate_rec(struct dentry *dentry, int *count,
923 /* Why to log precreate?? MDS will do this in any case
924 if (SMFS_DO_REC(S2SMI(dentry->d_inode->i_sb)))
925 rc = smfs_rec_precreate(dentry, count, oa);
930 // should be rewrote when needed
931 static int fsfilt_smfs_get_ino_write_extents(struct super_block *sb, ino_t ino,
932 char **pbuf, int *size)
936 struct fs_extent *fs_extents;
937 struct ldlm_extent *extents = NULL;
939 struct inode *cache_inode;
940 struct fsfilt_operations *cache_fsfilt = NULL;
941 struct lvfs_run_ctxt saved;
942 int fs_ex_size, ex_num, flags;
943 char *buf = NULL, *ex_buf = NULL;
946 push_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
948 inode = iget(sb, ino);
950 if (!inode || is_bad_inode(inode)) {
951 CWARN("Can not get inode %lu ino\n", ino);
954 cache_inode = I2CI(inode);
955 cache_fsfilt = I2FOPS(inode);
957 rc = cache_fsfilt->fs_get_xattr(cache_inode, REINT_EXTENTS_FLAGS,
958 &flags, sizeof(int));
959 if (!(flags & SMFS_OVER_WRITE) && !(flags & SMFS_DIRTY_WRITE)) {
961 } else if (flags & SMFS_OVER_WRITE) {
963 OBD_ALLOC(ex_buf, sizeof(struct ldlm_extent));
965 GOTO(out, rc=-ENOMEM);
966 extents = (struct ldlm_extent*)(ex_buf);
968 extents->end = 0xffffffff;
972 rc = cache_fsfilt->fs_get_write_extents_num(cache_inode, &fs_ex_size);
975 OBD_ALLOC(buf, fs_ex_size);
977 GOTO(out, rc=-ENOMEM);
979 rc = cache_fsfilt->fs_get_inode_write_extents(cache_inode, &buf,
984 ex_num = fs_ex_size / sizeof(struct fs_extent);
986 OBD_ALLOC(ex_buf, ex_num* sizeof(struct ldlm_extent));
988 GOTO(out, rc=-ENOMEM);
990 fs_extents = (struct fs_extent*)(buf);
991 extents = (struct ldlm_extent*)(ex_buf);
993 int blk_size = I2CI(inode)->i_blksize;
995 extents->start = fs_extents->e_block * blk_size;
996 extents->end = extents->start + fs_extents->e_num * blk_size;
1005 OBD_FREE(buf, fs_ex_size);
1007 OBD_FREE(ex_buf, (*size) * (sizeof(struct ldlm_extent)));
1008 pop_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
1013 static int fsfilt_smfs_set_snap_item(struct super_block *sb, char *name)
1019 #warning "still not implement for add snap item -wangdi"
1023 static int fsfilt_smfs_do_write_cow(struct dentry *de, void *extents,
1028 struct write_extents *w_ext = (struct write_extents *)extents;
1031 for (i = 0; i < num_extents; i++) {
1032 size_t count = w_ext->w_count;
1033 loff_t off = w_ext->w_pos;
1034 rc = smfs_cow_write_pre(de->d_inode, de, &count, &off);
1043 static int fsfilt_smfs_add_dir_entry(struct obd_device * obd,
1044 struct dentry * parent, char* name,
1045 int namelen, unsigned long ino,
1046 unsigned long generation,
1050 struct fsfilt_operations *cache_fsfilt = I2FOPS(parent->d_inode);
1051 struct dentry *cache_dentry = NULL, *dentry = NULL;
1052 struct inode *cache_parent = I2CI(parent->d_inode);
1060 if (!cache_fsfilt->fs_add_dir_entry)
1063 dentry = ll_lookup_one_len(name, parent, namelen);
1064 if (IS_ERR(dentry)) {
1065 CERROR("can't lookup %*s in %lu/%lu: %d\n", namelen,
1066 name, parent->d_inode->i_ino,
1067 (unsigned long) parent->d_inode->i_generation,
1068 (int) PTR_ERR(dentry));
1069 RETURN(PTR_ERR(dentry));
1071 if (dentry->d_inode != NULL || dentry->d_flags & DCACHE_CROSS_REF) {
1072 CERROR("dentry %*s(0x%p) found\n", dentry->d_name.len,
1073 dentry->d_name.name, dentry);
1077 /* mds_reint_rename() may use this method to add dir entry
1078 * that points onto local inode. and we don't want to find
1079 * it cross-ref by subsequent lookups */
1082 dentry->d_flags |= DCACHE_CROSS_REF;
1083 dentry->d_inum = ino;
1084 dentry->d_mdsnum = mds;
1085 dentry->d_generation = generation;
1086 dentry->d_fid = fid;
1089 cache_dentry = pre_smfs_dentry(NULL, cache_parent, parent);
1090 if (!cache_dentry) {
1094 pre_smfs_inode(parent->d_inode, cache_parent);
1096 rc = cache_fsfilt->fs_add_dir_entry(obd, cache_dentry, name, namelen,
1097 ino, generation, mds, fid);
1099 post_smfs_inode(parent->d_inode, cache_parent);
1101 post_smfs_dentry(cache_dentry);
1107 static int fsfilt_smfs_del_dir_entry(struct obd_device * obd,
1108 struct dentry * dentry)
1110 struct fsfilt_operations *cache_fsfilt = I2FOPS(dentry->d_parent->d_inode);
1111 struct dentry *cache_dentry = NULL, *cache_parent = NULL;
1112 struct inode * cache_dir = I2CI(dentry->d_parent->d_inode);
1113 struct inode * cache_inode = NULL;
1121 if (!cache_fsfilt->fs_del_dir_entry)
1124 if (dentry->d_inode)
1125 cache_inode = I2CI(dentry->d_inode);
1127 cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent);
1128 cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
1129 if (!cache_parent || !cache_dentry) {
1134 pre_smfs_inode(dentry->d_parent->d_inode, cache_dir);
1135 pre_smfs_inode(dentry->d_inode, cache_inode);
1137 rc = cache_fsfilt->fs_del_dir_entry(obd, cache_dentry);
1142 post_smfs_inode(dentry->d_inode, cache_inode);
1143 if (S_ISDIR(dentry->d_inode->i_mode))
1144 dentry->d_parent->d_inode->i_nlink--;
1146 post_smfs_inode(dentry->d_parent->d_inode, cache_dir);
1149 post_smfs_dentry(cache_dentry);
1150 post_smfs_dentry(cache_parent);
1156 static struct fsfilt_operations fsfilt_smfs_ops = {
1158 .fs_owner = THIS_MODULE,
1159 .fs_start = fsfilt_smfs_start,
1160 .fs_brw_start = fsfilt_smfs_brw_start,
1161 .fs_commit = fsfilt_smfs_commit,
1162 .fs_commit_async = fsfilt_smfs_commit_async,
1163 .fs_commit_wait = fsfilt_smfs_commit_wait,
1164 .fs_setattr = fsfilt_smfs_setattr,
1165 .fs_iocontrol = fsfilt_smfs_iocontrol,
1166 .fs_set_md = fsfilt_smfs_set_md,
1167 .fs_get_md = fsfilt_smfs_get_md,
1168 .fs_readpage = fsfilt_smfs_readpage,
1169 .fs_getpage = fsfilt_smfs_getpage,
1170 .fs_add_journal_cb = fsfilt_smfs_add_journal_cb,
1171 .fs_statfs = fsfilt_smfs_statfs,
1172 .fs_sync = fsfilt_smfs_sync,
1173 .fs_map_inode_pages = fsfilt_smfs_map_inode_pages,
1174 .fs_prep_san_write = fsfilt_smfs_prep_san_write,
1175 .fs_write_record = fsfilt_smfs_write_record,
1176 .fs_read_record = fsfilt_smfs_read_record,
1177 .fs_setup = fsfilt_smfs_setup,
1178 .fs_send_bio = fsfilt_smfs_send_bio,
1179 .fs_set_xattr = fsfilt_smfs_set_xattr,
1180 .fs_get_xattr = fsfilt_smfs_get_xattr,
1181 .fs_get_op_len = NULL,
1182 .fs_del_dir_entry = fsfilt_smfs_del_dir_entry,
1183 .fs_add_dir_entry = fsfilt_smfs_add_dir_entry,
1184 .fs_insert_extents_ea = fsfilt_smfs_insert_extents_ea,
1185 .fs_remove_extents_ea = fsfilt_smfs_remove_extents_ea,
1186 .fs_init_extents_ea = fsfilt_smfs_init_extents_ea,
1187 .fs_get_ino_write_extents = fsfilt_smfs_get_ino_write_extents,
1188 .fs_get_write_extents_num = NULL,
1190 .fs_free_write_extents = fsfilt_smfs_free_extents,
1191 .fs_write_extents = fsfilt_smfs_write_extents,
1192 .fs_post_setup = fsfilt_smfs_post_setup,
1193 .fs_post_cleanup = fsfilt_smfs_post_cleanup,
1194 .fs_set_fs_flags = fsfilt_smfs_set_fs_flags,
1195 .fs_clear_fs_flags = fsfilt_smfs_clear_fs_flags,
1196 .fs_get_fs_flags = fsfilt_smfs_get_fs_flags,
1197 .fs_set_ost_flags = fsfilt_smfs_set_ost_flags,
1198 .fs_set_mds_flags = fsfilt_smfs_set_mds_flags,
1199 .fs_precreate_rec = fsfilt_smfs_precreate_rec,
1200 .fs_get_reint_log_ctxt = NULL, /*fsfilt_smfs_get_reint_log_ctxt,*/
1201 .fs_set_snap_item = fsfilt_smfs_set_snap_item,
1202 .fs_do_write_cow = fsfilt_smfs_do_write_cow,
1205 struct fsfilt_operations *get_smfs_fs_ops(void)
1207 return (&fsfilt_smfs_ops);
1209 EXPORT_SYMBOL(get_smfs_fs_ops);