|
|
9ae3a8 |
From f262d114ddfe11bad7b2f109cb965873f132f74e Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Date: Sat, 13 Jun 2015 16:22:02 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 08/42] qcow2: Add qcow2_signal_corruption()
|
|
|
9ae3a8 |
MIME-Version: 1.0
|
|
|
9ae3a8 |
Content-Type: text/plain; charset=UTF-8
|
|
|
9ae3a8 |
Content-Transfer-Encoding: 8bit
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Message-id: <1434212556-3927-9-git-send-email-mreitz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 66027
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.2 qemu-kvm PATCH 08/42] qcow2: Add qcow2_signal_corruption()
|
|
|
9ae3a8 |
Bugzilla: 1129893
|
|
|
9ae3a8 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
BZ: 1129893
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Add a helper function for easily marking an image corrupt (on fatal
|
|
|
9ae3a8 |
corruptions) while outputting an informative message to stderr and via
|
|
|
9ae3a8 |
QAPI.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: BenoƮt Canet <benoit.canet@nodalink.com>
|
|
|
9ae3a8 |
Message-id: 1409926039-29044-3-git-send-email-mreitz@redhat.com
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 85186ebdac7e183242deaa55d5049988de832be1)
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
block/qcow2.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
No qapi_event_send_*() downstream.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/qcow2.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
block/qcow2.h | 5 +++++
|
|
|
9ae3a8 |
2 files changed, 67 insertions(+)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/qcow2.c b/block/qcow2.c
|
|
|
9ae3a8 |
index 6026f8a..be7e8e8 100644
|
|
|
9ae3a8 |
--- a/block/qcow2.c
|
|
|
9ae3a8 |
+++ b/block/qcow2.c
|
|
|
9ae3a8 |
@@ -31,6 +31,8 @@
|
|
|
9ae3a8 |
#include "qapi/qmp/qerror.h"
|
|
|
9ae3a8 |
#include "qapi/qmp/qbool.h"
|
|
|
9ae3a8 |
#include "qapi/util.h"
|
|
|
9ae3a8 |
+#include "qapi/qmp/types.h"
|
|
|
9ae3a8 |
+#include "monitor/monitor.h"
|
|
|
9ae3a8 |
#include "trace.h"
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/*
|
|
|
9ae3a8 |
@@ -2329,6 +2331,66 @@ static int qcow2_amend_options(BlockDriverState *bs,
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * If offset or size are negative, respectively, they will not be included in
|
|
|
9ae3a8 |
+ * the BLOCK_IMAGE_CORRUPTED event emitted.
|
|
|
9ae3a8 |
+ * fatal will be ignored for read-only BDS; corruptions found there will always
|
|
|
9ae3a8 |
+ * be considered non-fatal.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
|
|
|
9ae3a8 |
+ int64_t size, const char *message_format, ...)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BDRVQcowState *s = bs->opaque;
|
|
|
9ae3a8 |
+ char *message;
|
|
|
9ae3a8 |
+ QObject *data;
|
|
|
9ae3a8 |
+ va_list ap;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ fatal = fatal && !bs->read_only;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (s->signaled_corruption &&
|
|
|
9ae3a8 |
+ (!fatal || (s->incompatible_features & QCOW2_INCOMPAT_CORRUPT)))
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ va_start(ap, message_format);
|
|
|
9ae3a8 |
+ message = g_strdup_vprintf(message_format, ap);
|
|
|
9ae3a8 |
+ va_end(ap);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (fatal) {
|
|
|
9ae3a8 |
+ fprintf(stderr, "qcow2: Marking image as corrupt: %s; further "
|
|
|
9ae3a8 |
+ "corruption events will be suppressed\n", message);
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ fprintf(stderr, "qcow2: Image is corrupt: %s; further non-fatal "
|
|
|
9ae3a8 |
+ "corruption events will be suppressed\n", message);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ assert((offset >= 0) == (size >= 0));
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (offset >= 0) {
|
|
|
9ae3a8 |
+ data = qobject_from_jsonf("{ 'device': %s, 'msg': %s, 'offset': %"
|
|
|
9ae3a8 |
+ PRId64 ", 'size': %" PRId64 ", 'fatal': %s }",
|
|
|
9ae3a8 |
+ bdrv_get_device_name(bs), message,
|
|
|
9ae3a8 |
+ offset, size, fatal ? "true" : "false");
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ data = qobject_from_jsonf("{ 'device': %s, 'msg': %s, 'fatal': %s }",
|
|
|
9ae3a8 |
+ bdrv_get_device_name(bs), message,
|
|
|
9ae3a8 |
+ fatal ? "true" : "false");
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ monitor_protocol_event(QEVENT_BLOCK_IMAGE_CORRUPTED, data);
|
|
|
9ae3a8 |
+ qobject_decref(data);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ g_free(message);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (fatal) {
|
|
|
9ae3a8 |
+ qcow2_mark_corrupt(bs);
|
|
|
9ae3a8 |
+ bs->drv = NULL; /* make BDS unusable */
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ s->signaled_corruption = true;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
static QEMUOptionParameter qcow2_create_options[] = {
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
.name = BLOCK_OPT_SIZE,
|
|
|
9ae3a8 |
diff --git a/block/qcow2.h b/block/qcow2.h
|
|
|
9ae3a8 |
index e958ab4..2138462 100644
|
|
|
9ae3a8 |
--- a/block/qcow2.h
|
|
|
9ae3a8 |
+++ b/block/qcow2.h
|
|
|
9ae3a8 |
@@ -252,6 +252,7 @@ typedef struct BDRVQcowState {
|
|
|
9ae3a8 |
bool discard_passthrough[QCOW2_DISCARD_MAX];
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
int overlap_check; /* bitmask of Qcow2MetadataOverlap values */
|
|
|
9ae3a8 |
+ bool signaled_corruption;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
uint64_t incompatible_features;
|
|
|
9ae3a8 |
uint64_t compatible_features;
|
|
|
9ae3a8 |
@@ -468,6 +469,10 @@ int qcow2_mark_corrupt(BlockDriverState *bs);
|
|
|
9ae3a8 |
int qcow2_mark_consistent(BlockDriverState *bs);
|
|
|
9ae3a8 |
int qcow2_update_header(BlockDriverState *bs);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
|
|
|
9ae3a8 |
+ int64_t size, const char *message_format, ...)
|
|
|
9ae3a8 |
+ GCC_FMT_ATTR(5, 6);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
/* qcow2-refcount.c functions */
|
|
|
9ae3a8 |
int qcow2_refcount_init(BlockDriverState *bs);
|
|
|
9ae3a8 |
void qcow2_refcount_close(BlockDriverState *bs);
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|