diff options
author | Max Reitz <mreitz@redhat.com> | 2015-10-26 21:39:08 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2015-11-11 16:22:47 +0100 |
commit | 7d8a9f71b9ec9fa295265392218efaf0771d96e0 (patch) | |
tree | afe0f85afbb521e8adfb7c523ad2da5a5e2d8438 /blockdev.c | |
parent | 38cb18f5b71428fb8a3e3759ac8fa21ac70cb1b5 (diff) |
blockdev: Add blockdev-open-tray
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r-- | blockdev.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/blockdev.c b/blockdev.c index 97be42f6cd..d01a99e9cf 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2088,6 +2088,42 @@ out: aio_context_release(aio_context); } +void qmp_blockdev_open_tray(const char *device, bool has_force, bool force, + Error **errp) +{ + BlockBackend *blk; + bool locked; + + if (!has_force) { + force = false; + } + + blk = blk_by_name(device); + if (!blk) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device); + return; + } + + if (!blk_dev_has_removable_media(blk)) { + error_setg(errp, "Device '%s' is not removable", device); + return; + } + + if (blk_dev_is_tray_open(blk)) { + return; + } + + locked = blk_dev_is_medium_locked(blk); + if (locked) { + blk_dev_eject_request(blk, force); + } + + if (!locked || force) { + blk_dev_change_media_cb(blk, false); + } +} + /* throttling disk I/O limits */ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, int64_t bps_wr, |