[sheepdog] [PATCH] util/sd_inode: add sd_inode_index_walk helper

Hitoshi Mitake mitake.hitoshi at gmail.com
Fri Feb 21 03:04:02 CET 2014


At Thu, 20 Feb 2014 16:55:48 +0800,
Liu Yuan wrote:
> 
> This is more easier for callers to understand what it does instead of calling
> a internal btree walker.
> 
> Signed-off-by: Liu Yuan <namei.unix at gmail.com>
> ---
>  dog/cluster.c            | 17 +++++-----
>  dog/vdi.c                | 21 ++++++-------
>  include/sheepdog_proto.h |  9 +++---
>  lib/sd_inode.c           | 76 +++++++++++++++++++++++++++++----------------
>  sheep/http/kv.c          | 80 ++++++++++++++++++++++--------------------------
>  sheep/vdi.c              | 16 ++++------
>  6 files changed, 112 insertions(+), 107 deletions(-)
> 
> diff --git a/dog/cluster.c b/dog/cluster.c
> index 169e837..815ecff 100644
> --- a/dog/cluster.c
> +++ b/dog/cluster.c
> @@ -281,19 +281,16 @@ out:
>  	return ret;
>  }
>  
> -static void fill_cb(void *data, enum btree_node_type type, void *arg)
> +static void fill_cb(struct sd_index *idx, void *arg,
> +		    enum btree_node_type ignore)
>  {
> -	struct sd_index *ext;
>  	struct sd_inode *inode = (struct sd_inode *)arg;
>  	uint64_t oid;
>  
> -	if (type == BTREE_INDEX) {
> -		ext = (struct sd_index *)data;
> -		if (ext->vdi_id) {
> -			oid = vid_to_data_oid(ext->vdi_id, ext->idx);
> -			object_tree_insert(oid, inode->nr_copies,
> -					   inode->copy_policy);
> -		}
> +	if (idx->vdi_id) {
> +		oid = vid_to_data_oid(idx->vdi_id, idx->idx);
> +		object_tree_insert(oid, inode->nr_copies,
> +				   inode->copy_policy);
>  	}
>  }
>  
> @@ -323,7 +320,7 @@ static void fill_object_tree(uint32_t vid, const char *name, const char *tag,
>  			object_tree_insert(oid, i->nr_copies, i->copy_policy);
>  		}
>  	} else
> -		traverse_btree(i, fill_cb, &i);
> +		sd_inode_index_walk(i, fill_cb, &i);
>  
>  	/* fill vmstate object id */
>  	nr_vmstate_object = DIV_ROUND_UP(i->vm_state_size, SD_DATA_OBJ_SIZE);
> diff --git a/dog/vdi.c b/dog/vdi.c
> index 49add72..ed4ab54 100644
> --- a/dog/vdi.c
> +++ b/dog/vdi.c
> @@ -1786,21 +1786,18 @@ struct check_arg {
>  	int nr_copies;
>  };
>  
> -static void check_cb(void *data, enum btree_node_type type, void *arg)
> +static void check_cb(struct sd_index *idx, void *arg,
> +		     enum btree_node_type ignore)
>  {
> -	struct sd_index *ext;
>  	struct check_arg *carg = arg;
>  	uint64_t oid;
>  
> -	if (type == BTREE_INDEX) {
> -		ext = (struct sd_index *)data;
> -		if (ext->vdi_id) {
> -			oid = vid_to_data_oid(ext->vdi_id, ext->idx);
> -			*(carg->done) = (uint64_t)ext->idx * SD_DATA_OBJ_SIZE;
> -			vdi_show_progress(*(carg->done), carg->inode->vdi_size);
> -			queue_vdi_check_work(carg->inode, oid, NULL, carg->wq,
> -					     carg->nr_copies);
> -		}
> +	if (idx->vdi_id) {
> +		oid = vid_to_data_oid(idx->vdi_id, idx->idx);
> +		*(carg->done) = (uint64_t)idx->idx * SD_DATA_OBJ_SIZE;
> +		vdi_show_progress(*(carg->done), carg->inode->vdi_size);
> +		queue_vdi_check_work(carg->inode, oid, NULL, carg->wq,
> +				     carg->nr_copies);
>  	}
>  }
>  
> @@ -1841,7 +1838,7 @@ int do_vdi_check(const struct sd_inode *inode)
>  		}
>  	} else {
>  		struct check_arg arg = {inode, &done, wq, nr_copies};
> -		traverse_btree(inode, check_cb, &arg);
> +		sd_inode_index_walk(inode, check_cb, &arg);
>  		vdi_show_progress(inode->vdi_size, inode->vdi_size);
>  	}
>  
> diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
> index 9746fcc..95f316e 100644
> --- a/include/sheepdog_proto.h
> +++ b/include/sheepdog_proto.h
> @@ -251,8 +251,8 @@ struct sd_index_header {
>  
>  enum btree_node_type {
>  	BTREE_HEAD = 1,
> -	BTREE_INDEX,
> -	BTREE_INDIRECT_IDX,
> +	BTREE_INDEX = 2 ,
> +	BTREE_INDIRECT_IDX = 4,
>  };

We should use #define instead of enum for defining bitmasks. Other
part looks good to me.

Thanks,
Hitoshi



More information about the sheepdog mailing list