From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8tiM-0004dU-Os for qemu-devel@nongnu.org; Fri, 03 Jun 2016 14:20:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8tiK-0003GO-MF for qemu-devel@nongnu.org; Fri, 03 Jun 2016 14:20:57 -0400 From: clord@redhat.com Date: Fri, 3 Jun 2016 14:20:48 -0400 Message-Id: <1464978048-32189-1-git-send-email-clord@redhat.com> Subject: [Qemu-devel] [PATCH] blockdev: fix error handling in do_open_tray List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com, Colin Lord From: Colin Lord 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 --- blockdev.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/blockdev.c b/blockdev.c index 717785e..d10ab35 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2286,17 +2286,14 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp) } rc = do_open_tray(device, force, &local_err); - if (local_err) { + if (rc == -ENOSYS) { + error_free(local_err); + local_err = NULL; + } else if (local_err) { error_propagate(errp, local_err); return; } - if (rc == EINPROGRESS) { - error_setg(errp, "Device '%s' is locked and force was not specified, " - "wait for tray to open and try again", device); - return; - } - qmp_x_blockdev_remove_medium(device, errp); } @@ -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; @@ -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)) { + error_free(local_err); + } else { + error_propagate(errp, local_err); + } } void qmp_blockdev_close_tray(const char *device, Error **errp) -- 2.5.5