qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <famz@redhat.com>,
	Jeff Cody <jcody@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Max Reitz <mreitz@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	john@redhat.com
Subject: [Qemu-devel] [PATCH 36/50] blockdev: Allow more options for BB-less BDS tree
Date: Mon, 26 Jan 2015 11:03:10 -0500	[thread overview]
Message-ID: <1422288204-29271-37-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1422288204-29271-1-git-send-email-mreitz@redhat.com>

Most of the options which blockdev_init() parses for both the
BlockBackend and the root BDS are valid for just the root BDS as well
(e.g. read-only). This patch allows specifying these options even if not
creating a BlockBackend.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 blockdev.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 150 insertions(+), 6 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index d573c5c..2f3ccb5 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -591,6 +591,61 @@ err_no_opts:
     return NULL;
 }
 
+static QemuOptsList qemu_root_bds_opts;
+
+/* Takes the ownership of bs_opts */
+static BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp)
+{
+    BlockDriverState *bs;
+    QemuOpts *opts;
+    Error *local_error = NULL;
+    ThrottleConfig cfg;
+    BlockdevDetectZeroesOptions detect_zeroes;
+    int ret;
+    int bdrv_flags = 0;
+
+    opts = qemu_opts_create(&qemu_root_bds_opts, NULL, 1, errp);
+    if (!opts) {
+        goto fail;
+    }
+
+    qemu_opts_absorb_qdict(opts, bs_opts, &local_error);
+    if (local_error) {
+        error_propagate(errp, local_error);
+        goto fail;
+    }
+
+    extract_common_blockdev_options(opts, &bdrv_flags, &cfg, &detect_zeroes,
+                                    &local_error);
+    if (local_error) {
+        error_propagate(errp, local_error);
+        goto fail;
+    }
+
+    bs = NULL;
+    ret = bdrv_open(&bs, NULL, NULL, bs_opts, bdrv_flags, NULL, errp);
+    if (ret < 0) {
+        goto fail_no_bs_opts;
+    }
+
+    bs->detect_zeroes = detect_zeroes;
+
+    /* disk I/O throttling */
+    if (throttle_enabled(&cfg)) {
+        bdrv_io_limits_enable(bs);
+        bdrv_set_io_limits(bs, &cfg);
+    }
+
+fail_no_bs_opts:
+    qemu_opts_del(opts);
+    return bs;
+
+fail:
+    qemu_opts_del(opts);
+    QDECREF(bs_opts);
+    return NULL;
+}
+
 static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to,
                             Error **errp)
 {
@@ -2994,12 +3049,8 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
 
         bs = blk_bs(blk);
     } else {
-        int ret;
-
-        bs = NULL;
-        ret = bdrv_open(&bs, NULL, NULL, qdict, BDRV_O_RDWR | BDRV_O_CACHE_WB,
-                        NULL, errp);
-        if (ret < 0) {
+        bs = bds_tree_init(qdict, errp);
+        if (!bs) {
             goto fail;
         }
     }
@@ -3150,6 +3201,99 @@ QemuOptsList qemu_common_drive_opts = {
     },
 };
 
+static QemuOptsList qemu_root_bds_opts = {
+    .name = "root-bds",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head),
+    .desc = {
+        {
+            .name = "discard",
+            .type = QEMU_OPT_STRING,
+            .help = "discard operation (ignore/off, unmap/on)",
+        },{
+            .name = "cache.writeback",
+            .type = QEMU_OPT_BOOL,
+            .help = "enables writeback mode for any caches",
+        },{
+            .name = "cache.direct",
+            .type = QEMU_OPT_BOOL,
+            .help = "enables use of O_DIRECT (bypass the host page cache)",
+        },{
+            .name = "cache.no-flush",
+            .type = QEMU_OPT_BOOL,
+            .help = "ignore any flush requests for the device",
+        },{
+            .name = "aio",
+            .type = QEMU_OPT_STRING,
+            .help = "host AIO implementation (threads, native)",
+        },{
+            .name = "read-only",
+            .type = QEMU_OPT_BOOL,
+            .help = "open drive file as read-only",
+        },{
+            .name = "throttling.iops-total",
+            .type = QEMU_OPT_NUMBER,
+            .help = "limit total I/O operations per second",
+        },{
+            .name = "throttling.iops-read",
+            .type = QEMU_OPT_NUMBER,
+            .help = "limit read operations per second",
+        },{
+            .name = "throttling.iops-write",
+            .type = QEMU_OPT_NUMBER,
+            .help = "limit write operations per second",
+        },{
+            .name = "throttling.bps-total",
+            .type = QEMU_OPT_NUMBER,
+            .help = "limit total bytes per second",
+        },{
+            .name = "throttling.bps-read",
+            .type = QEMU_OPT_NUMBER,
+            .help = "limit read bytes per second",
+        },{
+            .name = "throttling.bps-write",
+            .type = QEMU_OPT_NUMBER,
+            .help = "limit write bytes per second",
+        },{
+            .name = "throttling.iops-total-max",
+            .type = QEMU_OPT_NUMBER,
+            .help = "I/O operations burst",
+        },{
+            .name = "throttling.iops-read-max",
+            .type = QEMU_OPT_NUMBER,
+            .help = "I/O operations read burst",
+        },{
+            .name = "throttling.iops-write-max",
+            .type = QEMU_OPT_NUMBER,
+            .help = "I/O operations write burst",
+        },{
+            .name = "throttling.bps-total-max",
+            .type = QEMU_OPT_NUMBER,
+            .help = "total bytes burst",
+        },{
+            .name = "throttling.bps-read-max",
+            .type = QEMU_OPT_NUMBER,
+            .help = "total bytes read burst",
+        },{
+            .name = "throttling.bps-write-max",
+            .type = QEMU_OPT_NUMBER,
+            .help = "total bytes write burst",
+        },{
+            .name = "throttling.iops-size",
+            .type = QEMU_OPT_NUMBER,
+            .help = "when limiting by iops max size of an I/O in bytes",
+        },{
+            .name = "copy-on-read",
+            .type = QEMU_OPT_BOOL,
+            .help = "copy read data from backing file into image file",
+        },{
+            .name = "detect-zeroes",
+            .type = QEMU_OPT_STRING,
+            .help = "try to optimize zero writes (off, on, unmap)",
+        },
+        { /* end of list */ }
+    },
+};
+
 QemuOptsList qemu_drive_opts = {
     .name = "drive",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head),
