From 39829a01ae524788c68dc0794e6912faa898eb75 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 24 Jan 2017 14:21:41 +0100 Subject: block: Allow error return in BlockDevOps.change_media_cb() Some devices allow a media change between read-only and read-write media. They need to adapt the permissions in their .change_media_cb() implementation, which can fail. So add an Error parameter to the function. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Acked-by: Fam Zheng --- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw/sd') diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8e88e8311a..8e31491089 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -458,7 +458,7 @@ static bool sd_get_readonly(SDState *sd) return sd->wp_switch; } -static void sd_cardchange(void *opaque, bool load) +static void sd_cardchange(void *opaque, bool load, Error **errp) { SDState *sd = opaque; DeviceState *dev = DEVICE(sd); -- cgit v1.2.3 From a17c17a274f24f0c0259f89d288f29b8ce0511aa Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 24 Jan 2017 13:43:31 +0100 Subject: hw/block: Request permissions This makes all device emulations with a qdev drive property request permissions on their BlockBackend. The only thing we block at this point is resizing images for some devices that can't support it. Signed-off-by: Kevin Wolf Acked-by: Fam Zheng Reviewed-by: Max Reitz --- hw/sd/sd.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'hw/sd') diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8e31491089..ba47bff4db 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1887,6 +1887,7 @@ static void sd_instance_finalize(Object *obj) static void sd_realize(DeviceState *dev, Error **errp) { SDState *sd = SD_CARD(dev); + int ret; if (sd->blk && blk_is_read_only(sd->blk)) { error_setg(errp, "Cannot use read-only drive as SD card"); @@ -1894,6 +1895,11 @@ static void sd_realize(DeviceState *dev, Error **errp) } if (sd->blk) { + ret = blk_set_perm(sd->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE, + BLK_PERM_ALL, errp); + if (ret < 0) { + return; + } blk_set_dev_ops(sd->blk, &sd_block_ops, sd); } } -- cgit v1.2.3