From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5Zbe-0007oF-Fk for qemu-devel@nongnu.org; Thu, 18 Jun 2015 09:11:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5Zbb-0008Ke-6K for qemu-devel@nongnu.org; Thu, 18 Jun 2015 09:11:46 -0400 Date: Thu, 18 Jun 2015 14:06:39 +0100 From: Stefan Hajnoczi Message-ID: <20150618130639.GG25387@stefanha-thinkpad.redhat.com> References: <1434617361-17778-1-git-send-email-wency@cn.fujitsu.com> <1434617361-17778-16-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="L+ofChggJdETEG3Y" Content-Disposition: inline In-Reply-To: <1434617361-17778-16-git-send-email-wency@cn.fujitsu.com> Subject: Re: [Qemu-devel] [PATCH COLO-Block v6 15/16] quorum: allow ignoring child errors 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 --L+ofChggJdETEG3Y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 18, 2015 at 04:49:20PM +0800, Wen Congyang wrote: CCing Alberto Garcia for the quorum block driver. > If the child is not ready, read/write/getlength/flush will > return -errno. It is not critical error, and can be ignored: > 1. read/write: > Just not report the error event. > 2. getlength: > just ignore it. If all children's getlength return -errno, > and be ignored, return -EIO. > 3. flush: > Just ignore it. If all children's getlength return -errno, > and be ignored, return 0. >=20 > Usage: children.x.ignore-errors=3Dtrue >=20 > Signed-off-by: Wen Congyang > Signed-off-by: zhanghailiang > Signed-off-by: Gonglei > --- > block/quorum.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +----- > 1 file changed, 77 insertions(+), 7 deletions(-) >=20 > diff --git a/block/quorum.c b/block/quorum.c > index 01cfac0..c5dbb69 100644 > --- a/block/quorum.c > +++ b/block/quorum.c > @@ -30,6 +30,7 @@ > #define QUORUM_OPT_BLKVERIFY "blkverify" > #define QUORUM_OPT_REWRITE "rewrite-corrupted" > #define QUORUM_OPT_READ_PATTERN "read-pattern" > +#define QUORUM_CHILDREN_OPT_IGNORE_ERRORS "ignore-errors" > =20 > /* This union holds a vote hash value */ > typedef union QuorumVoteValue { > @@ -65,6 +66,7 @@ typedef struct QuorumVotes { > /* the following structure holds the state of one quorum instance */ > typedef struct BDRVQuorumState { > BlockDriverState **bs; /* children BlockDriverStates */ > + bool *ignore_errors; /* ignore children's error? */ > int num_children; /* children count */ > int threshold; /* if less than threshold children reads gave= the > * same result a quorum error occurs. > @@ -99,6 +101,7 @@ typedef struct QuorumChildRequest { > uint8_t *buf; > int ret; > QuorumAIOCB *parent; > + int index; > } QuorumChildRequest; > =20 > /* Quorum will use the following structure to track progress of each rea= d/write > @@ -211,6 +214,7 @@ static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s, > acb->qcrs[i].buf =3D NULL; > acb->qcrs[i].ret =3D 0; > acb->qcrs[i].parent =3D acb; > + acb->qcrs[i].index =3D i; > } > =20 > return acb; > @@ -304,7 +308,7 @@ static void quorum_aio_cb(void *opaque, int ret) > acb->count++; > if (ret =3D=3D 0) { > acb->success_count++; > - } else { > + } else if (!s->ignore_errors[sacb->index]) { > quorum_report_bad(acb, sacb->aiocb->bs->node_name, ret); > } > assert(acb->count <=3D s->num_children); > @@ -719,19 +723,31 @@ static BlockAIOCB *quorum_aio_writev(BlockDriverSta= te *bs, > static int64_t quorum_getlength(BlockDriverState *bs) > { > BDRVQuorumState *s =3D bs->opaque; > - int64_t result; > + int64_t result =3D -EIO; > int i; > =20 > /* check that all file have the same length */ > - result =3D bdrv_getlength(s->bs[0]); > - if (result < 0) { > - return result; > - } > - for (i =3D 1; i < s->num_children; i++) { > + for (i =3D 0; i < s->num_children; i++) { > int64_t value =3D bdrv_getlength(s->bs[i]); > + > if (value < 0) { > return value; > } > + > + if (value =3D=3D 0 && s->ignore_errors[i]) { > + /* > + * If the child is not ready, it cannot return -errno, > + * otherwise refresh_total_sectors() will fail when > + * we open the child. > + */ > + continue; > + } > + > + if (result =3D=3D -EIO) { > + result =3D value; > + continue; > + } > + > if (value !=3D result) { > return -EIO; > } > @@ -769,6 +785,9 @@ static coroutine_fn int quorum_co_flush(BlockDriverSt= ate *bs) > =20 > for (i =3D 0; i < s->num_children; i++) { > result =3D bdrv_co_flush(s->bs[i]); > + if (result < 0 && s->ignore_errors[i]) { > + result =3D 0; > + } > result_value.l =3D result; > quorum_count_vote(&error_votes, &result_value, i); > } > @@ -843,6 +862,19 @@ static QemuOptsList quorum_runtime_opts =3D { > }, > }; > =20 > +static QemuOptsList quorum_children_common_opts =3D { > + .name =3D "quorum children", > + .head =3D QTAILQ_HEAD_INITIALIZER(quorum_children_common_opts.head), > + .desc =3D { > + { > + .name =3D QUORUM_CHILDREN_OPT_IGNORE_ERRORS, > + .type =3D QEMU_OPT_BOOL, > + .help =3D "ignore child I/O error", > + }, > + { /* end of list */ } > + }, > +}; > + > static int parse_read_pattern(const char *opt) > { > int i; > @@ -861,6 +893,37 @@ static int parse_read_pattern(const char *opt) > return -EINVAL; > } > =20 > +static int parse_children_options(BDRVQuorumState *s, QDict *options, > + const char *indexstr, int index, > + Error **errp) > +{ > + QemuOpts *children_opts =3D NULL; > + Error *local_err =3D NULL; > + int ret =3D 0; > + bool value; > + > + children_opts =3D qemu_opts_create(&quorum_children_common_opts, NUL= L, 0, > + &error_abort); > + qemu_opts_absorb_qdict_by_index(children_opts, options, indexstr, > + &local_err); > + if (local_err) { > + ret =3D -EINVAL; > + goto out; > + } > + > + value =3D qemu_opt_get_bool(children_opts, QUORUM_CHILDREN_OPT_IGNOR= E_ERRORS, > + false); > + s->ignore_errors[index] =3D value; > + > +out: > + qemu_opts_del(children_opts); > + /* propagate error */ > + if (local_err) { > + error_propagate(errp, local_err); > + } > + return ret; > +} > + > static int quorum_open(BlockDriverState *bs, QDict *options, int flags, > Error **errp) > { > @@ -931,12 +994,18 @@ static int quorum_open(BlockDriverState *bs, QDict = *options, int flags, > /* allocate the children BlockDriverState array */ > s->bs =3D g_new0(BlockDriverState *, s->num_children); > opened =3D g_new0(bool, s->num_children); > + s->ignore_errors =3D g_new0(bool, s->num_children); > =20 > for (i =3D 0; i < s->num_children; i++) { > char indexstr[32]; > ret =3D snprintf(indexstr, 32, "children.%d", i); > assert(ret < 32); > =20 > + ret =3D parse_children_options(s, options, indexstr, i, &local_e= rr); > + if (ret < 0) { > + goto close_exit; > + } > + > ret =3D bdrv_open_image(&s->bs[i], NULL, options, indexstr, bs, > &child_format, false, &local_err); > if (ret < 0) { > @@ -979,6 +1048,7 @@ static void quorum_close(BlockDriverState *bs) > } > =20 > g_free(s->bs); > + g_free(s->ignore_errors); > } > =20 > static void quorum_detach_aio_context(BlockDriverState *bs) > --=20 > 2.4.3 >=20 >=20 --L+ofChggJdETEG3Y Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVgsJfAAoJEJykq7OBq3PIC4kIAL3ScbvLirSOr7bsY0uJ4Pzb SViFEFbPN3ucPeRoMj5DUGDNg2wWmNpZKwXQVevmgEsaXcA9ZfwVTYJxKljk+K6E +BrFhpdf3uYLMs389qH/nsdemgJAIMMkxk1/nnhzfducXtKr/URAxLvYHVmXYaFZ bjnRPhXA3a69zkdEBv1KfosriqfWurU+wqEQtm6LPhW9DTe10VkelqKm8KWiEpw+ aWdC7M15esFJpa42l+BWkWkH9094EHx6QVKwZrmu2z2sy6oqNCZiz4g367NhG3HX L3/rj5o8A3BRmaXsji/o6S2eus99Dy/jQ7FOspUsVSSuPmoHsWtFGWcnWPJc/tk= =Urx9 -----END PGP SIGNATURE----- --L+ofChggJdETEG3Y--