cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-vhdx-improve-error-message-and-.bdrv_check-imp.patch

0a122b
From ef9c4188157e2349ff68710982d9922f4a335b82 Mon Sep 17 00:00:00 2001
0a122b
From: Jeffrey Cody <jcody@redhat.com>
0a122b
Date: Mon, 13 Jan 2014 20:52:04 +0100
0a122b
Subject: [PATCH 12/16] block: vhdx - improve error message, and .bdrv_check implementation
0a122b
0a122b
RH-Author: Jeffrey Cody <jcody@redhat.com>
0a122b
Message-id: <f13406a07edd6ca0f7c7c5a9f87c0376dc4c1663.1389634483.git.jcody@redhat.com>
0a122b
Patchwork-id: 56643
0a122b
O-Subject: [RHEL7 qemu-kvm PATCH] block: vhdx - improve error message, and .bdrv_check implementation
0a122b
Bugzilla: 1035001
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
0a122b
If there is a dirty log file to be replayed in a VHDX image, it is
0a122b
replayed in .vhdx_open().  However, if the file is opened read-only,
0a122b
then a somewhat cryptic error message results.
0a122b
0a122b
This adds a more helpful error message for the user.  If an image file
0a122b
contains a log to be replayed, and is opened read-only, the user is
0a122b
instructed to run 'qemu-img check -r all' on the image file.
0a122b
0a122b
Running qemu-img check -r all will cause the image file to be opened
0a122b
r/w, which will replay the log file.  If a log file replay is detected,
0a122b
this is flagged, and bdrv_check will increase the corruptions_fixed
0a122b
count for the image.
0a122b
0a122b
[Fixed typo in error message that was pointed out by Eric Blake
0a122b
<eblake@redhat.com>.
0a122b
--Stefan]
0a122b
0a122b
Signed-off-by: Jeff Cody <jcody@redhat.com>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit 7e30e6a6746b417c7e0dbc9af009560fbb63f336)
0a122b
0a122b
Conflicts:
0a122b
	block/vhdx.c
0a122b
0a122b
RHEL7 Notes:  Conflict due to different order of members in the
0a122b
              BlockDriver struct.  Resolved so that the order matches
0a122b
              what is upstream.
0a122b
0a122b
BZ 1035001
0a122b
Brew: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=6861970
0a122b
0a122b
Signed-off-by: Jeff Cody <jcody@redhat.com>
0a122b
---
0a122b
 block/vhdx-log.c | 13 ++++++++++++-
0a122b
 block/vhdx.c     | 25 ++++++++++++++++++++++---
0a122b
 block/vhdx.h     |  5 ++++-
0a122b
 3 files changed, 38 insertions(+), 5 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 block/vhdx-log.c |   13 ++++++++++++-
0a122b
 block/vhdx.c     |   25 ++++++++++++++++++++++---
0a122b
 block/vhdx.h     |    5 ++++-
0a122b
 3 files changed, 38 insertions(+), 5 deletions(-)
0a122b
0a122b
diff --git a/block/vhdx-log.c b/block/vhdx-log.c
0a122b
index ee5583c..8c9ae0d 100644
0a122b
--- a/block/vhdx-log.c
0a122b
+++ b/block/vhdx-log.c
0a122b
@@ -706,7 +706,8 @@ exit:
0a122b
  *
0a122b
  * If read-only, we must replay the log in RAM (or refuse to open
0a122b
  * a dirty VHDX file read-only) */
0a122b
-int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed)
0a122b
+int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed,
0a122b
+                   Error **errp)
0a122b
 {
0a122b
     int ret = 0;
0a122b
     VHDXHeader *hdr;
0a122b
@@ -761,6 +762,16 @@ int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed)
0a122b
     }
0a122b
 
