[sheepdog] [PATCH 2/4] dog: size_to_str -> strnumber

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Mon Aug 26 06:52:54 CEST 2013


At Sun, 25 Aug 2013 20:27:28 +0800,
Liu Yuan wrote:
> 
> And make strnumber() take only one parameter instead of lengthy 3.
> 
> Signed-off-by: Liu Yuan <namei.unix at gmail.com>
> ---
>  dog/common.c |   43 +++++++++++++++++++++++++------------------
>  dog/dog.h    |    3 ++-
>  dog/node.c   |   36 +++++++++++++-----------------------
>  dog/vdi.c    |   40 ++++++++++++++++------------------------
>  4 files changed, 56 insertions(+), 66 deletions(-)
> 
> diff --git a/dog/common.c b/dog/common.c
> index b185d4e..062eedd 100644
> --- a/dog/common.c
> +++ b/dog/common.c
> @@ -13,15 +13,25 @@
>  #include "sha1.h"
>  #include "sockfd_cache.h"
>  
> -char *size_to_str(uint64_t _size, char *str, int str_size)
> +char *strnumber(uint64_t size)
> +{
> +	return strnumber_raw(size, raw_output);
> +}
> +
> +char *strnumber_raw(uint64_t _size, bool raw)
>  {
>  	const char *units[] = {"MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
> +	static struct size_str {
> +		char str[UINT64_DECIMAL_SIZE];
> +	} s[1024]; /* Is this big enough ? */

How about adding __thread to make this function thread-safe?  Though
no one calls this function from the worker thread now, we may do it in
future.

Thanks,

Kazutaka



More information about the sheepdog mailing list