qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Changlong Xie <xiecl.fnst@cn.fujitsu.com>
To: qemu devel <qemu-devel@nongnu.org>,
	Eric Blake <eblake@redhat.com>, Alberto Garcia <berto@igalia.com>,
	Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Dong Eddie <eddie.dong@intel.com>,
	Jiang Yunhong <yunhong.jiang@intel.com>,
	Wen Congyang <wency@cn.fujitsu.com>,
	qemu block <qemu-block@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v13 2/3] quorum: implement bdrv_add_child() and bdrv_del_child()
Date: Wed, 20 Apr 2016 11:36:19 +0800	[thread overview]
Message-ID: <5716F933.2060905@cn.fujitsu.com> (raw)
In-Reply-To: <1460536389-9161-3-git-send-email-xiecl.fnst@cn.fujitsu.com>

ping...

On 04/13/2016 04:33 PM, Changlong Xie wrote:
> From: Wen Congyang <wency@cn.fujitsu.com>
>
> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> Signed-off-by: Changlong Xie <xiecl.fnst@cn.fujitsu.com>
> ---
>   block.c               |  8 +++---
>   block/quorum.c        | 78 +++++++++++++++++++++++++++++++++++++++++++++++++--
>   include/block/block.h |  4 +++
>   3 files changed, 84 insertions(+), 6 deletions(-)
>
> diff --git a/block.c b/block.c
> index 68cd3b2..4bdc6b3 100644
> --- a/block.c
> +++ b/block.c
> @@ -1176,10 +1176,10 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
>       return child;
>   }
>
> -static BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
> -                                    BlockDriverState *child_bs,
> -                                    const char *child_name,
> -                                    const BdrvChildRole *child_role)
> +BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
> +                             BlockDriverState *child_bs,
> +                             const char *child_name,
> +                             const BdrvChildRole *child_role)
>   {
>       BdrvChild *child = bdrv_root_attach_child(child_bs, child_name, child_role);
>       QLIST_INSERT_HEAD(&parent_bs->children, child, next);
> diff --git a/block/quorum.c b/block/quorum.c
> index da15465..2553f82 100644
> --- a/block/quorum.c
> +++ b/block/quorum.c
> @@ -14,6 +14,7 @@
>    */
>
>   #include "qemu/osdep.h"
> +#include "qemu/cutils.h"
>   #include "block/block_int.h"
>   #include "qapi/qmp/qbool.h"
>   #include "qapi/qmp/qdict.h"
> @@ -67,6 +68,9 @@ typedef struct QuorumVotes {
>   typedef struct BDRVQuorumState {
>       BdrvChild **children;  /* children BlockDriverStates */
>       int num_children;      /* children count */
> +    uint64_t last_index;   /* indicate the child role name of the last
> +                            * element of children array
> +                            */
>       int threshold;         /* if less than threshold children reads gave the
>                               * same result a quorum error occurs.
>                               */
> @@ -898,9 +902,9 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
>           ret = -EINVAL;
>           goto exit;
>       }
> -    if (s->num_children < 2) {
> +    if (s->num_children < 1) {
>           error_setg(&local_err,
> -                   "Number of provided children must be greater than 1");
> +                   "Number of provided children must be 1 or more");
>           ret = -EINVAL;
>           goto exit;
>       }
> @@ -964,6 +968,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
>
>           opened[i] = true;
>       }
> +    s->last_index = s->num_children;
>
>       g_free(opened);
>       goto exit;
> @@ -1020,6 +1025,72 @@ static void quorum_attach_aio_context(BlockDriverState *bs,
>       }
>   }
>
> +static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs,
> +                             Error **errp)
> +{
> +    BDRVQuorumState *s = bs->opaque;
> +    BdrvChild *child;
> +    char indexstr[32];
> +    int ret;
> +
> +    assert(s->num_children <= INT_MAX / sizeof(BdrvChild *) &&
> +           s->last_index <= UINT64_MAX);
> +    if (s->num_children == INT_MAX / sizeof(BdrvChild *) ||
> +        s->last_index == UINT64_MAX) {
> +        error_setg(errp, "Too many children");
> +        return;
> +    }
> +
> +    ret = snprintf(indexstr, 32, "children.%" PRIu64, s->last_index);
> +    if (ret < 0 || ret >= 32) {
> +        error_setg(errp, "cannot generate child name");
> +        return;
> +    }
> +    s->last_index++;
> +
> +    bdrv_drain(bs);
> +
> +    /* We can safely add the child now */
> +    bdrv_ref(child_bs);
> +    child = bdrv_attach_child(bs, child_bs, indexstr, &child_format);
> +    s->children = g_renew(BdrvChild *, s->children, s->num_children + 1);
> +    s->children[s->num_children++] = child;
> +}
> +
> +static void quorum_del_child(BlockDriverState *bs, BdrvChild *child,
> +                             Error **errp)
> +{
> +    BDRVQuorumState *s = bs->opaque;
> +    int i;
> +
> +    for (i = 0; i < s->num_children; i++) {
> +        if (s->children[i] == child) {
> +            break;
> +        }
> +    }
> +
> +    /* we have checked it in bdrv_del_child() */
> +    assert(i < s->num_children);
> +
> +    if (s->num_children <= s->threshold) {
> +        error_setg(errp,
> +            "The number of children cannot be lower than the vote threshold %d",
> +            s->threshold);
> +        return;
> +    }
> +
> +    /* child->name is "children.%d" */
> +    assert(!strncmp(child->name, "children.", 9));
> +
> +    bdrv_drain(bs);
> +
> +    /* We can safely remove this child now */
> +    memmove(&s->children[i], &s->children[i + 1],
> +            (s->num_children - i - 1) * sizeof(BdrvChild *));
> +    s->children = g_renew(BdrvChild *, s->children, --s->num_children);
> +    bdrv_unref_child(bs, child);
> +}
> +
>   static void quorum_refresh_filename(BlockDriverState *bs, QDict *options)
>   {
>       BDRVQuorumState *s = bs->opaque;
> @@ -1075,6 +1146,9 @@ static BlockDriver bdrv_quorum = {
>       .bdrv_detach_aio_context            = quorum_detach_aio_context,
>       .bdrv_attach_aio_context            = quorum_attach_aio_context,
>
> +    .bdrv_add_child                     = quorum_add_child,
> +    .bdrv_del_child                     = quorum_del_child,
> +
>       .is_filter                          = true,
>       .bdrv_recurse_is_first_non_filter   = quorum_recurse_is_first_non_filter,
>   };
> diff --git a/include/block/block.h b/include/block/block.h
> index 694ca76..52902cd 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -476,6 +476,10 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);
>   void bdrv_ref(BlockDriverState *bs);
>   void bdrv_unref(BlockDriverState *bs);
>   void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child);
> +BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
> +                             BlockDriverState *child_bs,
> +                             const char *child_name,
> +                             const BdrvChildRole *child_role);
>
>   bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp);
>   void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason);
>

  reply	other threads:[~2016-04-20  3:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-13  8:33 [Qemu-devel] [PATCH v13 0/3] qapi: child add/delete support Changlong Xie
2016-04-13  8:33 ` [Qemu-devel] [PATCH v13 1/3] Add new block driver interface to add/delete a BDS's child Changlong Xie
2016-04-13  8:33 ` [Qemu-devel] [PATCH v13 2/3] quorum: implement bdrv_add_child() and bdrv_del_child() Changlong Xie
2016-04-20  3:36   ` Changlong Xie [this message]
2016-05-06 15:20   ` Max Reitz
2016-05-09  9:26     ` Changlong Xie
2016-05-09 15:52   ` Alberto Garcia
2016-05-09 16:50     ` Max Reitz
2016-05-10  6:59     ` Changlong Xie
2016-05-10  8:39     ` Kevin Wolf
2016-05-10  8:45       ` Alberto Garcia
2016-04-13  8:33 ` [Qemu-devel] [PATCH v13 3/3] qmp: add monitor command to add/remove a child Changlong Xie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5716F933.2060905@cn.fujitsu.com \
    --to=xiecl.fnst@cn.fujitsu.com \
    --cc=armbru@redhat.com \
    --cc=berto@igalia.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eddie.dong@intel.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=wency@cn.fujitsu.com \
    --cc=yunhong.jiang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).