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