From 9673350cea241bac28f2191be548fba8aca9b1d9 Mon Sep 17 00:00:00 2001 From: wangdi Date: Mon, 9 Feb 2004 16:39:39 +0000 Subject: [PATCH] update smfs 1)delete inode->i_list in smfs_delete_inode for the cache inode will have no chance to release it in iput 2)fix bugs in file read and write 3) some fixs for unlink and rmdir --- lustre/smfs/dir.c | 34 ++++++++++++++++++---------------- lustre/smfs/file.c | 15 ++++++++++++--- lustre/smfs/inode.c | 20 +++++++++++++++----- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/lustre/smfs/dir.c b/lustre/smfs/dir.c index 0252608..5f3e8df 100644 --- a/lustre/smfs/dir.c +++ b/lustre/smfs/dir.c @@ -100,7 +100,7 @@ static int smfs_create(struct inode *dir, int mode) { struct inode *cache_dir; - struct inode *cache_inode, *inode; + struct inode *cache_inode = NULL, *inode; int rc; ENTRY; @@ -129,7 +129,8 @@ static int smfs_create(struct inode *dir, sm_set_inode_ops(cache_inode, inode); exit: smfs_clear_dentry(&cache_dentry); - iput(cache_inode); + if (cache_inode) + iput(cache_inode); RETURN(rc); } @@ -137,7 +138,7 @@ static struct dentry *smfs_lookup(struct inode *dir, struct dentry *dentry) { struct inode *cache_dir; - struct inode *cache_inode, *inode; + struct inode *cache_inode = NULL, *inode; struct dentry tmp; struct dentry cache_dentry; struct dentry *rc = NULL; @@ -166,8 +167,9 @@ static struct dentry *smfs_lookup(struct inode *dir, d_add(dentry, inode); exit: smfs_clear_dentry(&cache_dentry); - iput(cache_inode); - + + if (cache_inode) + iput(cache_inode); RETURN(rc); } @@ -220,6 +222,7 @@ static int smfs_link(struct dentry * old_dentry, smfs_clear_dentry(&cache_dentry); RETURN(rc); } + static int smfs_unlink(struct inode * dir, struct dentry *dentry) { @@ -236,20 +239,16 @@ static int smfs_unlink(struct inode * dir, smfs_prepare_dentry(&cache_dentry, &tmp, &dentry->d_name); d_add(&cache_dentry, cache_inode); - igrab(cache_inode); - if (cache_dir->i_op->unlink) rc = cache_dir->i_op->unlink(cache_dir, &cache_dentry); - duplicate_inode(cache_dentry.d_inode, dentry->d_inode); duplicate_inode(cache_dir, dir); - iput(cache_dentry.d_inode); smfs_clear_dentry(&cache_dentry); - RETURN(rc); } + static int smfs_symlink (struct inode * dir, struct dentry *dentry, const char * symname) @@ -264,7 +263,7 @@ static int smfs_symlink (struct inode * dir, if (!cache_dir) RETURN(-ENOENT); - prepare_parent_dentry(&tmp, NULL); + prepare_parent_dentry(&tmp, cache_dir); smfs_prepare_dentry(&cache_dentry, &tmp, &dentry->d_name); if (cache_inode->i_op->symlink) @@ -296,7 +295,7 @@ static int smfs_mkdir(struct inode * dir, if (!cache_dir) RETURN(-ENOENT); - prepare_parent_dentry(&tmp, NULL); + prepare_parent_dentry(&tmp, cache_dir); smfs_prepare_dentry(&cache_dentry, &tmp, &dentry->d_name); if (cache_dir->i_op->mkdir) @@ -315,10 +314,12 @@ exit: smfs_clear_dentry(&cache_dentry); RETURN(rc); } + static int smfs_rmdir(struct inode * dir, struct dentry *dentry) { struct inode *cache_dir = I2CI(dir); + struct inode *cache_inode = I2CI(dentry->d_inode); struct dentry cache_dentry; struct dentry tmp; int rc = 0; @@ -326,8 +327,9 @@ static int smfs_rmdir(struct inode * dir, if (!cache_dir) RETURN(-ENOENT); - prepare_parent_dentry(&tmp, NULL); + prepare_parent_dentry(&tmp, cache_dir); smfs_prepare_dentry(&cache_dentry, &tmp, &dentry->d_name); + d_add(&cache_dentry, cache_inode); if (cache_dir->i_op->rmdir) rc = cache_dir->i_op->rmdir(cache_dir, &cache_dentry); @@ -350,7 +352,7 @@ static int smfs_mknod(struct inode * dir, struct dentry *dentry, if (!cache_dir) RETURN(-ENOENT); - prepare_parent_dentry(&tmp, NULL); + prepare_parent_dentry(&tmp, cache_dir); smfs_prepare_dentry(&cache_dentry, &tmp, &dentry->d_name); if (cache_dir->i_op->mknod) @@ -379,11 +381,11 @@ static int smfs_rename(struct inode * old_dir, struct dentry *old_dentry, if (!cache_old_dir || !cache_new_dir || !cache_old_inode) RETURN(-ENOENT); - prepare_parent_dentry(&tmp_old, old_dir); + prepare_parent_dentry(&tmp_old, cache_old_dir); smfs_prepare_dentry(&cache_old_dentry, &tmp_old, &old_dentry->d_name); d_add(&cache_old_dentry, cache_old_inode); - prepare_parent_dentry(&tmp_new, NULL); + prepare_parent_dentry(&tmp_new, cache_new_dir); smfs_prepare_dentry(&cache_new_dentry, &tmp_new, &new_dentry->d_name); if (cache_old_dir->i_op->rename) diff --git a/lustre/smfs/file.c b/lustre/smfs/file.c index 455fccd..e9afdd1 100644 --- a/lustre/smfs/file.c +++ b/lustre/smfs/file.c @@ -153,8 +153,9 @@ static ssize_t smfs_write (struct file *filp, const char *buf, &open_file, &open_dentry); if (cache_inode->i_fop->write) - rc = cache_inode->i_fop->write(&open_file, buf, count, ppos); + rc = cache_inode->i_fop->write(&open_file, buf, count, &open_file.f_pos); + *ppos = open_file.f_pos; duplicate_inode(cache_inode, inode); smfs_update_file(filp, &open_file); @@ -191,6 +192,9 @@ static ssize_t smfs_read (struct file *filp, char *buf, { struct inode *cache_inode; struct dentry *dentry = filp->f_dentry; + struct inode *inode = dentry->d_inode; + struct file open_file; + struct dentry open_dentry; ssize_t rc; ENTRY; @@ -199,10 +203,15 @@ static ssize_t smfs_read (struct file *filp, char *buf, if (!cache_inode) RETURN(-ENOENT); + smfs_prepare_cachefile(inode, filp, cache_inode, + &open_file, &open_dentry); + if (cache_inode->i_fop->read) - rc = cache_inode->i_fop->read(filp, buf, count, ppos); + rc = cache_inode->i_fop->read(&open_file, buf, count, &open_file.f_pos); - duplicate_inode(cache_inode, dentry->d_inode); + *ppos = open_file.f_pos; + duplicate_inode(cache_inode, inode); + smfs_update_file(filp, &open_file); RETURN(rc); } diff --git a/lustre/smfs/inode.c b/lustre/smfs/inode.c index d3e14fd..3baaa2f 100644 --- a/lustre/smfs/inode.c +++ b/lustre/smfs/inode.c @@ -79,7 +79,7 @@ static void smfs_clear_inode(struct inode *inode) if (cache_sb->s_op->clear_inode) cache_sb->s_op->clear_inode(cache_inode); - clear_inode(cache_inode); + //clear_inode(cache_inode); duplicate_inode(inode, cache_inode); return; @@ -98,6 +98,14 @@ static void smfs_delete_inode(struct inode *inode) duplicate_inode(inode, cache_inode); + list_del(&cache_inode->i_hash); + INIT_LIST_HEAD(&cache_inode->i_hash); + list_del(&cache_inode->i_list); + INIT_LIST_HEAD(&cache_inode->i_list); + + if (cache_inode->i_data.nrpages) + truncate_inode_pages(&cache_inode->i_data, 0); + if (cache_sb->s_op->delete_inode) cache_sb->s_op->delete_inode(cache_inode); @@ -211,9 +219,10 @@ static void smfs_unlockfs(struct super_block *sb) duplicate_sb(cache_sb, sb); return; } -static void smfs_statfs(struct super_block * sb, struct statfs * buf) +static int smfs_statfs(struct super_block * sb, struct statfs * buf) { struct super_block *cache_sb; + int rc = 0; ENTRY; cache_sb = S2CSB(sb); @@ -222,10 +231,11 @@ static void smfs_statfs(struct super_block * sb, struct statfs * buf) return; if (cache_sb->s_op->statfs) - cache_sb->s_op->statfs(cache_sb, buf); + rc = cache_sb->s_op->statfs(cache_sb, buf); duplicate_sb(cache_sb, sb); - return; + + return rc; } static int smfs_remount(struct super_block * sb, int * flags, char * data) { @@ -246,7 +256,7 @@ static int smfs_remount(struct super_block * sb, int * flags, char * data) } struct super_operations smfs_super_ops = { read_inode: smfs_read_inode, - clear_inode: smfs_clear_inode, + //clear_inode: smfs_clear_inode, put_super: smfs_put_super, delete_inode: smfs_delete_inode, write_inode: smfs_write_inode, -- 1.8.3.1