[Ocfs2-tools-devel] [PATCH 3/5] Abstract truncating process for "set sparse", take 2

Mark Fasheh mark.fasheh at oracle.com
Tue Oct 30 22:23:38 PDT 2007


On Thu, Oct 25, 2007 at 03:36:43PM +0800, tao.ma wrote:
> In ocfs2_truncate, we will free all the clusters and empty the
> extra bytes in the last cluster. This function is also useful
> for "set-sparse" function in tunefs.ocfs2, so abstract the process
> and move the prototype to ocfs2.h for other functions to use it.

This looks mostly good - one comment below.


> Signed-off-by: Tao Ma <tao.ma at oracle.com>
> ---
>  libocfs2/include/ocfs2.h |    4 +++
>  libocfs2/truncate.c      |   65 +++++++++++++++++++++++++++++----------------
>  2 files changed, 46 insertions(+), 23 deletions(-)
> 
> diff --git a/libocfs2/include/ocfs2.h b/libocfs2/include/ocfs2.h
> index ab84119..9fd0b83 100644
> --- a/libocfs2/include/ocfs2.h
> +++ b/libocfs2/include/ocfs2.h
> @@ -469,6 +469,10 @@ errcode_t ocfs2_allocate_unwritten_extents(ocfs2_filesys *fs, uint64_t ino,
>  					   uint64_t offset, uint64_t len);
>  
>  errcode_t ocfs2_truncate(ocfs2_filesys *fs, uint64_t ino, uint64_t new_i_size);
> +errcode_t ocfs2_zero_tail_and_truncate(ocfs2_filesys *fs,
> +				       ocfs2_cached_inode *ci,
> +				       uint64_t new_size,
> +				       uint32_t *new_clusters);
>  errcode_t ocfs2_new_clusters(ocfs2_filesys *fs,
>  			     uint32_t min,
>  			     uint32_t requested,
> diff --git a/libocfs2/truncate.c b/libocfs2/truncate.c
> index f1784e7..467f808 100644
> --- a/libocfs2/truncate.c
> +++ b/libocfs2/truncate.c
> @@ -147,9 +147,6 @@ static errcode_t ocfs2_zero_tail_for_truncate(ocfs2_cached_inode *ci,
>  	uint64_t start_blk, p_blkno, contig_blocks, start_off;
>  	int count, byte_counts, bpc = fs->fs_clustersize /fs->fs_blocksize;
>  
> -	if (new_size >= ci->ci_inode->i_size || new_size == 0)
> -		return 0;
> -

We lost the check for new_size == 0 here. I think we're still safe though,
because any lookup will return a hole, which we skip. Can we either re-add
the new_size == 0 check, or put a comment here which explains the situation?
	--Mark

--
Mark Fasheh
Senior Software Developer, Oracle
mark.fasheh at oracle.com



More information about the Ocfs2-tools-devel mailing list