From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XQzkR-0000T7-E9 for qemu-devel@nongnu.org; Mon, 08 Sep 2014 10:16:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XQzkM-0001Qa-B6 for qemu-devel@nongnu.org; Mon, 08 Sep 2014 10:16:51 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:59670 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XQzkM-0001QK-0x for qemu-devel@nongnu.org; Mon, 08 Sep 2014 10:16:46 -0400 Date: Mon, 8 Sep 2014 16:15:53 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140908141553.GD22582@irqsave.net> References: <1409926039-29044-1-git-send-email-mreitz@redhat.com> <1409926039-29044-3-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1409926039-29044-3-git-send-email-mreitz@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 2/5] qcow2: Add qcow2_signal_corruption() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi The Friday 05 Sep 2014 =E0 16:07:16 (+0200), Max Reitz wrote : > Add a helper function for easily marking an image corrupt (on fatal > corruptions) while outputting an informative message to stderr and via > QAPI. >=20 > Signed-off-by: Max Reitz > --- > block/qcow2.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ > block/qcow2.h | 5 +++++ > 2 files changed, 53 insertions(+) >=20 > diff --git a/block/qcow2.c b/block/qcow2.c > index f9e045f..fc4217b 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -30,6 +30,8 @@ > #include "qemu/error-report.h" > #include "qapi/qmp/qerror.h" > #include "qapi/qmp/qbool.h" > +#include "qapi/qmp/types.h" > +#include "qapi-event.h" > #include "trace.h" > #include "qemu/option_int.h" > =20 > @@ -2478,6 +2480,52 @@ static int qcow2_amend_options(BlockDriverState = *bs, QemuOpts *opts) > return 0; > } > =20 > +/* > + * If offset or size are negative, respectively, they will not be incl= uded in > + * the BLOCK_IMAGE_CORRUPTED event emitted. > + * fatal will be ignored for read-only BDS; corruptions found there wi= ll always > + * be considered non-fatal. > + */ > +void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t= offset, > + int64_t size, const char *message_format,= ...) > +{ > + BDRVQcowState *s =3D bs->opaque; > + char *message; > + va_list ap; > + > + fatal =3D fatal && !bs->read_only; > + > + if (s->signaled_corruption && > + (!fatal || (s->incompatible_features & QCOW2_INCOMPAT_CORRUPT)= )) > + { > + return; > + } > + > + va_start(ap, message_format); > + message =3D g_strdup_vprintf(message_format, ap); > + va_end(ap); > + > + if (fatal) { > + fprintf(stderr, "qcow2: Marking image as corrupt: %s; further = " > + "corruption events will be suppressed\n", message); > + } else { > + fprintf(stderr, "qcow2: Image is corrupt: %s; further non-fata= l " > + "corruption events will be suppressed\n", message); > + } > + > + qapi_event_send_block_image_corrupted(bdrv_get_device_name(bs), me= ssage, > + offset >=3D 0, offset, size = >=3D 0, size, > + fatal, &error_abort); > + g_free(message); > + > + if (fatal) { > + qcow2_mark_corrupt(bs); > + bs->drv =3D NULL; /* make BDS unusable */ > + } > + > + s->signaled_corruption =3D true; > +} > + > static QemuOptsList qcow2_create_opts =3D { > .name =3D "qcow2-create-opts", > .head =3D QTAILQ_HEAD_INITIALIZER(qcow2_create_opts.head), > diff --git a/block/qcow2.h b/block/qcow2.h > index 6aeb7ea..7b7b6a6 100644 > --- a/block/qcow2.h > +++ b/block/qcow2.h > @@ -261,6 +261,7 @@ typedef struct BDRVQcowState { > bool discard_passthrough[QCOW2_DISCARD_MAX]; > =20 > int overlap_check; /* bitmask of Qcow2MetadataOverlap values */ > + bool signaled_corruption; > =20 > uint64_t incompatible_features; > uint64_t compatible_features; > @@ -477,6 +478,10 @@ int qcow2_mark_corrupt(BlockDriverState *bs); > int qcow2_mark_consistent(BlockDriverState *bs); > int qcow2_update_header(BlockDriverState *bs); > =20 > +void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t= offset, > + int64_t size, const char *message_format,= ...) > + GCC_FMT_ATTR(5, 6); > + > /* qcow2-refcount.c functions */ > int qcow2_refcount_init(BlockDriverState *bs); > void qcow2_refcount_close(BlockDriverState *bs); > --=20 > 2.1.0 >=20 >=20 Reviewed-by: Beno=EEt Canet