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 10/18] block: Move 'discard' option to bdrv_open_common()
Date: Tue, 27 Sep 2016 15:53:53 +0200	[thread overview]
Message-ID: <1474984441-28516-11-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1474984441-28516-1-git-send-email-kwolf@redhat.com>

This enables its use for nested child nodes. The compatibility
between the 'discard' and 'detect-zeroes' setting is checked in
bdrv_open_common() now as the former setting isn't available before
calling bdrv_open() any more.

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

diff --git a/block.c b/block.c
index 1f10457..bb1f1ec 100644
--- a/block.c
+++ b/block.c
@@ -765,7 +765,7 @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options,
     /* Our block drivers take care to send flushes and respect unmap policy,
      * so we can default to enable both on lower layers regardless of the
      * corresponding parent options. */
-    flags |= BDRV_O_UNMAP;
+    qdict_set_default_str(child_options, BDRV_OPT_DISCARD, "unmap");
 
     /* Clear flags that only apply to the top layer */
     flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ |
@@ -960,6 +960,11 @@ static QemuOptsList bdrv_runtime_opts = {
             .type = QEMU_OPT_STRING,
             .help = "try to optimize zero writes (off, on, unmap)",
         },
+        {
+            .name = "discard",
+            .type = QEMU_OPT_STRING,
+            .help = "discard operation (ignore/off, unmap/on)",
+        },
         { /* end of list */ }
     },
 };
@@ -976,6 +981,7 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
     const char *filename;
     const char *driver_name = NULL;
     const char *node_name = NULL;
+    const char *discard;
     const char *detect_zeroes;
     QemuOpts *opts;
     BlockDriver *drv;
@@ -1045,6 +1051,15 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
         }
     }
 
+    discard = qemu_opt_get(opts, "discard");
+    if (discard != NULL) {
+        if (bdrv_parse_discard_flags(discard, &bs->open_flags) != 0) {
+            error_setg(errp, "Invalid discard option");
+            ret = -EINVAL;
+            goto fail_opts;
+        }
+    }
+
     detect_zeroes = qemu_opt_get(opts, "detect-zeroes");
     if (detect_zeroes) {
         BlockdevDetectZeroesOptions value =
diff --git a/blockdev.c b/blockdev.c
index 7b87bd8..e2ace04 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -356,7 +356,6 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,
     const char **throttling_group, ThrottleConfig *throttle_cfg,
     BlockdevDetectZeroesOptions *detect_zeroes, Error **errp)
 {
-    const char *discard;
     Error *local_error = NULL;
     const char *aio;
 
@@ -365,13 +364,6 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,
             *bdrv_flags |= BDRV_O_COPY_ON_READ;
         }
 
-        if ((discard = qemu_opt_get(opts, "discard")) != NULL) {
-            if (bdrv_parse_discard_flags(discard, bdrv_flags) != 0) {
-                error_setg(errp, "Invalid discard option");
-                return;
-            }
-        }
-
         if ((aio = qemu_opt_get(opts, "aio")) != NULL) {
             if (!strcmp(aio, "native")) {
                 *bdrv_flags |= BDRV_O_NATIVE_AIO;
@@ -449,15 +441,6 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,
             error_propagate(errp, local_error);
             return;
         }
-
-        if (bdrv_flags &&
-            *detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP &&
-            !(*bdrv_flags & BDRV_O_UNMAP))
-        {
-            error_setg(errp, "setting detect-zeroes to unmap is not allowed "
-                             "without setting discard operation to unmap");
-            return;
-        }
     }
 }
 
@@ -3990,10 +3973,6 @@ QemuOptsList qemu_common_drive_opts = {
             .type = QEMU_OPT_BOOL,
             .help = "enable/disable snapshot mode",
         },{
-            .name = "discard",
-            .type = QEMU_OPT_STRING,
-            .help = "discard operation (ignore/off, unmap/on)",
-        },{
             .name = "aio",
             .type = QEMU_OPT_STRING,
             .help = "host AIO implementation (threads, native)",
@@ -4125,10 +4104,6 @@ static QemuOptsList qemu_root_bds_opts = {
     .head = QTAILQ_HEAD_INITIALIZER(qemu_root_bds_opts.head),
     .desc = {
         {
-            .name = "discard",
-            .type = QEMU_OPT_STRING,
-            .help = "discard operation (ignore/off, unmap/on)",
-        },{
             .name = "aio",
             .type = QEMU_OPT_STRING,
             .help = "host AIO implementation (threads, native)",
diff --git a/include/block/block.h b/include/block/block.h
index 811b060..107c603 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -108,6 +108,7 @@ typedef struct HDGeometry {
 #define BDRV_OPT_CACHE_DIRECT   "cache.direct"
 #define BDRV_OPT_CACHE_NO_FLUSH "cache.no-flush"
 #define BDRV_OPT_READ_ONLY      "read-only"
+#define BDRV_OPT_DISCARD        "discard"
 
 
 #define BDRV_SECTOR_BITS   9
-- 
1.8.3.1

  parent reply	other threads:[~2016-09-27 13:54 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-27 13:53 [Qemu-devel] [PULL 00/18] Block layer patches Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 01/18] block: reintroduce bdrv_flush_all Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 02/18] qemu: use bdrv_flush_all for vm_stop et al Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 03/18] block-backend: remove blk_flush_all Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 04/18] block: Fix error path in qmp_blockdev_change_medium() Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 05/18] block: Drop aio/cache consistency check from qmp_blockdev_add() Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 06/18] block/qapi: Use separate options type for curl driver Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 07/18] block/qapi: Move 'aio' option to file driver Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 08/18] block: Parse 'detect-zeroes' in bdrv_open_common() Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 09/18] block: Use 'detect-zeroes' option for 'blockdev-change-medium' Kevin Wolf
2016-09-27 13:53 ` Kevin Wolf [this message]
2016-10-07  9:01   ` [Qemu-devel] [PULL 10/18] block: Move 'discard' option to bdrv_open_common() Gerd Hoffmann
2016-10-07 10:20     ` Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 11/18] block: Remove qemu_root_bds_opts Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 12/18] oslib-posix: add helpers for stack alloc and free Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 13/18] coroutine-sigaltstack: rename coroutine struct appropriately Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 14/18] coroutine: add a macro for the coroutine stack size Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 15/18] coroutine-ucontext: use helper for allocating stack memory Kevin Wolf
2016-09-27 13:53 ` [Qemu-devel] [PULL 16/18] coroutine-sigaltstack: " Kevin Wolf
2016-09-27 13:54 ` [Qemu-devel] [PULL 17/18] oslib-posix: add a configure switch to debug stack usage Kevin Wolf
2016-09-27 13:54 ` [Qemu-devel] [PULL 18/18] coroutine: reduce stack size to 60kB Kevin Wolf
2016-09-27 19:42 ` [Qemu-devel] [PULL 00/18] Block layer patches Peter Maydell
2016-09-28  9:37   ` Kevin Wolf
2016-09-28 14:52     ` Peter Maydell
2016-09-28 19:03     ` Peter Maydell
2016-09-29 10:25       ` Kevin Wolf
2016-09-29 17:02         ` John Snow
2016-09-29 18:17           ` Paolo Bonzini
2016-09-29 18:19             ` John Snow
2016-09-29 17:18         ` Peter Maydell
2016-09-29 18:19           ` John Snow

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=1474984441-28516-11-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.