[sheepdog] [PATCH] sheep: refactor get_nth_node() and get_vnode_pos()

Liu Yuan namei.unix at gmail.com
Sat Aug 4 13:15:29 CEST 2012


On 08/04/2012 06:17 PM, Yunkai Zhang wrote:
> -static inline void obj_to_sheeps(struct sd_vnode *entries,
> -		  int nr_entries, uint64_t oid, int nr_copies, int *idxs)
> +static inline int obj_to_sheep(struct sd_vnode *entries, int nr_entries,
> +			       uint64_t oid, int nth_idx)
>  {
> -	int pos = get_vnode_pos(entries, nr_entries, oid);
> -	int idx;
> +	return get_vnode_nth_idx(entries, nr_entries, oid, nth_idx);
> +}
>  
> -	for (idx = 0; idx < nr_copies; idx++)
> -		idxs[idx] = get_nth_node(entries, nr_entries,
> -				(pos + 1) % nr_entries, idx);
> +static inline void obj_to_sheeps(struct sd_vnode *entries, int nr_entries,
> +				 uint64_t oid, int nr_copies, int *idxs)
> +{
> +	int nr_idxs = 0;
> +
> +	idxs[nr_idxs++] = get_vnode_first_idx(entries, nr_entries, oid);
> +
> +	while (nr_idxs < nr_copies) {
> +		idxs[nr_idxs] = get_vnode_next_idx(entries, nr_entries,
> +						     idxs, nr_idxs);
> +		nr_idxs++;
> +	}
>  }

Both obj_to_sheep and obj_to_sheeps would better be folded into their
callers and every one should rely on the oid_to_vnodes(),
oid_to_vnode(), which are much more descriptive, to map oid to vnode(s).

Thanks,
Yuan



More information about the sheepdog mailing list