[Ocfs2-tools-devel] [PATCH 20/22] tunefs rework: Add the libocfs2ne sources.

Tao Ma tao.ma at oracle.com
Thu Aug 7 01:30:58 PDT 2008



Joel Becker wrote:
> The libocfs2ne library contains the routines shared by all ocfs2ne
> methods and programs.  This includes opening and closing the filesystem,
> locking the cluster, managing online operations, and interacting with
> the user.
> 
> Signed-off-by: Joel Becker <joel.becker at oracle.com>
> ---
>  tunefs.ocfs2/libocfs2ne.c | 1914 +++++++++++++++++++++++++++++++++++++++++++++
>  tunefs.ocfs2/libocfs2ne.h |  315 ++++++++
>  2 files changed, 2229 insertions(+), 0 deletions(-)
>  create mode 100644 tunefs.ocfs2/libocfs2ne.c
>  create mode 100644 tunefs.ocfs2/libocfs2ne.h
> 
> diff --git a/tunefs.ocfs2/libocfs2ne.c b/tunefs.ocfs2/libocfs2ne.c
> new file mode 100644
> index 0000000..0804fa8
> --- /dev/null
> +++ b/tunefs.ocfs2/libocfs2ne.c
> @@ -0,0 +1,1914 @@
> +/* -*- mode: c; c-basic-offset: 8; -*-
> + * vim: noexpandtab sw=8 ts=8 sts=0:
> + *
> + * libocfs2ne.c
> + *
> + * Shared routines for the ocfs2 tunefs utility
> + *
> + * Copyright (C) 2004, 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.
> + */
> +
> +#define _LARGEFILE64_SOURCE
> +errcode_t tunefs_foreach_inode(ocfs2_filesys *fs, int filetype_mask,
> +			       errcode_t (*func)(ocfs2_filesys *fs,
> +						 struct ocfs2_dinode *di,
> +						 void *user_data),
> +			       void *user_data)
> +{
> +	errcode_t ret;
> +	uint64_t blkno;
> +	char *buf;
> +	struct ocfs2_dinode *di;
> +	ocfs2_inode_scan *scan;
> +
> +	ret = ocfs2_malloc_block(fs->fs_io, &buf);
> +	if (ret) {
> +		verbosef(VL_LIB,
> +			 "%s while allocating a buffer for inode scanning\n",
> +			 error_message(ret));
> +		goto out;
> +	}
> +
> +	di = (struct ocfs2_dinode *)buf;
> +
> +	ret = ocfs2_open_inode_scan(fs, &scan);
> +	if (ret) {
> +		verbosef(VL_LIB,
> +			 "%s while opening inode scan\n",
> +			 error_message(ret));
> +		goto out_free;
> +	}
> +
> +	for(;;) {
> +		ret = ocfs2_get_next_inode(scan, &blkno, buf);
> +		if (ret) {
> +			verbosef(VL_LIB, "%s while getting next inode\n",
> +				 error_message(ret));
> +			break;
> +		}
> +		if (blkno == 0)
> +			break;
> +
> +		ret = tunefs_validate_inode(fs, di);
> +		if (ret)
> +			continue;
> +
> +		if (di->i_flags & OCFS2_SYSTEM_FL)
> +			continue;
you'd better leave this judgement to the func itself. inline data also 
need to iterate all the inodes and it will also modify system files if 
we want to remove "inline-data" support from the volume(orphand_dir is 
intialized as inline dir).
> +
> +		if (!func)
> +			continue;
> +
> +		if (di->i_mode & filetype_mask) {
> +			ret = func(fs, di, user_data);
> +			if (ret)
> +				break;
> +		}
> +	}
> +
> +	ocfs2_close_inode_scan(scan);
> +out_free:
> +	ocfs2_free(&buf);
> +
> +out:
> +	return ret;
> +}

Regards,
Tao



More information about the Ocfs2-tools-devel mailing list