qemu-block
[Top][All Lists]
Advanced

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

Re: [Qemu-block] [PATCH] blockdev: fix error handling in do_open_tray


From: Kevin Wolf
Subject: Re: [Qemu-block] [PATCH] blockdev: fix error handling in do_open_tray
Date: Fri, 3 Jun 2016 21:13:01 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Am 03.06.2016 um 20:20 hat address@hidden geschrieben:
> From: Colin Lord <address@hidden>
> 
> Returns negative error codes and accompanying error messages in cases where
> the device has no tray or the tray is locked and isn't forced open. This
> extra information should result in better flexibility in functions that
> call do_open_tray.
> 
> Signed-off-by: Colin Lord <address@hidden>

Strictly speaking not a fix, but just a cleanup, right? Maybe change
that in the subject line.

> @@ -2348,8 +2345,8 @@ static int do_open_tray(const char *device, bool force, 
> Error **errp)
>      }
>  
>      if (!blk_dev_has_tray(blk)) {
> -        /* Ignore this command on tray-less devices */
> -        return ENOSYS;
> +        error_setg(errp, "Device '%s' does not have a tray", device);
> +        return -ENOSYS;
>      }
>  
>      if (blk_dev_is_tray_open(blk)) {
> @@ -2366,7 +2363,9 @@ static int do_open_tray(const char *device, bool force, 
> Error **errp)
>      }
>  
>      if (locked && !force) {
> -        return EINPROGRESS;
> +        error_setg(errp, "Device '%s' is locked and force was not specified, 
> "
> +                   "wait for tray to open and try again", device);
> +        return -EINPROGRESS;
>      }
>  
>      return 0;

You're changing the return values here (which is fine), but we need to
update the function comment as well. It still says:

 * May return +ENOSYS if the device has no tray,
 * or +EINPROGRESS if the tray is locked and the guest has been notified.

> @@ -2375,10 +2374,18 @@ static int do_open_tray(const char *device, bool 
> force, Error **errp)
>  void qmp_blockdev_open_tray(const char *device, bool has_force, bool force,
>                              Error **errp)
>  {
> +    Error *local_err = NULL;
> +    int rc;
> +
>      if (!has_force) {
>          force = false;
>      }
> -    do_open_tray(device, force, errp);
> +    rc = do_open_tray(device, force, &local_err);
> +    if (local_err && (rc == -EINPROGRESS || rc == -ENOSYS)) {

rc < 0 already implies that local_err is set, so while that check
doesn't hurt, technically it's redundant.

> +        error_free(local_err);
> +    } else {
> +        error_propagate(errp, local_err);
> +    }
>  }

Kevin



reply via email to

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