From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp> Now we allow sparse objects, it's better to calculate the actually allocated sizes. Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp> --- sheep/md.c | 11 +++++++++-- sheep/ops.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sheep/md.c b/sheep/md.c index 66abe79..32b6628 100644 --- a/sheep/md.c +++ b/sheep/md.c @@ -181,10 +181,17 @@ static inline void calculate_vdisks(struct disk *disks, int nr_disks, #define MDNAME "user.md.size" #define MDSIZE sizeof(uint64_t) -static int get_total_object_size(uint64_t oid, char *ignore, void *total) +static int get_total_object_size(uint64_t oid, char *wd, void *total) { uint64_t *t = total; - *t += get_objsize(oid); + struct stat s; + char path[PATH_MAX]; + + snprintf(path, PATH_MAX, "%s/%016" PRIx64, wd, oid); + if (stat(path, &s) == 0) + *t += s.st_blocks * SECTOR_SIZE; + else + *t += get_objsize(oid); return SD_RES_SUCCESS; } diff --git a/sheep/ops.c b/sheep/ops.c index 9f15fb8..133ccc7 100644 --- a/sheep/ops.c +++ b/sheep/ops.c @@ -61,10 +61,17 @@ struct sd_op_template { int (*process_main)(const struct sd_req *req, struct sd_rsp *rsp, void *data); }; -static int get_total_object_size(uint64_t oid, char *ignore, void *total) +static int get_total_object_size(uint64_t oid, char *wd, void *total) { uint64_t *t = total; - *t += get_objsize(oid); + struct stat s; + char path[PATH_MAX]; + + snprintf(path, PATH_MAX, "%s/%016" PRIx64, wd, oid); + if (stat(path, &s) == 0) + *t += s.st_blocks * SECTOR_SIZE; + else + *t += get_objsize(oid); return SD_RES_SUCCESS; } -- 1.7.9.5 |