All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 13/40] block: Fix snapshot=on cache modes
Date: Mon, 14 Mar 2016 18:37:14 +0100	[thread overview]
Message-ID: <1457977061-28087-14-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1457977061-28087-1-git-send-email-kwolf@redhat.com>

Since commit 91a097e, we end up with a somewhat weird cache mode
configuration with snapshot=on: The commit broke the cache mode
inheritance for the snapshot overlay so that it is opened as
writethrough instead of unsafe now. The following bdrv_append() call to
put it on top of the tree swaps the WCE flag with the snapshot's backing
file (i.e. the originally given file), so what we eventually get is
cache=writeback on the temporary overlay and
cache=writethrough,cache.no-flush=on on the real image file.

This patch changes things so that the temporary overlay gets
cache=unsafe again like it used to, and the real images get whatever the
user specified. This means that cache.direct is now respected even with
snapshot=on, and in the case of committing changes, the final flush is
no longer ignored except explicitly requested by the user.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 block.c               | 36 +++++++++++++++++++++++++-----------
 blockdev.c            |  7 -------
 include/block/block.h |  1 -
 3 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/block.c b/block.c
index ba24b8e..cf5eb34 100644
--- a/block.c
+++ b/block.c
@@ -687,13 +687,19 @@ int bdrv_parse_cache_flags(const char *mode, int *flags)
 }
 
 /*
- * Returns the flags that a temporary snapshot should get, based on the
- * originally requested flags (the originally requested image will have flags
- * like a backing file)
+ * Returns the options and flags that a temporary snapshot should get, based on
+ * the originally requested flags (the originally requested image will have
+ * flags like a backing file)
  */
-static int bdrv_temp_snapshot_flags(int flags)
+static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options,
+                                       int parent_flags, QDict *parent_options)
 {
-    return (flags & ~BDRV_O_SNAPSHOT) | BDRV_O_TEMPORARY;
+    *child_flags = (parent_flags & ~BDRV_O_SNAPSHOT) | BDRV_O_TEMPORARY;
+
+    /* For temporary files, unconditional cache=unsafe is fine */
+    qdict_set_default_str(child_options, BDRV_OPT_CACHE_WB, "on");
+    qdict_set_default_str(child_options, BDRV_OPT_CACHE_DIRECT, "off");
+    qdict_set_default_str(child_options, BDRV_OPT_CACHE_NO_FLUSH, "on");
 }
 
 /*
@@ -1424,13 +1430,13 @@ done:
     return c;
 }
 
-int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
+static int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags,
+                                     QDict *snapshot_options, Error **errp)
 {
     /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
     char *tmp_filename = g_malloc0(PATH_MAX + 1);
     int64_t total_size;
     QemuOpts *opts = NULL;
-    QDict *snapshot_options;
     BlockDriverState *bs_snapshot;
     Error *local_err = NULL;
     int ret;
@@ -1464,8 +1470,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
         goto out;
     }
 
-    /* Prepare a new options QDict for the temporary file */
-    snapshot_options = qdict_new();
+    /* Prepare options QDict for the temporary file */
     qdict_put(snapshot_options, "file.driver",
               qstring_from_str("file"));
     qdict_put(snapshot_options, "file.filename",
@@ -1477,6 +1482,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
 
     ret = bdrv_open(&bs_snapshot, NULL, NULL, snapshot_options,
                     flags, &local_err);
+    snapshot_options = NULL;
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto out;
@@ -1485,6 +1491,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
     bdrv_append(bs_snapshot, bs);
 
 out:
+    QDECREF(snapshot_options);
     g_free(tmp_filename);
     return ret;
 }
@@ -1516,6 +1523,7 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
     const char *drvname;
     const char *backing;
     Error *local_err = NULL;
+    QDict *snapshot_options = NULL;
     int snapshot_flags = 0;
 
     assert(pbs);
@@ -1607,7 +1615,9 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
             flags |= BDRV_O_ALLOW_RDWR;
         }
         if (flags & BDRV_O_SNAPSHOT) {
-            snapshot_flags = bdrv_temp_snapshot_flags(flags);
+            snapshot_options = qdict_new();
+            bdrv_temp_snapshot_options(&snapshot_flags, snapshot_options,
+                                       flags, options);
             bdrv_backing_options(&flags, options, flags, options);
         }
 
