qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [RFC PATCH 18/41] block: Allow error return in BlockDev


From: Max Reitz
Subject: Re: [Qemu-block] [RFC PATCH 18/41] block: Allow error return in BlockDevOps.change_media_cb()
Date: Mon, 20 Feb 2017 12:31:04 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0

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 <address@hidden>
> ---
>  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) {

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]