[Ocfs2-tools-devel] [PATCH 2/6] Add truncate_log clear process in fsck.ocfs2.

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


comments inlined.

Tao Ma wrote:
> Add functions in fsck.ocfs2 to clear the truncate_log
> for all the nodes.
>
> Signed-off-by: Tao Ma <tao.ma at oracle.com>
> ---
>  fsck.ocfs2/Makefile                |    1 +
>  fsck.ocfs2/include/slot_recovery.h |   31 ++++++++++++++++
>  fsck.ocfs2/include/util.h          |    4 ++
>  fsck.ocfs2/slot_recovery.c         |   70 ++++++++++++++++++++++++++++++++++++
>  fsck.ocfs2/util.c                  |   45 +++++++++++++++++++++++
>  5 files changed, 151 insertions(+), 0 deletions(-)
>  create mode 100644 fsck.ocfs2/include/slot_recovery.h
>  create mode 100644 fsck.ocfs2/slot_recovery.c
>
> diff --git a/fsck.ocfs2/Makefile b/fsck.ocfs2/Makefile
> index b804f67..74963d7 100644
> --- a/fsck.ocfs2/Makefile
> +++ b/fsck.ocfs2/Makefile
> @@ -29,6 +29,7 @@ CFILES =	fsck.c		\
>  		pass3.c 	\
>  		pass4.c 	\
>  		problem.c 	\
> +		slot_recovery.c \
>  		strings.c 	\
>  		util.c
>  
> diff --git a/fsck.ocfs2/include/slot_recovery.h b/fsck.ocfs2/include/slot_recovery.h
> new file mode 100644
> index 0000000..2d8e756
> --- /dev/null
> +++ b/fsck.ocfs2/include/slot_recovery.h
> @@ -0,0 +1,31 @@
> +/*
> + * slot_recovery.h
> + *
> + * Copyright (C) 2008 Oracle Corporation.  All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public
> + * License as published by the Free Software Foundation; either
> + * version 2 of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public
> + * License along with this program; if not, write to the
> + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
> + * Boston, MA 021110-1307, USA.
> + *
> + */
> +
> +#ifndef __O2FSCK_SLOT_RECOVERY_H__
> +#define __O2FSCK_SLOT_RECOVERY_H__
> +
> +#include "fsck.h"
> +
> +errcode_t o2fsck_replay_truncate_logs(ocfs2_filesys *fs);
> +
> +#endif /* __O2FSCK_SLOT_RECOVERY_H__ */
> +
> diff --git a/fsck.ocfs2/include/util.h b/fsck.ocfs2/include/util.h
> index 5ee4f8e..58146fb 100644
> --- a/fsck.ocfs2/include/util.h
> +++ b/fsck.ocfs2/include/util.h
> @@ -48,4 +48,8 @@ errcode_t o2fsck_type_from_dinode(o2fsck_state *ost, uint64_t ino,
>  errcode_t o2fsck_read_publish(o2fsck_state *ost);
>  size_t o2fsck_bitcount(unsigned char *bytes, size_t len);
>  
> +errcode_t handle_slots_system_file(ocfs2_filesys *fs,
> +				   int type,
> +				   errcode_t (*func)(ocfs2_filesys *fs,
> +						     struct ocfs2_dinode *di));
>  #endif /* __O2FSCK_UTIL_H__ */
> diff --git a/fsck.ocfs2/slot_recovery.c b/fsck.ocfs2/slot_recovery.c
> new file mode 100644
> index 0000000..2c912a6
> --- /dev/null
> +++ b/fsck.ocfs2/slot_recovery.c
> @@ -0,0 +1,70 @@
> +/* -*- mode: c; c-basic-offset: 8; -*-
> + * vim: noexpandtab sw=8 ts=8 sts=0:
> + *
> + * slot_recovery.c
> + *
> + * Slot recovery handler.
> + *
> + * Copyright (C) 2008 Oracle.  All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public
> + * License, version 2,  as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public
> + * License along with this program; if not, write to the
> + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
> + * Boston, MA 021110-1307, USA.
> + */
> +#include "slot_recovery.h"
> +
> +static errcode_t ocfs2_clear_truncate_log(ocfs2_filesys *fs,
> +					  struct ocfs2_dinode *di)
> +{
> +	errcode_t ret = 0;
> +	struct ocfs2_truncate_log *tl;
> +	struct ocfs2_truncate_rec *tr;
> +	int i, max = ocfs2_truncate_recs_per_inode(fs->fs_blocksize);
> +
> +	if (!(di->i_flags & OCFS2_VALID_FL) ||
> +	    !(di->i_flags & OCFS2_SYSTEM_FL) ||
> +	    !(di->i_flags & OCFS2_DEALLOC_FL))
> +		goto bail;

Shouldn't this be an error. As in, do you see a reason a case
in which this could be harmless.

> +
> +	tl = &di->id2.i_dealloc;
> +
> +	if (tl->tl_used > max)
> +		return OCFS2_ET_INTERNAL_FAILURE;
> +
> +	for (i = 0; i < tl->tl_used; i++) {
> +		tr = &tl->tl_recs[i];
> +
> +		if (tr->t_start == 0)
> +			continue;
> +

So we could test the bitmap here. Refer prev email.

> +		ret = ocfs2_free_clusters(fs, tr->t_clusters,
> +				ocfs2_clusters_to_blocks(fs, tr->t_start));
> +		if (ret)
> +			goto bail;
> +	}
> +
> +	tl->tl_used = 0;
> +	memset(tl->tl_recs, 0, fs->fs_blocksize -
> +	       offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs));
> +	ret = ocfs2_write_inode(fs, di->i_blkno, (char *)di);
> +
> +bail:
> +	return ret;
> +}
> +
> +errcode_t o2fsck_replay_truncate_logs(ocfs2_filesys *fs)
> +{
> +	return handle_slots_system_file(fs,
> +					TRUNCATE_LOG_SYSTEM_INODE,
> +					ocfs2_clear_truncate_log);
> +}
> diff --git a/fsck.ocfs2/util.c b/fsck.ocfs2/util.c
> index c2382ac..a7da245 100644
> --- a/fsck.ocfs2/util.c
> +++ b/fsck.ocfs2/util.c
> @@ -124,3 +124,48 @@ size_t o2fsck_bitcount(unsigned char *bytes, size_t len)
>  
>  	return count;
>  }
> +
> +errcode_t handle_slots_system_file(ocfs2_filesys *fs,
> +				   int type,
> +				   errcode_t (*func)(ocfs2_filesys *fs,
> +						     struct ocfs2_dinode *di))
> +{
> +	errcode_t ret;
> +	uint64_t blkno;
> +	int slot, max_slots;
> +	char *buf = NULL;
> +	struct ocfs2_dinode *di;
> +
> +	ret = ocfs2_malloc_block(fs->fs_io, &buf);
> +	if (ret)
> +		goto bail;
> +
> +	di = (struct ocfs2_dinode *)buf;
> +
> +	max_slots = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;
> +
> +	for (slot = 0; slot < max_slots; slot++) {
> +		ret = ocfs2_lookup_system_inode(fs,
> +						type,
> +						slot, &blkno);
> +		if (ret)
> +			goto bail;
> +
> +		ret = ocfs2_read_inode(fs, blkno, buf);
> +		if (ret)
> +			goto bail;
> +
> +		if (func) {
> +			ret = func(fs, di);
> +			if (ret)
> +				goto bail;
> +		}
> +	}
> +
> +bail:
> +
> +	if (buf)
> +		ocfs2_free(&buf);
> +	return ret;
> +}
> +

very nicely done.



More information about the Ocfs2-tools-devel mailing list