[sheepdog] [PATCH v2 1/1] sheep: clean vdi_state when formatting cluster

Liu Yuan namei.unix at gmail.com
Mon May 13 10:17:59 CEST 2013


On 05/13/2013 04:06 PM, Kai Zhang wrote:
> Signed-off-by: Kai Zhang <kyle at zelin.io>
> ---
>  sheep/ops.c        |    1 +
>  sheep/sheep_priv.h |    1 +
>  sheep/vdi.c        |   17 +++++++++++++++++
>  3 files changed, 19 insertions(+), 0 deletions(-)
> 
> diff --git a/sheep/ops.c b/sheep/ops.c
> index 26bd84c..e40fc65 100644
> --- a/sheep/ops.c
> +++ b/sheep/ops.c
> @@ -286,6 +286,7 @@ static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
>  		remove_epoch(i);
>  
>  	memset(sys->vdi_inuse, 0, sizeof(sys->vdi_inuse));
> +	clean_vdi_state();
>  
>  	sys->epoch = 1;
>  
> diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
> index 5596215..ab2636a 100644
> --- a/sheep/sheep_priv.h
> +++ b/sheep/sheep_priv.h
> @@ -266,6 +266,7 @@ int vdi_exist(uint32_t vid);
>  int vdi_create(struct vdi_iocb *iocb, uint32_t *new_vid);
>  int vdi_delete(struct vdi_iocb *iocb, struct request *req);
>  int vdi_lookup(struct vdi_iocb *iocb, struct vdi_info *info);
> +void clean_vdi_state(void);
>  
>  int read_vdis(char *data, int len, unsigned int *rsp_len);
>  
> diff --git a/sheep/vdi.c b/sheep/vdi.c
> index 7e67ff1..98abe10 100644
> --- a/sheep/vdi.c
> +++ b/sheep/vdi.c
> @@ -933,3 +933,20 @@ int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len,
>  out:
>  	return ret;
>  }
> +
> +void clean_vdi_state(void)
> +{
> +	struct rb_node *current_node = rb_first(&vdi_state_root);
> +	struct vdi_state_entry *entry = NULL;
> +
> +	pthread_rwlock_wrlock(&vdi_state_lock);
> +	while (current_node) {
> +		entry = rb_entry(current_node, struct vdi_state_entry, node);
> +		rb_erase(current_node, &vdi_state_root);
> +		free(entry);
> +		entry = NULL;
> +		current_node = rb_first(&vdi_state_root);
> +	}
> +	INIT_RB_ROOT(&vdi_state_root);
> +	pthread_rwlock_unlock(&vdi_state_lock);
> +}
> 

Applied, thanks.

Yuan



More information about the sheepdog mailing list