cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From c5321890678045bf4de3b1845110aeed348203b9 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Mon, 4 Nov 2013 22:32:34 +0100
9ae3a8
Subject: [PATCH 41/87] qcow2: Evaluate overlap check options
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383604354-12743-44-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55343
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 43/43] qcow2: Evaluate overlap check options
9ae3a8
Bugzilla: 1004347
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
BZ: 1004347
9ae3a8
9ae3a8
Evaluate the runtime overlap check options and set
9ae3a8
BDRVQcowState.overlap_check appropriately.
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 1fa5cc839aa6068c9182ad8d611f844c58f95f42)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 block/qcow2.c | 29 ++++++++++++++++++++++++++++-
9ae3a8
 1 file changed, 28 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/qcow2.c |   29 ++++++++++++++++++++++++++++-
9ae3a8
 1 files changed, 28 insertions(+), 1 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/qcow2.c b/block/qcow2.c
9ae3a8
index b6f300d..01b535d 100644
9ae3a8
--- a/block/qcow2.c
9ae3a8
+++ b/block/qcow2.c
9ae3a8
@@ -425,6 +425,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
     Error *local_err = NULL;
9ae3a8
     uint64_t ext_end;
9ae3a8
     uint64_t l1_vm_state_index;
9ae3a8
+    const char *opt_overlap_check;
9ae3a8
+    int overlap_check_template = 0;
9ae3a8
 
9ae3a8
     ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
9ae3a8
     if (ret < 0) {
9ae3a8
@@ -687,7 +689,32 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
     s->discard_passthrough[QCOW2_DISCARD_OTHER] =
9ae3a8
         qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_OTHER, false);
9ae3a8
 
9ae3a8
-    s->overlap_check = QCOW2_OL_CACHED;
9ae3a8
+    opt_overlap_check = qemu_opt_get(opts, "overlap-check") ?: "cached";
9ae3a8
+    if (!strcmp(opt_overlap_check, "none")) {
9ae3a8
+        overlap_check_template = 0;
9ae3a8
+    } else if (!strcmp(opt_overlap_check, "constant")) {
9ae3a8
+        overlap_check_template = QCOW2_OL_CONSTANT;
9ae3a8
+    } else if (!strcmp(opt_overlap_check, "cached")) {
9ae3a8
+        overlap_check_template = QCOW2_OL_CACHED;
9ae3a8
+    } else if (!strcmp(opt_overlap_check, "all")) {
9ae3a8
+        overlap_check_template = QCOW2_OL_ALL;
9ae3a8
+    } else {
9ae3a8
+        error_setg(errp, "Unsupported value '%s' for qcow2 option "
9ae3a8
+                   "'overlap-check'. Allowed are either of the following: "
9ae3a8
+                   "none, constant, cached, all", opt_overlap_check);
9ae3a8
+        qemu_opts_del(opts);
9ae3a8
+        ret = -EINVAL;
9ae3a8
+        goto fail;
9ae3a8
+    }
9ae3a8
+
9ae3a8
+    s->overlap_check = 0;
9ae3a8
+    for (i = 0; i < QCOW2_OL_MAX_BITNR; i++) {
9ae3a8
+        /* overlap-check defines a template bitmask, but every flag may be
9ae3a8
+         * overwritten through the associated boolean option */
9ae3a8
+        s->overlap_check |=
9ae3a8
+            qemu_opt_get_bool(opts, overlap_bool_option_names[i],
9ae3a8
+                              overlap_check_template & (1 << i)) << i;
9ae3a8
+    }
9ae3a8
 
9ae3a8
     qemu_opts_del(opts);
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8