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 smfs_super_info *sbi = S2SMI(dentry->d_inode->i_sb);
657 struct hook_setattr_msg msg = {
666 if (!cache_fsfilt->fs_setattr)
669 cache_dentry = pre_smfs_dentry(NULL, cache_inode, dentry);
673 pre_smfs_inode(dentry->d_inode, cache_inode);
675 SMFS_PRE_HOOK(dentry->d_inode, HOOK_F_SETATTR, &msg);
677 if (SMFS_DO_HND_IBLOCKS(sbi)) {
678 /* size-on-mds changes i_blocks directly to reflect
679 * aggregated i_blocks from all OSTs -bzzz */
680 cache_inode->i_blocks = dentry->d_inode->i_blocks;
682 rc = cache_fsfilt->fs_setattr(cache_dentry, handle, iattr, do_trunc);
684 SMFS_POST_HOOK(dentry->d_inode, HOOK_F_SETATTR, &msg, rc);
685 post_smfs_inode(dentry->d_inode, cache_inode);
687 post_smfs_dentry(cache_dentry);
690 static int fsfilt_smfs_set_xattr(struct inode *inode, void *handle, char *name,
691 void *buffer, int buffer_size)
693 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
694 struct inode *cache_inode = NULL;
695 struct hook_setxattr_msg msg = {
699 .buffer_size = buffer_size
708 cache_inode = I2CI(inode);
712 pre_smfs_inode(inode, cache_inode);
714 SMFS_PRE_HOOK(inode, HOOK_F_SETXATTR, &msg);
715 if (cache_fsfilt->fs_set_xattr)
716 rc = cache_fsfilt->fs_set_xattr(cache_inode, handle, name,
717 buffer, buffer_size);
719 SMFS_POST_HOOK(inode, HOOK_F_SETXATTR, &msg, rc);
720 post_smfs_inode(inode, cache_inode);
725 static int fsfilt_smfs_get_xattr(struct inode *inode, char *name,
726 void *buffer, int buffer_size)
728 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
729 struct inode *cache_inode = NULL;
735 cache_inode = I2CI(inode);
739 pre_smfs_inode(inode, cache_inode);
741 if (cache_fsfilt->fs_get_xattr)
742 rc = cache_fsfilt->fs_get_xattr(cache_inode, name,
743 buffer, buffer_size);
744 post_smfs_inode(inode, cache_inode);
749 #define XATTR_LUSTRE_MDS_LOV_EA "lov"
750 #define XATTR_LUSTRE_MDS_MEA_EA "mea"
751 #define XATTR_LUSTRE_MDS_MID_EA "mid"
752 #define XATTR_LUSTRE_MDS_SID_EA "sid"
754 static int fsfilt_smfs_set_md(struct inode *inode, void *handle,
755 void *lmm, int lmm_size, enum ea_type type)
761 rc = fsfilt_smfs_set_xattr(inode, handle,
762 XATTR_LUSTRE_MDS_LOV_EA,
766 rc = fsfilt_smfs_set_xattr(inode, handle,
767 XATTR_LUSTRE_MDS_MEA_EA,
771 rc = fsfilt_smfs_set_xattr(inode, handle,
772 XATTR_LUSTRE_MDS_SID_EA,
776 rc = fsfilt_smfs_set_xattr(inode, handle,
777 XATTR_LUSTRE_MDS_MID_EA,
787 static int fsfilt_smfs_get_md(struct inode *inode, void *lmm,
788 int lmm_size, enum ea_type type)
794 rc = fsfilt_smfs_get_xattr(inode,
795 XATTR_LUSTRE_MDS_LOV_EA,
799 rc = fsfilt_smfs_get_xattr(inode,
800 XATTR_LUSTRE_MDS_MEA_EA,
804 rc = fsfilt_smfs_get_xattr(inode,
805 XATTR_LUSTRE_MDS_SID_EA,
809 rc = fsfilt_smfs_get_xattr(inode,
810 XATTR_LUSTRE_MDS_MID_EA,
820 static int fsfilt_smfs_insert_extents_ea(struct inode *inode,
821 unsigned long from, unsigned long num)
823 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
824 struct inode *cache_inode = NULL;
830 cache_inode = I2CI(inode);
834 pre_smfs_inode(inode, cache_inode);
836 if (cache_fsfilt->fs_insert_extents_ea)
837 rc = cache_fsfilt->fs_insert_extents_ea(cache_inode, from, num);
839 post_smfs_inode(inode, cache_inode);
843 static int fsfilt_smfs_remove_extents_ea(struct inode *inode,
844 unsigned long from, unsigned long num)
846 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
847 struct inode *cache_inode = NULL;
853 cache_inode = I2CI(inode);
857 pre_smfs_inode(inode, cache_inode);
859 if (cache_fsfilt->fs_remove_extents_ea)
860 rc = cache_fsfilt->fs_remove_extents_ea(cache_inode, from, num);
862 post_smfs_inode(inode, cache_inode);
866 static int fsfilt_smfs_init_extents_ea(struct inode *inode)
868 struct fsfilt_operations *cache_fsfilt = I2FOPS(inode);
869 struct inode *cache_inode = NULL;
876 cache_inode = I2CI(inode);
880 pre_smfs_inode(inode, cache_inode);
882 if (cache_fsfilt->fs_init_extents_ea)
883 rc = cache_fsfilt->fs_init_extents_ea(cache_inode);
885 post_smfs_inode(inode, cache_inode);
889 static int fsfilt_smfs_free_extents(struct super_block *sb, ino_t ino,
890 char *pbuf, int size)
892 OBD_FREE(pbuf, size * (sizeof(struct ldlm_extent)));
896 static int fsfilt_smfs_write_extents(struct dentry *dentry,
897 unsigned long from, unsigned long num)
899 /* TODO: fix this later */
902 struct inode * cache_inode = I2CI(dentry->d_inode);
903 struct hook_write_msg msg = {
911 pre_smfs_inode(dentry->d_inode, cache_inode);
913 SMFS_PRE_HOOK(dentry->d_inode, HOOK_WRITE, &msg);
915 rc = smfs_write_extents(dentry->d_inode, dentry, from, num);
916 SMFS_POST_HOOK(dentry->d_inode, HOOK_WRITE, &msg, rc);
917 post_smfs_inode(dentry->d_inode, cache_inode);
925 static int fsfilt_smfs_precreate_rec(struct dentry *dentry, int *count,
929 /* Why to log precreate?? MDS will do this in any case
930 if (SMFS_DO_REC(S2SMI(dentry->d_inode->i_sb)))
931 rc = smfs_rec_precreate(dentry, count, oa);
936 // should be rewrote when needed
937 static int fsfilt_smfs_get_ino_write_extents(struct super_block *sb, ino_t ino,
938 char **pbuf, int *size)
942 struct fs_extent *fs_extents;
943 struct ldlm_extent *extents = NULL;
945 struct inode *cache_inode;
946 struct fsfilt_operations *cache_fsfilt = NULL;
947 struct lvfs_run_ctxt saved;
948 int fs_ex_size, ex_num, flags;
949 char *buf = NULL, *ex_buf = NULL;
952 push_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
954 inode = iget(sb, ino);
956 if (!inode || is_bad_inode(inode)) {
957 CWARN("Can not get inode %lu ino\n", ino);
960 cache_inode = I2CI(inode);
961 cache_fsfilt = I2FOPS(inode);
963 rc = cache_fsfilt->fs_get_xattr(cache_inode, REINT_EXTENTS_FLAGS,
964 &flags, sizeof(int));
965 if (!(flags & SMFS_OVER_WRITE) && !(flags & SMFS_DIRTY_WRITE)) {
967 } else if (flags & SMFS_OVER_WRITE) {
969 OBD_ALLOC(ex_buf, sizeof(struct ldlm_extent));
971 GOTO(out, rc=-ENOMEM);
972 extents = (struct ldlm_extent*)(ex_buf);
974 extents->end = 0xffffffff;
978 rc = cache_fsfilt->fs_get_write_extents_num(cache_inode, &fs_ex_size);
981 OBD_ALLOC(buf, fs_ex_size);
983 GOTO(out, rc=-ENOMEM);
985 rc = cache_fsfilt->fs_get_inode_write_extents(cache_inode, &buf,
990 ex_num = fs_ex_size / sizeof(struct fs_extent);
992 OBD_ALLOC(ex_buf, ex_num* sizeof(struct ldlm_extent));
994 GOTO(out, rc=-ENOMEM);
996 fs_extents = (struct fs_extent*)(buf);
997 extents = (struct ldlm_extent*)(ex_buf);
999 int blk_size = I2CI(inode)->i_blksize;
1001 extents->start = fs_extents->e_block * blk_size;
1002 extents->end = extents->start + fs_extents->e_num * blk_size;
1011 OBD_FREE(buf, fs_ex_size);
1013 OBD_FREE(ex_buf, (*size) * (sizeof(struct ldlm_extent)));
1014 pop_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
1019 static int fsfilt_smfs_set_snap_item(struct super_block *sb, char *name)
1025 #warning "still not implement for add snap item -wangdi"
1029 static int fsfilt_smfs_do_write_cow(struct dentry *de, void *extents,
1034 struct write_extents *w_ext = (struct write_extents *)extents;
1037 for (i = 0; i < num_extents; i++) {
1038 size_t count = w_ext->w_count;
1039 loff_t off = w_ext->w_pos;
1040 rc = smfs_cow_write_pre(de->d_inode, de, &count, &off);
1049 static int fsfilt_smfs_add_dir_entry(struct obd_device * obd,
1050 struct dentry * parent, char* name,
1051 int namelen, unsigned long ino,
1052 unsigned long generation,
1056 struct fsfilt_operations *cache_fsfilt = I2FOPS(parent->d_inode);
1057 struct dentry *cache_dentry = NULL, *dentry = NULL;
1058 struct inode *cache_parent = I2CI(parent->d_inode);
1066 if (!cache_fsfilt->fs_add_dir_entry)
1069 dentry = ll_lookup_one_len(name, parent, namelen);
1070 if (IS_ERR(dentry)) {
1071 CERROR("can't lookup %*s in %lu/%lu: %d\n", namelen,
1072 name, parent->d_inode->i_ino,
1073 (unsigned long) parent->d_inode->i_generation,
1074 (int) PTR_ERR(dentry));
1075 RETURN(PTR_ERR(dentry));
1077 if (dentry->d_inode != NULL || dentry->d_flags & DCACHE_CROSS_REF) {
1078 CERROR("dentry %*s(0x%p) found\n", dentry->d_name.len,
1079 dentry->d_name.name, dentry);
1083 /* mds_reint_rename() may use this method to add dir entry
1084 * that points onto local inode. and we don't want to find
1085 * it cross-ref by subsequent lookups */
1088 dentry->d_flags |= DCACHE_CROSS_REF;
1089 dentry->d_inum = ino;
1090 dentry->d_mdsnum = mds;
1091 dentry->d_generation = generation;
1092 dentry->d_fid = fid;
1095 cache_dentry = pre_smfs_dentry(NULL, cache_parent, parent);
1096 if (!cache_dentry) {
1100 pre_smfs_inode(parent->d_inode, cache_parent);
1102 rc = cache_fsfilt->fs_add_dir_entry(obd, cache_dentry, name, namelen,
1103 ino, generation, mds, fid);
1105 post_smfs_inode(parent->d_inode, cache_parent);
1107 post_smfs_dentry(cache_dentry);
1113 static int fsfilt_smfs_del_dir_entry(struct obd_device * obd,
1114 struct dentry * dentry)
1116 struct fsfilt_operations *cache_fsfilt = I2FOPS(dentry->d_parent->d_inode);
1117 struct dentry *cache_dentry = NULL, *cache_parent = NULL;
1118 struct inode * cache_dir = I2CI(dentry->d_parent->d_inode);
1119 struct inode * cache_inode = NULL;
1127 if (!cache_fsfilt->fs_del_dir_entry)
1130 if (dentry->d_inode)
1131 cache_inode = I2CI(dentry->d_inode);
1133 cache_parent = pre_smfs_dentry(NULL, cache_dir, dentry->d_parent);
1134 cache_dentry = pre_smfs_dentry(cache_parent, cache_inode, dentry);
1135 if (!cache_parent || !cache_dentry) {
1140 pre_smfs_inode(dentry->d_parent->d_inode, cache_dir);
1141 pre_smfs_inode(dentry->d_inode, cache_inode);
1143 rc = cache_fsfilt->fs_del_dir_entry(obd, cache_dentry);
1148 post_smfs_inode(dentry->d_inode, cache_inode);
1149 if (S_ISDIR(dentry->d_inode->i_mode))
1150 dentry->d_parent->d_inode->i_nlink--;
1152 post_smfs_inode(dentry->d_parent->d_inode, cache_dir);
1155 post_smfs_dentry(cache_dentry);
1156 post_smfs_dentry(cache_parent);
1162 static struct fsfilt_operations fsfilt_smfs_ops = {
1164 .fs_owner = THIS_MODULE,
1165 .fs_start = fsfilt_smfs_start,
1166 .fs_brw_start = fsfilt_smfs_brw_start,
1167 .fs_commit = fsfilt_smfs_commit,
1168 .fs_commit_async = fsfilt_smfs_commit_async,
1169 .fs_commit_wait = fsfilt_smfs_commit_wait,
1170 .fs_setattr = fsfilt_smfs_setattr,
1171 .fs_iocontrol = fsfilt_smfs_iocontrol,
1172 .fs_set_md = fsfilt_smfs_set_md,
1173 .fs_get_md = fsfilt_smfs_get_md,
1174 .fs_readpage = fsfilt_smfs_readpage,
1175 .fs_getpage = fsfilt_smfs_getpage,
1176 .fs_add_journal_cb = fsfilt_smfs_add_journal_cb,
1177 .fs_statfs = fsfilt_smfs_statfs,
1178 .fs_sync = fsfilt_smfs_sync,
1179 .fs_map_inode_pages = fsfilt_smfs_map_inode_pages,
1180 .fs_prep_san_write = fsfilt_smfs_prep_san_write,
1181 .fs_write_record = fsfilt_smfs_write_record,
1182 .fs_read_record = fsfilt_smfs_read_record,
1183 .fs_setup = fsfilt_smfs_setup,
1184 .fs_send_bio = fsfilt_smfs_send_bio,
1185 .fs_set_xattr = fsfilt_smfs_set_xattr,
1186 .fs_get_xattr = fsfilt_smfs_get_xattr,
1187 .fs_get_op_len = NULL,
1188 .fs_del_dir_entry = fsfilt_smfs_del_dir_entry,
1189 .fs_add_dir_entry = fsfilt_smfs_add_dir_entry,
1190 .fs_insert_extents_ea = fsfilt_smfs_insert_extents_ea,
1191 .fs_remove_extents_ea = fsfilt_smfs_remove_extents_ea,
1192 .fs_init_extents_ea = fsfilt_smfs_init_extents_ea,
1193 .fs_get_ino_write_extents = fsfilt_smfs_get_ino_write_extents,
1194 .fs_get_write_extents_num = NULL,
1196 .fs_free_write_extents = fsfilt_smfs_free_extents,
1197 .fs_write_extents = fsfilt_smfs_write_extents,
1198 .fs_post_setup = fsfilt_smfs_post_setup,
1199 .fs_post_cleanup = fsfilt_smfs_post_cleanup,
1200 .fs_set_fs_flags = fsfilt_smfs_set_fs_flags,
1201 .fs_clear_fs_flags = fsfilt_smfs_clear_fs_flags,
1202 .fs_get_fs_flags = fsfilt_smfs_get_fs_flags,
1203 .fs_set_ost_flags = fsfilt_smfs_set_ost_flags,
1204 .fs_set_mds_flags = fsfilt_smfs_set_mds_flags,
1205 .fs_precreate_rec = fsfilt_smfs_precreate_rec,
1206 .fs_get_reint_log_ctxt = NULL, /*fsfilt_smfs_get_reint_log_ctxt,*/
1207 .fs_set_snap_item = fsfilt_smfs_set_snap_item,
1208 .fs_do_write_cow = fsfilt_smfs_do_write_cow,
1211 struct fsfilt_operations *get_smfs_fs_ops(void)
1213 return (&fsfilt_smfs_ops);
1215 EXPORT_SYMBOL(get_smfs_fs_ops);