summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2016-07-14 11:48:46 +0100
committerPeter Maydell <peter.maydell@linaro.org>2016-07-14 11:48:46 +0100
commit9358450e98ed4a5350df4754863d116ff2e6186c (patch)
treec151c42717ff86db6b01c9b596eda9d9c9703ac2 /hw
parent5bb2399f9b08198b6c03db10dd46e5a88caa2968 (diff)
parent543d7a42baf39c09db754ba9eca1d386e5958110 (diff)
downloadqemu-9358450e98ed4a5350df4754863d116ff2e6186c.tar.gz
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches # gpg: Signature made Wed 13 Jul 2016 12:46:17 BST # gpg: using RSA key 0x7F09B272C88F2FD6 # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * remotes/kevin/tags/for-upstream: (34 commits) iotests: Make 157 actually format-agnostic vvfat: Fix qcow write target driver specification hmp: show all of snapshot info on every block dev in output of 'info snapshots' hmp: use snapshot name to determine whether a snapshot is 'fully available' qemu-iotests: Test naming of throttling groups blockdev: Fix regression with the default naming of throttling groups vmdk: fix metadata write regression Improve block job rate limiting for small bandwidth values qcow2: Fix qcow2_get_cluster_offset() qemu-io: Use correct range limitations qcow2: Avoid making the L1 table too big qemu-img: Use strerror() for generic resize error block: Remove BB options from blockdev-add qemu-iotests: Test setting WCE with qdev block/qdev: Allow configuring rerror/werror with qdev properties commit: Fix use of error handling policy block/qdev: Allow configuring WCE with qdev properties block/qdev: Allow node name for drive properties coroutine: move entry argument to qemu_coroutine_create test-coroutine: prepare for the next patch ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r--hw/9pfs/9p.c4
-rw-r--r--hw/9pfs/coth.c4
-rw-r--r--hw/block/block.c28
-rw-r--r--hw/block/nvme.c1
-rw-r--r--hw/block/virtio-blk.c2
-rw-r--r--hw/core/qdev-properties-system.c39
-rw-r--r--hw/core/qdev-properties.c13
-rw-r--r--hw/ide/qdev.c2
-rw-r--r--hw/scsi/scsi-disk.c2
-rw-r--r--hw/usb/dev-storage.c6
10 files changed, 90 insertions, 11 deletions
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 9acff9293c..b6b02b46a9 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3278,8 +3278,8 @@ void pdu_submit(V9fsPDU *pdu)
if (is_ro_export(&s->ctx) && !is_read_only_op(pdu)) {
handler = v9fs_fs_ro;
}
- co = qemu_coroutine_create(handler);
- qemu_coroutine_enter(co, pdu);
+ co = qemu_coroutine_create(handler, pdu);
+ qemu_coroutine_enter(co);
}
/* Returns 0 on success, 1 on failure. */
diff --git a/hw/9pfs/coth.c b/hw/9pfs/coth.c
index 9b1151b60e..89018de6bf 100644
--- a/hw/9pfs/coth.c
+++ b/hw/9pfs/coth.c
@@ -22,14 +22,14 @@
static void coroutine_enter_cb(void *opaque, int ret)
{
Coroutine *co = opaque;
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
}
/* Called from worker thread. */
static int coroutine_enter_func(void *arg)
{
Coroutine *co = arg;
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
return 0;
}
diff --git a/hw/block/block.c b/hw/block/block.c
index 97a59d4fa2..8dc9d84a39 100644
--- a/hw/block/block.c
+++ b/hw/block/block.c
@@ -51,6 +51,34 @@ void blkconf_blocksizes(BlockConf *conf)
}
}
+void blkconf_apply_backend_options(BlockConf *conf)
+{
+ BlockBackend *blk = conf->blk;
+ BlockdevOnError rerror, werror;
+ 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();
+ }
+
+ rerror = conf->rerror;
+ if (rerror == BLOCKDEV_ON_ERROR_AUTO) {
+ rerror = blk_get_on_error(blk, true);
+ }
+
+ werror = conf->werror;
+ if (werror == BLOCKDEV_ON_ERROR_AUTO) {
+ werror = blk_get_on_error(blk, false);
+ }
+
+ blk_set_enable_write_cache(blk, wce);
+ blk_set_on_error(blk, rerror, werror);
+}
+
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..357ff9081e 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) {
@@ -959,6 +960,7 @@ static void virtio_blk_instance_init(Object *obj)
static Property virtio_blk_properties[] = {
DEFINE_BLOCK_PROPERTIES(VirtIOBlock, conf.conf),
+ DEFINE_BLOCK_ERROR_PROPERTIES(VirtIOBlock, conf.conf),
DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, conf.conf),
DEFINE_PROP_STRING("serial", VirtIOBlock, conf.serial),
DEFINE_PROP_BIT("config-wce", VirtIOBlock, conf.config_wce, 0, true),
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 65d9fa9f53..ab1bc5e945 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -72,12 +72,21 @@ static void parse_drive(DeviceState *dev, const char *str, void **ptr,
const char *propname, Error **errp)
{
BlockBackend *blk;
+ bool blk_created = false;
blk = blk_by_name(str);
if (!blk) {
+ BlockDriverState *bs = bdrv_lookup_bs(NULL, str, NULL);
+ if (bs) {
+ blk = blk_new();
+ blk_insert_bs(blk, bs);
+ blk_created = true;
+ }
+ }
+ if (!blk) {
error_setg(errp, "Property '%s.%s' can't find value '%s'",
object_get_typename(OBJECT(dev)), propname, str);
- return;
+ goto fail;
}
if (blk_attach_dev(blk, dev) < 0) {
DriveInfo *dinfo = blk_legacy_dinfo(blk);
@@ -91,9 +100,16 @@ static void parse_drive(DeviceState *dev, const char *str, void **ptr,
error_setg(errp, "Drive '%s' is already in use by another device",
str);
}
- return;
+ goto fail;
}
+
*ptr = blk;
+
+fail:
+ if (blk_created) {
+ /* If we need to keep a reference, blk_attach_dev() took it */
+ blk_unref(blk);
+ }
}
static void release_drive(Object *obj, const char *name, void *opaque)
@@ -103,8 +119,8 @@ static void release_drive(Object *obj, const char *name, void *opaque)
BlockBackend **ptr = qdev_get_prop_ptr(dev, prop);
if (*ptr) {
- blk_detach_dev(*ptr, dev);
blockdev_auto_del(*ptr);
+ blk_detach_dev(*ptr, dev);
}
}
@@ -127,7 +143,7 @@ static void set_drive(Object *obj, Visitor *v, const char *name, void *opaque,
PropertyInfo qdev_prop_drive = {
.name = "str",
- .description = "ID of a drive to use as a backend",
+ .description = "Node name or ID of a block device to use as a backend",
.get = get_drive,
.set = set_drive,
.release = release_drive,
@@ -362,8 +378,19 @@ PropertyInfo qdev_prop_vlan = {
void qdev_prop_set_drive(DeviceState *dev, const char *name,
BlockBackend *value, Error **errp)
{
- object_property_set_str(OBJECT(dev), value ? blk_name(value) : "",
- name, errp);
+ const char *ref = "";
+
+ if (value) {
+ ref = blk_name(value);
+ if (!*ref) {
+ BlockDriverState *bs = blk_bs(value);
+ if (bs) {
+ ref = bdrv_get_node_name(bs);
+ }
+ }
+ }
+
+ object_property_set_str(OBJECT(dev), ref, name, errp);
}
void qdev_prop_set_chr(DeviceState *dev, const char *name,
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 3c20c8e4b2..14e544ab17 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -539,6 +539,19 @@ PropertyInfo qdev_prop_losttickpolicy = {
.set = set_enum,
};
+/* --- Block device error handling policy --- */
+
+QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError) != sizeof(int));
+
+PropertyInfo qdev_prop_blockdev_on_error = {
+ .name = "BlockdevOnError",
+ .description = "Error handling policy, "
+ "report/ignore/enospc/stop/auto",
+ .enum_table = BlockdevOnError_lookup,
+ .get = get_enum,
+ .set = set_enum,
+};
+
/* --- BIOS CHS translation */
QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation) != sizeof(int));
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index d07b44eed5..67c76bfcd6 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -180,6 +180,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
return -1;
}
}
+ blkconf_apply_backend_options(&dev->conf);
if (ide_init_drive(s, dev->conf.blk, kind,
dev->version, dev->serial, dev->model, dev->wwn,
@@ -263,6 +264,7 @@ static int ide_drive_initfn(IDEDevice *dev)
#define DEFINE_IDE_DEV_PROPERTIES() \
DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \
+ DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf), \
DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \
DEFINE_PROP_UINT64("wwn", IDEDrive, dev.wwn, 0), \
DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 36f8a85a70..8dbfc10b78 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2309,6 +2309,7 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
return;
}
}
+ blkconf_apply_backend_options(&dev->conf);
if (s->qdev.conf.discard_granularity == -1) {
s->qdev.conf.discard_granularity =
@@ -2848,6 +2849,7 @@ static const TypeInfo scsi_disk_base_info = {
#define DEFINE_SCSI_DISK_PROPERTIES() \
DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf), \
+ DEFINE_BLOCK_ERROR_PROPERTIES(SCSIDiskState, qdev.conf), \
DEFINE_PROP_STRING("ver", SCSIDiskState, version), \
DEFINE_PROP_STRING("serial", SCSIDiskState, serial), \
DEFINE_PROP_STRING("vendor", SCSIDiskState, vendor), \
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 4d605b8a6a..c607f7606d 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -603,16 +603,19 @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp)
blkconf_serial(&s->conf, &dev->serial);
blkconf_blocksizes(&s->conf);
+ blkconf_apply_backend_options(&s->conf);
/*
* Hack alert: this pretends to be a block device, but it's really
* a SCSI bus that can serve only a single device, which it
* creates automatically. But first it needs to detach from its
* blockdev, or else scsi_bus_legacy_add_drive() dies when it
- * attaches again.
+ * attaches again. We also need to take another reference so that
+ * blk_detach_dev() doesn't free blk while we still need it.
*
* The hack is probably a bad idea.
*/
+ blk_ref(blk);
blk_detach_dev(blk, &s->dev.qdev);
s->conf.blk = NULL;
@@ -623,6 +626,7 @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp)
scsi_dev = scsi_bus_legacy_add_drive(&s->bus, blk, 0, !!s->removable,
s->conf.bootindex, dev->serial,
&err);
+ blk_unref(blk);
if (!scsi_dev) {
error_propagate(errp, err);
return;