aboutsummaryrefslogtreecommitdiff
path: root/hw/block
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2016-06-23 15:12:35 +0200
committerKevin Wolf <kwolf@redhat.com>2016-07-13 13:32:27 +0200
commitf6166a06ffdb1cd5dd80adf2d82c35c3bda88239 (patch)
tree36aa065e263e1adcdc7a923ae55528ea3224e91b /hw/block
parent8daea510951dd309a44cea8de415c685c43851cf (diff)
block/qdev: Allow configuring WCE with qdev properties
As cache.writeback is a BlockBackend property and as such more related to the guest device than the BlockDriverState, we already removed it from the blockdev-add interface. This patch adds the new way to set it, as a qdev property of the corresponding guest device. For example: -drive if=none,file=test.img,node-name=img -device ide-hd,drive=img,write-cache=off Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'hw/block')
-rw-r--r--hw/block/block.c16
-rw-r--r--hw/block/nvme.c1
-rw-r--r--hw/block/virtio-blk.c1
3 files changed, 18 insertions, 0 deletions
diff --git a/hw/block/block.c b/hw/block/block.c
index 97a59d4fa2..396b0d5de1 100644
--- a/hw/block/block.c
+++ b/hw/block/block.c
@@ -51,6 +51,22 @@ void blkconf_blocksizes(BlockConf *conf)
}
}
+void blkconf_apply_backend_options(BlockConf *conf)
+{
+ BlockBackend *blk = conf->blk;
+ bool wce;
+
+ switch (conf->wce) {
+ case ON_OFF_AUTO_ON: wce = true; break;
+ case ON_OFF_AUTO_OFF: wce = false; break;
+ case ON_OFF_AUTO_AUTO: wce = blk_enable_write_cache(blk); break;
+ default:
+ abort();
+ }
+
+ blk_set_enable_write_cache(blk, wce);
+}
+
void blkconf_geometry(BlockConf *conf, int *ptrans,
unsigned cyls_max, unsigned heads_max, unsigned secs_max,
Error **errp)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 280d54d8eb..2ded2475ee 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -803,6 +803,7 @@ static int nvme_init(PCIDevice *pci_dev)
return -1;
}
blkconf_blocksizes(&n->conf);
+ blkconf_apply_backend_options(&n->conf);
pci_conf = pci_dev->config;
pci_conf[PCI_INTERRUPT_PIN] = 1;
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index ae86e944ea..ecd8ea34b6 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -897,6 +897,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
}
blkconf_serial(&conf->conf, &conf->serial);
+ blkconf_apply_backend_options(&conf->conf);
s->original_wce = blk_enable_write_cache(conf->conf.blk);
blkconf_geometry(&conf->conf, NULL, 65535, 255, 255, &err);
if (err) {