-- 
2.1.0

  parent reply	other threads:[~2015-01-26 16:04 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-26 16:02 [Qemu-devel] [PATCH 00/50] blockdev: BlockBackend and media Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 01/50] blockdev: Allow creation of BDS trees without BB Max Reitz
2015-01-27 18:22   ` Eric Blake
2015-01-27 18:26     ` Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 02/50] iotests: Only create BB if necessary Max Reitz
2015-01-27 18:49   ` Eric Blake
2015-01-26 16:02 ` [Qemu-devel] [PATCH 03/50] hw/block/fdc: Implement tray status Max Reitz
2015-01-27 18:58   ` Eric Blake
2015-01-26 16:02 ` [Qemu-devel] [PATCH 04/50] hw/usb-storage: Check whether BB is inserted Max Reitz
2015-01-27 19:05   ` Eric Blake
2015-01-26 16:02 ` [Qemu-devel] [PATCH 05/50] block: Fix BB AIOCB AioContext without BDS Max Reitz
2015-01-27 19:12   ` Eric Blake
2015-01-26 16:02 ` [Qemu-devel] [PATCH 06/50] block: Add blk_is_available() Max Reitz
2015-01-27 19:15   ` Eric Blake
2015-01-27 19:16     ` Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 07/50] block: Make bdrv_is_inserted() recursive Max Reitz
2015-01-27 19:18   ` Eric Blake
2015-01-26 16:02 ` [Qemu-devel] [PATCH 08/50] block/quorum: Implement bdrv_is_inserted() Max Reitz
2015-01-27 19:20   ` Eric Blake
2015-01-26 16:02 ` [Qemu-devel] [PATCH 09/50] block: Move guest_block_size into BlockBackend Max Reitz
2015-01-27 19:22   ` Eric Blake
2015-01-27 19:37     ` John Priddy
2015-01-27 19:40       ` Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 10/50] block: Remove wr_highest_offset from BlockAcctStats Max Reitz
2015-01-27 20:01   ` Eric Blake
2015-01-27 20:02     ` Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 11/50] block: Move BlockAcctStats into BlockBackend Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 12/50] block: Move I/O status and error actions into BB Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 13/50] block: Add BlockBackendRootState Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 14/50] block: Make some BB functions fall back to BBRS Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 15/50] block: Fail requests to empty BlockBackend Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 16/50] block: Prepare remaining BB functions for NULL BDS Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 17/50] block: Respect empty BB in bdrv_lookup_bs() Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 18/50] block: Respect empty BB in bdrv_query_info() Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 19/50] blockdev: Use BlockBackend for blockdev-backup TA Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 20/50] blockdev: Check blk_is_available() in sn-del-int-sync Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 21/50] blockdev: Check BB validity in internal snapshot TA Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 22/50] blockdev: Check BB validity in drive-backup TA Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 23/50] blockdev: Catch NULL BDS in block_set_io_throttle Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 24/50] blockdev: Check BB validity in block-stream Max Reitz
2015-01-26 16:02 ` [Qemu-devel] [PATCH 25/50] blockdev: Check BB validity in block-commit Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 26/50] blockdev: Check BB validity in drive-backup Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 27/50] blockdev: Check BB validity in blockdev-backup Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 28/50] blockdev: Check BB validity in drive-mirror Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 29/50] blockdev: Check BB validity in find_block_job() Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 30/50] blockdev: Check BB validity in change-backing-file Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 31/50] block: Add blk_insert_bs() Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 32/50] blockdev: Check BB validity in eject and change Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 33/50] blockdev: Respect NULL BDS in do_drive_del() Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 34/50] blockdev: Do not create BDS for empty drive Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 35/50] blockdev: Pull out blockdev option extraction Max Reitz
2015-01-26 16:03 ` Max Reitz [this message]
2015-01-26 16:03 ` [Qemu-devel] [PATCH 37/50] block: Add blk_remove_bs() Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 38/50] blockdev: Add blockdev-open-tray Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 39/50] blockdev: Add blockdev-close-tray Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 40/50] blockdev: Add blockdev-remove-medium Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 41/50] blockdev: Add blockdev-insert-medium Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 42/50] blockdev: Implement eject with basic operations Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 43/50] blockdev: Implement change " Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 44/50] block: Inquire tray state before tray-moved events Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 45/50] qmp: Introduce blockdev-change-medium Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 46/50] hmp: Use blockdev-change-medium for change command Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 47/50] blockdev: Add read-only option to blockdev-change-medium Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 48/50] hmp: Add read-only option to change command Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 49/50] iotests: More options for VM.add_drive() Max Reitz
2015-01-26 16:03 ` [Qemu-devel] [PATCH 50/50] iotests: Add test for change-related QMP commands Max Reitz
2015-01-27 19:30 ` [Qemu-devel] [PATCH 00/50] blockdev: BlockBackend and media Eric Blake
2015-01-27 19:38   ` Max Reitz
2015-01-27 19:49 ` Max Reitz

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=1422288204-29271-37-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=john@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).