aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2016-03-15 14:34:37 +0100
committerKevin Wolf <kwolf@redhat.com>2016-03-30 12:16:01 +0200
commit72e775c7d9de3eaa35a6edaf9d87cedee149d0f5 (patch)
tree6146ef9c8ce3f93f11df617a2e6d4dfeba72b82e
parente4b24b497e4171a89da541fe83c3dc84c51d42da (diff)
block: Always set writeback mode in blk_new_open()
All callers of blk_new_open() either don't rely on the WCE bit set after blk_new_open() because they explicitly set it anyway, or they pass BDRV_O_CACHE_WB unconditionally. This patch changes blk_new_open() so that it always enables writeback mode and asserts that BDRV_O_CACHE_WB is clear. For those callers that used to pass BDRV_O_CACHE_WB unconditionally, the flag is removed now. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
-rw-r--r--block/block-backend.c4
-rw-r--r--block/crypto.c3
-rw-r--r--block/parallels.c3
-rw-r--r--block/qcow.c3
-rw-r--r--block/qcow2.c9
-rw-r--r--block/qed.c3
-rw-r--r--block/sheepdog.c5
-rw-r--r--block/vdi.c3
-rw-r--r--block/vhdx.c3
-rw-r--r--block/vmdk.c8
-rw-r--r--block/vpc.c3
-rw-r--r--blockdev.c1
12 files changed, 20 insertions, 28 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index e578a2d5e3..048f48e935 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -148,6 +148,8 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,
BlockBackend *blk;
int ret;
+ assert((flags & BDRV_O_CACHE_WB) == 0);
+
blk = blk_new_with_bs(errp);
if (!blk) {
QDECREF(options);
@@ -160,6 +162,8 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,
return NULL;
}
+ blk_set_enable_write_cache(blk, true);
+
return blk;
}
diff --git a/block/crypto.c b/block/crypto.c
index 3db0965fe1..be3498581c 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -121,8 +121,7 @@ static ssize_t block_crypto_init_func(QCryptoBlock *block,
}
data->blk = blk_new_open(data->filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- errp);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, errp);
if (!data->blk) {
return -1;
}
diff --git a/block/parallels.c b/block/parallels.c
index 9bba8b3d06..324ed43ac4 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -480,8 +480,7 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)
}
file = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
if (file == NULL) {
error_propagate(errp, local_err);
return -EIO;
diff --git a/block/qcow.c b/block/qcow.c
index b6c2e6ec78..60ddb12eca 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -804,8 +804,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
}
qcow_blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
if (qcow_blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
diff --git a/block/qcow2.c b/block/qcow2.c
index 73c4f6b0ba..056525c7fd 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2168,8 +2168,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
}
blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
return -EIO;
@@ -2233,8 +2232,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
options = qdict_new();
qdict_put(options, "driver", qstring_from_str("qcow2"));
blk = blk_new_open(filename, NULL, options,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_NO_FLUSH, &local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
@@ -2295,8 +2293,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
options = qdict_new();
qdict_put(options, "driver", qstring_from_str("qcow2"));
blk = blk_new_open(filename, NULL, options,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_NO_BACKING, &local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
diff --git a/block/qed.c b/block/qed.c
index c1cc625d55..0af52741df 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -576,8 +576,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
}
blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
return -EIO;
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 48fc165422..33e0a33824 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1648,8 +1648,7 @@ static int sd_prealloc(const char *filename, Error **errp)
int ret;
blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- errp);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, errp);
if (blk == NULL) {
ret = -EIO;
goto out_with_err_set;
@@ -1845,7 +1844,7 @@ static int sd_create(const char *filename, QemuOpts *opts,
}
blk = blk_new_open(backing_file, NULL, NULL,
- BDRV_O_PROTOCOL | BDRV_O_CACHE_WB, errp);
+ BDRV_O_PROTOCOL, errp);
if (blk == NULL) {
ret = -EIO;
goto out;
diff --git a/block/vdi.c b/block/vdi.c
index 71f417c461..75d4819edb 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -770,8 +770,7 @@ static int vdi_create(const char *filename, QemuOpts *opts, Error **errp)
}
blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
diff --git a/block/vhdx.c b/block/vhdx.c
index 59426d6c0f..2b7b332404 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1840,8 +1840,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
}
blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
diff --git a/block/vmdk.c b/block/vmdk.c
index a1a9371bf8..45f9d3c5b9 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1663,8 +1663,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
}
blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
@@ -1948,7 +1947,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
}
blk = blk_new_open(full_backing, NULL, NULL,
- BDRV_O_NO_BACKING | BDRV_O_CACHE_WB, errp);
+ BDRV_O_NO_BACKING, errp);
g_free(full_backing);
if (blk == NULL) {
ret = -EIO;
@@ -2020,8 +2019,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
}
new_blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
if (new_blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
diff --git a/block/vpc.c b/block/vpc.c
index 912dfc1a82..8830b5b2b0 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -890,8 +890,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
}
blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- &local_err);
+ BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
if (blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
diff --git a/blockdev.c b/blockdev.c
index b65891382b..00a77dc750 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -598,6 +598,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_WB, writethrough ? "off" : "on");
qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_DIRECT, "off");
qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_NO_FLUSH, "off");
+ assert((bdrv_flags & BDRV_O_CACHE_MASK) == 0);
if (runstate_check(RUN_STATE_INMIGRATE)) {
bdrv_flags |= BDRV_O_INACTIVE;