From 15536fec0812786260f59f64085fd08217347736 Mon Sep 17 00:00:00 2001 From: wangdi <wangdi> Date: Tue, 24 Feb 2004 18:44:49 +0000 Subject: [PATCH] Update smfs: 1)unlock cache inode after we call bottom fs methods 2)minor fix in symlink ops --- lustre/smfs/dir.c | 23 ++++++++-------- lustre/smfs/file.c | 33 ++++++++++++---------- lustre/smfs/inode.c | 64 +++++++++++++++++++++++++++---------------- lustre/smfs/symlink.c | 24 ++++++++++++---- 4 files changed, 88 insertions(+), 56 deletions(-) diff --git a/lustre/smfs/dir.c b/lustre/smfs/dir.c index e7507a3be5..d194bb8f21 100644 --- a/lustre/smfs/dir.c +++ b/lustre/smfs/dir.c @@ -17,7 +17,7 @@ #define NAME_ALLOC_LEN(len) ((len+16) & ~15) -static void prepare_parent_dentry(struct dentry *dentry, struct inode *inode) +void prepare_parent_dentry(struct dentry *dentry, struct inode *inode) { atomic_set(&dentry->d_count, 1); dentry->d_vfs_flags = 0; @@ -170,7 +170,7 @@ static int smfs_link(struct dentry * old_dentry, GOTO(exit, rc); atomic_inc(&inode->i_count); - duplicate_inode(cache_old_dentry->d_inode, inode); + post_smfs_inode(inode, cache_old_dentry->d_inode); d_instantiate(dentry, inode); exit: @@ -205,8 +205,8 @@ static int smfs_unlink(struct inode * dir, rc = cache_dir->i_op->unlink(cache_dir, cache_dentry); - duplicate_inode(cache_dentry->d_inode, dentry->d_inode); - duplicate_inode(cache_dir, dir); + post_smfs_inode(dentry->d_inode, cache_dentry->d_inode); + post_smfs_inode(dir, cache_dir); igrab(cache_dentry->d_inode); @@ -289,7 +289,7 @@ static int smfs_mkdir(struct inode * dir, rc = post_kml_mkdir(dir, dentry); GOTO(exit, rc); } - duplicate_inode(cache_dir, dir); + post_smfs_inode(dir, cache_dir); exit: unlock_kernel(); smfs_trans_commit(handle); @@ -318,9 +318,8 @@ static int smfs_rmdir(struct inode * dir, if (cache_dir->i_op->rmdir) rc = cache_dir->i_op->rmdir(cache_dir, cache_dentry); - duplicate_inode(cache_dir, dir); - duplicate_inode(cache_dentry->d_inode, dentry->d_inode); - + post_smfs_inode(dir, cache_dir); + post_smfs_inode(dentry->d_inode, cache_dentry->d_inode); d_unalloc(cache_dentry); RETURN(rc); } @@ -351,8 +350,8 @@ static int smfs_mknod(struct inode * dir, struct dentry *dentry, inode = iget(dir->i_sb, cache_inode->i_ino); d_instantiate(dentry, inode); - duplicate_inode(cache_dir, dir); - duplicate_inode(cache_dentry->d_inode, dentry->d_inode); + post_smfs_inode(dir, cache_dir); + post_smfs_inode(dentry->d_inode, cache_dentry->d_inode); exit: d_unalloc(cache_dentry); RETURN(rc); @@ -384,8 +383,8 @@ static int smfs_rename(struct inode * old_dir, struct dentry *old_dentry, rc = cache_old_dir->i_op->rename(cache_old_dir, cache_old_dentry, cache_new_dir, cache_new_dentry); - duplicate_inode(cache_old_dir, old_dir); - duplicate_inode(cache_new_dir, new_dir); + post_smfs_inode(old_dir, cache_old_dir) ; + post_smfs_inode(new_dir, cache_new_dir); if (cache_new_dentry->d_inode) { igrab(cache_new_dentry->d_inode); } diff --git a/lustre/smfs/file.c b/lustre/smfs/file.c index aad7c327f7..15d57e6cd4 100644 --- a/lustre/smfs/file.c +++ b/lustre/smfs/file.c @@ -91,7 +91,7 @@ static ssize_t smfs_write (struct file *filp, const char *buf, rc = cache_inode->i_fop->write(&open_file, buf, count, cache_ppos); *ppos = *cache_ppos; - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); smfs_update_file(filp, &open_file); RETURN(rc); @@ -118,7 +118,7 @@ int smfs_ioctl(struct inode * inode, struct file * filp, if (cache_inode->i_fop->ioctl) rc = cache_inode->i_fop->ioctl(cache_inode, &open_file, cmd, arg); - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); smfs_update_file(filp, &open_file); RETURN(rc); } @@ -157,7 +157,7 @@ static ssize_t smfs_read (struct file *filp, char *buf, rc = cache_inode->i_fop->read(&open_file, buf, count, cache_ppos); *ppos = *cache_ppos; - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); smfs_update_file(filp, &open_file); RETURN(rc); } @@ -184,7 +184,7 @@ static loff_t smfs_llseek(struct file *file, if (cache_inode->i_fop->llseek) rc = cache_inode->i_fop->llseek(&open_file, offset, origin); - duplicate_inode(cache_inode, dentry->d_inode); + post_smfs_inode(dentry->d_inode, cache_inode); smfs_update_file(file, &open_file); RETURN(rc); @@ -211,7 +211,7 @@ static int smfs_mmap(struct file * file, struct vm_area_struct * vma) if (cache_inode->i_fop->mmap) rc = cache_inode->i_fop->mmap(&open_file, vma); - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); smfs_update_file(file, &open_file); RETURN(rc); @@ -234,7 +234,7 @@ static int smfs_open(struct inode * inode, struct file * filp) if (cache_inode->i_fop->open) rc = cache_inode->i_fop->open(cache_inode, &open_file); - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); smfs_update_file(filp, &open_file); RETURN(rc); @@ -257,7 +257,7 @@ static int smfs_release(struct inode * inode, struct file * filp) if (cache_inode->i_fop->release) rc = cache_inode->i_fop->release(cache_inode, &open_file); - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); smfs_update_file(filp, &open_file); RETURN(rc); @@ -282,7 +282,7 @@ int smfs_fsync(struct file * file, if (cache_inode->i_fop->fsync) rc = cache_inode->i_fop->fsync(&open_file, &open_dentry, datasync); - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); smfs_update_file(file, &open_file); RETURN(rc); @@ -326,7 +326,7 @@ static void smfs_truncate(struct inode * inode) if (cache_inode->i_op->truncate) cache_inode->i_op->truncate(cache_inode); - duplicate_inode(inode, cache_inode); + post_smfs_inode(inode, cache_inode); return; } @@ -344,10 +344,11 @@ int smfs_setattr(struct dentry *dentry, struct iattr *attr) RETURN(-ENOENT); smfs_prepare_cache_dentry(&open_dentry, cache_inode); + pre_smfs_inode(dentry->d_inode, cache_inode); if (cache_inode->i_op->setattr) rc = cache_inode->i_op->setattr(&open_dentry, attr); - duplicate_inode(cache_inode, dentry->d_inode); + post_smfs_inode(dentry->d_inode, cache_inode); RETURN(rc); } @@ -364,12 +365,13 @@ int smfs_setxattr(struct dentry *dentry, const char *name, if (!cache_inode) RETURN(-ENOENT); + pre_smfs_inode(dentry->d_inode, cache_inode); smfs_prepare_cache_dentry(&open_dentry, cache_inode); if (cache_inode->i_op->setattr) rc = cache_inode->i_op->setxattr(&open_dentry, name, value, size, flags); - duplicate_inode(cache_inode, dentry->d_inode); + post_smfs_inode(dentry->d_inode, cache_inode); RETURN(rc); } @@ -386,11 +388,12 @@ int smfs_getxattr(struct dentry *dentry, const char *name, RETURN(-ENOENT); smfs_prepare_cache_dentry(&open_dentry, cache_inode); + pre_smfs_inode(dentry->d_inode, cache_inode); if (cache_inode->i_op->setattr) rc = cache_inode->i_op->getxattr(&open_dentry, name, buffer, size); - duplicate_inode(cache_inode, dentry->d_inode); + post_smfs_inode(dentry->d_inode, cache_inode); RETURN(rc); } @@ -406,11 +409,12 @@ ssize_t smfs_listxattr(struct dentry *dentry, char *buffer, size_t size) RETURN(-ENOENT); smfs_prepare_cache_dentry(&open_dentry, cache_inode); + pre_smfs_inode(dentry->d_inode, cache_inode); if (cache_inode->i_op->listxattr) rc = cache_inode->i_op->listxattr(&open_dentry, buffer, size); - duplicate_inode(cache_inode, dentry->d_inode); + post_smfs_inode(dentry->d_inode, cache_inode); RETURN(rc); } @@ -426,11 +430,12 @@ int smfs_removexattr(struct dentry *dentry, const char *name) RETURN(-ENOENT); smfs_prepare_cache_dentry(&open_dentry, cache_inode); + pre_smfs_inode(dentry->d_inode, cache_inode); if (cache_inode->i_op->removexattr) rc = cache_inode->i_op->removexattr(&open_dentry, name); - duplicate_inode(cache_inode, dentry->d_inode); + post_smfs_inode(dentry->d_inode, cache_inode); RETURN(rc); } diff --git a/lustre/smfs/inode.c b/lustre/smfs/inode.c index 8160d32e47..dbc42a2960 100644 --- a/lustre/smfs/inode.c +++ b/lustre/smfs/inode.c @@ -13,25 +13,39 @@ #include <linux/lustre_idl.h> #include "smfs_internal.h" -void duplicate_inode(struct inode *cache_inode, struct inode *inode) +static void duplicate_inode(struct inode *dst_inode, + struct inode *src_inode) { - - inode->i_mode = cache_inode->i_mode; - inode->i_uid = cache_inode->i_uid; - inode->i_gid = cache_inode->i_gid; - - inode->i_nlink = cache_inode->i_nlink; - inode->i_size = cache_inode->i_size; - inode->i_atime = cache_inode->i_atime; - inode->i_ctime = cache_inode->i_ctime; - inode->i_mtime = cache_inode->i_mtime; - inode->i_blksize = cache_inode->i_blksize; /* This is the optimal IO size - * (for stat), not the fs block - * size */ - inode->i_blocks = cache_inode->i_blocks; - inode->i_version = cache_inode->i_version; - inode->i_state = cache_inode->i_state; + dst_inode->i_mode = src_inode->i_mode; + dst_inode->i_uid = src_inode->i_uid; + dst_inode->i_gid = src_inode->i_gid; + dst_inode->i_nlink = src_inode->i_nlink; + dst_inode->i_size = src_inode->i_size; + dst_inode->i_atime = src_inode->i_atime; + dst_inode->i_ctime = src_inode->i_ctime; + dst_inode->i_mtime = src_inode->i_mtime; + dst_inode->i_blksize = src_inode->i_blksize; + dst_inode->i_blocks = src_inode->i_blocks; + dst_inode->i_version = src_inode->i_version; + dst_inode->i_state = src_inode->i_state; +} + +void post_smfs_inode(struct inode *inode, + struct inode *cache_inode) +{ + duplicate_inode(inode, cache_inode); + /*Here we must release the cache_inode, + *Otherwise we will have no chance to + *do it + */ + cache_inode->i_state &=~I_LOCK; } +void pre_smfs_inode(struct inode *inode, + struct inode *cache_inode) +{ + duplicate_inode(cache_inode, inode); +} + static void smfs_read_inode(struct inode *inode) { struct super_block *cache_sb; @@ -50,7 +64,7 @@ static void smfs_read_inode(struct inode *inode) if(cache_sb && cache_sb->s_op->read_inode) cache_sb->s_op->read_inode(cache_inode); - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); sm_set_inode_ops(cache_inode, inode); CDEBUG(D_INODE, "read_inode ino %lu icount %d \n", @@ -59,6 +73,7 @@ static void smfs_read_inode(struct inode *inode) iput(cache_inode); return; } + /* Although some filesystem(such as ext3) do not have * clear_inode method, but we need it to free the * cache inode @@ -115,7 +130,7 @@ static void smfs_delete_inode(struct inode *inode) atomic_dec(&cache_inode->i_count); } - duplicate_inode(inode, cache_inode); + pre_smfs_inode(inode, cache_inode); list_del(&cache_inode->i_hash); INIT_LIST_HEAD(&cache_inode->i_hash); @@ -128,7 +143,7 @@ static void smfs_delete_inode(struct inode *inode) if (cache_sb->s_op->delete_inode) cache_sb->s_op->delete_inode(cache_inode); - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); I2CI(inode) = NULL; return; @@ -145,11 +160,12 @@ static void smfs_write_inode(struct inode *inode, int wait) if (!cache_inode || !cache_sb) return; - duplicate_inode(inode, cache_inode); + pre_smfs_inode(inode, cache_inode); + if (cache_sb->s_op->write_inode) cache_sb->s_op->write_inode(cache_inode, wait); - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); return; } @@ -165,11 +181,11 @@ static void smfs_dirty_inode(struct inode *inode) if (!cache_inode || !cache_sb) return; - duplicate_inode(inode, cache_inode); + pre_smfs_inode(inode, cache_inode); if (cache_sb->s_op->dirty_inode) cache_sb->s_op->dirty_inode(cache_inode); - duplicate_inode(cache_inode, inode); + post_smfs_inode(inode, cache_inode); return; } diff --git a/lustre/smfs/symlink.c b/lustre/smfs/symlink.c index b0b3714e4b..e1ca7624ed 100644 --- a/lustre/smfs/symlink.c +++ b/lustre/smfs/symlink.c @@ -17,13 +17,18 @@ static int smfs_readlink(struct dentry * dentry, char * buffer, int buflen) { struct inode *cache_inode = I2CI(dentry->d_inode); + struct inode *cache_dir = NULL; struct dentry *cache_dentry; + struct dentry parent; int rc = 0; if (!cache_inode) RETURN(-ENOENT); - - cache_dentry = d_alloc(NULL, &dentry->d_name); + if (dentry->d_parent && dentry->d_parent->d_inode){ + cache_dir = I2CI(dentry->d_parent->d_inode); + prepare_parent_dentry(&parent, cache_dir); + } + cache_dentry = d_alloc(&parent, &dentry->d_name); d_add(cache_dentry, cache_inode); igrab(cache_inode); @@ -37,21 +42,28 @@ static int smfs_readlink(struct dentry * dentry, char * buffer, int buflen) static int smfs_follow_link(struct dentry *dentry, struct nameidata *nd) { struct inode *cache_inode = I2CI(dentry->d_inode); + struct inode *cache_dir = NULL; struct dentry *cache_dentry; + struct dentry parent; int rc = 0; if (!cache_inode) RETURN(-ENOENT); - - cache_dentry = d_alloc(NULL, &dentry->d_name); + + if (dentry->d_parent && dentry->d_parent->d_inode){ + cache_dir = I2CI(dentry->d_parent->d_inode); + prepare_parent_dentry(&parent, cache_dir); + } + + cache_dentry = d_alloc(&parent, &dentry->d_name); + d_add(cache_dentry, cache_inode); igrab(cache_inode); - + if (cache_inode->i_op && cache_inode->i_op->follow_link) rc = cache_inode->i_op->follow_link(cache_dentry, nd); d_unalloc(cache_dentry); return rc; - } struct inode_operations smfs_sym_iops = { readlink: smfs_readlink, -- GitLab