[sheepdog] [PATCH 2/2] sheep: handle broken epoch file at get_latest_epoch

Hitoshi Mitake mitake.hitoshi at gmail.com
Thu Apr 4 09:19:22 CEST 2013


At Wed,  3 Apr 2013 15:06:17 +0800,
Liu Yuan wrote:
> 
> From: Liu Yuan <tailai.ly at taobao.com>
> 
> Without journaling enabled, we might have empty epoch file or
> partial write file.
> 
> Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
> ---
>  sheep/store.c |   23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/sheep/store.c b/sheep/store.c
> index f112751..8c63f5e 100644
> --- a/sheep/store.c
> +++ b/sheep/store.c
> @@ -136,6 +136,27 @@ int epoch_log_read_with_timestamp(uint32_t epoch, struct sd_node *nodes,
>  	return do_epoch_log_read(epoch, nodes, len, timestamp);
>  }
>  
> +static bool check_epoch(uint32_t epoch)
> +{
> +	char path[PATH_MAX];
> +	struct stat st;
> +
> +	snprintf(path, PATH_MAX, "%s/%08"PRIu32, epoch_path, epoch);
> +
> +	if (stat(path, &st) < 0)
> +		goto err;
> +
> +	/* Both empty file and ill-sized case are handled */
> +	if (st.st_size - sizeof(time_t) % sizeof(struct sd_node))
> +		goto err;

The condition should be:
    (st.st_size - sizeof(time_t)) % sizeof(struct sd_node)
for the priority of operators of C.

Thanks,
Hitoshi



More information about the sheepdog mailing list