[sheepdog] [PATCH 07/10] sheep: remove max children limit
MORITA Kazutaka
morita.kazutaka at gmail.com
Tue May 21 02:11:56 CEST 2013
From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
We no longer need it. This also reduces the vdi header size.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
collie/common.c | 10 +++++-----
collie/vdi.c | 19 ++++++++++---------
include/sheepdog_proto.h | 9 +++++++--
sheep/gateway.c | 4 ++--
sheep/ops.c | 2 +-
sheep/vdi.c | 16 +---------------
sheepfs/volume.c | 3 +--
7 files changed, 27 insertions(+), 36 deletions(-)
diff --git a/collie/common.c b/collie/common.c
index 9f4e001..9559d63 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -120,7 +120,6 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
static struct sd_inode i;
struct sd_req req;
static DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
- unsigned int rlen = sizeof(vdi_inuse);
sd_init_req(&req, SD_OP_READ_VDIS);
req.data_length = sizeof(vdi_inuse);
@@ -146,10 +145,11 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
continue;
if (size > SD_INODE_HEADER_SIZE) {
- rlen = DIV_ROUND_UP(i.vdi_size, SD_DATA_OBJ_SIZE) *
- sizeof(i.data_vdi_id[0]);
- if (rlen > size - SD_INODE_HEADER_SIZE)
- rlen = size - SD_INODE_HEADER_SIZE;
+ size_t rlen;
+ int idx = DIV_ROUND_UP(i.vdi_size, SD_DATA_OBJ_SIZE);
+
+ rlen = min(data_vid_offset(idx), size);
+ rlen -= SD_INODE_HEADER_SIZE;
ret = sd_read_object(oid, ((char *)&i) + SD_INODE_HEADER_SIZE,
rlen, SD_INODE_HEADER_SIZE, true);
diff --git a/collie/vdi.c b/collie/vdi.c
index fe999c0..da745de 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -597,8 +597,8 @@ static int vdi_create(int argc, char **argv)
inode->data_vdi_id[idx] = vid;
ret = sd_write_object(vid_to_vdi_oid(vid), 0, &vid, sizeof(vid),
- SD_INODE_HEADER_SIZE + sizeof(vid) * idx, 0,
- inode->nr_copies, false, true);
+ data_vid_offset(idx), 0, inode->nr_copies,
+ false, true);
if (ret) {
ret = EXIT_FAILURE;
goto out;
@@ -699,8 +699,8 @@ static int vdi_clone(int argc, char **argv)
goto out;
}
- ret = sd_write_object(vid_to_vdi_oid(new_vid), 0, &new_vid, sizeof(new_vid),
- SD_INODE_HEADER_SIZE + sizeof(new_vid) * idx, 0,
+ ret = sd_write_object(vid_to_vdi_oid(new_vid), 0, &new_vid,
+ sizeof(new_vid), data_vid_offset(idx), 0,
inode->nr_copies, false, true);
if (ret) {
ret = EXIT_FAILURE;
@@ -1345,9 +1345,10 @@ static int vdi_write(int argc, char **argv)
}
if (create) {
- ret = sd_write_object(vid_to_vdi_oid(vid), 0, &vid, sizeof(vid),
- SD_INODE_HEADER_SIZE + sizeof(vid) * idx,
- flags, inode->nr_copies, false, false);
+ ret = sd_write_object(vid_to_vdi_oid(vid), 0, &vid,
+ sizeof(vid), data_vid_offset(idx),
+ flags, inode->nr_copies, false,
+ false);
if (ret) {
ret = EXIT_FAILURE;
goto out;
@@ -1851,8 +1852,8 @@ static int restore_obj(struct obj_backup *backup, uint32_t vid,
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, false, true);
+ data_vid_offset(backup->idx), 0,
+ parent_inode->nr_copies, false, true);
}
static uint32_t do_restore(const char *vdiname, int snapid, const char *tag)
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index de37401..0e21445 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -101,7 +101,7 @@
#define SD_MAX_VDI_SIZE (SD_DATA_OBJ_SIZE * MAX_DATA_OBJS)
#define SD_INODE_SIZE (sizeof(struct sd_inode))
-#define SD_INODE_HEADER_SIZE offsetof(struct sd_inode, data_vdi_id)
+#define SD_INODE_HEADER_SIZE offsetof(struct sd_inode, __unused)
#define SD_ATTR_OBJ_SIZE (sizeof(struct sheepdog_vdi_attr))
#define SD_LEDGER_OBJ_SIZE (UINT64_C(1) << 22)
#define CURRENT_VDI_ID 0
@@ -215,7 +215,7 @@ struct sd_inode {
uint32_t snap_id;
uint32_t vdi_id;
uint32_t parent_vdi_id;
- uint32_t child_vdi_id[MAX_CHILDREN];
+ uint32_t __unused[MAX_CHILDREN];
uint32_t data_vdi_id[MAX_DATA_OBJS];
struct generation_reference data_ref[MAX_DATA_OBJS];
};
@@ -354,4 +354,9 @@ static inline uint64_t data_oid_to_ledger_oid(uint64_t oid)
return LEDGER_BIT | oid;
}
+static inline uint64_t data_vid_offset(int idx)
+{
+ return offsetof(struct sd_inode, data_vdi_id[idx]);
+}
+
#endif
diff --git a/sheep/gateway.c b/sheep/gateway.c
index fb7ed21..4829e0a 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -387,9 +387,9 @@ static int update_obj_refcnt(const struct sd_req *hdr, uint32_t *vids,
static bool is_data_vid_update(const struct sd_req *hdr)
{
return is_vdi_obj(hdr->obj.oid) &&
- SD_INODE_HEADER_SIZE <= hdr->obj.offset &&
+ data_vid_offset(0) <= hdr->obj.offset &&
hdr->obj.offset + hdr->data_length <=
- offsetof(struct sd_inode, data_ref);
+ data_vid_offset(MAX_DATA_OBJS);
}
int gateway_write_obj(struct request *req)
diff --git a/sheep/ops.c b/sheep/ops.c
index d57f933..9f15fb8 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -822,7 +822,7 @@ static int local_discard_obj(struct request *req)
sd_dprintf("%"PRIx64, oid);
ret = write_object(vid_to_vdi_oid(vid), (char *)&zero, sizeof(zero),
- SD_INODE_HEADER_SIZE + sizeof(vid) * idx, false);
+ data_vid_offset(idx), false);
if (ret != SD_RES_SUCCESS)
return ret;
if (remove_object(oid) != SD_RES_SUCCESS)
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 8681519..c29af29 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -275,24 +275,10 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
new->snap_id = iocb->snapid;
if (iocb->base_vid) {
- int i;
-
new->parent_vdi_id = iocb->base_vid;
memcpy(new->data_vdi_id, base->data_vdi_id, sizeof(new->data_vdi_id));
- for (i = 0; i < ARRAY_SIZE(base->child_vdi_id); i++) {
- if (!base->child_vdi_id[i]) {
- base->child_vdi_id[i] = new_vid;
- break;
- }
- }
-
- if (i == ARRAY_SIZE(base->child_vdi_id)) {
- ret = SD_RES_NO_BASE_VDI;
- goto out;
- }
-
- for (i = 0; i < ARRAY_SIZE(base->data_ref); i++) {
+ for (int i = 0; i < ARRAY_SIZE(base->data_ref); i++) {
base->data_ref[i].count++;
new->data_ref[i].generation =
base->data_ref[i].generation + 1;
diff --git a/sheepfs/volume.c b/sheepfs/volume.c
index ae1f520..420a73a 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -213,8 +213,7 @@ static int volume_rw_object(char *buf, uint64_t oid, size_t size,
vdi->inode->data_vdi_id[idx] = vid;
/* writeback inode update */
if (volume_rw_object((char *)&vid, vid_to_vdi_oid(vid),
- sizeof(vid),
- SD_INODE_HEADER_SIZE + sizeof(vid) * idx,
+ sizeof(vid), data_vid_offset(idx),
VOLUME_WRITE) < 0)
return -1;
}
--
1.7.9.5
More information about the sheepdog
mailing list