On 13.02.2017 18:22, Kevin Wolf wrote: > 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 <kw...@redhat.com> > --- > block/block-backend.c | 12 +++++++++--- > blockdev.c | 19 +++++++++++++++---- > hw/block/fdc.c | 2 +- > hw/ide/core.c | 2 +- > hw/scsi/scsi-disk.c | 2 +- > hw/sd/sd.c | 2 +- > include/block/block_int.h | 2 +- > include/sysemu/block-backend.h | 2 +- > 8 files changed, 30 insertions(+), 13 deletions(-) > > diff --git a/block/block-backend.c b/block/block-backend.c > index e10a278..0c23add 100644 > --- a/block/block-backend.c > +++ b/block/block-backend.c > @@ -671,15 +671,21 @@ void blk_set_dev_ops(BlockBackend *blk, const > BlockDevOps *ops, > * Else, notify of media eject. > * Also send DEVICE_TRAY_MOVED events as appropriate. > */ > -void blk_dev_change_media_cb(BlockBackend *blk, bool load) > +void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp)
May deserve a comment that this function never fails with load == false. The assertion is not too hidden, but it's not extremely visible either. Max > { > if (blk->dev_ops && blk->dev_ops->change_media_cb) { > bool tray_was_open, tray_is_open; > + Error *local_err = NULL; > > assert(!blk->legacy_dev); > > tray_was_open = blk_dev_is_tray_open(blk); > - blk->dev_ops->change_media_cb(blk->dev_opaque, load); > + blk->dev_ops->change_media_cb(blk->dev_opaque, load, &local_err); > + if (local_err) { > + assert(load == true); > + error_propagate(errp, local_err); > + return; > + } > tray_is_open = blk_dev_is_tray_open(blk); > > if (tray_was_open != tray_is_open) {
signature.asc
Description: OpenPGP digital signature