[sheepdog] [PATCH v3 2/3] lib: change interface sd_inode_set_vid()

Robin Dong robin.k.dong at gmail.com
Tue Feb 18 03:11:40 CET 2014


From: Robin Dong <sanbai at taobao.com>

sd_inode_set_vid() only set one 'vid' at before, we change it
to support 'set range of vids'.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 dog/dog.h                |  7 ++++++-
 include/sheepdog_proto.h |  4 ++--
 lib/sd_inode.c           | 27 ++++++++++++++++-----------
 sheep/sheep_priv.h       |  7 ++++++-
 sheepfs/volume.c         |  6 +++++-
 5 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/dog/dog.h b/dog/dog.h
index 76d5b49..cfc4bec 100644
--- a/dog/dog.h
+++ b/dog/dog.h
@@ -102,7 +102,12 @@ int dog_bnode_reader(uint64_t oid, void **mem, unsigned int len,
 #define INODE_GET_VID(inode, idx) (sd_inode_get_vid(dog_bnode_reader, \
 							inode, idx))
 #define INODE_SET_VID(inode, idx, vdi_id) (sd_inode_set_vid(dog_bnode_writer, \
-					dog_bnode_reader, inode, idx, vdi_id))
+					   dog_bnode_reader, inode, idx, idx, \
+					   vdi_id))
+#define INODE_SET_VID_RANGE(inode, idx_start, idx_end, vdi_id) \
+				(sd_inode_set_vid(dog_bnode_writer, \
+				dog_bnode_reader, inode, idx_start, \
+				idx_end, vdi_id))
 
 extern struct command vdi_command;
 extern struct command node_command;
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 95ee4f2..d553da9 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -275,8 +275,8 @@ extern void sd_inode_init(void *data, int depth);
 extern uint32_t sd_inode_get_vid(read_node_fn reader,
 				 const struct sd_inode *inode, uint32_t idx);
 extern void sd_inode_set_vid(write_node_fn writer, read_node_fn reader,
-			     struct sd_inode *inode, uint32_t idx,
-			     uint32_t vdi_id);
+			     struct sd_inode *inode, uint32_t idx_start,
+			     uint32_t idx_end, uint32_t vdi_id);
 extern int sd_inode_write(write_node_fn writer, struct sd_inode *inode,
 			  int flags, bool create, bool direct);
 extern int sd_inode_write_vid(write_node_fn writer, struct sd_inode *inode,
diff --git a/lib/sd_inode.c b/lib/sd_inode.c
index 4d95b7a..53035b0 100644
--- a/lib/sd_inode.c
+++ b/lib/sd_inode.c
@@ -620,19 +620,24 @@ out:
 }
 
 void sd_inode_set_vid(write_node_fn writer, read_node_fn reader,
-		      struct sd_inode *inode, uint32_t idx, uint32_t vdi_id)
+		      struct sd_inode *inode, uint32_t idx_start,
+		      uint32_t idx_end, uint32_t vdi_id)
 {
 	struct sd_extent_header *header;
-
-	if (inode->store_policy == 0)
-		inode->data_vdi_id[idx] = vdi_id;
-	else {
-		if (inode->data_vdi_id[0] == 0)
-			sd_inode_init(inode->data_vdi_id, 1);
-		header = EXT_HEADER(inode->data_vdi_id);
-		if (header->magic != INODE_BTREE_MAGIC)
-			panic("%s() B-tree in inode is corrupt!", __func__);
-		set_vid_for_btree(writer, reader, inode, idx, vdi_id);
+	int idx;
+
+	for (idx = idx_start; idx <= idx_end; idx++) {
+		if (inode->store_policy == 0)
+			inode->data_vdi_id[idx] = vdi_id;
+		else {
+			if (inode->data_vdi_id[0] == 0)
+				sd_inode_init(inode->data_vdi_id, 1);
+			header = EXT_HEADER(inode->data_vdi_id);
+			if (header->magic != INODE_BTREE_MAGIC)
+				panic("%s() B-tree in inode is corrupt!",
+				      __func__);
+			set_vid_for_btree(writer, reader, inode, idx, vdi_id);
+		}
 	}
 	if (inode->store_policy != 0)
 		dump_btree(reader, inode);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index eab784b..108318e 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -401,7 +401,12 @@ int sheep_bnode_reader(uint64_t oid, void **mem, unsigned int len,
 #define INODE_GET_VID(inode, idx) (sd_inode_get_vid(sheep_bnode_reader, \
 					inode, idx))
 #define INODE_SET_VID(inode, idx, vdi_id) (sd_inode_set_vid(sheep_bnode_writer,\
-					sheep_bnode_reader, inode, idx, vdi_id))
+					   sheep_bnode_reader, inode, idx, idx,\
+					   vdi_id))
+#define INODE_SET_VID_RANGE(inode, idx_start, idx_end, vdi_id) \
+				(sd_inode_set_vid(sheep_bnode_writer,\
+				sheep_bnode_reader, inode, idx_start, \
+				idx_end, vdi_id))
 
 /* Operations */
 
diff --git a/sheepfs/volume.c b/sheepfs/volume.c
index f862c4a..26decf8 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -76,7 +76,11 @@ static int sheepfs_bnode_reader(uint64_t oid, void **mem, unsigned int len,
 #define INODE_SET_VID(inode, idx, vdi_id) (sd_inode_set_vid( \
 					sheepfs_bnode_writer, \
 					sheepfs_bnode_reader, \
-					inode, idx, vdi_id))
+					inode, idx, idx, vdi_id))
+#define INODE_SET_VID_RANGE(inode, idx_start, idx_end, vdi_id) \
+				(sd_inode_set_vid(sheepfs_bnode_writer, \
+				sheepfs_bnode_reader, inode, idx_start, \
+				idx_end, vdi_id))
 
 static inline bool is_data_obj_writeable(const struct sd_inode *inode,
 					 uint32_t idx)
-- 
1.7.12.4




More information about the sheepdog mailing list