0a122b
     if (logs.valid) {
0a122b
+        if (bs->read_only) {
0a122b
+            ret = -EPERM;
0a122b
+            error_setg_errno(errp, EPERM,
0a122b
+                             "VHDX image file '%s' opened read-only, but "
0a122b
+                             "contains a log that needs to be replayed.  To "
0a122b
+                             "replay the log, execute:\n qemu-img check -r "
0a122b
+                             "all '%s'",
0a122b
+                             bs->filename, bs->filename);
0a122b
+            goto exit;
0a122b
+        }
0a122b
         /* now flush the log */
0a122b
         ret = vhdx_log_flush(bs, s, &logs);
0a122b
         if (ret < 0) {
0a122b
diff --git a/block/vhdx.c b/block/vhdx.c
0a122b
index 8e3b371..8b1a5c9 100644
0a122b
--- a/block/vhdx.c
0a122b
+++ b/block/vhdx.c
0a122b
@@ -878,7 +878,6 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
     int ret = 0;
0a122b
     uint32_t i;
0a122b
     uint64_t signature;
0a122b
-    bool log_flushed = false;
0a122b
 
0a122b
 
0a122b
     s->bat = NULL;
0a122b
@@ -907,7 +906,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
         goto fail;
0a122b
     }
0a122b
 
0a122b
-    ret = vhdx_parse_log(bs, s, &log_flushed);
0a122b
+    ret = vhdx_parse_log(bs, s, &s->log_replayed_on_open, errp);
0a122b
     if (ret < 0) {
0a122b
         goto fail;
0a122b
     }
0a122b
@@ -1854,6 +1853,24 @@ exit:
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
+/* If opened r/w, the VHDX driver will automatically replay the log,
0a122b
+ * if one is present, inside the vhdx_open() call.
0a122b
+ *
0a122b
+ * If qemu-img check -r all is called, the image is automatically opened
0a122b
+ * r/w and any log has already been replayed, so there is nothing (currently)
0a122b
+ * for us to do here
0a122b
+ */
0a122b
+static int vhdx_check(BlockDriverState *bs, BdrvCheckResult *result,
0a122b
+                       BdrvCheckMode fix)
0a122b
+{
0a122b
+    BDRVVHDXState *s = bs->opaque;
0a122b
+
0a122b
+    if (s->log_replayed_on_open) {
0a122b
+        result->corruptions_fixed++;
0a122b
+    }
0a122b
+    return 0;
0a122b
+}
0a122b
+
0a122b
 static QEMUOptionParameter vhdx_create_options[] = {
0a122b
     {
0a122b
         .name = BLOCK_OPT_SIZE,
0a122b
@@ -1896,8 +1913,10 @@ static BlockDriver bdrv_vhdx = {
0a122b
     .bdrv_reopen_prepare    = vhdx_reopen_prepare,
0a122b
     .bdrv_co_readv          = vhdx_co_readv,
0a122b
     .bdrv_co_writev         = vhdx_co_writev,
0a122b
-    .bdrv_get_info          = vhdx_get_info,
0a122b
     .bdrv_create            = vhdx_create,
0a122b
+    .bdrv_get_info          = vhdx_get_info,
0a122b
+    .bdrv_check             = vhdx_check,
0a122b
+
0a122b
     .create_options         = vhdx_create_options,
0a122b
 };
0a122b
 
0a122b
diff --git a/block/vhdx.h b/block/vhdx.h
0a122b
index 365eca0..469e95c 100644
0a122b
--- a/block/vhdx.h
0a122b
+++ b/block/vhdx.h
0a122b
@@ -394,6 +394,8 @@ typedef struct BDRVVHDXState {
0a122b
 
0a122b
     Error *migration_blocker;
0a122b
 
0a122b
+    bool log_replayed_on_open;
0a122b
+
0a122b
     QLIST_HEAD(VHDXRegionHead, VHDXRegionEntry) regions;
0a122b
 } BDRVVHDXState;
0a122b
 
0a122b
@@ -408,7 +410,8 @@ uint32_t vhdx_checksum_calc(uint32_t crc, uint8_t *buf, size_t size,
0a122b
 
0a122b
 bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, int crc_offset);
0a122b
 
0a122b
-int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed);
0a122b
+int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed,
0a122b
+                   Error **errp);
0a122b
 
0a122b
 int vhdx_log_write_and_flush(BlockDriverState *bs, BDRVVHDXState *s,
0a122b
                              void *data, uint32_t length, uint64_t offset);
0a122b
-- 
0a122b
1.7.1
0a122b