[sheepdog] [PATCH RFC 2/4] sheep: make oid_to_vid support any kind of objects

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Apr 25 12:23:25 CEST 2013


Currently, get_obj_copy_number() doesn't take vmstate objects into
account.  To fix it, this patch removes attr_oid_to_vid() and makes
oid_to_vid support any kind of objects.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/sheepdog_proto.h |    8 ++------
 sheep/vdi.c              |    8 +-------
 2 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 028b1be..d015281 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -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)
@@ -269,7 +270,7 @@ 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)
@@ -277,11 +278,6 @@ 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 sd_is_snapshot(const struct sheepdog_inode *inode)
 {
 	return inode->snap_ctime != 0;
diff --git a/sheep/vdi.c b/sheep/vdi.c
index e3c6c80..18dfef4 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -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)
-- 
1.7.2.5




More information about the sheepdog mailing list