[sheepdog] [PATCH 11/12] sheep: make stat_data_objs a generic function
Hitoshi Mitake
mitake.hitoshi at gmail.com
Wed Jan 29 02:45:05 CET 2014
At Wed, 29 Jan 2014 04:19:11 +0800,
Liu Yuan wrote:
>
> and rename it as sd_inode_stat()
>
> Signed-off-by: Liu Yuan <namei.unix at gmail.com>
> ---
> dog/vdi.c | 96 +---------------------------------------
> include/internal_proto.h | 3 ++
> lib/Makefile.am | 3 +-
> lib/sd.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 118 insertions(+), 96 deletions(-)
> create mode 100644 lib/sd.c
>
> diff --git a/dog/vdi.c b/dog/vdi.c
> index 1e175b3..091ce91 100644
> --- a/dog/vdi.c
> +++ b/dog/vdi.c
> @@ -87,100 +87,6 @@ static void vdi_show_progress(uint64_t done, uint64_t total)
> return show_progress(done, total, false);
> }
>
> -struct stat_arg {
> - uint64_t *my;
> - uint64_t *cow;
> - uint32_t vid;
> -};
> -
> -static void stat_cb(void *data, enum btree_node_type type, void *arg)
> -{
> - struct sd_extent *ext;
> - struct stat_arg *sarg = arg;
> - uint64_t *my = sarg->my;
> - uint64_t *cow = sarg->cow;
> -
> - if (type == BTREE_EXT) {
> - ext = (struct sd_extent *)data;
> - if (ext->vdi_id == sarg->vid)
> - (*my)++;
> - else if (ext->vdi_id != 0)
> - (*cow)++;
> - }
> -}
> -
> -static void stat_data_objs_btree(const struct sd_inode *inode,
> - uint64_t *my_objs, uint64_t *cow_objs)
> -{
> - struct stat_arg arg = {my_objs, cow_objs, inode->vdi_id};
> - traverse_btree(dog_bnode_reader, inode, stat_cb, &arg);
> -}
> -
> -static void stat_data_objs_array(const struct sd_inode *inode,
> - uint64_t *my_objs, uint64_t *cow_objs)
> -{
> - int nr;
> - uint64_t my, cow, *p;
> - uint32_t vid = inode->vdi_id;
> -
> - my = 0;
> - cow = 0;
> - nr = count_data_objs(inode);
> -
> - if (nr % 2 != 0) {
> - if (is_data_obj_writeable(inode, 0))
> - my++;
> - else if (inode->data_vdi_id[0] != 0)
> - cow++;
> - p = (uint64_t *)(inode->data_vdi_id + 1);
> - } else
> - p = (uint64_t *)inode->data_vdi_id;
> -
> - /*
> - * To boost performance, this function checks data_vdi_id for each 64
> - * bit integer.
> - */
> - nr /= 2;
> - for (int i = 0; i < nr; i++) {
> - if (p[i] == 0)
> - continue;
> - if (p[i] == (((uint64_t)vid << 32) | vid)) {
> - my += 2;
> - continue;
> - }
> -
> - /* Check the higher 32 bit */
> - if (p[i] >> 32 == vid)
> - my++;
> - else if ((p[i] & 0xFFFFFFFF00000000) != 0)
> - cow++;
> -
> - /* Check the lower 32 bit */
> - if ((p[i] & 0xFFFFFFFF) == vid)
> - my++;
> - else if ((p[i] & 0xFFFFFFFF) != 0)
> - cow++;
> - }
> -
> - *my_objs = my;
> - *cow_objs = cow;
> -}
> -
> -/*
> - * Get the number of objects.
> - *
> - * 'my_objs' means the number objects which belongs to this vdi. 'cow_objs'
> - * means the number of the other objects.
> - */
> -static void stat_data_objs(const struct sd_inode *inode, uint64_t *my_objs,
> - uint64_t *cow_objs)
> -{
> - if (inode->store_policy == 0)
> - stat_data_objs_array(inode, my_objs, cow_objs);
> - else
> - stat_data_objs_btree(inode, my_objs, cow_objs);
> -}
> -
> static char *redundancy_scheme(uint8_t copy_nr, uint8_t policy)
> {
> static char str[10];
> @@ -218,7 +124,7 @@ static void print_vdi_list(uint32_t vid, const char *name, const char *tag,
> "%Y-%m-%d %H:%M", &tm);
> }
>
> - stat_data_objs(i, &my_objs, &cow_objs);
> + sd_inode_stat(i, &my_objs, &cow_objs, dog_bnode_reader);
>
> if (i->snap_id == 1 && i->parent_vdi_id != 0)
> is_clone = true;
> diff --git a/include/internal_proto.h b/include/internal_proto.h
> index 2e5c81c..22ea897 100644
> --- a/include/internal_proto.h
> +++ b/include/internal_proto.h
> @@ -263,6 +263,9 @@ struct sd_stat {
> } r;
> };
>
> +void sd_inode_stat(const struct sd_inode *inode, uint64_t *, uint64_t *,
> + read_node_fn reader);
> +
> #ifdef HAVE_TRACE
>
> #define TRACE_GRAPH_ENTRY 0x01
> diff --git a/lib/Makefile.am b/lib/Makefile.am
> index 5204879..7d56c2d 100644
> --- a/lib/Makefile.am
> +++ b/lib/Makefile.am
> @@ -5,7 +5,8 @@ AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
> noinst_LIBRARIES = libsheepdog.a
>
> libsheepdog_a_SOURCES = event.c logger.c net.c util.c rbtree.c strbuf.c \
> - sha1.c option.c work.c sockfd_cache.c fec.c sd_inode.c
> + sha1.c option.c work.c sockfd_cache.c fec.c \
> + sd_inode.c sd.c
>
> if BUILD_SHA1_HW
> libsheepdog_a_SOURCES += sha1_ssse3.S
> diff --git a/lib/sd.c b/lib/sd.c
The name sd.c is too generic,
> new file mode 100644
> index 0000000..a254c1e
> --- /dev/null
> +++ b/lib/sd.c
> @@ -0,0 +1,112 @@
> +/*
> + * Copyright (C) 2014 Taobao Inc.
> + *
> + * Liu Yuan <namei.unix at gmail.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License version
> + * 2 as published by the Free Software Foundation.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <nfs://www.gnu.org/licenses/>.
> + */
> +
> +/* This file contains functions shared by sheep and dog */
and the above comment is true for all of other stuff in
libsheepdog. You don't have to describe. Do we need to create a new
file for the below stuff? I think sd_inode.c would be a suitable place
for them.
Thanks,
Hitoshi
> +
> +#include "internal_proto.h"
> +
> +struct stat_arg {
> + uint64_t *my;
> + uint64_t *cow;
> + uint32_t vid;
> +};
> +
> +static void stat_cb(void *data, enum btree_node_type type, void *arg)
> +{
> + struct sd_extent *ext;
> + struct stat_arg *sarg = arg;
> + uint64_t *my = sarg->my;
> + uint64_t *cow = sarg->cow;
> +
> + if (type == BTREE_EXT) {
> + ext = (struct sd_extent *)data;
> + if (ext->vdi_id == sarg->vid)
> + (*my)++;
> + else if (ext->vdi_id != 0)
> + (*cow)++;
> + }
> +}
> +
> +static void hypver_volume_stat(const struct sd_inode *inode,
> + uint64_t *my_objs, uint64_t *cow_objs,
> + read_node_fn reader)
> +{
> + struct stat_arg arg = {my_objs, cow_objs, inode->vdi_id};
> + traverse_btree(reader, inode, stat_cb, &arg);
> +}
> +
> +static void volume_stat(const struct sd_inode *inode, uint64_t *my_objs,
> + uint64_t *cow_objs)
> +{
> + int nr;
> + uint64_t my, cow, *p;
> + uint32_t vid = inode->vdi_id;
> +
> + my = 0;
> + cow = 0;
> + nr = count_data_objs(inode);
> +
> + if (nr % 2 != 0) {
> + if (inode->data_vdi_id[0] != inode->vdi_id)
> + my++;
> + else if (inode->data_vdi_id[0] != 0)
> + cow++;
> + p = (uint64_t *)(inode->data_vdi_id + 1);
> + } else
> + p = (uint64_t *)inode->data_vdi_id;
> +
> + /*
> + * To boost performance, this function checks data_vdi_id for each 64
> + * bit integer.
> + */
> + nr /= 2;
> + for (int i = 0; i < nr; i++) {
> + if (p[i] == 0)
> + continue;
> + if (p[i] == (((uint64_t)vid << 32) | vid)) {
> + my += 2;
> + continue;
> + }
> +
> + /* Check the higher 32 bit */
> + if (p[i] >> 32 == vid)
> + my++;
> + else if ((p[i] & 0xFFFFFFFF00000000) != 0)
> + cow++;
> +
> + /* Check the lower 32 bit */
> + if ((p[i] & 0xFFFFFFFF) == vid)
> + my++;
> + else if ((p[i] & 0xFFFFFFFF) != 0)
> + cow++;
> + }
> +
> + *my_objs = my;
> + *cow_objs = cow;
> +}
> +
> +/*
> + * Get the number of objects.
> + *
> + * 'my_objs' means the number objects which belongs to this vdi. 'cow_objs'
> + * means the number of the other objects.
> + */
> +void sd_inode_stat(const struct sd_inode *inode, uint64_t *my_objs,
> + uint64_t *cow_objs, read_node_fn reader)
> +{
> + if (inode->store_policy == 0)
> + volume_stat(inode, my_objs, cow_objs);
> + else
> + hypver_volume_stat(inode, my_objs, cow_objs, reader);
> +}
> +
> --
> 1.8.1.2
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog
More information about the sheepdog
mailing list