diff mbox

[RESEND,42/50] blockdev: Implement eject with basic operations

Message ID 1422387983-32153-43-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Jan. 27, 2015, 7:46 p.m. UTC
Implement 'eject' by calling blockdev-open-tray and
blockdev-remove-medium.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 blockdev.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Eric Blake Jan. 28, 2015, 8:26 p.m. UTC | #1
On 01/27/2015 12:46 PM, Max Reitz wrote:
> Implement 'eject' by calling blockdev-open-tray and
> blockdev-remove-medium.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  blockdev.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)

Hmm. If you decide to enforce node-name only on the low-level command,
but still want this high-level command to support BDS->BB lookup for
convenience, you might need additional code here.  I don't know if that
is an argument in favor or against supporting BDS->BB as convenience at
the low level.  I don't have a strong enough opinion towards either
decision, so I'll let others chime in or let your original choice be
good enough.  Therefore:

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index e4588b3..0b204eb 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1865,15 +1865,15 @@  out:
 
 void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
 {
-    BlockBackend *blk;
+    Error *local_err = NULL;
 
-    blk = blk_by_name(device);
-    if (!blk) {
-        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+    qmp_blockdev_open_tray(device, has_force, force, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
         return;
     }
 
-    eject_device(blk, force, errp);
+    qmp_blockdev_remove_medium(device, errp);
 }
 
 void qmp_block_passwd(bool has_device, const char *device,