[sheepdog] [PATCH v3 3/5] replace structure of inode->data_vdi_id[] from array to btree
Liu Yuan
namei.unix at gmail.com
Fri Oct 25 08:35:56 CEST 2013
On Thu, Oct 24, 2013 at 05:46:20PM +0800, Robin Dong wrote:
> 1. add sd_extent_header to manage meta-data in data_vdi_id[] or middle-node
> 2. add new type of object: B-tree object as middle-node
>
> Signed-off-by: Robin Dong <sanbai at taobao.com>
> ---
> dog/vdi.c | 2 +-
> include/sheepdog_proto.h | 43 ++++-
> lib/sd_inode.c | 519 +++++++++++++++++++++++++++++++++++++++++++++-
> sheep/vdi.c | 1 +
> sheepfs/volume.c | 2 +-
> 5 files changed, 558 insertions(+), 9 deletions(-)
>
> diff --git a/dog/vdi.c b/dog/vdi.c
> index faf06f0..960e2a0 100644
> --- a/dog/vdi.c
> +++ b/dog/vdi.c
> @@ -558,7 +558,7 @@ static int vdi_create(int argc, char **argv)
> goto out;
> }
>
> - sd_inode_set_vdi(inode, idx, vid);
> + INODE_SET_VDI(inode, 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, inode->copy_policy,
> diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
> index 30ff397..c338efa 100644
> --- a/include/sheepdog_proto.h
> +++ b/include/sheepdog_proto.h
> @@ -74,6 +74,9 @@
> #define SD_RES_JOIN_FAILED 0x18 /* Target node had failed to join sheepdog */
> #define SD_RES_HALT 0x19 /* Sheepdog is stopped doing IO */
> #define SD_RES_READONLY 0x1A /* Object is read-only */
> +#define SD_RES_BTREE_NOT_FOUND 0x1B /* Cannot found node in btree */
> +#define SD_RES_BTREE_FOUND 0x1C /* Found node in btree */
> +#define SD_RES_BTREE_REPEAT 0x1D /* Should repeat op in btree */
>
> /* errors above 0x80 are sheepdog-internal */
>
> @@ -92,8 +95,9 @@
> #define VDI_BIT (UINT64_C(1) << 63)
> #define VMSTATE_BIT (UINT64_C(1) << 62)
> #define VDI_ATTR_BIT (UINT64_C(1) << 61)
> +#define VDI_BTREE_BIT (UINT64_C(1) << 60)
> #define MAX_DATA_OBJS (1ULL << 20)
> -#define MAX_CHILDREN 1024U
> +#define MAX_CHILDREN (1024U - 1) /* we use the last uint32_t as btree_counter */
> #define SD_MAX_VDI_LEN 256U
> #define SD_MAX_VDI_TAG_LEN 256U
> #define SD_MAX_VDI_ATTR_KEY_LEN 256U
> @@ -104,8 +108,8 @@
> #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 (sizeof(struct sd_inode) - \
> - sizeof(uint32_t) * MAX_DATA_OBJS)
> +#define SD_INODE_INDEX_SIZE (sizeof(uint32_t) * MAX_DATA_OBJS)
> +#define SD_INODE_HEADER_SIZE (sizeof(struct sd_inode) - SD_INODE_INDEX_SIZE)
> #define SD_ATTR_OBJ_SIZE (sizeof(struct sheepdog_vdi_attr))
> #define CURRENT_VDI_ID 0
>
> @@ -215,16 +219,35 @@ struct sd_inode {
> uint64_t vdi_size;
> uint64_t vm_state_size;
> uint8_t copy_policy;
> - uint8_t reserved;
> + uint8_t store_policy;
> uint8_t nr_copies;
> uint8_t block_size_shift;
> uint32_t snap_id;
> uint32_t vdi_id;
> uint32_t parent_vdi_id;
> uint32_t child_vdi_id[MAX_CHILDREN];
> + uint32_t btree_counter;
> uint32_t data_vdi_id[MAX_DATA_OBJS];
> };
>
> +struct sd_extent {
> + int idx;
> + uint32_t vdi_id;
> +};
Any reason not type idx as uint32_t? I enable debug and see
yliu at ubuntu-precise:~/sheepdog$ echo hello | dog/dog vdi write test 13P 512
btree> header: 25204 3 1
btree> ext: -805306368, 8137509
btree> ext: -536870912, 8137509
btree> ext: -268435456, 8137509
I wonder if it is better to make idx as uint32_t?
Thanks
Yuan
More information about the sheepdog
mailing list