@@ -1709,7 +1719,9 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
     /* For snapshot=on, create a temporary qcow2 overlay. bs points to the
      * temporary snapshot afterwards. */
     if (snapshot_flags) {
-        ret = bdrv_append_temp_snapshot(bs, snapshot_flags, &local_err);
+        ret = bdrv_append_temp_snapshot(bs, snapshot_flags, snapshot_options,
+                                        &local_err);
+        snapshot_options = NULL;
         if (local_err) {
             goto close_and_fail;
         }
@@ -1721,6 +1733,7 @@ fail:
     if (file != NULL) {
         bdrv_unref_child(bs, file);
     }
+    QDECREF(snapshot_options);
     QDECREF(bs->explicit_options);
     QDECREF(bs->options);
     QDECREF(options);
@@ -1743,6 +1756,7 @@ close_and_fail:
     } else {
         bdrv_unref(bs);
     }
+    QDECREF(snapshot_options);
     QDECREF(options);
     if (local_err) {
         error_propagate(errp, local_err);
diff --git a/blockdev.c b/blockdev.c
index e1c1540..eecd78d 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -593,13 +593,6 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
         qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_DIRECT, "off");
         qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_NO_FLUSH, "off");
 
-        if (snapshot) {
-            /* always use cache=unsafe with snapshot */
-            qdict_put(bs_opts, BDRV_OPT_CACHE_WB, qstring_from_str("on"));
-            qdict_put(bs_opts, BDRV_OPT_CACHE_DIRECT, qstring_from_str("off"));
-            qdict_put(bs_opts, BDRV_OPT_CACHE_NO_FLUSH, qstring_from_str("on"));
-        }
-
         if (runstate_check(RUN_STATE_INMIGRATE)) {
             bdrv_flags |= BDRV_O_INACTIVE;
         }
diff --git a/include/block/block.h b/include/block/block.h
index 1c4f4d8..3900c4d 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -215,7 +215,6 @@ BdrvChild *bdrv_open_child(const char *filename,
 void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd);
 int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
                            const char *bdref_key, Error **errp);
-int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp);
 int bdrv_open(BlockDriverState **pbs, const char *filename,
               const char *reference, QDict *options, int flags, Error **errp);
 BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
-- 
1.8.3.1

  parent reply	other threads:[~2016-03-14 17:38 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-14 17:37 [Qemu-devel] [PULL 00/40] Block patches Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 01/40] qemu-img: eliminate memory leak Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 02/40] block/qapi: Factor out bdrv_query_blk_stats() Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 03/40] block/qapi: Factor out bdrv_query_bds_stats() Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 04/40] block/qapi: Include empty drives in query-blockstats Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 05/40] block/vpc: choose size calculation method based on creator_app field Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 06/40] block/vpc: tests for auto-detecting VPC and Hyper-V VHD images Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 07/40] block/vpc: give option to force the current_size field in .bdrv_create Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 08/40] block/vpc: add tests for image creation force_size parameter Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 09/40] docs: fix invalid node name in qmp event Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 10/40] qmp event: Refactor QUORUM_REPORT_BAD Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 11/40] quorum: modify vote rules for flush operation Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 12/40] blockdev: Snapshotting must not open second instance of old top Kevin Wolf
2016-03-14 17:37 ` Kevin Wolf [this message]
2016-03-14 17:37 ` [Qemu-devel] [PULL 14/40] block: Fix cache mode defaults in bds_tree_init() Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 15/40] vmdk: Switch to heap arrays for vmdk_write_cid Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 16/40] vmdk: Switch to heap arrays for vmdk_read_cid Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 17/40] vmdk: Switch to heap arrays for vmdk_parent_open Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 18/40] hmp: 'drive_add -n' for creating a node without BB Kevin Wolf
2016-03-16 10:41   ` Paolo Bonzini
2016-03-16 10:47     ` Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 19/40] hmp: Extend drive_del to delete nodes " Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 20/40] block: Use writeback in .bdrv_create() implementations Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 21/40] block: Introduce blk_set_allow_write_beyond_eof() Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 22/40] parallels: Use BB functions in .bdrv_create() Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 23/40] qcow: " Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 24/40] qcow2: " Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 25/40] qed: " Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 26/40] sheepdog: " Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 27/40] vdi: " Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 28/40] vhdx: " Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 29/40] vmdk: " Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 30/40] vpc: " Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 31/40] backup: Use Bitmap to replace "s->bitmap" Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 32/40] block: Include hbitmap.h in block.h Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 33/40] typedefs: Add BdrvDirtyBitmap Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 34/40] block: Move block dirty bitmap code to separate files Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 35/40] block: Remove unused typedef of BlockDriverDirtyHandler Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 36/40] iotests: Correct 081's reference output Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 37/40] quorum: Fix crash in quorum_aio_cb() Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 38/40] monitor: Separate QUORUM_REPORT_BAD events according to the node name Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 39/40] monitor: Use QEMU_CLOCK_VIRTUAL for the event queue in qtest mode Kevin Wolf
2016-03-14 17:37 ` [Qemu-devel] [PULL 40/40] iotests: Add test for QMP event rates Kevin Wolf
2016-03-15 10:07 ` [Qemu-devel] [PULL 00/40] Block patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457977061-28087-14-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.