Skip to content

Commit

Permalink
sheep: make oid_to_vid support any kind of objects
Browse files Browse the repository at this point in the history
get_obj_copy_number() doesn't take into account vmstate objects.  This
fixes the problem by changing oid_to_vid() so that it supports any
kind of objects.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
  • Loading branch information
kazum authored and liuy committed May 2, 2013
1 parent 310983e commit 4ca2127
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
8 changes: 2 additions & 6 deletions include/sheepdog_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
*/

#define VDI_SPACE_SHIFT 32
#define SD_VDI_MASK 0x00FFFFFF00000000
#define VDI_BIT (UINT64_C(1) << 63)
#define VMSTATE_BIT (UINT64_C(1) << 62)
#define VDI_ATTR_BIT (UINT64_C(1) << 61)
Expand Down Expand Up @@ -292,19 +293,14 @@ static inline uint64_t vid_to_data_oid(uint32_t vid, uint32_t idx)

static inline uint32_t oid_to_vid(uint64_t oid)
{
return (~VDI_BIT & oid) >> VDI_SPACE_SHIFT;
return (oid & SD_VDI_MASK) >> VDI_SPACE_SHIFT;
}

static inline uint64_t vid_to_attr_oid(uint32_t vid, uint32_t attrid)
{
return ((uint64_t)vid << VDI_SPACE_SHIFT) | VDI_ATTR_BIT | attrid;
}

static inline uint32_t attr_oid_to_vid(uint64_t oid)
{
return (~VDI_ATTR_BIT & oid) >> VDI_SPACE_SHIFT;
}

static inline bool vdi_is_snapshot(const struct sd_inode *inode)
{
return !!inode->snap_ctime;
Expand Down
8 changes: 1 addition & 7 deletions sheep/vdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@ int get_vdi_copy_number(uint32_t vid)

int get_obj_copy_number(uint64_t oid, int nr_zones)
{
uint32_t vid;
if (is_vdi_attr_obj(oid))
vid = attr_oid_to_vid(oid);
else
vid = oid_to_vid(oid);

return min(get_vdi_copy_number(vid), nr_zones);
return min(get_vdi_copy_number(oid_to_vid(oid)), nr_zones);
}

int get_req_copy_number(struct request *req)
Expand Down

0 comments on commit 4ca2127

Please sign in to comment.