[sheepdog] [PATCH 1/2] sheep: pass epoch number to for_each_object_in_path() callback

Liu Yuan namei.unix at gmail.com
Tue May 28 06:40:43 CEST 2013


On 05/28/2013 12:43 AM, MORITA Kazutaka wrote:
> From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
> 
> This prepares the next patch.
> 
> Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
> ---
>  sheep/md.c          |   19 ++++++++++++++-----
>  sheep/plain_store.c |   14 +++++++++-----
>  sheep/sheep_priv.h  |    6 ++++--
>  3 files changed, 27 insertions(+), 12 deletions(-)
> 
> diff --git a/sheep/md.c b/sheep/md.c
> index 4302b80..a0fbe8c 100644
> --- a/sheep/md.c
> +++ b/sheep/md.c
> @@ -181,7 +181,8 @@ static inline void calculate_vdisks(struct disk *disks, int nr_disks,
>  #define MDNAME	"user.md.size"
>  #define MDSIZE	sizeof(uint64_t)
>  
> -static int get_total_object_size(uint64_t oid, char *wd, void *total)
> +static int get_total_object_size(uint64_t oid, char *wd, uint32_t epoch,
> +				 void *total)
>  {
>  	uint64_t *t = total;
>  	struct stat s;
> @@ -198,7 +199,8 @@ static int get_total_object_size(uint64_t oid, char *wd, void *total)
>  
>  /* If cleanup is true, temporary objects will be removed */
>  static int for_each_object_in_path(char *path,
> -				   int (*func)(uint64_t, char *, void *),
> +				   int (*func)(uint64_t, char *, uint32_t,
> +					       void *),
>  				   bool cleanup, void *arg)
>  {
>  	DIR *dir;
> @@ -214,6 +216,8 @@ static int for_each_object_in_path(char *path,
>  	}
>  
>  	while ((d = readdir(dir))) {
> +		uint32_t epoch = 0;
> +
>  		if (!strncmp(d->d_name, ".", 1))
>  			continue;
>  
> @@ -233,7 +237,10 @@ static int for_each_object_in_path(char *path,
>  			continue;
>  		}
>  
> -		ret = func(oid, path, arg);
> +		if (strlen(d->d_name) > 17 && d->d_name[16] == '.')
> +			epoch = strtoul(d->d_name + 17, NULL, 10);
> +
> +		ret = func(oid, path, epoch, arg);
>  		if (ret != SD_RES_SUCCESS)
>  			break;
>  	}
> @@ -366,7 +373,8 @@ static char *md_get_object_path_nolock(uint64_t oid)
>  	return md_disks[vd->idx].path;
>  }
>  
> -int for_each_object_in_wd(int (*func)(uint64_t oid, char *path, void *arg),
> +int for_each_object_in_wd(int (*func)(uint64_t oid, char *path, uint32_t epoch,
> +				      void *arg),
>  			  bool cleanup, void *arg)
>  {
>  	int i, ret = SD_RES_SUCCESS;
> @@ -382,7 +390,8 @@ int for_each_object_in_wd(int (*func)(uint64_t oid, char *path, void *arg),
>  	return ret;
>  }
>  
> -int for_each_object_in_stale(int (*func)(uint64_t oid, char *path, void *arg),
> +int for_each_object_in_stale(int (*func)(uint64_t oid, char *path,
> +					 uint32_t epoch, void *arg),
>  			     void *arg)
>  {
>  	int i, ret = SD_RES_SUCCESS;
> diff --git a/sheep/plain_store.c b/sheep/plain_store.c
> index 086e18e..c372238 100644
> --- a/sheep/plain_store.c
> +++ b/sheep/plain_store.c
> @@ -209,7 +209,8 @@ out:
>  	return SD_RES_SUCCESS;
>  }
>  
> -static int init_objlist_and_vdi_bitmap(uint64_t oid, char *wd, void *arg)
> +static int init_objlist_and_vdi_bitmap(uint64_t oid, char *wd, uint32_t epoch,
> +				       void *arg)
>  {
>  	int ret;
>  	objlist_cache_insert(oid);
> @@ -413,7 +414,8 @@ out:
>  	return ret;
>  }
>  
> -static int move_object_to_stale_dir(uint64_t oid, char *wd, void *arg)
> +static int move_object_to_stale_dir(uint64_t oid, char *wd, uint32_t epoch,
> +				    void *arg)
>  {
>  	char path[PATH_MAX], stale_path[PATH_MAX];
>  	uint32_t tgt_epoch = *(int *)arg;
> @@ -432,10 +434,11 @@ static int move_object_to_stale_dir(uint64_t oid, char *wd, void *arg)
>  	return SD_RES_SUCCESS;
>  }
>  
> -static int check_stale_objects(uint64_t oid, char *wd, void *arg)
> +static int check_stale_objects(uint64_t oid, char *wd, uint32_t epoch,
> +			       void *arg)
>  {
>  	if (oid_stale(oid))
> -		return move_object_to_stale_dir(oid, wd, arg);
> +		return move_object_to_stale_dir(oid, wd, 0, arg);
>  
>  	return SD_RES_SUCCESS;
>  }
> @@ -581,7 +584,8 @@ int default_purge_obj(void)
>  {
>  	uint32_t tgt_epoch = get_latest_epoch();
>  
> -	return for_each_object_in_wd(move_object_to_stale_dir, true, &tgt_epoch);
> +	return for_each_object_in_wd(move_object_to_stale_dir, true,
> +				     &tgt_epoch);
>  }
>  
>  static struct store_driver plain_store = {
> diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
> index 00459db..dddec70 100644
> --- a/sheep/sheep_priv.h
> +++ b/sheep/sheep_priv.h
> @@ -175,8 +175,10 @@ int default_format(void);
>  int default_remove_object(uint64_t oid);
>  int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1);
>  int default_purge_obj(void);
> -int for_each_object_in_wd(int (*func)(uint64_t, char *, void *), bool, void *);
> -int for_each_object_in_stale(int (*func)(uint64_t oid, char *path, void *arg),
> +int for_each_object_in_wd(int (*func)(uint64_t, char *, uint32_t, void *), bool,
> +			  void *);
> +int for_each_object_in_stale(int (*func)(uint64_t oid, char *path,
> +					 uint32_t epoch, void *arg),
>  			     void *arg);
>  int for_each_obj_path(int (*func)(char *path));
>  
> 

Applied these two patches, thanks.

Yuan



More information about the sheepdog mailing list