[Ocfs2-tools-devel] [PATCH] libocfs2: Don't free cached_inode in ocfs2_file_write.

Joel Becker Joel.Becker at oracle.com
Tue Oct 13 14:45:44 PDT 2009


On Tue, Oct 13, 2009 at 05:03:26PM +0800, Tao Ma wrote:
> In ocfs2_file_write, ci is passed from the caller, so
> we can't free it and then initialize.

sob

> 
> Add a new function named ocfs2_refresh_cached_inode which
> will re-read the inode from the disk to refresh
> the stale inode information in ocfs2_cached_inode.
> 
> Note:
> There are also some functions which call free_cached_inode
> first and then read_cached_inode. They also can be changed
> to ocfs2_refresh_cached_inode, but it should be in another
> separate patch of course.
> 
> Signed-off-by: Tao Ma <tao.ma at oracle.com>
> ---
>  include/ocfs2/ocfs2.h   |    2 ++
>  libocfs2/cached_inode.c |   10 ++++++++++
>  libocfs2/fileio.c       |   11 ++++++++---
>  3 files changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
> index 652d41a..a1db2a4 100644
> --- a/include/ocfs2/ocfs2.h
> +++ b/include/ocfs2/ocfs2.h
> @@ -329,6 +329,8 @@ errcode_t ocfs2_write_cached_inode(ocfs2_filesys *fs,
>  				   ocfs2_cached_inode *cinode);
>  errcode_t ocfs2_free_cached_inode(ocfs2_filesys *fs,
>  				  ocfs2_cached_inode *cinode);
> +errcode_t ocfs2_refresh_cached_inode(ocfs2_filesys *fs,
> +				     ocfs2_cached_inode *cinode);
>  
>  /*
>   * obj is the object containing the extent list.  eg, if you are swapping
> diff --git a/libocfs2/cached_inode.c b/libocfs2/cached_inode.c
> index eedfd96..4dbb9ea 100644
> --- a/libocfs2/cached_inode.c
> +++ b/libocfs2/cached_inode.c
> @@ -101,3 +101,13 @@ errcode_t ocfs2_write_cached_inode(ocfs2_filesys *fs,
>  
>  	return ret;
>  }
> +
> +errcode_t ocfs2_refresh_cached_inode(ocfs2_filesys *fs,
> +				     ocfs2_cached_inode *cinode)
> +{
> +	if (cinode->ci_chains)
> +		ocfs2_bitmap_free(cinode->ci_chains);
> +
> +	return ocfs2_read_inode(fs, cinode->ci_blkno,
> +				(char *)cinode->ci_inode);
> +}
> diff --git a/libocfs2/fileio.c b/libocfs2/fileio.c
> index 7c51e13..c4664ec 100644
> --- a/libocfs2/fileio.c
> +++ b/libocfs2/fileio.c
> @@ -302,7 +302,6 @@ static errcode_t ocfs2_file_block_write(ocfs2_cached_inode *ci,
>  	uint32_t	tmp;
>  	uint64_t	num_blocks;
>  	int		bs_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
> -	uint64_t	ino = ci->ci_blkno;
>  	uint32_t	n_clusters, cluster_begin, cluster_end;
>  	uint64_t	bpc = fs->fs_clustersize/fs->fs_blocksize;
>  	int		insert = 0;
> @@ -438,8 +437,14 @@ static errcode_t ocfs2_file_block_write(ocfs2_cached_inode *ci,
>  					p_blkno & ~(bpc - 1));
>  			if (ret)
>  				return ret;
> -			ocfs2_free_cached_inode(fs, ci);
> -			ocfs2_read_cached_inode(fs,ino, &ci);
> +			/*
> +			 * We don't cache in the library right now, so any
> +			 * work done in mark_extent_written won't be reflected
> +			 * in our now stale copy. So refresh it.
> +			 */
> +			ret = ocfs2_refresh_cached_inode(fs, ci);
> +			if (ret)
> +				return ret;
>  		}
>  
>  		*wrote += (contig_blocks << bs_bits);
> -- 
> 1.5.5
> 

-- 

"And yet I find,
 And yet I find repeating in my head.
 If I can't be my own, 
 I'd feel better dead."

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127



More information about the Ocfs2-tools-devel mailing list