[Ocfs2-tools-devel] [PATCH 02/12] libocfs2: Pass the dinode to ocfs2_read/write_dir_block().

Sunil Mushran sunil.mushran at oracle.com
Tue Jan 6 17:40:35 PST 2009


Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>


Joel Becker wrote:
> Future code will need to look at the dinode when reading and writing
> dirblocks, so let's pass it in.
>
> Signed-off-by: Joel Becker <joel.becker at oracle.com>
> ---
>  fsck.ocfs2/pass2.c     |    4 ++--
>  include/ocfs2/ocfs2.h  |    8 ++++----
>  libocfs2/dir_iterate.c |   16 ++++++++++++++--
>  libocfs2/dir_iterate.h |    1 +
>  libocfs2/dir_scan.c    |    3 ++-
>  libocfs2/dirblock.c    |    8 ++++----
>  libocfs2/expanddir.c   |    4 ++--
>  libocfs2/fileio.c      |    3 ++-
>  8 files changed, 31 insertions(+), 16 deletions(-)
>
> diff --git a/fsck.ocfs2/pass2.c b/fsck.ocfs2/pass2.c
> index c53c264..8239c10 100644
> --- a/fsck.ocfs2/pass2.c
> +++ b/fsck.ocfs2/pass2.c
> @@ -656,7 +656,7 @@ static unsigned pass2_dir_block_iterate(o2fsck_dirblock_entry *dbe,
>  							     di->i_size))
>  			goto out;
>  
> -		ret = ocfs2_read_dir_block(dd->fs, dbe->e_blkno,
> +		ret = ocfs2_read_dir_block(dd->fs, di, dbe->e_blkno,
>  					   dd->dirblock_buf);
>  		if (ret && ret != OCFS2_ET_DIR_CORRUPTED) {
>  			com_err(whoami, ret, "while reading dir block %"PRIu64,
> @@ -759,7 +759,7 @@ next:
>  			ret = ocfs2_write_inode(dd->fs, dbe->e_ino,
>  						dd->dirblock_buf);
>  		} else
> -			ret = ocfs2_write_dir_block(dd->fs, dbe->e_blkno,
> +			ret = ocfs2_write_dir_block(dd->fs, di, dbe->e_blkno,
>  						    dd->dirblock_buf);
>  		if (ret) {
>  			com_err(whoami, ret, "while writing dir block %"PRIu64,
> diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
> index 030bc18..32c4c2a 100644
> --- a/include/ocfs2/ocfs2.h
> +++ b/include/ocfs2/ocfs2.h
> @@ -305,10 +305,10 @@ errcode_t ocfs2_write_extent_block(ocfs2_filesys *fs, uint64_t blkno,
>         				   char *eb_buf);
>  errcode_t ocfs2_swap_dir_entries_from_cpu(void *buf, uint64_t bytes);
>  errcode_t ocfs2_swap_dir_entries_to_cpu(void *buf, uint64_t bytes);
> -errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, uint64_t block,
> -			       void *buf);
> -errcode_t ocfs2_write_dir_block(ocfs2_filesys *fs, uint64_t block,
> -				void *buf);
> +errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, struct ocfs2_dinode *di,
> +			       uint64_t block, void *buf);
> +errcode_t ocfs2_write_dir_block(ocfs2_filesys *fs, struct ocfs2_dinode *di,
> +				uint64_t block, void *buf);
>  
>  errcode_t ocfs2_dir_iterate2(ocfs2_filesys *fs,
>  			     uint64_t dir,
> diff --git a/libocfs2/dir_iterate.c b/libocfs2/dir_iterate.c
> index 31ed6e2..83b0b08 100644
> --- a/libocfs2/dir_iterate.c
> +++ b/libocfs2/dir_iterate.c
> @@ -95,10 +95,20 @@ errcode_t ocfs2_dir_iterate2(ocfs2_filesys *fs,
>  	ctx.priv_data = priv_data;
>  	ctx.errcode = 0;
>  
> +	retval = ocfs2_malloc_block(fs->fs_io, &ctx.di);
> +	if (retval)
> +		goto out;
> +
>  	retval = ocfs2_read_inode(fs, dir, ctx.buf);
>  	if (retval)
>  		goto out;
>  
> +	/*
> +	 * Save off the inode - some paths use the buffer for dirent
> +	 * data.
> +	 */
> +	memcpy(ctx.di, ctx.buf, fs->fs_blocksize);
> +
>  	di = (struct ocfs2_dinode *)ctx.buf;
>  
>  	if (ocfs2_support_inline_data(OCFS2_RAW_SB(fs->fs_super)) &&
> @@ -112,6 +122,8 @@ errcode_t ocfs2_dir_iterate2(ocfs2_filesys *fs,
>  out:
>  	if (!block_buf)
>  		ocfs2_free(&ctx.buf);
> +	if (ctx.di)
> +		ocfs2_free(&ctx.di);
>  	if (retval)
>  		return retval;
>  	return ctx.errcode;
> @@ -271,7 +283,7 @@ int ocfs2_process_dir_block(ocfs2_filesys *fs,
>  	entry = blockcnt ? OCFS2_DIRENT_OTHER_FILE :
>  		OCFS2_DIRENT_DOT_FILE;
>  
> -	ctx->errcode = ocfs2_read_dir_block(fs, blocknr, ctx->buf);
> +	ctx->errcode = ocfs2_read_dir_block(fs, ctx->di, blocknr, ctx->buf);
>  	if (ctx->errcode)
>  		return OCFS2_BLOCK_ABORT;
>  
> @@ -281,7 +293,7 @@ int ocfs2_process_dir_block(ocfs2_filesys *fs,
>  		return ret;
>  
>  	if (changed) {
> -		ctx->errcode = ocfs2_write_dir_block(fs, blocknr,
> +		ctx->errcode = ocfs2_write_dir_block(fs, ctx->di, blocknr,
>  						     ctx->buf);
>  		if (ctx->errcode)
>  			return OCFS2_BLOCK_ABORT;
> diff --git a/libocfs2/dir_iterate.h b/libocfs2/dir_iterate.h
> index 9ec11a3..f281af2 100644
> --- a/libocfs2/dir_iterate.h
> +++ b/libocfs2/dir_iterate.h
> @@ -30,6 +30,7 @@
>  struct dir_context {
>  	uint64_t dir;
>  	int flags;
> +	struct ocfs2_dinode *di;
>  	char *buf;
>  	int (*func)(uint64_t dir,
>  		    int entry,
> diff --git a/libocfs2/dir_scan.c b/libocfs2/dir_scan.c
> index ea70671..ad14120 100644
> --- a/libocfs2/dir_scan.c
> +++ b/libocfs2/dir_scan.c
> @@ -61,7 +61,8 @@ static errcode_t get_more_dir_blocks(ocfs2_dir_scan *scan)
>  	if (ret)
>  		return ret;
>  
> -	ret = ocfs2_read_dir_block(scan->fs, blkno, scan->buf);
> +	ret = ocfs2_read_dir_block(scan->fs, scan->inode->ci_inode, blkno,
> +				   scan->buf);
>  	if (ret)
>  		return ret;
>  
> diff --git a/libocfs2/dirblock.c b/libocfs2/dirblock.c
> index 4684406..f116fb2 100644
> --- a/libocfs2/dirblock.c
> +++ b/libocfs2/dirblock.c
> @@ -84,8 +84,8 @@ errcode_t ocfs2_swap_dir_entries_to_cpu(void *buf, uint64_t bytes)
>  	return ocfs2_swap_dir_entries_direction(buf, bytes, 1);
>  }
>  
> -errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, uint64_t block,
> -                               void *buf)
> +errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, struct ocfs2_dinode *di,
> +			       uint64_t block, void *buf)
>  {
>  	errcode_t	retval;
>  
> @@ -96,8 +96,8 @@ errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, uint64_t block,
>  	return ocfs2_swap_dir_entries_to_cpu(buf, fs->fs_blocksize);
>  }
>  
> -errcode_t ocfs2_write_dir_block(ocfs2_filesys *fs, uint64_t block,
> -                                void *inbuf)
> +errcode_t ocfs2_write_dir_block(ocfs2_filesys *fs, struct ocfs2_dinode *di,
> +				uint64_t block, void *inbuf)
>  {
>  	errcode_t	retval;
>  	char		*buf = NULL;
> diff --git a/libocfs2/expanddir.c b/libocfs2/expanddir.c
> index d886881..fc7e055 100644
> --- a/libocfs2/expanddir.c
> +++ b/libocfs2/expanddir.c
> @@ -107,7 +107,7 @@ errcode_t ocfs2_expand_dir(ocfs2_filesys *fs,
>  	de->rec_len = fs->fs_blocksize;
>  
>  	/* write new dir block */
> -	ret = ocfs2_write_dir_block(fs, new_blk, buf);
> +	ret = ocfs2_write_dir_block(fs, cinode->ci_inode, new_blk, buf);
>  	if (ret)
>  		goto bail;
>  
> @@ -212,7 +212,7 @@ errcode_t ocfs2_init_dir(ocfs2_filesys *fs,
>  	ocfs2_fill_initial_dirents(dir, parent_dir, data, size);
>  
>  	if (!(cinode->ci_inode->i_dyn_features & OCFS2_INLINE_DATA_FL)) {
> -		ret = ocfs2_write_dir_block(fs, blkno, buf);
> +		ret = ocfs2_write_dir_block(fs, cinode->ci_inode, blkno, buf);
>  		if (ret)
>  			goto bail;
>  	}
> diff --git a/libocfs2/fileio.c b/libocfs2/fileio.c
> index cc554f8..276a568 100644
> --- a/libocfs2/fileio.c
> +++ b/libocfs2/fileio.c
> @@ -526,7 +526,8 @@ errcode_t ocfs2_convert_inline_data_to_extents(ocfs2_cached_inode *ci)
>  						 fs->fs_blocksize);
>  
>  			di->i_size = fs->fs_blocksize;
> -			ret = ocfs2_write_dir_block(fs, p_start, inline_data);
> +			ret = ocfs2_write_dir_block(fs, di, p_start,
> +						    inline_data);
>  		} else
>  			ret = io_write_block(fs->fs_io, p_start,
>  					     1, inline_data);
>   




More information about the Ocfs2-tools-devel mailing list