[sheepdog] [PATCH] sheep/http: merge the calls of sd_inode_write_vid() in oalloc
Robin Dong
robin.k.dong at gmail.com
Mon Dec 16 09:18:59 CET 2013
From: Robin Dong <sanbai at taobao.com>
Function sd_inode_write_vid() will write all meta-data of sd_inode to disk even
its name is 'write_vid', to fix this confusion, we add a new function
sd_inode_write() to do this job and just let sd_inode_write_vid() call it if the
type of sd_inode is B-tree.
Then, we don't need to call sd_inode_write_vid() many time when alloc blocks
in oalloc_new_finish() but just call sd_inode_write() one time after set all
vids.
Signed-off-by: Robin Dong <sanbai at taobao.com>
---
include/sheepdog_proto.h | 2 ++
lib/sd_inode.c | 46 ++++++++++++++++++++++++++++++++++------------
sheep/http/oalloc.c | 15 ++++++---------
3 files changed, 42 insertions(+), 21 deletions(-)
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 366499e..6a7ada7 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -280,6 +280,8 @@ extern uint32_t sd_inode_get_vid(read_node_fn reader,
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);
+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,
uint32_t idx, uint32_t vid, uint32_t value,
int flags, bool create, bool direct);
diff --git a/lib/sd_inode.c b/lib/sd_inode.c
index 6d9be89..0043981 100644
--- a/lib/sd_inode.c
+++ b/lib/sd_inode.c
@@ -632,35 +632,57 @@ uint32_t sd_inode_get_meta_size(struct sd_inode *inode, size_t size)
return len;
}
-/* Write the meta-data of inode out */
-int sd_inode_write_vid(write_node_fn writer, struct sd_inode *inode,
- uint32_t idx, uint32_t vid, uint32_t value,
- int flags, bool create, bool direct)
+/* Write the whole meta-data of inode out */
+int sd_inode_write(write_node_fn writer, struct sd_inode *inode, int flags,
+ bool create, bool direct)
{
uint32_t len;
- int ret = SD_RES_SUCCESS;
+ int ret;
if (inode->store_policy == 0)
- ret = writer(vid_to_vdi_oid(vid), &value, sizeof(value),
- SD_INODE_HEADER_SIZE + sizeof(value) * idx,
+ ret = writer(vid_to_vdi_oid(inode->vdi_id), inode,
+ SD_INODE_HEADER_SIZE, 0,
flags, inode->nr_copies, inode->copy_policy,
create, direct);
else {
len = SD_INODE_HEADER_SIZE + sd_inode_get_meta_size(inode, 0);
- ret = writer(vid_to_vdi_oid(vid), inode, len, 0, flags,
- inode->nr_copies, inode->copy_policy,
+ ret = writer(vid_to_vdi_oid(inode->vdi_id), inode, len, 0,
+ flags, inode->nr_copies, inode->copy_policy,
create, false);
if (ret != SD_RES_SUCCESS)
goto out;
- ret = writer(vid_to_vdi_oid(vid), inode, sizeof(uint32_t),
- offsetof(struct sd_inode, btree_counter),
- flags, inode->nr_copies, inode->copy_policy,
+ ret = writer(vid_to_vdi_oid(inode->vdi_id), inode,
+ sizeof(uint32_t),
+ offsetof(struct sd_inode, btree_counter), flags,
+ inode->nr_copies, inode->copy_policy,
create, false);
}
out:
return ret;
}
+/* Write the meta-data of inode out */
+int sd_inode_write_vid(write_node_fn writer, struct sd_inode *inode,
+ uint32_t idx, uint32_t vid, uint32_t value,
+ int flags, bool create, bool direct)
+{
+ int ret = SD_RES_SUCCESS;
+
+ if (inode->store_policy == 0)
+ ret = writer(vid_to_vdi_oid(vid), &value, sizeof(value),
+ SD_INODE_HEADER_SIZE + sizeof(value) * idx,
+ flags, inode->nr_copies, inode->copy_policy,
+ create, direct);
+ else {
+ /*
+ * For btree type sd_inode, we only have to write all
+ * meta-data of sd_inode out.
+ */
+ ret = sd_inode_write(writer, inode, flags, create, direct);
+ }
+ return ret;
+}
+
void sd_inode_copy_vdis(write_node_fn writer, read_node_fn reader,
uint32_t *data_vdi_id, uint8_t store_policy,
uint8_t nr_copies, uint8_t copy_policy,
diff --git a/sheep/http/oalloc.c b/sheep/http/oalloc.c
index 56362fa..b3d9583 100644
--- a/sheep/http/oalloc.c
+++ b/sheep/http/oalloc.c
@@ -178,17 +178,14 @@ int oalloc_new_finish(uint32_t vid, uint64_t start, uint64_t count)
goto out;
}
- /* TODO: add range support for inode update */
- for (uint64_t i = 0; i < count; i++) {
+ for (uint64_t i = 0; i < count; i++)
INODE_SET_VID(inode, start + i, vid);
- ret = sd_inode_write_vid(sheep_bnode_writer, inode, start + i,
- vid, vid, 0, false, false);
- if (ret != SD_RES_SUCCESS) {
- sd_err("failed to update inode, %" PRIx64", %s",
- vid_to_vdi_oid(vid), sd_strerror(ret));
- goto out;
- }
+ ret = sd_inode_write(sheep_bnode_writer, inode, 0, false, false);
+ if (ret != SD_RES_SUCCESS) {
+ sd_err("failed to update inode, %" PRIx64", %s",
+ vid_to_vdi_oid(vid), sd_strerror(ret));
+ goto out;
}
out:
free(inode);
--
1.7.12.4
More information about the sheepdog
mailing list