[Ocfs2-tools-devel] [RFC 4/4] dx_dirs v1: indexed dir for fsck.ocfs2
Tao Ma
tao.ma at ORACLE.COM
Sun Dec 20 21:29:26 PST 2009
Coly Li wrote:
> This patch includes the rested part to support indexed dirs for fsck.ocfs2.
>
> Signed-off-by: Coly Li <coly.li at suse.de>
> ---
> diff --git a/fsck.ocfs2/dirblocks.c b/fsck.ocfs2/dirblocks.c
> index 1fd5560..c502eef 100644
> --- a/fsck.ocfs2/dirblocks.c
> +++ b/fsck.ocfs2/dirblocks.c
> @@ -134,6 +134,79 @@ static int try_to_cache(ocfs2_filesys *fs, struct rb_node *node,
> return cached_blocks;
> }
>
> +uint64_t o2fsck_search_reidx_dir(struct rb_root *root, uint64_t dino)
> +{
> + struct rb_node *node = root->rb_node;
> + o2fsck_dirblock_entry *dbe;
> +
> + while (node) {
> + dbe = rb_entry(node, o2fsck_dirblock_entry, e_node);
> +
> + if (dino < dbe->e_ino)
> + node = node->rb_left;
> + else if (dino > dbe->e_ino)
> + node = node->rb_right;
> + else
> + return dbe->e_ino;
> + }
> + return 0;
> +}
> +
> +static errcode_t o2fsck_add_reidx_dir_ino(struct rb_root *root, uint64_t dino)
> +{
> + struct rb_node **p = &root->rb_node;
> + struct rb_node *parent = NULL;
> + o2fsck_dirblock_entry *dp, *tmp_dp;
> + errcode_t ret = 0;
> +
> + dp = calloc(1, sizeof (*dp));
you can use ocfs2_malloc0 here.
> + if (dp == NULL) {
> + ret = OCFS2_ET_NO_MEMORY;
> + goto out;
> + }
> +
> + dp->e_ino = dino;
> +
> + while(*p)
> + {
> + parent = *p;
> + tmp_dp = rb_entry(parent, o2fsck_dirblock_entry, e_node);
> +
> + if (dp->e_ino < tmp_dp->e_ino)
> + p = &(*p)->rb_left;
> + else if (dp->e_ino > tmp_dp->e_ino)
> + p = &(*p)->rb_right;
> + else {
> + ret = OCFS2_ET_INTERNAL_FAILURE;
> + free(dp);
change to ocfs2_free of course if you use ocfs2_malloc0.
> + goto out;
> + }
> + }
> +
> + rb_link_node(&dp->e_node, parent, p);
> + rb_insert_color(&dp->e_node, root);
> +
> +out:
> + return ret;
> +}
> +
> +errcode_t o2fsck_try_add_reidx_dir(struct rb_root *root, uint64_t dino)
> +{
> + errcode_t ret = 1;
> + uint64_t ino;
> + ino = o2fsck_search_reidx_dir(root, dino);
> + if (ino) {
> + ret = 0;
> + goto out;
> + }
> + ret = o2fsck_add_reidx_dir_ino(root, dino);
> + if (ret)
> + printf("some error happens.\n");
com_err should work for you in this case.
> +
> +out:
> + return ret;
> +}
> +
I can't give more comments on your dir work now since they haven't been
implemented yet.
Thanks again for your work for implementing index dir support in
ocfs2-tools.
Regards,
Tao
More information about the Ocfs2-tools-devel
mailing list