[sheepdog] [PATCH v2 07/11] sheep: remove max children limit
MORITA Kazutaka
morita.kazutaka at gmail.com
Tue Jun 18 19:14:27 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 8fae140..228fef6 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -148,7 +148,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);
@@ -174,10 +173,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 987be29..a15ecc3 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -600,8 +600,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;
@@ -702,8 +702,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;
@@ -1339,9 +1339,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;
@@ -1819,8 +1820,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 3340f2b..77f3b42 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -102,7 +102,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
@@ -218,7 +218,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];
};
@@ -349,4 +349,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 6f12d14..fc57f28 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -390,9 +390,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 6a39f1e..4e828e1 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -830,7 +830,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 93ab536..9e3cc34 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 4000e97..cfe90a8 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -208,8 +208,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