Am 16.08.2014 um 23:16 hat Max Reitz geschrieben:
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 <address@hidden>
---
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);
The BDS isn't made unusable in read-only mode, so we can produce quite a
lot of these messages and fill up the log. Perhaps it would be better to
print the message only the first time (or the first n times) and then
tell the user that further errors won't be logged.
Also, including the block device or file name (or both) wouldn't hurt.