[Ocfs2-tools-devel] [PATCH 4/6] fsck.ocfs2: Add the clear journal flag function.

Sunil Mushran sunil.mushran at oracle.com
Tue Sep 16 17:56:15 PDT 2008


Tao Ma wrote:
> Add the clear journal flag function in fsck.ocfs2.
>
> Signed-off-by: Tao Ma <tao.ma at oracle.com>
> ---
>  fsck.ocfs2/fsck.c            |    7 +++++--
>  fsck.ocfs2/include/fsck.h    |    3 ++-
>  fsck.ocfs2/include/journal.h |    4 +++-
>  fsck.ocfs2/journal.c         |   35 ++++++++++++++++++++++++++++++++++-
>  4 files changed, 44 insertions(+), 5 deletions(-)
>
> diff --git a/fsck.ocfs2/fsck.c b/fsck.ocfs2/fsck.c
> index 6669e56..ed275a3 100644
> --- a/fsck.ocfs2/fsck.c
> +++ b/fsck.ocfs2/fsck.c
> @@ -449,12 +449,15 @@ static errcode_t maybe_replay_journals(o2fsck_state *ost, char *filename,
>  				       int open_flags, uint64_t blkno,
>  				       uint64_t blksize)
>  {	
> -	int replayed = 0, should = 0;
> +	int replayed = 0, should = 0, has_dirty = 0;
>  	errcode_t ret = 0;
>  
> -	ret = o2fsck_should_replay_journals(ost->ost_fs, &should);
> +	ret = o2fsck_should_replay_journals(ost->ost_fs, &should, &has_dirty);
>  	if (ret)
>  		goto out;
> +
> +	ost->ost_has_journal_dirty = has_dirty ? 1 : 0;
> +
>  	if (!should)
>  		goto out;
>  
> diff --git a/fsck.ocfs2/include/fsck.h b/fsck.ocfs2/include/fsck.h
> index eccd7ab..eab7197 100644
> --- a/fsck.ocfs2/include/fsck.h
> +++ b/fsck.ocfs2/include/fsck.h
> @@ -70,7 +70,8 @@ typedef struct _o2fsck_state {
>   					  * errors as we exit */
>   			ost_stale_mounts:1, /* set when reading publish blocks
>   					     * that still indicated mounted */
> -			ost_fix_fs_gen:1;
> +			ost_fix_fs_gen:1,
> +			ost_has_journal_dirty:1;
>  } o2fsck_state;
>  
>  errcode_t o2fsck_state_reinit(ocfs2_filesys *fs, o2fsck_state *ost);
> diff --git a/fsck.ocfs2/include/journal.h b/fsck.ocfs2/include/journal.h
> index 46792ab..b9c6c46 100644
> --- a/fsck.ocfs2/include/journal.h
> +++ b/fsck.ocfs2/include/journal.h
> @@ -27,7 +27,9 @@
>  #include "fsck.h"
>  
>  errcode_t o2fsck_replay_journals(ocfs2_filesys *fs, int *replayed);
> -errcode_t o2fsck_should_replay_journals(ocfs2_filesys *fs, int *should);
> +errcode_t o2fsck_should_replay_journals(ocfs2_filesys *fs, int *should,
> +					int *has_dirty);
> +errcode_t o2fsck_clear_journal_flags(o2fsck_state *ost);
>  errcode_t o2fsck_check_journals(o2fsck_state *ost);
>  
>  #endif /* __O2FSCK_JOURNAL_H__ */
> diff --git a/fsck.ocfs2/journal.c b/fsck.ocfs2/journal.c
> index 75f500b..b926a3a 100644
> --- a/fsck.ocfs2/journal.c
> +++ b/fsck.ocfs2/journal.c
> @@ -516,7 +516,8 @@ out:
>   * stop a second journal replay but leave the dirty bit set so that the kernel
>   * will truncate the orphaned inodes. 
>   */
> -errcode_t o2fsck_should_replay_journals(ocfs2_filesys *fs, int *should)
> +errcode_t o2fsck_should_replay_journals(ocfs2_filesys *fs, int *should,
> +					int *has_dirty)
>  {
>  	uint16_t i, max_slots;
>  	char *buf = NULL;
> @@ -564,6 +565,8 @@ errcode_t o2fsck_should_replay_journals(ocfs2_filesys *fs, int *should)
>  		verbosef("slot %d JOURNAL_DIRTY_FL: %d\n", i, is_dirty);
>  		if (!is_dirty)
>  			continue;
> +		else
> +			*has_dirty = 1;
>  
>  		ret = ocfs2_extent_map_get_blocks(cinode, 0, 1, &blkno,
>  						  &contig, NULL);
> @@ -804,3 +807,33 @@ out:
>  	return ret;
>  }
>  
> +static errcode_t ocfs2_clear_journal_flag(ocfs2_filesys *fs,
> +					  struct ocfs2_dinode *di)
> +{
> +	errcode_t ret = 0;
> +
> +	if (!(di->i_flags & OCFS2_VALID_FL) ||
> +	    !(di->i_flags & OCFS2_SYSTEM_FL) ||
> +	    !(di->i_flags & OCFS2_JOURNAL_FL))
> +		goto bail;
> +

same issue.

> +	if (!(di->id1.journal1.ij_flags & OCFS2_JOURNAL_DIRTY_FL))
> +		goto bail;
> +
> +	di->id1.journal1.ij_flags &= ~OCFS2_JOURNAL_DIRTY_FL;
> +
> +	ret = ocfs2_write_inode(fs, di->i_blkno, (char *)di);
> +
> +bail:
> +	return ret;
> +}
> +
> +errcode_t o2fsck_clear_journal_flags(o2fsck_state *ost)
> +{
> +	if (!ost->ost_has_journal_dirty)
> +		return 0;
> +
> +	return handle_slots_system_file(ost->ost_fs,
> +					JOURNAL_SYSTEM_INODE,
> +					ocfs2_clear_journal_flag);
> +}
Looks good otherwise.



More information about the Ocfs2-tools-devel mailing list