summaryrefslogtreecommitdiff
path: root/hw/block
diff options
context:
space:
mode:
authorKlaus Jensen <k.jensen@samsung.com>2020-07-06 08:12:55 +0200
committerKlaus Jensen <k.jensen@samsung.com>2020-09-02 08:48:50 +0200
commitd21d37f5ab8c439ea183d8b04c469823d3b0b5ef (patch)
tree38604fc9e36a5c8604014745275d84a7654c7a67 /hw/block
parent46ac29c38bb45184db71dfbfbf5a31b3c12dbe29 (diff)
downloadqemu-d21d37f5ab8c439ea183d8b04c469823d3b0b5ef.zip
hw/block/nvme: flush write cache when disabled
If the write cache is disabled with a Set Features command, flush it if currently enabled. Signed-off-by: Klaus Jensen <k.jensen@samsung.com> Reviewed-by: Dmitry Fomichev <dmitry.fomichev@wdc.com> Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Message-Id: <20200706061303.246057-11-its@irrelevant.dk>
Diffstat (limited to 'hw/block')
-rw-r--r--hw/block/nvme.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 41a15da3f6..298b250199 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -1181,6 +1181,10 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
break;
case NVME_VOLATILE_WRITE_CACHE:
+ if (!(dw11 & 0x1) && blk_enable_write_cache(n->conf.blk)) {
+ blk_flush(n->conf.blk);
+ }
+
blk_set_enable_write_cache(n->conf.blk, dw11 & 1);
break;
case NVME_NUMBER_OF_QUEUES: