From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFomc-0000Rh-5b for qemu-devel@nongnu.org; Tue, 18 Feb 2014 12:48:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFomV-0002RL-Dk for qemu-devel@nongnu.org; Tue, 18 Feb 2014 12:48:38 -0500 Received: from lnantes-156-75-100-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:37935 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFomV-0002Qy-2H for qemu-devel@nongnu.org; Tue, 18 Feb 2014 12:48:31 -0500 Date: Tue, 18 Feb 2014 18:48:27 +0100 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140218174827.GA3877@irqsave.net> References: <1392725487-18330-1-git-send-email-benoit.canet@irqsave.net> <1392725487-18330-12-git-send-email-benoit.canet@irqsave.net> <20140218173708.GA25938@dorilex> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20140218173708.GA25938@dorilex> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V18 11/12] quorum: Add quorum_open() and quorum_close(). List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Leandro Dorileo Cc: Beno??t Canet , kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com The Tuesday 18 Feb 2014 =E0 17:37:08 (+0000), Leandro Dorileo wrote : > On Tue, Feb 18, 2014 at 01:11:26PM +0100, Beno??t Canet wrote: > > From: Beno??t Canet > >=20 > > Example of command line: > >=20 > > -drive if=3Dvirtio,driver=3Dquorum,\ > > children.0.file.filename=3D1.raw,\ > > children.0.node-name=3D1.raw,\ > > children.0.driver=3Draw,\ > > children.1.file.filename=3D2.raw,\ > > children.1.node-name=3D2.raw,\ > > children.1.driver=3Draw,\ > > children.2.file.filename=3D3.raw,\ > > children.2.node-name=3D3.raw,\ > > children.2.driver=3Draw,\ > > vote-threshold=3D2 > >=20 > > blkverify=3Don with vote-threshold=3D2 and two files can be passed to > > emulate blkverify. > >=20 > > Signed-off-by: Benoit Canet > > --- > > block/quorum.c | 161 +++++++++++++++++++++++++++++++++++++++++++++= ++++++++++ > > monitor.c | 3 ++ > > qapi-schema.json | 21 +++++++- > > 3 files changed, 184 insertions(+), 1 deletion(-) > >=20 > > diff --git a/block/quorum.c b/block/quorum.c > > index 40832c0..18721ba 100644 > > --- a/block/quorum.c > > +++ b/block/quorum.c > > @@ -20,6 +20,9 @@ > > =20 > > #define HASH_LENGTH 32 > > =20 > > +#define QUORUM_OPT_VOTE_THRESHOLD "vote-threshold" > > +#define QUORUM_OPT_BLKVERIFY "blkverify" > > + > > /* This union holds a vote hash value */ > > typedef union QuorumVoteValue { > > char h[HASH_LENGTH]; /* SHA-256 hash */ > > @@ -672,12 +675,170 @@ static bool quorum_recurse_is_first_non_filter= (BlockDriverState *bs, > > return false; > > } > > =20 > > +static int quorum_valid_threshold(int threshold, int num_children, E= rror **errp) > > +{ > > + > > + if (threshold < 1) { > > + error_set(errp, QERR_INVALID_PARAMETER_VALUE, > > + "vote-threshold", "value >=3D 1"); > > + return -ERANGE; > > + } > > + > > + if (threshold > num_children) { > > + error_setg(errp, "threshold may not exceed children count"); > > + return -ERANGE; > > + } > > + > > + return 0; > > +} > > + > > +static QemuOptsList quorum_runtime_opts =3D { > > + .name =3D "quorum", > > + .head =3D QTAILQ_HEAD_INITIALIZER(quorum_runtime_opts.head), > > + .desc =3D { > > + { > > + .name =3D QUORUM_OPT_VOTE_THRESHOLD, > > + .type =3D QEMU_OPT_NUMBER, > > + .help =3D "The number of vote needed for reaching quorum= ", > > + }, > > + { > > + .name =3D QUORUM_OPT_BLKVERIFY, > > + .type =3D QEMU_OPT_BOOL, > > + .help =3D "Trigger block verify mode if set", > > + }, > > + { /* end of list */ } > > + }, > > +}; > > + > > +static int quorum_open(BlockDriverState *bs, QDict *options, int fla= gs, > > + Error **errp) > > +{ > > + BDRVQuorumState *s =3D bs->opaque; > > + Error *local_err =3D NULL; > > + QemuOpts *opts; > > + bool *opened; > > + QDict *sub =3D NULL; > > + QList *list =3D NULL; > > + const QListEntry *lentry; > > + const QDictEntry *dentry; > > + int i; > > + int ret =3D 0; > > + > > + qdict_flatten(options); > > + qdict_extract_subqdict(options, &sub, "children."); > > + qdict_array_split(sub, &list); > > + > > + /* count how many different children are present and validate > > + * qdict_size(sub) address the open by reference case > > + */ > > + s->num_children =3D !qlist_size(list) ? qdict_size(sub) : qlist_= size(list); > > + if (s->num_children < 2) { > > + error_setg(&local_err, > > + "Number of provided children must be greater than= 1"); > > + ret =3D -EINVAL; > > + goto exit; > > + } > > + > > + opts =3D qemu_opts_create(&quorum_runtime_opts, NULL, 0, &error_= abort); > > + qemu_opts_absorb_qdict(opts, options, &local_err); > > + if (error_is_set(&local_err)) { > > + ret =3D -EINVAL; > > + goto exit; > > + } > > + > > + s->threshold =3D qemu_opt_get_number(opts, QUORUM_OPT_VOTE_THRES= HOLD, 0); > > + > > + /* and validate it against s->num_children */ > > + ret =3D quorum_valid_threshold(s->threshold, s->num_children, &l= ocal_err); > > + if (ret < 0) { > > + goto exit; > > + } > > + > > + /* is the driver in blkverify mode */ > > + if (qemu_opt_get_bool(opts, QUORUM_OPT_BLKVERIFY, false) && > > + s->num_children =3D=3D 2 && s->threshold =3D=3D 2) { > > + s->is_blkverify =3D true; > > + } else if (qemu_opt_get_bool(opts, QUORUM_OPT_BLKVERIFY, false))= { > > + fprintf(stderr, "blkverify mode is set by setting blkverify=3D= on " > > + "and using two files with vote_threshold=3D2\n"); > > + } > > + > > + /* allocate the children BlockDriverState array */ > > + s->bs =3D g_new0(BlockDriverState *, s->num_children); > > + opened =3D g_new0(bool, s->num_children); > > + > > + /* Open by file name or options dict (command line or QMP) */ > > + if (s->num_children =3D=3D qlist_size(list)) { > > + for (i =3D 0, lentry =3D qlist_first(list); lentry; > > + lentry =3D qlist_next(lentry), i++) { > > + QDict *d =3D qobject_to_qdict(lentry->value); > > + QINCREF(d); > > + ret =3D bdrv_open(&s->bs[i], NULL, NULL, d, flags, NULL,= &local_err); >=20 >=20 > Shouldn't this bdrv_open call be? >=20 > ret =3D bdrv_open(s->bs[i], NULL, d, flags, NULL, &local_err); >=20 >=20 > > + if (ret < 0) { > > + goto close_exit; > > + } > > + opened[i] =3D true; > > + } > > + /* Open by QMP references */ > > + } else { > > + for (i =3D 0, dentry =3D qdict_first(sub); dentry; > > + dentry =3D qdict_next(sub, dentry), i++) { > > + QString *string =3D qobject_to_qstring(dentry->value); > > + ret =3D bdrv_open(&s->bs[i], NULL, qstring_get_str(strin= g), NULL, > > + flags, NULL, &local_err); >=20 >=20 > This other bdrv_open() call seems to be not right as well, I think it s= hould be: >=20 > ret =3D bdrv_open(s->bs[i], qstring_get_str(string), NULL, > flags, NULL, &local_err); These calls use the new syntax of bdrv_open based on the "[PATCH v4 0/8] block: Integrate bdrv_file_open() into bdrv_open()" serie= s by Max Reitz. Best regards Beno=EEt >=20 >=20 >=20 > > + if (ret < 0) { > > + goto close_exit; > > + } > > + opened[i] =3D true; > > + } > > + } > > + > > + g_free(opened); > > + goto exit; > > + > > +close_exit: > > + /* cleanup on error */ > > + for (i =3D 0; i < s->num_children; i++) { > > + if (!opened[i]) { > > + continue; > > + } > > + bdrv_unref(s->bs[i]); > > + } > > + g_free(s->bs); > > + g_free(opened); > > +exit: > > + /* propagate error */ > > + if (error_is_set(&local_err)) { > > + error_propagate(errp, local_err); > > + } > > + QDECREF(list); > > + QDECREF(sub); > > + return ret; > > +} > > + > > +static void quorum_close(BlockDriverState *bs) > > +{ > > + BDRVQuorumState *s =3D bs->opaque; > > + int i; > > + > > + for (i =3D 0; i < s->num_children; i++) { > > + bdrv_unref(s->bs[i]); > > + } > > + > > + g_free(s->bs); > > +} > > + > > static BlockDriver bdrv_quorum =3D { > > .format_name =3D "quorum", > > .protocol_name =3D "quorum", > > =20 > > .instance_size =3D sizeof(BDRVQuorumState), > > =20 > > + .bdrv_file_open =3D quorum_open, > > + .bdrv_close =3D quorum_close, > > + > > + .authorizations =3D { true, true }, > > + > > .bdrv_co_flush_to_disk =3D quorum_co_flush, > > =20 > > .bdrv_getlength =3D quorum_getlength, > > diff --git a/monitor.c b/monitor.c > > index 81ffa0f..ed5bb98 100644 > > --- a/monitor.c > > +++ b/monitor.c > > @@ -639,6 +639,9 @@ static void monitor_protocol_event_init(void) > > monitor_protocol_event_throttle(QEVENT_RTC_CHANGE, 1000); > > monitor_protocol_event_throttle(QEVENT_BALLOON_CHANGE, 1000); > > monitor_protocol_event_throttle(QEVENT_WATCHDOG, 1000); > > + /* limit the rate of quorum events to avoid hammering the manage= ment */ > > + monitor_protocol_event_throttle(QEVENT_QUORUM_REPORT_BAD, 1000); > > + monitor_protocol_event_throttle(QEVENT_QUORUM_FAILURE, 1000); > > } > > =20 > > /** > > diff --git a/qapi-schema.json b/qapi-schema.json > > index 7cfb5e5..990d0c5 100644 > > --- a/qapi-schema.json > > +++ b/qapi-schema.json > > @@ -4352,6 +4352,24 @@ > > 'raw': 'BlockdevRef' } } > > =20 > > ## > > +# @BlockdevOptionsQuorum > > +# > > +# Driver specific block device options for Quorum > > +# > > +# @blkverify: #optional true if the driver must print content m= ismatch > > +# > > +# @children: the children block device to use > > +# > > +# @vote_threshold: the vote limit under which a read will fail > > +# > > +# Since: 2.0 > > +## > > +{ 'type': 'BlockdevOptionsQuorum', > > + 'data': { '*blkverify': 'bool', > > + 'children': [ 'BlockdevRef' ], > > + 'vote-threshold': 'int' } } > > + > > +## > > # @BlockdevOptions > > # > > # Options for creating a block device. > > @@ -4390,7 +4408,8 @@ > > 'vdi': 'BlockdevOptionsGenericFormat', > > 'vhdx': 'BlockdevOptionsGenericFormat', > > 'vmdk': 'BlockdevOptionsGenericCOWFormat', > > - 'vpc': 'BlockdevOptionsGenericFormat' > > + 'vpc': 'BlockdevOptionsGenericFormat', > > + 'quorum': 'BlockdevOptionsQuorum' > > } } > > =20 > > ## > > --=20 > > 1.8.3.2 > >=20 > >=20 >=20 > --=20 > Leandro Dorileo