[sheepdog] [PATCH v3 5/9] sheep: remove max children limit
Hitoshi Mitake
mitake.hitoshi at gmail.com
Sun Feb 23 06:28:24 CET 2014
We no longer need it. This also reduces the vdi header size.
Cc: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
Cc: Valerio Pachera <sirio81 at gmail.com>
Cc: Alessandro Bolgia <alessandro at extensys.it>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v3: Keep SD_INODE_HEADER_SIZE as offsetof(struct sd_inode, data_vdi_id), not
offsetof(struct sd_inode, __unused). Because hypervolume code depends on the
old value.
include/sheepdog_proto.h | 7 ++++++-
sheep/gateway.c | 4 ++--
sheep/vdi.c | 46 +++-------------------------------------------
3 files changed, 11 insertions(+), 46 deletions(-)
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index a1db359..de746d8 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -238,7 +238,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[SD_INODE_DATA_INDEX];
uint32_t btree_counter;
struct generation_reference data_ref[SD_INODE_DATA_INDEX];
@@ -499,4 +499,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 5a3d333..7066f81 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -645,9 +645,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(SD_INODE_DATA_INDEX);
}
int gateway_read_obj(struct request *req)
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 2edda45..fc39472 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -255,17 +255,6 @@ static struct sd_inode *alloc_inode(const struct vdi_iocb *iocb,
return new;
}
-/* Find the first zeroed index to be used for a child vid. */
-static int find_free_idx(uint32_t *vdi_id, size_t max_idx)
-{
- for (int i = 0; i < max_idx; i++) {
- if (vdi_id[i] == 0)
- return i;
- }
-
- return -1;
-}
-
/* Create a fresh vdi */
static int create_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,
uint32_t new_vid)
@@ -309,7 +298,7 @@ static int clone_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,
uint32_t new_vid, uint32_t base_vid)
{
struct sd_inode *new = NULL, *base = xzalloc(sizeof(*base));
- int ret, idx;
+ int ret;
sd_debug("%s: size %" PRIu64 ", vid %" PRIx32 ", base %" PRIx32 ", "
"copies %d, snapid %" PRIu32, iocb->name, iocb->size, new_vid,
@@ -322,12 +311,6 @@ static int clone_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,
goto out;
}
- idx = find_free_idx(base->child_vdi_id, ARRAY_SIZE(base->child_vdi_id));
- if (idx < 0) {
- ret = SD_RES_FULL_VDI;
- goto out;
- }
-
/* TODO: multiple sd_write_object should be performed atomically */
for (int i = 0; i < ARRAY_SIZE(base->data_ref); i++)
@@ -375,7 +358,7 @@ static int snapshot_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,
uint32_t new_vid, uint32_t base_vid)
{
struct sd_inode *new = NULL, *base = xzalloc(sizeof(*base));
- int ret, idx;
+ int ret;
sd_debug("%s: size %" PRIu64 ", vid %" PRIx32 ", base %" PRIx32 ", "
"copies %d, snapid %" PRIu32, iocb->name, iocb->size, new_vid,
@@ -388,17 +371,10 @@ static int snapshot_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,
goto out;
}
- idx = find_free_idx(base->child_vdi_id, ARRAY_SIZE(base->child_vdi_id));
- if (idx < 0) {
- ret = SD_RES_FULL_VDI;
- goto out;
- }
-
/* 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;
for (int i = 0; i < ARRAY_SIZE(base->data_ref); i++) {
base->data_ref[i].generation++;
@@ -452,7 +428,7 @@ static int rebase_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,
uint32_t new_vid, uint32_t base_vid, uint32_t cur_vid)
{
struct sd_inode *new = NULL, *base = xzalloc(sizeof(*base));
- int ret, idx;
+ int ret;
sd_debug("%s: size %" PRIu64 ", vid %" PRIx32 ", base %" PRIx32 ", "
"cur %" PRIx32 ", copies %d, snapid %" PRIu32, iocb->name,
@@ -466,12 +442,6 @@ static int rebase_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,
goto out;
}
- idx = find_free_idx(base->child_vdi_id, ARRAY_SIZE(base->child_vdi_id));
- if (idx < 0) {
- ret = SD_RES_FULL_VDI;
- goto out;
- }
-
/* TODO: multiple sd_write_object should be performed atomically */
ret = sd_write_object(vid_to_vdi_oid(cur_vid), (char *)&iocb->time,
@@ -493,16 +463,6 @@ static int rebase_vdi(const struct vdi_iocb *iocb, uint32_t new_snapid,
goto out;
}
- /* update base vdi */
- 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;
- }
-
/* create a new vdi */
new = alloc_inode(iocb, new_snapid, new_vid, base->data_vdi_id,
base->data_ref);
--
1.8.3.2
More information about the sheepdog
mailing list