For backend store, the object size is determined by copy_policy.

Also add a helper to get store object size for future use.

Signed-off-by: Liu Yuan <[email protected]>
---
 dog/common.c        |   10 ++++++++++
 dog/dog.h           |    1 +
 dog/vdi.c           |    5 +++--
 sheep/md.c          |    4 ++--
 sheep/ops.c         |    2 +-
 sheep/plain_store.c |    2 +-
 6 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/dog/common.c b/dog/common.c
index 0685be6..a2fb945 100644
--- a/dog/common.c
+++ b/dog/common.c
@@ -12,6 +12,7 @@
 #include "dog.h"
 #include "sha1.h"
 #include "sockfd_cache.h"
+#include "fec.h"
 
 static char *strnumber_raw(uint64_t _size, bool raw)
 {
@@ -328,3 +329,12 @@ void show_progress(uint64_t done, uint64_t total, bool raw)
 
        free(buf);
 }
+
+size_t get_store_objsize(uint8_t copy_policy, uint64_t oid)
+{
+       if (is_vdi_obj(oid))
+               return SD_INODE_SIZE;
+       if (copy_policy != 0)
+               return SD_EC_OBJECT_SIZE;
+       return get_objsize(oid);
+}
diff --git a/dog/dog.h b/dog/dog.h
index e8b7f0f..cfc9d54 100644
--- a/dog/dog.h
+++ b/dog/dog.h
@@ -82,6 +82,7 @@ int do_vdi_create(const char *vdiname, int64_t vdi_size,
                  uint8_t nr_copies, uint8_t copy_policy);
 int do_vdi_check(const struct sd_inode *inode);
 void show_progress(uint64_t done, uint64_t total, bool raw);
+size_t get_store_objsize(uint8_t copy_policy, uint64_t oid);
 
 extern struct command vdi_command;
 extern struct command node_command;
diff --git a/dog/vdi.c b/dog/vdi.c
index 5324f97..6eec5b4 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -877,11 +877,11 @@ static int vdi_object(int argc, char **argv)
                return EXIT_MISSING;
        }
 
-       size = info.copy_policy ? SD_EC_OBJECT_SIZE : SD_DATA_OBJ_SIZE;
        if (idx == ~0) {
                printf("Looking for the inode object 0x%" PRIx32 " with %d 
nodes\n\n",
                       vid, sd_nodes_nr);
-               parse_objs(vid_to_vdi_oid(vid), do_print_obj, NULL, size);
+               parse_objs(vid_to_vdi_oid(vid), do_print_obj, NULL,
+                          SD_INODE_SIZE);
        } else {
                struct obj_info_filler_info oid_info = {0};
 
@@ -893,6 +893,7 @@ static int vdi_object(int argc, char **argv)
                        exit(EXIT_FAILURE);
                }
 
+               size = info.copy_policy ? SD_EC_OBJECT_SIZE : SD_DATA_OBJ_SIZE;
                parse_objs(vid_to_vdi_oid(vid), obj_info_filler, &oid_info,
                           size);
 
diff --git a/sheep/md.c b/sheep/md.c
index 9fc1b6e..e6d175c 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -153,7 +153,7 @@ static int get_total_object_size(uint64_t oid, const char 
*wd, uint32_t epoch,
        if (stat(path, &s) == 0)
                *t += s.st_blocks * SECTOR_SIZE;
        else
-               *t += get_objsize(oid);
+               *t += get_store_objsize(oid);
 
        return SD_RES_SUCCESS;
 }
@@ -486,7 +486,7 @@ static int md_move_object(uint64_t oid, const char *old, 
const char *new)
 {
        struct strbuf buf = STRBUF_INIT;
        int fd, ret = -1;
-       size_t sz = get_objsize(oid);
+       size_t sz = get_store_objsize(oid);
 
        fd = open(old, O_RDONLY);
        if (fd < 0) {
diff --git a/sheep/ops.c b/sheep/ops.c
index 428f09e..5c6c571 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -972,7 +972,7 @@ static int peer_create_and_write_obj(struct request *req)
 
        memset(&iocb, 0, sizeof(iocb));
        iocb.epoch = epoch;
-       iocb.length = get_objsize(oid);
+       iocb.length = get_store_objsize(oid);
        iocb.ec_index = hdr->obj.ec_index;
        if (hdr->flags & SD_FLAG_CMD_COW) {
                sd_debug("%" PRIx64 ", %" PRIx64, oid, hdr->obj.cow_oid);
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 4318c5c..9dc3b7a 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -613,7 +613,7 @@ int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t 
*sha1)
                }
        }
 
-       length = get_objsize(oid);
+       length = get_store_objsize(oid);
        buf = valloc(length);
        if (buf == NULL)
                return SD_RES_NO_MEM;
-- 
1.7.9.5

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to