From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIlLZ-0004a5-6d for qemu-devel@nongnu.org; Sat, 16 Aug 2014 17:17:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIlLR-0003uL-Gj for qemu-devel@nongnu.org; Sat, 16 Aug 2014 17:17:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50208) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIlLR-0003uG-6t for qemu-devel@nongnu.org; Sat, 16 Aug 2014 17:17:01 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7GLH0kq011423 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 16 Aug 2014 17:17:00 -0400 From: Max Reitz Date: Sat, 16 Aug 2014 23:16:51 +0200 Message-Id: <1408223814-23999-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1408223814-23999-1-git-send-email-mreitz@redhat.com> References: <1408223814-23999-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 1/4] qcow2: Add qcow2_signal_corruption() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Add a helper function for easily marking an image corrupt while outputting an informative message to stderr and via QAPI. Signed-off-by: Max Reitz --- block/qcow2.c | 28 ++++++++++++++++++++++++++++ block/qcow2.h | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 435e0e1..ef2c931 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" @@ -2378,6 +2380,32 @@ static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts) return 0; } +void qcow2_signal_corruption(BlockDriverState *bs, int64_t offset, int64_t size, + const char *message_format, ...) +{ + char *message; + va_list ap; + + va_start(ap, message_format); + message = g_strdup_vprintf(message_format, ap); + va_end(ap); + + if (bs->read_only) { + fprintf(stderr, "qcow2: Image is corrupt: %s\n", message); + } else { + fprintf(stderr, "qcow2: Marking image as corrupt: %s\n", message); + qapi_event_send_block_image_corrupted(bdrv_get_device_name(bs), message, + offset >= 0, offset, + size >= 0, size, &error_abort); + } + g_free(message); + + if (!bs->read_only) { + qcow2_mark_corrupt(bs); + bs->drv = NULL; /* make BDS unusable */ + } +} + static QemuOptsList qcow2_create_opts = { .name = "qcow2-create-opts", .head = QTAILQ_HEAD_INITIALIZER(qcow2_create_opts.head), diff --git a/block/qcow2.h b/block/qcow2.h index b49424b..f66238e 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -468,6 +468,10 @@ int qcow2_mark_corrupt(BlockDriverState *bs); int qcow2_mark_consistent(BlockDriverState *bs); int qcow2_update_header(BlockDriverState *bs); +void qcow2_signal_corruption(BlockDriverState *bs, int64_t offset, int64_t size, + const char *message_format, ...) + GCC_FMT_ATTR(4, 5); + /* qcow2-refcount.c functions */ int qcow2_refcount_init(BlockDriverState *bs); void qcow2_refcount_close(BlockDriverState *bs); -- 2.0.4