<div dir="ltr"><span class="" style="border-collapse:separate;color:rgb(0,0,0);font-family:Times;font-size:13px;white-space:pre-wrap;border-spacing:0px">Reviewed-by: Robin Dong <<a href="mailto:sanbai@taobao.com">sanbai@taobao.com</a>></span><br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/11/29 Liu Yuan <span dir="ltr"><<a href="mailto:namei.unix@gmail.com" target="_blank">namei.unix@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- add prefix for sheep helpers<br>
- rename sd_{read, write}_object as dog_xxx in dog<br>
<br>
Signed-off-by: Liu Yuan <<a href="mailto:namei.unix@gmail.com">namei.unix@gmail.com</a>><br>
---<br>
dog/common.c | 21 ++++----<br>
dog/dog.h | 10 ++--<br>
dog/farm/farm.c | 4 +-<br>
dog/vdi.c | 66 ++++++++++++-----------<br>
sheep/http/kv.c | 42 ++++++++-------<br>
sheep/ops.c | 8 +--<br>
sheep/sheep_priv.h | 10 ++--<br>
sheep/store.c | 10 ++--<br>
sheep/vdi.c | 116 +++++++++++++++++++++--------------------<br>
tests/unit/sheep/mock_store.c | 6 +--<br>
10 files changed, 151 insertions(+), 142 deletions(-)<br>
<br>
diff --git a/dog/common.c b/dog/common.c<br>
index 59d38dc..546690a 100644<br>
--- a/dog/common.c<br>
+++ b/dog/common.c<br>
@@ -55,8 +55,8 @@ char *strnumber(uint64_t size)<br>
return strnumber_raw(size, raw_output);<br>
}<br>
<br>
-int sd_read_object(uint64_t oid, void *data, unsigned int datalen,<br>
- uint64_t offset, bool direct)<br>
+int dog_read_object(uint64_t oid, void *data, unsigned int datalen,<br>
+ uint64_t offset, bool direct)<br>
{<br>
struct sd_req hdr;<br>
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;<br>
@@ -85,10 +85,10 @@ int sd_read_object(uint64_t oid, void *data, unsigned int datalen,<br>
return SD_RES_SUCCESS;<br>
}<br>
<br>
-int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,<br>
- unsigned int datalen, uint64_t offset, uint32_t flags,<br>
- uint8_t copies, uint8_t copy_policy, bool create,<br>
- bool direct)<br>
+int dog_write_object(uint64_t oid, uint64_t cow_oid, void *data,<br>
+ unsigned int datalen, uint64_t offset, uint32_t flags,<br>
+ uint8_t copies, uint8_t copy_policy, bool create,<br>
+ bool direct)<br>
{<br>
struct sd_req hdr;<br>
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;<br>
@@ -156,8 +156,8 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)<br>
oid = vid_to_vdi_oid(nr);<br>
<br>
/* for B-tree inode, we also need sd_extent_header */<br>
- ret = sd_read_object(oid, &i, SD_INODE_HEADER_SIZE +<br>
- sizeof(struct sd_extent_header), 0, true);<br>
+ ret = dog_read_object(oid, &i, SD_INODE_HEADER_SIZE +<br>
+ sizeof(struct sd_extent_header), 0, true);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("Failed to read inode header");<br>
continue;<br>
@@ -168,8 +168,9 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)<br>
<br>
if (size > SD_INODE_HEADER_SIZE) {<br>
rlen = sd_inode_get_meta_size(&i, size);<br>
- ret = sd_read_object(oid, ((char *)&i) + SD_INODE_HEADER_SIZE,<br>
- rlen, SD_INODE_HEADER_SIZE, true);<br>
+ ret = dog_read_object(oid,<br>
+ ((char *)&i) + SD_INODE_HEADER_SIZE,<br>
+ rlen, SD_INODE_HEADER_SIZE, true);<br>
<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("Failed to read inode");<br>
diff --git a/dog/dog.h b/dog/dog.h<br>
index af3cefa..73518d4 100644<br>
--- a/dog/dog.h<br>
+++ b/dog/dog.h<br>
@@ -71,11 +71,11 @@ typedef void (*vdi_parser_func_t)(uint32_t vid, const char *name,<br>
uint32_t flags,<br>
const struct sd_inode *i, void *data);<br>
int parse_vdi(vdi_parser_func_t func, size_t size, void *data);<br>
-int sd_read_object(uint64_t oid, void *data, unsigned int datalen,<br>
- uint64_t offset, bool direct);<br>
-int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,<br>
- unsigned int datalen, uint64_t offset, uint32_t flags,<br>
- uint8_t copies, uint8_t, bool create, bool direct);<br>
+int dog_read_object(uint64_t oid, void *data, unsigned int datalen,<br>
+ uint64_t offset, bool direct);<br>
+int dog_write_object(uint64_t oid, uint64_t cow_oid, void *data,<br>
+ unsigned int datalen, uint64_t offset, uint32_t flags,<br>
+ uint8_t copies, uint8_t, bool create, bool direct);<br>
int dog_exec_req(const struct node_id *, struct sd_req *hdr, void *data);<br>
int send_light_req(const struct node_id *, struct sd_req *hdr);<br>
int do_generic_subcommand(struct subcommand *sub, int argc, char **argv);<br>
diff --git a/dog/farm/farm.c b/dog/farm/farm.c<br>
index 3886445..07dcbd4 100644<br>
--- a/dog/farm/farm.c<br>
+++ b/dog/farm/farm.c<br>
@@ -253,7 +253,7 @@ static void do_save_object(struct work *work)<br>
size = get_objsize(sw->entry.oid);<br>
buf = xmalloc(size);<br>
<br>
- if (sd_read_object(sw->entry.oid, buf, size, 0, true) < 0)<br>
+ if (dog_read_object(sw->entry.oid, buf, size, 0, true) < 0)<br>
goto error;<br>
<br>
if (slice_write(buf, size, sw->entry.sha1) < 0)<br>
@@ -364,7 +364,7 @@ static void do_load_object(struct work *work)<br>
if (!buffer)<br>
goto error;<br>
<br>
- if (sd_write_object(sw->entry.oid, 0, buffer, size, 0, 0,<br>
+ if (dog_write_object(sw->entry.oid, 0, buffer, size, 0, 0,<br>
sw->entry.nr_copies, sw->entry.copy_policy,<br>
true, true) != 0)<br>
goto error;<br>
diff --git a/dog/vdi.c b/dog/vdi.c<br>
index bfee11f..399b17c 100644<br>
--- a/dog/vdi.c<br>
+++ b/dog/vdi.c<br>
@@ -64,14 +64,14 @@ int dog_bnode_writer(uint64_t oid, void *mem, unsigned int len, uint64_t offset,<br>
uint32_t flags, int copies, int copy_policy, bool create,<br>
bool direct)<br>
{<br>
- return sd_write_object(oid, 0, mem, len, offset, flags, copies,<br>
+ return dog_write_object(oid, 0, mem, len, offset, flags, copies,<br>
copy_policy, create, direct);<br>
}<br>
<br>
int dog_bnode_reader(uint64_t oid, void **mem, unsigned int len,<br>
uint64_t offset)<br>
{<br>
- return sd_read_object(oid, *mem, len, offset, true);<br>
+ return dog_read_object(oid, *mem, len, offset, true);<br>
}<br>
<br>
static inline bool is_data_obj_writeable(const struct sd_inode *inode,<br>
@@ -513,7 +513,7 @@ static int read_vdi_obj(const char *vdiname, int snapid, const char *tag,<br>
return EXIT_FAILURE;<br>
}<br>
<br>
- ret = sd_read_object(vid_to_vdi_oid(vid), inode, size, 0, true);<br>
+ ret = dog_read_object(vid_to_vdi_oid(vid), inode, size, 0, true);<br>
if (ret != SD_RES_SUCCESS) {<br>
if (snapid) {<br>
sd_err("Failed to read a snapshot %s:%d", vdiname,<br>
@@ -615,7 +615,8 @@ static int vdi_create(int argc, char **argv)<br>
<br>
inode = xmalloc(sizeof(*inode));<br>
<br>
- ret = sd_read_object(vid_to_vdi_oid(vid), inode, sizeof(*inode), 0, true);<br>
+ ret = dog_read_object(vid_to_vdi_oid(vid), inode, sizeof(*inode), 0,<br>
+ true);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("Failed to read a newly created VDI object");<br>
ret = EXIT_FAILURE;<br>
@@ -627,7 +628,7 @@ static int vdi_create(int argc, char **argv)<br>
vdi_show_progress(idx * SD_DATA_OBJ_SIZE, inode->vdi_size);<br>
oid = vid_to_data_oid(vid, idx);<br>
<br>
- ret = sd_write_object(oid, 0, NULL, 0, 0, 0, inode->nr_copies,<br>
+ ret = dog_write_object(oid, 0, NULL, 0, 0, 0, inode->nr_copies,<br>
inode->copy_policy, true, true);<br>
if (ret != SD_RES_SUCCESS) {<br>
ret = EXIT_FAILURE;<br>
@@ -675,11 +676,12 @@ static int vdi_snapshot(int argc, char **argv)<br>
if (ret != EXIT_SUCCESS)<br>
return ret;<br>
<br>
- ret = sd_write_object(vid_to_vdi_oid(vid), 0, vdi_cmd_data.snapshot_tag,<br>
- SD_MAX_VDI_TAG_LEN,<br>
- offsetof(struct sd_inode, tag),<br>
- 0, inode->nr_copies, inode->copy_policy,<br>
- false, false);<br>
+ ret = dog_write_object(vid_to_vdi_oid(vid), 0,<br>
+ vdi_cmd_data.snapshot_tag,<br>
+ SD_MAX_VDI_TAG_LEN,<br>
+ offsetof(struct sd_inode, tag),<br>
+ 0, inode->nr_copies, inode->copy_policy,<br>
+ false, false);<br>
if (ret != SD_RES_SUCCESS)<br>
return EXIT_FAILURE;<br>
<br>
@@ -750,7 +752,8 @@ static int vdi_clone(int argc, char **argv)<br>
vdi_id = INODE_GET_VID(inode, idx);<br>
if (vdi_id) {<br>
oid = vid_to_data_oid(vdi_id, idx);<br>
- ret = sd_read_object(oid, buf, SD_DATA_OBJ_SIZE, 0, true);<br>
+ ret = dog_read_object(oid, buf, SD_DATA_OBJ_SIZE, 0,<br>
+ true);<br>
if (ret) {<br>
ret = EXIT_FAILURE;<br>
goto out;<br>
@@ -760,8 +763,9 @@ static int vdi_clone(int argc, char **argv)<br>
size = 0;<br>
<br>
oid = vid_to_data_oid(new_vid, idx);<br>
- ret = sd_write_object(oid, 0, buf, size, 0, 0, inode->nr_copies,<br>
- inode->copy_policy, true, true);<br>
+ ret = dog_write_object(oid, 0, buf, size, 0, 0,<br>
+ inode->nr_copies,<br>
+ inode->copy_policy, true, true);<br>
if (ret != SD_RES_SUCCESS) {<br>
ret = EXIT_FAILURE;<br>
goto out;<br>
@@ -829,7 +833,7 @@ static int vdi_resize(int argc, char **argv)<br>
}<br>
inode->vdi_size = new_size;<br>
<br>
- ret = sd_write_object(vid_to_vdi_oid(vid), 0,<br>
+ ret = dog_write_object(vid_to_vdi_oid(vid), 0,<br>
inode, SD_INODE_HEADER_SIZE, 0,<br>
0, inode->nr_copies, inode->copy_policy,<br>
false, true);<br>
@@ -1263,7 +1267,7 @@ static int vdi_getattr(int argc, char **argv)<br>
<br>
oid = attr_oid;<br>
<br>
- ret = sd_read_object(oid, &vattr, SD_ATTR_OBJ_SIZE, 0, true);<br>
+ ret = dog_read_object(oid, &vattr, SD_ATTR_OBJ_SIZE, 0, true);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("Failed to read attribute oid: %s", sd_strerror(ret));<br>
return EXIT_SYSFAIL;<br>
@@ -1317,7 +1321,7 @@ static int vdi_read(int argc, char **argv)<br>
vdi_id = INODE_GET_VID(inode, idx);<br>
if (vdi_id) {<br>
oid = vid_to_data_oid(vdi_id, idx);<br>
- ret = sd_read_object(oid, buf, len, offset, false);<br>
+ ret = dog_read_object(oid, buf, len, offset, false);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("Failed to read VDI");<br>
ret = EXIT_FAILURE;<br>
@@ -1414,7 +1418,7 @@ static int vdi_write(int argc, char **argv)<br>
<br>
INODE_SET_VID(inode, idx, inode->vdi_id);<br>
oid = vid_to_data_oid(inode->vdi_id, idx);<br>
- ret = sd_write_object(oid, old_oid, buf, len, offset, flags,<br>
+ ret = dog_write_object(oid, old_oid, buf, len, offset, flags,<br>
inode->nr_copies, inode->copy_policy,<br>
create, false);<br>
if (ret != SD_RES_SUCCESS) {<br>
@@ -1943,8 +1947,8 @@ static int get_obj_backup(uint32_t idx, uint32_t from_vid, uint32_t to_vid,<br>
backup->length = SD_DATA_OBJ_SIZE;<br>
<br>
if (to_vid) {<br>
- ret = sd_read_object(vid_to_data_oid(to_vid, idx), backup->data,<br>
- SD_DATA_OBJ_SIZE, 0, true);<br>
+ ret = dog_read_object(vid_to_data_oid(to_vid, idx),<br>
+ backup->data, SD_DATA_OBJ_SIZE, 0, true);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("Failed to read object %" PRIx32 ", %d", to_vid,<br>
idx);<br>
@@ -1954,8 +1958,8 @@ static int get_obj_backup(uint32_t idx, uint32_t from_vid, uint32_t to_vid,<br>
memset(backup->data, 0, SD_DATA_OBJ_SIZE);<br>
<br>
if (from_vid) {<br>
- ret = sd_read_object(vid_to_data_oid(from_vid, idx), from_data,<br>
- SD_DATA_OBJ_SIZE, 0, true);<br>
+ ret = dog_read_object(vid_to_data_oid(from_vid, idx), from_data,<br>
+ SD_DATA_OBJ_SIZE, 0, true);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("Failed to read object %" PRIx32 ", %d",<br>
from_vid, idx);<br>
@@ -2074,17 +2078,17 @@ static int restore_obj(struct obj_backup *backup, uint32_t vid,<br>
parent_oid = vid_to_data_oid(parent_vid, backup->idx);<br>
<br>
/* send a copy-on-write request */<br>
- ret = sd_write_object(vid_to_data_oid(vid, backup->idx), parent_oid,<br>
- backup->data, backup->length, backup->offset,<br>
- 0, parent_inode->nr_copies,<br>
- parent_inode->copy_policy, true, true);<br>
+ ret = dog_write_object(vid_to_data_oid(vid, backup->idx), parent_oid,<br>
+ backup->data, backup->length, backup->offset,<br>
+ 0, parent_inode->nr_copies,<br>
+ parent_inode->copy_policy, true, true);<br>
if (ret != SD_RES_SUCCESS)<br>
return ret;<br>
<br>
- return sd_write_object(vid_to_vdi_oid(vid), 0, &vid, sizeof(vid),<br>
- SD_INODE_HEADER_SIZE + sizeof(vid) * backup->idx,<br>
- 0, parent_inode->nr_copies,<br>
- parent_inode->copy_policy, false, true);<br>
+ return dog_write_object(vid_to_vdi_oid(vid), 0, &vid, sizeof(vid),<br>
+ SD_INODE_HEADER_SIZE + sizeof(vid) * backup->idx,<br>
+ 0, parent_inode->nr_copies,<br>
+ parent_inode->copy_policy, false, true);<br>
}<br>
<br>
static uint32_t do_restore(const char *vdiname, int snapid, const char *tag)<br>
@@ -2190,7 +2194,7 @@ static int vdi_restore(int argc, char **argv)<br>
if (ret != EXIT_SUCCESS)<br>
goto out;<br>
<br>
- ret = sd_read_object(vid_to_vdi_oid(current_inode->parent_vdi_id),<br>
+ ret = dog_read_object(vid_to_vdi_oid(current_inode->parent_vdi_id),<br>
parent_inode, SD_INODE_HEADER_SIZE, 0, true);<br>
if (ret != SD_RES_SUCCESS) {<br>
printf("error\n");<br>
@@ -2291,7 +2295,7 @@ static int vid_to_name_tag(uint32_t vid, char *name, char *tag)<br>
struct sd_inode inode;<br>
int ret;<br>
<br>
- ret = sd_read_object(vid_to_vdi_oid(vid), &inode, SD_INODE_HEADER_SIZE,<br>
+ ret = dog_read_object(vid_to_vdi_oid(vid), &inode, SD_INODE_HEADER_SIZE,<br>
0, true);<br>
if (ret != SD_RES_SUCCESS)<br>
return ret;<br>
diff --git a/sheep/http/kv.c b/sheep/http/kv.c<br>
index c04e629..8113389 100644<br>
--- a/sheep/http/kv.c<br>
+++ b/sheep/http/kv.c<br>
@@ -147,7 +147,8 @@ int kv_list_buckets(struct http_request *req,<br>
<br>
oid = vid_to_vdi_oid(nr);<br>
<br>
- ret = read_object(oid, (char *)inode, SD_INODE_HEADER_SIZE, 0);<br>
+ ret = sd_read_object(oid, (char *)inode, SD_INODE_HEADER_SIZE,<br>
+ 0);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("Failed to read inode header");<br>
continue;<br>
@@ -212,17 +213,17 @@ static int kv_create_inlined_object(struct sd_inode *inode,<br>
<br>
if (overwrite) {<br>
sd_info("overwrite object %s", onode-><a href="http://hdr.name" target="_blank">hdr.name</a>);<br>
- ret = write_object(oid, (char *)onode,<br>
- sizeof(onode->hdr) + onode->hdr.size,<br>
- 0, false);<br>
+ ret = sd_write_object(oid, (char *)onode,<br>
+ sizeof(onode->hdr) + onode->hdr.size,<br>
+ 0, false);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("failed to write object, %" PRIx64, oid);<br>
goto out;<br>
}<br>
} else {<br>
- ret = write_object(oid, (char *)onode,<br>
- sizeof(onode->hdr) + onode->hdr.size,<br>
- 0, true);<br>
+ ret = sd_write_object(oid, (char *)onode,<br>
+ sizeof(onode->hdr) + onode->hdr.size,<br>
+ 0, true);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("failed to create object, %" PRIx64, oid);<br>
goto out;<br>
@@ -261,8 +262,8 @@ static int do_kv_create_object(struct http_request *req,<br>
uint32_t tmp_vid;<br>
int ret;<br>
<br>
- ret = read_object(vid_to_vdi_oid(vid), (char *)inode,<br>
- sizeof(*inode), 0);<br>
+ ret = sd_read_object(vid_to_vdi_oid(vid), (char *)inode,<br>
+ sizeof(*inode), 0);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("failed to read inode, %" PRIx64,<br>
vid_to_vdi_oid(vid));<br>
@@ -270,7 +271,7 @@ static int do_kv_create_object(struct http_request *req,<br>
}<br>
tmp_vid = INODE_GET_VID(inode, idx);<br>
if (tmp_vid) {<br>
- ret = read_object(oid, (char *)&hdr, sizeof(hdr), 0);<br>
+ ret = sd_read_object(oid, (char *)&hdr, sizeof(hdr), 0);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("failed to read object, %" PRIx64, oid);<br>
goto out;<br>
@@ -356,7 +357,7 @@ static int do_kv_read_object(struct http_request *req, const char *obj_name,<br>
uint64_t oid = vid_to_data_oid(vid, idx);<br>
int ret;<br>
<br>
- ret = read_object(oid, (char *)obj, sizeof(*obj), 0);<br>
+ ret = sd_read_object(oid, (char *)obj, sizeof(*obj), 0);<br>
switch (ret) {<br>
case SD_RES_SUCCESS:<br>
break;<br>
@@ -418,7 +419,7 @@ static int do_kv_update_object(struct http_request *req, const char *obj_name,<br>
uint64_t oid = vid_to_data_oid(vid, idx);<br>
int ret;<br>
<br>
- ret = read_object(oid, (char *)&obj->hdr, sizeof(obj->hdr), 0);<br>
+ ret = sd_read_object(oid, (char *)&obj->hdr, sizeof(obj->hdr), 0);<br>
switch (ret) {<br>
case SD_RES_SUCCESS:<br>
break;<br>
@@ -439,8 +440,9 @@ static int do_kv_update_object(struct http_request *req, const char *obj_name,<br>
obj->hdr.mtime = (uint64_t) tv.tv_sec << 32 | tv.tv_usec * 1000;<br>
obj->hdr.size = size;<br>
<br>
- ret = write_object(oid, (char *)obj,<br>
- sizeof(obj->hdr) + obj->hdr.size, 0, false);<br>
+ ret = sd_write_object(oid, (char *)obj,<br>
+ sizeof(obj->hdr) + obj->hdr.size,<br>
+ 0, false);<br>
if (ret == SD_RES_SUCCESS)<br>
http_response_header(req, ACCEPTED);<br>
else {<br>
@@ -501,7 +503,7 @@ static int do_kv_delete_object(struct http_request *req, const char *obj_name,<br>
char name[SD_MAX_OBJECT_NAME];<br>
int ret;<br>
<br>
- ret = read_object(oid, name, sizeof(name), 0);<br>
+ ret = sd_read_object(oid, name, sizeof(name), 0);<br>
switch (ret) {<br>
case SD_RES_SUCCESS:<br>
break;<br>
@@ -517,7 +519,7 @@ static int do_kv_delete_object(struct http_request *req, const char *obj_name,<br>
<br>
if (strcmp(name, obj_name) == 0) {<br>
memset(name, 0, sizeof(name));<br>
- ret = write_object(oid, name, sizeof(name), 0, false);<br>
+ ret = sd_write_object(oid, name, sizeof(name), 0, false);<br>
if (ret == SD_RES_SUCCESS)<br>
http_response_header(req, NO_CONTENT);<br>
else {<br>
@@ -569,9 +571,9 @@ int kv_list_objects(struct http_request *req, const char *bucket,<br>
return ret;<br>
<br>
inode = xzalloc(sizeof(*inode));<br>
- ret = read_object(vid_to_vdi_oid(vid), (char *)inode->data_vdi_id,<br>
- sizeof(inode->data_vdi_id),<br>
- offsetof(typeof(*inode), data_vdi_id));<br>
+ ret = sd_read_object(vid_to_vdi_oid(vid), (char *)inode->data_vdi_id,<br>
+ sizeof(inode->data_vdi_id),<br>
+ offsetof(typeof(*inode), data_vdi_id));<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("%s: bucket %s", sd_strerror(ret), bucket);<br>
http_response_header(req, INTERNAL_SERVER_ERROR);<br>
@@ -589,7 +591,7 @@ int kv_list_objects(struct http_request *req, const char *bucket,<br>
<br>
oid = vid_to_data_oid(vid, idx);<br>
<br>
- ret = read_object(oid, name, sizeof(name), 0);<br>
+ ret = sd_read_object(oid, name, sizeof(name), 0);<br>
switch (ret) {<br>
case SD_RES_SUCCESS:<br>
if (name[0] != '\0')<br>
diff --git a/sheep/ops.c b/sheep/ops.c<br>
index 43876d4..b626489 100644<br>
--- a/sheep/ops.c<br>
+++ b/sheep/ops.c<br>
@@ -824,8 +824,8 @@ static int local_discard_obj(struct request *req)<br>
struct sd_inode *inode = xmalloc(sizeof(struct sd_inode));<br>
<br>
sd_debug("%"PRIx64, oid);<br>
- ret = read_object(vid_to_vdi_oid(vid), (char *)inode,<br>
- sizeof(struct sd_inode), 0);<br>
+ ret = sd_read_object(vid_to_vdi_oid(vid), (char *)inode,<br>
+ sizeof(struct sd_inode), 0);<br>
if (ret != SD_RES_SUCCESS)<br>
goto out;<br>
<br>
@@ -837,11 +837,11 @@ static int local_discard_obj(struct request *req)<br>
zero, 0, false, false);<br>
if (ret != SD_RES_SUCCESS)<br>
goto out;<br>
- if (remove_object(oid) != SD_RES_SUCCESS)<br>
+ if (sd_remove_object(oid) != SD_RES_SUCCESS)<br>
sd_err("failed to remove %"PRIx64, oid);<br>
}<br>
/*<br>
- * Return success even if remove_object fails because we have updated<br>
+ * Return success even if sd_remove_object fails because we have updated<br>
* inode successfully.<br>
*/<br>
out:<br>
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h<br>
index d333573..685aeb3 100644<br>
--- a/sheep/sheep_priv.h<br>
+++ b/sheep/sheep_priv.h<br>
@@ -361,11 +361,11 @@ void get_recovery_state(struct recovery_state *state);<br>
<br>
int read_backend_object(uint64_t oid, char *data, unsigned int datalen,<br>
uint64_t offset);<br>
-int write_object(uint64_t oid, char *data, unsigned int datalen,<br>
- uint64_t offset, bool create);<br>
-int read_object(uint64_t oid, char *data, unsigned int datalen,<br>
- uint64_t offset);<br>
-int remove_object(uint64_t oid);<br>
+int sd_write_object(uint64_t oid, char *data, unsigned int datalen,<br>
+ uint64_t offset, bool create);<br>
+int sd_read_object(uint64_t oid, char *data, unsigned int datalen,<br>
+ uint64_t offset);<br>
+int sd_remove_object(uint64_t oid);<br>
<br>
int exec_local_req(struct sd_req *rq, void *data);<br>
void local_req_init(void);<br>
diff --git a/sheep/store.c b/sheep/store.c<br>
index b092dea..d67a215 100644<br>
--- a/sheep/store.c<br>
+++ b/sheep/store.c<br>
@@ -346,8 +346,8 @@ int init_global_pathnames(const char *d, char *argp)<br>
}<br>
<br>
/* Write data to both local object cache (if enabled) and backends */<br>
-int write_object(uint64_t oid, char *data, unsigned int datalen,<br>
- uint64_t offset, bool create)<br>
+int sd_write_object(uint64_t oid, char *data, unsigned int datalen,<br>
+ uint64_t offset, bool create)<br>
{<br>
struct sd_req hdr;<br>
int ret;<br>
@@ -406,8 +406,8 @@ int read_backend_object(uint64_t oid, char *data, unsigned int datalen,<br>
* Read data firstly from local object cache(if enabled), if fail,<br>
* try read backends<br>
*/<br>
-int read_object(uint64_t oid, char *data, unsigned int datalen,<br>
- uint64_t offset)<br>
+int sd_read_object(uint64_t oid, char *data, unsigned int datalen,<br>
+ uint64_t offset)<br>
{<br>
int ret;<br>
<br>
@@ -425,7 +425,7 @@ forward_read:<br>
return read_backend_object(oid, data, datalen, offset);<br>
}<br>
<br>
-int remove_object(uint64_t oid)<br>
+int sd_remove_object(uint64_t oid)<br>
{<br>
struct sd_req hdr;<br>
int ret;<br>
diff --git a/sheep/vdi.c b/sheep/vdi.c<br>
index 5b2be97..60bc52d 100644<br>
--- a/sheep/vdi.c<br>
+++ b/sheep/vdi.c<br>
@@ -33,13 +33,13 @@ int sheep_bnode_writer(uint64_t oid, void *mem, unsigned int len,<br>
uint64_t offset, uint32_t flags, int copies,<br>
int copy_policy, bool create, bool direct)<br>
{<br>
- return write_object(oid, mem, len, offset, create);<br>
+ return sd_write_object(oid, mem, len, offset, create);<br>
}<br>
<br>
int sheep_bnode_reader(uint64_t oid, void **mem, unsigned int len,<br>
uint64_t offset)<br>
{<br>
- return read_object(oid, *mem, len, offset);<br>
+ return sd_read_object(oid, *mem, len, offset);<br>
}<br>
<br>
static int vdi_state_cmp(const struct vdi_state_entry *a,<br>
@@ -202,8 +202,8 @@ int vdi_exist(uint32_t vid)<br>
int ret = 1;<br>
<br>
inode = xzalloc(sizeof(*inode));<br>
- ret = read_object(vid_to_vdi_oid(vid), (char *)inode,<br>
- sizeof(*inode), 0);<br>
+ ret = sd_read_object(vid_to_vdi_oid(vid), (char *)inode,<br>
+ sizeof(*inode), 0);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("fail to read vdi inode (%" PRIx32 ")", vid);<br>
ret = 0;<br>
@@ -270,8 +270,8 @@ static int create_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,<br>
iocb->name, iocb->size, new_vid, iocb->nr_copies, new_snapid,<br>
new->copy_policy, new->store_policy);<br>
<br>
- ret = write_object(vid_to_vdi_oid(new_vid), (char *)new, sizeof(*new),<br>
- 0, true);<br>
+ ret = sd_write_object(vid_to_vdi_oid(new_vid), (char *)new,<br>
+ sizeof(*new), 0, true);<br>
if (ret != SD_RES_SUCCESS)<br>
ret = SD_RES_VDI_WRITE;<br>
<br>
@@ -306,8 +306,8 @@ static int clone_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,<br>
"copies %d, snapid %" PRIu32, iocb->name, iocb->size, new_vid,<br>
base_vid, iocb->nr_copies, new_snapid);<br>
<br>
- ret = read_object(vid_to_vdi_oid(base_vid), (char *)base, sizeof(*base),<br>
- 0);<br>
+ ret = sd_read_object(vid_to_vdi_oid(base_vid), (char *)base,<br>
+ sizeof(*base), 0);<br>
if (ret != SD_RES_SUCCESS) {<br>
ret = SD_RES_BASE_VDI_READ;<br>
goto out;<br>
@@ -319,12 +319,13 @@ static int clone_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,<br>
goto out;<br>
}<br>
<br>
- /* TODO: multiple write_object should be performed atomically */<br>
+ /* TODO: multiple sd_write_object should be performed atomically */<br>
<br>
/* update a base vdi */<br>
- ret = write_object(vid_to_vdi_oid(base_vid), (char *)&new_vid,<br>
- sizeof(new_vid),<br>
- offsetof(struct sd_inode, child_vdi_id[idx]), false);<br>
+ ret = sd_write_object(vid_to_vdi_oid(base_vid), (char *)&new_vid,<br>
+ sizeof(new_vid),<br>
+ offsetof(struct sd_inode, child_vdi_id[idx]),<br>
+ false);<br>
if (ret != SD_RES_SUCCESS) {<br>
ret = SD_RES_BASE_VDI_WRITE;<br>
goto out;<br>
@@ -332,8 +333,8 @@ static int clone_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,<br>
<br>
/* create a new vdi */<br>
new = alloc_inode(iocb, new_snapid, new_vid, base->data_vdi_id);<br>
- ret = write_object(vid_to_vdi_oid(new_vid), (char *)new, sizeof(*new),<br>
- 0, true);<br>
+ ret = sd_write_object(vid_to_vdi_oid(new_vid), (char *)new,<br>
+ sizeof(*new), 0, true);<br>
if (ret != SD_RES_SUCCESS)<br>
ret = SD_RES_VDI_WRITE;<br>
<br>
@@ -369,8 +370,8 @@ static int snapshot_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,<br>
"copies %d, snapid %" PRIu32, iocb->name, iocb->size, new_vid,<br>
base_vid, iocb->nr_copies, new_snapid);<br>
<br>
- ret = read_object(vid_to_vdi_oid(base_vid), (char *)base, sizeof(*base),<br>
- 0);<br>
+ ret = sd_read_object(vid_to_vdi_oid(base_vid), (char *)base,<br>
+ sizeof(*base), 0);<br>
if (ret != SD_RES_SUCCESS) {<br>
ret = SD_RES_BASE_VDI_READ;<br>
goto out;<br>
@@ -382,13 +383,13 @@ static int snapshot_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,<br>
goto out;<br>
}<br>
<br>
- /* TODO: multiple write_object should be performed atomically */<br>
+ /* TODO: multiple sd_write_object should be performed atomically */<br>
<br>
/* update a base vdi */<br>
base->snap_ctime = iocb->time;<br>
base->child_vdi_id[idx] = new_vid;<br>
- ret = write_object(vid_to_vdi_oid(base_vid), (char *)base,<br>
- SD_INODE_HEADER_SIZE, 0, false);<br>
+ ret = sd_write_object(vid_to_vdi_oid(base_vid), (char *)base,<br>
+ SD_INODE_HEADER_SIZE, 0, false);<br>
if (ret != SD_RES_SUCCESS) {<br>
ret = SD_RES_BASE_VDI_WRITE;<br>
goto out;<br>
@@ -396,8 +397,8 @@ static int snapshot_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,<br>
<br>
/* create a new vdi */<br>
new = alloc_inode(iocb, new_snapid, new_vid, base->data_vdi_id);<br>
- ret = write_object(vid_to_vdi_oid(new_vid), (char *)new, sizeof(*new),<br>
- 0, true);<br>
+ ret = sd_write_object(vid_to_vdi_oid(new_vid), (char *)new,<br>
+ sizeof(*new), 0, true);<br>
if (ret != SD_RES_SUCCESS)<br>
ret = SD_RES_VDI_WRITE;<br>
<br>
@@ -438,8 +439,8 @@ static int rebase_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,<br>
iocb->size, new_vid, base_vid, cur_vid, iocb->nr_copies,<br>
new_snapid);<br>
<br>
- ret = read_object(vid_to_vdi_oid(base_vid), (char *)base, sizeof(*base),<br>
- 0);<br>
+ ret = sd_read_object(vid_to_vdi_oid(base_vid), (char *)base,<br>
+ sizeof(*base), 0);<br>
if (ret != SD_RES_SUCCESS) {<br>
ret = SD_RES_BASE_VDI_READ;<br>
goto out;<br>
@@ -451,21 +452,22 @@ static int rebase_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,<br>
goto out;<br>
}<br>
<br>
- /* TODO: multiple write_object should be performed atomically */<br>
+ /* TODO: multiple sd_write_object should be performed atomically */<br>
<br>
/* update current working vdi */<br>
- ret = write_object(vid_to_vdi_oid(cur_vid), (char *)&iocb->time,<br>
- sizeof(iocb->time),<br>
- offsetof(struct sd_inode, snap_ctime), false);<br>
+ ret = sd_write_object(vid_to_vdi_oid(cur_vid), (char *)&iocb->time,<br>
+ sizeof(iocb->time),<br>
+ offsetof(struct sd_inode, snap_ctime), false);<br>
if (ret != SD_RES_SUCCESS) {<br>
ret = SD_RES_BASE_VDI_READ;<br>
goto out;<br>
}<br>
<br>
/* update base vdi */<br>
- ret = write_object(vid_to_vdi_oid(base_vid), (char *)&new_vid,<br>
- sizeof(new_vid),<br>
- offsetof(struct sd_inode, child_vdi_id[idx]), false);<br>
+ ret = sd_write_object(vid_to_vdi_oid(base_vid), (char *)&new_vid,<br>
+ sizeof(new_vid),<br>
+ offsetof(struct sd_inode, child_vdi_id[idx]),<br>
+ false);<br>
if (ret != SD_RES_SUCCESS) {<br>
ret = SD_RES_BASE_VDI_WRITE;<br>
goto out;<br>
@@ -473,8 +475,8 @@ static int rebase_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,<br>
<br>
/* create a new vdi */<br>
new = alloc_inode(iocb, new_snapid, new_vid, base->data_vdi_id);<br>
- ret = write_object(vid_to_vdi_oid(new_vid), (char *)new, sizeof(*new),<br>
- 0, true);<br>
+ ret = sd_write_object(vid_to_vdi_oid(new_vid), (char *)new,<br>
+ sizeof(*new), 0, true);<br>
if (ret != SD_RES_SUCCESS)<br>
ret = SD_RES_VDI_WRITE;<br>
<br>
@@ -547,8 +549,8 @@ static int fill_vdi_info_range(uint32_t left, uint32_t right,<br>
goto out;<br>
}<br>
for (i = right - 1; i >= left; i--) {<br>
- ret = read_object(vid_to_vdi_oid(i), (char *)inode,<br>
- SD_INODE_HEADER_SIZE, 0);<br>
+ ret = sd_read_object(vid_to_vdi_oid(i), (char *)inode,<br>
+ SD_INODE_HEADER_SIZE, 0);<br>
if (ret != SD_RES_SUCCESS)<br>
goto out;<br>
<br>
@@ -798,8 +800,8 @@ static int delete_inode(struct deletion_work *dw)<br>
int ret = SD_RES_SUCCESS;<br>
<br>
inode = xzalloc(sizeof(*inode));<br>
- ret = read_object(vid_to_vdi_oid(dw->vid), (char *)inode,<br>
- SD_INODE_HEADER_SIZE, 0);<br>
+ ret = sd_read_object(vid_to_vdi_oid(dw->vid), (char *)inode,<br>
+ SD_INODE_HEADER_SIZE, 0);<br>
if (ret != SD_RES_SUCCESS) {<br>
ret = SD_RES_EIO;<br>
goto out;<br>
@@ -807,8 +809,8 @@ static int delete_inode(struct deletion_work *dw)<br>
<br>
memset(inode->name, 0, sizeof(inode->name));<br>
<br>
- ret = write_object(vid_to_vdi_oid(dw->vid), (char *)inode,<br>
- SD_INODE_HEADER_SIZE, 0, false);<br>
+ ret = sd_write_object(vid_to_vdi_oid(dw->vid), (char *)inode,<br>
+ SD_INODE_HEADER_SIZE, 0, false);<br>
if (ret != 0) {<br>
ret = SD_RES_EIO;<br>
goto out;<br>
@@ -858,7 +860,7 @@ static void delete_cb(void *data, enum btree_node_type type, void *arg)<br>
sd_debug("object %" PRIx64 " is base's data, would"<br>
" not be deleted.", oid);<br>
else {<br>
- ret = remove_object(oid);<br>
+ ret = sd_remove_object(oid);<br>
if (ret != SD_RES_SUCCESS)<br>
sd_err("remove object %" PRIx64 " fail, %d",<br>
oid, ret);<br>
@@ -884,7 +886,7 @@ static void delete_one(struct work *work)<br>
}<br>
<br>
ret = read_backend_object(vid_to_vdi_oid(vdi_id),<br>
- (void *)inode, sizeof(*inode), 0);<br>
+ (void *)inode, sizeof(*inode), 0);<br>
<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("cannot find VDI object");<br>
@@ -911,7 +913,7 @@ static void delete_one(struct work *work)<br>
continue;<br>
}<br>
<br>
- ret = remove_object(oid);<br>
+ ret = sd_remove_object(oid);<br>
if (ret != SD_RES_SUCCESS)<br>
sd_err("remove object %" PRIx64 " fail, %d",<br>
oid, ret);<br>
@@ -929,8 +931,8 @@ static void delete_one(struct work *work)<br>
inode->vdi_size = 0;<br>
memset(inode->name, 0, sizeof(inode->name));<br>
<br>
- write_object(vid_to_vdi_oid(vdi_id), (void *)inode,<br>
- sizeof(*inode), 0, false);<br>
+ sd_write_object(vid_to_vdi_oid(vdi_id), (void *)inode,<br>
+ sizeof(*inode), 0, false);<br>
<br>
if (nr_deleted)<br>
notify_vdi_deletion(vdi_id);<br>
@@ -981,7 +983,7 @@ static int fill_vdi_list(struct deletion_work *dw, uint32_t root_vid)<br>
again:<br>
vid = dw->buf[done++];<br>
ret = read_backend_object(vid_to_vdi_oid(vid), (char *)inode,<br>
- SD_INODE_HEADER_SIZE, 0);<br>
+ SD_INODE_HEADER_SIZE, 0);<br>
<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("cannot find VDI object");<br>
@@ -1023,11 +1025,11 @@ static uint64_t get_vdi_root(uint32_t vid, bool *cloned)<br>
}<br>
next:<br>
ret = read_backend_object(vid_to_vdi_oid(vid), (char *)inode,<br>
- SD_INODE_HEADER_SIZE, 0);<br>
+ SD_INODE_HEADER_SIZE, 0);<br>
<br>
if (vid == inode->vdi_id && inode->snap_id == 1<br>
- && inode->parent_vdi_id != 0<br>
- && !inode->snap_ctime) {<br>
+ && inode->parent_vdi_id != 0<br>
+ && !inode->snap_ctime) {<br>
sd_debug("vdi %" PRIx32 " is a cloned vdi.", vid);<br>
/* current vdi is a cloned vdi */<br>
*cloned = true;<br>
@@ -1143,12 +1145,12 @@ int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len,<br>
end = *attrid - 1;<br>
while (*attrid != end) {<br>
oid = vid_to_attr_oid(vid, *attrid);<br>
- ret = read_object(oid, (char *)&tmp_attr,<br>
- sizeof(tmp_attr), 0);<br>
+ ret = sd_read_object(oid, (char *)&tmp_attr,<br>
+ sizeof(tmp_attr), 0);<br>
<br>
if (ret == SD_RES_NO_OBJ && wr) {<br>
- ret = write_object(oid, (char *)vattr, data_len, 0,<br>
- true);<br>
+ ret = sd_write_object(oid, (char *)vattr, data_len, 0,<br>
+ true);<br>
if (ret)<br>
ret = SD_RES_EIO;<br>
else<br>
@@ -1167,17 +1169,17 @@ int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len,<br>
if (excl)<br>
ret = SD_RES_VDI_EXIST;<br>
else if (delete) {<br>
- ret = write_object(oid, (char *)"", 1,<br>
- offsetof(struct sheepdog_vdi_attr, name),<br>
- false);<br>
+ ret = sd_write_object(oid, (char *)"", 1,<br>
+ offsetof(struct sheepdog_vdi_attr, name),<br>
+ false);<br>
if (ret)<br>
ret = SD_RES_EIO;<br>
else<br>
ret = SD_RES_SUCCESS;<br>
} else if (wr) {<br>
- ret = write_object(oid, (char *)vattr,<br>
- SD_ATTR_OBJ_SIZE, 0,<br>
- false);<br>
+ ret = sd_write_object(oid, (char *)vattr,<br>
+ SD_ATTR_OBJ_SIZE, 0,<br>
+ false);<br>
<br>
if (ret)<br>
ret = SD_RES_EIO;<br>
diff --git a/tests/unit/sheep/mock_store.c b/tests/unit/sheep/mock_store.c<br>
index fe6c0d9..3a638be 100644<br>
--- a/tests/unit/sheep/mock_store.c<br>
+++ b/tests/unit/sheep/mock_store.c<br>
@@ -14,12 +14,12 @@<br>
#include "mock.h"<br>
#include "sheep_priv.h"<br>
<br>
-MOCK_METHOD(read_object, int, 0,<br>
+MOCK_METHOD(sd_read_object, int, 0,<br>
uint64_t oid, char *data, unsigned int datalen, uint64_t offset)<br>
-MOCK_METHOD(write_object, int, 0,<br>
+MOCK_METHOD(sd_write_object, int, 0,<br>
uint64_t oid, char *data, unsigned int datalen, uint64_t offset,<br>
bool create)<br>
MOCK_METHOD(read_backend_object, int, 0,<br>
uint64_t oid, char *data, unsigned int datalen, uint64_t offset)<br>
-MOCK_METHOD(remove_object, int, 0,<br>
+MOCK_METHOD(sd_remove_object, int, 0,<br>
uint64_t oid)<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.9.5<br>
<br>
--<br>
sheepdog mailing list<br>
<a href="mailto:sheepdog@lists.wpkg.org">sheepdog@lists.wpkg.org</a><br>
<a href="http://lists.wpkg.org/mailman/listinfo/sheepdog" target="_blank">http://lists.wpkg.org/mailman/listinfo/sheepdog</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>--<br>Best Regard<br>Robin Dong
</div>