[sheepdog] [PATCH v6 5/9] upgrade 'idx' in object_cache from 32bit to 64bit

Liu Yuan namei.unix at gmail.com
Mon Nov 11 08:42:28 CET 2013


On Mon, Nov 11, 2013 at 02:55:31PM +0800, Robin Dong wrote:
> Change 'idx' in object cache from uint32_t to uint64_t for working correctly
> on hyper volume.
> 
> Signed-off-by: Robin Dong <sanbai at taobao.com>
> ---
>  include/sheepdog_proto.h |    2 +-
>  sheep/object_cache.c     |   97 +++++++++++++++++++++++----------------------
>  2 files changed, 51 insertions(+), 48 deletions(-)
> 
> diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
> index 5b2bfa8..72a1e3a 100644
> --- a/include/sheepdog_proto.h
> +++ b/include/sheepdog_proto.h
> @@ -419,7 +419,7 @@ static inline uint64_t vid_to_vdi_oid(uint32_t vid)
>  	return VDI_BIT | ((uint64_t)vid << VDI_SPACE_SHIFT);
>  }
>  
> -static inline uint64_t vid_to_data_oid(uint32_t vid, uint32_t idx)
> +static inline uint64_t vid_to_data_oid(uint32_t vid, uint64_t idx)
>  {
>  	return ((uint64_t)vid << VDI_SPACE_SHIFT) | idx;
>  }
> diff --git a/sheep/object_cache.c b/sheep/object_cache.c
> index e1968fc..ae4a103 100644
> --- a/sheep/object_cache.c
> +++ b/sheep/object_cache.c
> @@ -16,15 +16,16 @@
>  /*
>   * Object Cache ID
>   *
> - *  0 - 19 (20 bits): data object space
> - *  20 - 27 (8 bits): object flag space
> - *  28 - 31 (4 bits): object type indentifier space
> + *  0 - 31 (32 bits): data object space
> + *  32 - 51 (20 bits): reserved
> + *  52 - 59 (8 bits): object flag space
> + *  60 - 63 (4 bits): object type indentifier space
>   */
> -#define CACHE_VDI_SHIFT       31 /* if the entry is identified as VDI object */
> -#define CACHE_CREATE_SHIFT    27 /* If the entry should be created at backend */
> +#define CACHE_VDI_SHIFT       63 /* if the entry is identified as VDI object */
> +#define CACHE_CREATE_SHIFT    59 /* If the entry should be created at backend */
>  
> -#define CACHE_VDI_BIT         (UINT32_C(1) << CACHE_VDI_SHIFT)
> -#define CACHE_CREATE_BIT      (UINT32_C(1) << CACHE_CREATE_SHIFT)
> +#define CACHE_VDI_BIT         (UINT64_C(1) << CACHE_VDI_SHIFT)
> +#define CACHE_CREATE_BIT      (UINT64_C(1) << CACHE_CREATE_SHIFT)
>  
>  #define CACHE_INDEX_MASK      (CACHE_CREATE_BIT)
>  
> @@ -39,7 +40,7 @@ struct global_cache {
>  };
>  
>  struct object_cache_entry {
> -	uint32_t idx; /* Index of this entry */
> +	uint64_t idx; /* Index of this entry */
>  	refcnt_t refcnt; /* Reference count of this entry */
>  	uint64_t bmap; /* Each bit represents one dirty block in object */
>  	struct object_cache *oc; /* Object cache this entry belongs to */
> @@ -97,7 +98,7 @@ static inline int hash(uint64_t vid)
>  }
>  
>  /* We should always use this helper to get entry idx */
> -static inline uint32_t entry_idx(const struct object_cache_entry *entry)
> +static inline uint64_t entry_idx(const struct object_cache_entry *entry)
>  {
>  	return entry->idx & ~CACHE_INDEX_MASK;
>  }
> @@ -108,15 +109,15 @@ static int object_cache_cmp(const struct object_cache_entry *a,
>  	return intcmp(entry_idx(a), entry_idx(b));
>  }
>  
> -static inline uint32_t object_cache_oid_to_idx(uint64_t oid)
> +static inline uint64_t object_cache_oid_to_idx(uint64_t oid)
>  {
> -	uint32_t idx = data_oid_to_idx(oid);
> +	uint64_t idx = data_oid_to_idx(oid);
>  	if (is_vdi_obj(oid))
> -		idx |= 1 << CACHE_VDI_SHIFT;
> +		idx |= 1ULL << CACHE_VDI_SHIFT;
>  	return idx;
>  }
>  
> -static inline bool idx_has_vdi_bit(uint32_t idx)
> +static inline bool idx_has_vdi_bit(uint64_t idx)
>  {
>  	return !!(idx & CACHE_VDI_BIT);
>  }
> @@ -209,7 +210,7 @@ lru_tree_insert(struct rb_root *root, struct object_cache_entry *new)
>  }
>  
>  static struct object_cache_entry *lru_tree_search(struct rb_root *root,
> -						  uint32_t idx)
> +						  uint64_t idx)
>  {
>  	struct object_cache_entry key = { .idx = idx };
>  
> @@ -279,7 +280,7 @@ free_cache_entry(struct object_cache_entry *entry)
>  	free(entry);
>  }
>  
> -static uint64_t idx_to_oid(uint32_t vid, uint32_t idx)
> +static uint64_t idx_to_oid(uint32_t vid, uint64_t idx)

I am not sure if we should deal with bnode object in idx_to_oid(). Your code
treat bnode object the same as data object but I am not sure if the conversion
from idx to oid for bnode is correct or not since we only call vid_to_data_oid()
for bnode too. Please double check it.

Thanks
Yuan



More information about the sheepdog mailing list