From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 29/48] qemu-img: Call blk_set_enable_write_cache() explicitly
Date: Tue, 29 Mar 2016 17:08:29 +0200 [thread overview]
Message-ID: <1459264128-12761-30-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1459264128-12761-1-git-send-email-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
qemu-img.c | 76 ++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 44 insertions(+), 32 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 4da54a8..1be3652 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -246,7 +246,7 @@ static int img_open_password(BlockBackend *blk, const char *filename,
static BlockBackend *img_open_opts(const char *optstr,
- QemuOpts *opts, int flags,
+ QemuOpts *opts, int flags, bool writethrough,
bool quiet)
{
QDict *options;
@@ -258,6 +258,7 @@ static BlockBackend *img_open_opts(const char *optstr,
error_reportf_err(local_err, "Could not open '%s'", optstr);
return NULL;
}
+ blk_set_enable_write_cache(blk, !writethrough);
if (img_open_password(blk, optstr, flags, quiet) < 0) {
blk_unref(blk);
@@ -268,7 +269,7 @@ static BlockBackend *img_open_opts(const char *optstr,
static BlockBackend *img_open_file(const char *filename,
const char *fmt, int flags,
- bool quiet)
+ bool writethrough, bool quiet)
{
BlockBackend *blk;
Error *local_err = NULL;
@@ -284,6 +285,7 @@ static BlockBackend *img_open_file(const char *filename,
error_reportf_err(local_err, "Could not open '%s': ", filename);
return NULL;
}
+ blk_set_enable_write_cache(blk, !writethrough);
if (img_open_password(blk, filename, flags, quiet) < 0) {
blk_unref(blk);
@@ -295,7 +297,7 @@ static BlockBackend *img_open_file(const char *filename,
static BlockBackend *img_open(bool image_opts,
const char *filename,
- const char *fmt, int flags,
+ const char *fmt, int flags, bool writethrough,
bool quiet)
{
BlockBackend *blk;
@@ -310,9 +312,9 @@ static BlockBackend *img_open(bool image_opts,
if (!opts) {
return NULL;
}
- blk = img_open_opts(filename, opts, flags, quiet);
+ blk = img_open_opts(filename, opts, flags, writethrough, quiet);
} else {
- blk = img_open_file(filename, fmt, flags, quiet);
+ blk = img_open_file(filename, fmt, flags, writethrough, quiet);
}
return blk;
}
@@ -590,7 +592,8 @@ static int img_check(int argc, char **argv)
BlockBackend *blk;
BlockDriverState *bs;
int fix = 0;
- int flags = BDRV_O_CACHE_WB | BDRV_O_CHECK;
+ int flags = BDRV_O_CHECK;
+ bool writethrough;
ImageCheck *check;
bool quiet = false;
Error *local_err = NULL;
@@ -599,6 +602,7 @@ static int img_check(int argc, char **argv)
fmt = NULL;
output = NULL;
cache = BDRV_DEFAULT_CACHE;
+
for(;;) {
int option_index = 0;
static const struct option long_options[] = {
@@ -678,13 +682,13 @@ static int img_check(int argc, char **argv)
return 1;
}
- ret = bdrv_parse_cache_flags(cache, &flags);
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid source cache option: %s", cache);
return 1;
}
- blk = img_open(image_opts, filename, fmt, flags, quiet);
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
if (!blk) {
return 1;
}
@@ -794,6 +798,7 @@ static int img_commit(int argc, char **argv)
BlockBackend *blk;
BlockDriverState *bs, *base_bs;
bool progress = false, quiet = false, drop = false;
+ bool writethrough;
Error *local_err = NULL;
CommonBlockJobCBInfo cbi;
bool image_opts = false;
@@ -870,13 +875,13 @@ static int img_commit(int argc, char **argv)
}
flags = BDRV_O_RDWR | BDRV_O_UNMAP;
- ret = bdrv_parse_cache_flags(cache, &flags);
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid cache option: %s", cache);
return 1;
}
- blk = img_open(image_opts, filename, fmt, flags, quiet);
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
if (!blk) {
return 1;
}
@@ -1120,6 +1125,7 @@ static int img_compare(int argc, char **argv)
int ret = 0; /* return value - 0 Ident, 1 Different, >1 Error */
bool progress = false, quiet = false, strict = false;
int flags;
+ bool writethrough;
int64_t total_sectors;
int64_t sector_num = 0;
int64_t nb_sectors;
@@ -1202,21 +1208,21 @@ static int img_compare(int argc, char **argv)
/* Initialize before goto out */
qemu_progress_init(progress, 2.0);
- flags = BDRV_O_CACHE_WB;
- ret = bdrv_parse_cache_flags(cache, &flags);
+ flags = 0;
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid source cache option: %s", cache);
ret = 2;
goto out3;
}
- blk1 = img_open(image_opts, filename1, fmt1, flags, quiet);
+ blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, quiet);
if (!blk1) {
ret = 2;
goto out3;
}
- blk2 = img_open(image_opts, filename2, fmt2, flags, quiet);
+ blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, quiet);
if (!blk2) {
ret = 2;
goto out2;
@@ -1710,6 +1716,7 @@ static int img_convert(int argc, char **argv)
int c, bs_n, bs_i, compress, cluster_sectors, skip_create;
int64_t ret = 0;
int progress = 0, flags, src_flags;
+ bool writethrough, src_writethrough;
const char *fmt, *out_fmt, *cache, *src_cache, *out_baseimg, *out_filename;
BlockDriver *drv, *proto_drv;
BlockBackend **blk = NULL, *out_blk = NULL;
@@ -1882,8 +1889,8 @@ static int img_convert(int argc, char **argv)
goto out;
}
- src_flags = BDRV_O_CACHE_WB;
- ret = bdrv_parse_cache_flags(src_cache, &src_flags);
+ src_flags = 0;
+ ret = bdrv_parse_cache_mode(src_cache, &src_flags, &src_writethrough);
if (ret < 0) {
error_report("Invalid source cache option: %s", src_cache);
goto out;
@@ -1898,7 +1905,7 @@ static int img_convert(int argc, char **argv)
total_sectors = 0;
for (bs_i = 0; bs_i < bs_n; bs_i++) {
blk[bs_i] = img_open(image_opts, argv[optind + bs_i],
- fmt, src_flags, quiet);
+ fmt, src_flags, src_writethrough, quiet);
if (!blk[bs_i]) {
ret = -1;
goto out;
@@ -2032,7 +2039,7 @@ static int img_convert(int argc, char **argv)
}
flags = min_sparse ? (BDRV_O_RDWR | BDRV_O_UNMAP) : BDRV_O_RDWR;
- ret = bdrv_parse_cache_flags(cache, &flags);
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid cache option: %s", cache);
goto out;
@@ -2043,7 +2050,7 @@ static int img_convert(int argc, char **argv)
* the bdrv_create() call which takes different params.
* Not critical right now, so fix can wait...
*/
- out_blk = img_open_file(out_filename, out_fmt, flags, quiet);
+ out_blk = img_open_file(out_filename, out_fmt, flags, writethrough, quiet);
if (!out_blk) {
ret = -1;
goto out;
@@ -2235,8 +2242,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts,
g_hash_table_insert(filenames, (gpointer)filename, NULL);
blk = img_open(image_opts, filename, fmt,
- BDRV_O_CACHE_WB | BDRV_O_NO_BACKING | BDRV_O_NO_IO,
- false);
+ BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false);
if (!blk) {
goto err;
}
@@ -2566,7 +2572,7 @@ static int img_map(int argc, char **argv)
return 1;
}
- blk = img_open(image_opts, filename, fmt, BDRV_O_CACHE_WB, false);
+ blk = img_open(image_opts, filename, fmt, 0, false, false);
if (!blk) {
return 1;
}
@@ -2630,7 +2636,7 @@ static int img_snapshot(int argc, char **argv)
Error *err = NULL;
bool image_opts = false;
- bdrv_oflags = BDRV_O_CACHE_WB | BDRV_O_RDWR;
+ bdrv_oflags = BDRV_O_RDWR;
/* Parse commandline parameters */
for(;;) {
static const struct option long_options[] = {
@@ -2711,7 +2717,7 @@ static int img_snapshot(int argc, char **argv)
}
/* Open the image */
- blk = img_open(image_opts, filename, NULL, bdrv_oflags, quiet);
+ blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet);
if (!blk) {
return 1;
}
@@ -2773,6 +2779,7 @@ static int img_rebase(int argc, char **argv)
char *filename;
const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg;
int c, flags, src_flags, ret;
+ bool writethrough, src_writethrough;
int unsafe = 0;
int progress = 0;
bool quiet = false;
@@ -2863,26 +2870,30 @@ static int img_rebase(int argc, char **argv)
qemu_progress_print(0, 100);
flags = BDRV_O_RDWR | (unsafe ? BDRV_O_NO_BACKING : 0);
- ret = bdrv_parse_cache_flags(cache, &flags);
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid cache option: %s", cache);
goto out;
}
- src_flags = BDRV_O_CACHE_WB;
- ret = bdrv_parse_cache_flags(src_cache, &src_flags);
+ src_flags = 0;
+ ret = bdrv_parse_cache_mode(src_cache, &src_flags, &src_writethrough);
if (ret < 0) {
error_report("Invalid source cache option: %s", src_cache);
goto out;
}
+ /* The source files are opened read-only, don't care about WCE */
+ assert((src_flags & BDRV_O_RDWR) == 0);
+ (void) src_writethrough;
+
/*
* Open the images.
*
* Ignore the old backing file for unsafe rebase in case we want to correct
* the reference to a renamed or moved backing file.
*/
- blk = img_open(image_opts, filename, fmt, flags, quiet);
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
if (!blk) {
ret = -1;
goto out;
@@ -3220,7 +3231,7 @@ static int img_resize(int argc, char **argv)
qemu_opts_del(param);
blk = img_open(image_opts, filename, fmt,
- BDRV_O_CACHE_WB | BDRV_O_RDWR, quiet);
+ BDRV_O_RDWR, false, quiet);
if (!blk) {
ret = -1;
goto out;
@@ -3276,6 +3287,7 @@ static int img_amend(int argc, char **argv)
QemuOpts *opts = NULL;
const char *fmt = NULL, *filename, *cache;
int flags;
+ bool writethrough;
bool quiet = false, progress = false;
BlockBackend *blk = NULL;
BlockDriverState *bs = NULL;
@@ -3372,14 +3384,14 @@ static int img_amend(int argc, char **argv)
goto out;
}
- flags = BDRV_O_CACHE_WB | BDRV_O_RDWR;
- ret = bdrv_parse_cache_flags(cache, &flags);
+ flags = BDRV_O_RDWR;
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid cache option: %s", cache);
goto out;
}
- blk = img_open(image_opts, filename, fmt, flags, quiet);
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
if (!blk) {
ret = -1;
goto out;
--
1.8.3.1
next prev parent reply other threads:[~2016-03-29 15:10 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-29 15:08 [Qemu-devel] [PULL 00/48] Block layer patches Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 01/48] block: Remove bdrv_make_anon() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 02/48] block: Remove copy-on-read from bdrv_move_feature_fields() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 03/48] block: Remove dirty bitmaps " Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 04/48] block: Remove cache.writeback from blockdev-add Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 05/48] block: Make backing files always writeback Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 06/48] block: Reject writethrough mode except at the root Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 07/48] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 08/48] block: Remove blk_set_bs() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 09/48] block/qapi: make two printf() formats literal Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 10/48] block/qapi: fix unbounded stack for dump_qdict Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 11/48] block/qapi: Set s->device in bdrv_query_stats() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 12/48] block/qapi: Pass bdrv_query_blk_stats() s->stats Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 13/48] block: add flag to indicate that no I/O will be performed Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 14/48] qemu-img/qemu-io: don't prompt for passwords if not required Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 15/48] tests: redirect stderr to stdout for iotests Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 16/48] tests: refactor python I/O tests helper main method Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 17/48] tests: add output filter to python I/O tests helper Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 18/48] block: add generic full disk encryption driver Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 19/48] block: move encryption deprecation warning into qcow code Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 20/48] block: an interoperability test for luks vs dm-crypt/cryptsetup Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 21/48] block: add flush callback Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 22/48] replay: bh scheduling fix Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 23/48] replay: fix error message Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 24/48] replay: introduce block devices record/replay Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 25/48] block: Add bdrv_parse_cache_mode() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 26/48] qemu-nbd: Call blk_set_enable_write_cache() explicitly Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 27/48] qemu-io: " Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 28/48] qemu-img: Expand all BDRV_O_FLAGS uses Kevin Wolf
2016-03-29 15:08 ` Kevin Wolf [this message]
2016-03-29 15:08 ` [Qemu-devel] [PULL 30/48] xen_disk: Call blk_set_enable_write_cache() explicitly Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 31/48] block: blockdev_init(): " Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 32/48] block: Always set writeback mode in blk_new_open() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 33/48] block: Handle flush error in bdrv_pwrite_sync() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 34/48] block: Move enable_write_cache to BB level Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 35/48] block/qapi: Use blk_enable_write_cache() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 36/48] block: Introduce bdrv_co_writev_flags() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 37/48] iscsi: Support BDRV_REQ_FUA Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 38/48] nbd: " Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 39/48] raw: " Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 40/48] block: Use bdrv_parse_cache_mode() in drive_init() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 41/48] qemu-io: Use bdrv_parse_cache_mode() in reopen_f() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 42/48] block: Remove bdrv_parse_cache_flags() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 43/48] block: Remove BDRV_O_CACHE_WB Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 44/48] block: Remove bdrv_(set_)enable_write_cache() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 45/48] qemu-img: Fix preallocation with -S 0 for convert Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 46/48] block/null-{co, aio}: Allow reading zeroes Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 47/48] block/null-{co, aio}: Implement get_block_status() Kevin Wolf
2016-03-29 15:08 ` [Qemu-devel] [PULL 48/48] iotests: Test qemu-img convert -S 0 behavior Kevin Wolf
2016-04-07 14:40 ` Paolo Bonzini
2016-04-08 1:18 ` Fam Zheng
2016-04-08 10:21 ` Kevin Wolf
2016-04-08 10:42 ` Fam Zheng
2016-03-29 19:56 ` [Qemu-devel] [PULL 00/48] Block layer patches Peter Maydell
2016-03-30 8:57 ` Kevin Wolf
2016-03-30 11:29 ` Peter Maydell
2016-03-30 12:07 ` Kevin Wolf
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=1459264128-12761-30-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 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).