From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5ZXJ-0006CA-HR for qemu-devel@nongnu.org; Thu, 18 Jun 2015 09:07:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5ZXF-0006kg-3o for qemu-devel@nongnu.org; Thu, 18 Jun 2015 09:07:17 -0400 Date: Thu, 18 Jun 2015 14:06:17 +0100 From: Stefan Hajnoczi Message-ID: <20150618130617.GF25387@stefanha-thinkpad.redhat.com> References: <1434617361-17778-1-git-send-email-wency@cn.fujitsu.com> <1434617361-17778-14-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="rWhLK7VZz0iBluhq" Content-Disposition: inline In-Reply-To: <1434617361-17778-14-git-send-email-wency@cn.fujitsu.com> Subject: Re: [Qemu-devel] [PATCH COLO-Block v6 13/16] quorum: implement block driver interfaces for block replication List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wen Congyang Cc: Kevin Wolf , Fam Zheng , Lai Jiangshan , qemu block , Jiang Yunhong , Dong Eddie , qemu devel , Max Reitz , Alberto Garcia , Gonglei , Stefan Hajnoczi , Paolo Bonzini , Yang Hongyang , "Dr. David Alan Gilbert" , zhanghailiang --rWhLK7VZz0iBluhq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 18, 2015 at 04:49:18PM +0800, Wen Congyang wrote: CCing Alberto Garcia for the quorum block driver. > Signed-off-by: Wen Congyang > Signed-off-by: zhanghailiang > Signed-off-by: Gonglei > --- > block/quorum.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 78 insertions(+) >=20 > diff --git a/block/quorum.c b/block/quorum.c > index 77e55b2..01cfac0 100644 > --- a/block/quorum.c > +++ b/block/quorum.c > @@ -82,6 +82,8 @@ typedef struct BDRVQuorumState { > */ > =20 > QuorumReadPattern read_pattern; > + > + int replication_index; /* store which child supports block replicati= on */ > } BDRVQuorumState; > =20 > typedef struct QuorumAIOCB QuorumAIOCB; > @@ -945,6 +947,7 @@ static int quorum_open(BlockDriverState *bs, QDict *o= ptions, int flags, > } > =20 > g_free(opened); > + s->replication_index =3D -1; > goto exit; > =20 > close_exit: > @@ -1032,6 +1035,77 @@ static void quorum_refresh_filename(BlockDriverSta= te *bs) > bs->full_open_options =3D opts; > } > =20 > +static void quorum_start_replication(BlockDriverState *bs, ReplicationMo= de mode, > + Error **errp) > +{ > + BDRVQuorumState *s =3D bs->opaque; > + int count =3D 0, i, index; > + Error *local_err =3D NULL; > + > + /* > + * TODO: support REPLICATION_MODE_SECONDARY if we allow secondary > + * QEMU becoming primary QEMU. > + */ > + if (mode !=3D REPLICATION_MODE_PRIMARY) { > + error_setg(errp, "Invalid parameter 'mode'"); > + return; > + } > + > + if (s->read_pattern !=3D QUORUM_READ_PATTERN_FIFO) { > + error_setg(errp, "Invalid parameter 'read pattern'"); > + return; > + } > + > + for (i =3D 0; i < s->num_children; i++) { > + bdrv_start_replication(s->bs[i], mode, &local_err); > + if (local_err) { > + error_free(local_err); > + local_err =3D NULL; > + } else { > + count++; > + index =3D i; > + } > + } > + > + if (count =3D=3D 0) { > + /* No child supports block replication */ > + error_setg(errp, "this feature or command is not currently suppo= rted"); > + } else if (count > 1) { > + for (i =3D 0; i < s->num_children; i++) { > + bdrv_stop_replication(s->bs[i], false, NULL); > + } > + error_setg(errp, "too many children support block replication"); > + } else { > + s->replication_index =3D index; > + } > +} > + > +static void quorum_do_checkpoint(BlockDriverState *bs, Error **errp) > +{ > + BDRVQuorumState *s =3D bs->opaque; > + > + if (s->replication_index < 0) { > + error_setg(errp, "Block replication is not started"); > + return; > + } > + > + bdrv_do_checkpoint(s->bs[s->replication_index], errp); > +} > + > +static void quorum_stop_replication(BlockDriverState *bs, bool failover, > + Error **errp) > +{ > + BDRVQuorumState *s =3D bs->opaque; > + > + if (s->replication_index < 0) { > + error_setg(errp, "Block replication is not started"); > + return; > + } > + > + bdrv_stop_replication(s->bs[s->replication_index], failover, errp); > + s->replication_index =3D -1; > +} > + > static BlockDriver bdrv_quorum =3D { > .format_name =3D "quorum", > .protocol_name =3D "quorum", > @@ -1055,6 +1129,10 @@ static BlockDriver bdrv_quorum =3D { > =20 > .is_filter =3D true, > .bdrv_recurse_is_first_non_filter =3D quorum_recurse_is_first_non_= filter, > + > + .bdrv_start_replication =3D quorum_start_replication, > + .bdrv_do_checkpoint =3D quorum_do_checkpoint, > + .bdrv_stop_replication =3D quorum_stop_replication, > }; > =20 > static void bdrv_quorum_init(void) > --=20 > 2.4.3 >=20 >=20 --rWhLK7VZz0iBluhq Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVgsJJAAoJEJykq7OBq3PIBAIIALGZKP8TJ/CAe9nXPXT4C52n DtmIW8CMjsP+FYxY+WLASljE8FEKbcCusvVpscQZMr3LNjVZVVWEg6YfcptL02bx t3CAKuZXo3CM1TQ5P8OQXETFl+pVst75kp/ORp26pkEL5/8Bf1NvA1SxJWHVbehJ TxA+sUSW26rqVj7+VAdBqXmCbf03QDsBi0Ol6deDQ8NrvWT4TOgFOAM04Js7AUjd D9NOxY6B1pIMQjp5jn5SbLqhoP7Ekt2t1Ianu4448uPz4GAW8b72JEw/Wf6rhyi+ 0whsz1YQlCdkhwdANVCW848UQWImeWajN9Cv8j5FhCfj/V9zeW8K3fZz9B+8gf8= =WLw6 -----END PGP SIGNATURE----- --rWhLK7VZz0iBluhq--