[Ocfs2-tools-devel] [PATCH 3/6] Add local alloc free in fsck.ocfs2.

Sunil Mushran sunil.mushran at oracle.com
Tue Sep 16 17:46:18 PDT 2008


comments inlined.

Tao Ma wrote:
> Add local alloc free process in fsck.ocfs2.
>
> Signed-off-by: Tao Ma <tao.ma at oracle.com>
> ---
>  fsck.ocfs2/include/slot_recovery.h |    1 +
>  fsck.ocfs2/slot_recovery.c         |   68 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 69 insertions(+), 0 deletions(-)
>
> diff --git a/fsck.ocfs2/include/slot_recovery.h b/fsck.ocfs2/include/slot_recovery.h
> index 2d8e756..a5cb513 100644
> --- a/fsck.ocfs2/include/slot_recovery.h
> +++ b/fsck.ocfs2/include/slot_recovery.h
> @@ -26,6 +26,7 @@
>  #include "fsck.h"
>  
>  errcode_t o2fsck_replay_truncate_logs(ocfs2_filesys *fs);
> +errcode_t o2fsck_replay_local_allocs(ocfs2_filesys *fs);
>  
>  #endif /* __O2FSCK_SLOT_RECOVERY_H__ */
>  
> diff --git a/fsck.ocfs2/slot_recovery.c b/fsck.ocfs2/slot_recovery.c
> index 2c912a6..631fff7 100644
> --- a/fsck.ocfs2/slot_recovery.c
> +++ b/fsck.ocfs2/slot_recovery.c
> @@ -68,3 +68,71 @@ errcode_t o2fsck_replay_truncate_logs(ocfs2_filesys *fs)
>  					TRUNCATE_LOG_SYSTEM_INODE,
>  					ocfs2_clear_truncate_log);
>  }
> +
> +static errcode_t ocfs2_clear_local_alloc(ocfs2_filesys *fs,
> +					 struct ocfs2_dinode *di)
> +{
> +	errcode_t ret = 0;
> +	int bit_off, left, count, start;
> +	uint64_t la_start_blk;
> +	uint64_t blkno;
> +	void *bitmap;
> +	struct ocfs2_local_alloc *la;
> +
> +	if (!(di->i_flags & OCFS2_VALID_FL) ||
> +	    !(di->i_flags & OCFS2_SYSTEM_FL) ||
> +	    !(di->i_flags & OCFS2_BITMAP_FL))
> +		goto bail;
> +

Same problem here. We should treat this as an error.

> +	if (!di->id1.bitmap1.i_total)
> +		goto bail;
> +
> +	if (di->id1.bitmap1.i_used == di->id1.bitmap1.i_total)
> +		goto clear_inode;
> +
> +	la = &di->id2.i_lab;
> +
> +	la_start_blk = ocfs2_clusters_to_blocks(fs, la->la_bm_off);
> +	bitmap = la->la_bitmap;
> +	start = count = bit_off = 0;
> +	left = di->id1.bitmap1.i_total;
> +
> +	while ((bit_off = ocfs2_find_next_bit_clear(bitmap, left, start))
> +	       != -1) {
> +		if ((bit_off < left) && (bit_off == start)) {
> +			count++;
> +			start++;
> +			continue;
> +		}
> +		if (count) {
> +			blkno = la_start_blk +
> +				ocfs2_clusters_to_blocks(fs, start - count);
> +

same test_bit here.

> +			ret = ocfs2_free_clusters(fs, count, blkno);
> +			if (ret)
> +				goto bail;
> +		}
> +
> +		if (bit_off >= left)
> +			break;
> +		count = 1;
> +		start = bit_off + 1;
> +	}
> +clear_inode:
> +	di->id1.bitmap1.i_total = 0;
> +	di->id1.bitmap1.i_used = 0;
> +	la->la_bm_off = 0;
> +	memset(la->la_bitmap, 0, ocfs2_local_alloc_size(fs->fs_blocksize));
> +
> +	ret = ocfs2_write_inode(fs, di->i_blkno, (char *)di);
> +
> +bail:
> +	return ret;
> +}
> +
> +errcode_t o2fsck_replay_local_allocs(ocfs2_filesys *fs)
> +{
> +	return handle_slots_system_file(fs,
> +					LOCAL_ALLOC_SYSTEM_INODE,
> +					ocfs2_clear_local_alloc);
> +}

Looks good otherwise.



More information about the Ocfs2-tools-devel mailing list