All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] blockdev: fix error handling in do_open_tray
@ 2016-06-03 18:20 clord
  2016-06-03 19:02 ` Eric Blake
  2016-06-03 19:13 ` Kevin Wolf
  0 siblings, 2 replies; 3+ messages in thread
From: clord @ 2016-06-03 18:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, armbru, qemu-block, mreitz, Colin Lord

From: Colin Lord <clord@redhat.com>

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 <clord@redhat.com>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-03 19:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-03 18:20 [Qemu-devel] [PATCH] blockdev: fix error handling in do_open_tray clord
2016-06-03 19:02 ` Eric Blake
2016-06-03 19:13 ` Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.