From 91a097e7478940483e76d52217f05bc05b98d5a5 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Fri, 8 May 2015 17:49:53 +0200 Subject: block: Move cache options into options QDict This adds the cache mode options to the QDict, so that they can be specified for child nodes (e.g. backing.cache.direct=off). The cache modes are not removed from the flags at this point; instead, options and flags are kept in sync. If the user specifies both flags and options, the options take precedence. Child node inherit cache modes as options now, they don't use flags any more. Note that this forbids specifying the cache mode for empty drives. It didn't make sense anyway to specify it there, because it didn't have any effect. blockdev_init() considers the cache options now bdrv_open() options and therefore doesn't create an empty drive any more but calls into bdrv_open(). This in turn will fail with no driver and filename specified. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- blockdev.c | 52 +++++++++++++++------------------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) (limited to 'blockdev.c') diff --git a/blockdev.c b/blockdev.c index 2f88004511..64dbfeb15b 100644 --- a/blockdev.c +++ b/blockdev.c @@ -387,16 +387,6 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } } - if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_WB, true)) { - *bdrv_flags |= BDRV_O_CACHE_WB; - } - if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_DIRECT, false)) { - *bdrv_flags |= BDRV_O_NOCACHE; - } - if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) { - *bdrv_flags |= BDRV_O_NO_FLUSH; - } - if ((aio = qemu_opt_get(opts, "aio")) != NULL) { if (!strcmp(aio, "native")) { *bdrv_flags |= BDRV_O_NATIVE_AIO; @@ -569,9 +559,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, } if (snapshot) { - /* always use cache=unsafe with snapshot */ - bdrv_flags &= ~BDRV_O_CACHE_MASK; - bdrv_flags |= (BDRV_O_SNAPSHOT|BDRV_O_CACHE_WB|BDRV_O_NO_FLUSH); + bdrv_flags |= BDRV_O_SNAPSHOT; } /* init */ @@ -603,6 +591,20 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, file = NULL; } + /* bdrv_open() defaults to the values in bdrv_flags (for compatibility + * with other callers) rather than what we want as the real defaults. + * Apply the defaults here instead. */ + qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_WB, "on"); + 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")); + } + blk = blk_new_open(qemu_opts_id(opts), file, NULL, bs_opts, bdrv_flags, errp); if (!blk) { @@ -3869,18 +3871,6 @@ QemuOptsList qemu_common_drive_opts = { .name = "discard", .type = QEMU_OPT_STRING, .help = "discard operation (ignore/off, unmap/on)", - },{ - .name = BDRV_OPT_CACHE_WB, - .type = QEMU_OPT_BOOL, - .help = "enables writeback mode for any caches", - },{ - .name = BDRV_OPT_CACHE_DIRECT, - .type = QEMU_OPT_BOOL, - .help = "enables use of O_DIRECT (bypass the host page cache)", - },{ - .name = BDRV_OPT_CACHE_NO_FLUSH, - .type = QEMU_OPT_BOOL, - .help = "ignore any flush requests for the device", },{ .name = "aio", .type = QEMU_OPT_STRING, @@ -3988,18 +3978,6 @@ static QemuOptsList qemu_root_bds_opts = { .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, -- cgit v1.2.3