[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/10] block: eject_device(): Use error_set()
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 04/10] block: eject_device(): Use error_set() |
Date: |
Mon, 9 Jan 2012 09:24:11 -0200 |
Also drops the leftover 'mon' argument.
This is a preparation for the next commits which will port the
eject and change commands to the QAPI.
Signed-off-by: Luiz Capitulino <address@hidden>
---
blockdev.c | 30 ++++++++++++++++++++++--------
1 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index c832782..9ee5bae 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -665,21 +665,22 @@ void qmp_blockdev_snapshot_sync(const char *device, const
char *snapshot_file,
}
}
-static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
+static void eject_device(BlockDriverState *bs, int force, Error **errp)
{
if (!bdrv_dev_has_removable_media(bs)) {
- qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
- return -1;
+ error_set(errp, QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
+ return;
}
+
if (bdrv_dev_is_medium_locked(bs) && !bdrv_dev_is_tray_open(bs)) {
bdrv_dev_eject_request(bs, force);
if (!force) {
- qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
- return -1;
+ error_set(errp, QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
+ return;
}
}
+
bdrv_close(bs);
- return 0;
}
int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data)
@@ -687,13 +688,22 @@ int do_eject(Monitor *mon, const QDict *qdict, QObject
**ret_data)
BlockDriverState *bs;
int force = qdict_get_try_bool(qdict, "force", 0);
const char *filename = qdict_get_str(qdict, "device");
+ Error *err = NULL;
bs = bdrv_find(filename);
if (!bs) {
qerror_report(QERR_DEVICE_NOT_FOUND, filename);
return -1;
}
- return eject_device(mon, bs, force);
+
+ eject_device(bs, force, &err);
+ if (error_is_set(&err)) {
+ qerror_report_err(err);
+ error_free(err);
+ return -1;
+ }
+
+ return 0;
}
void qmp_block_passwd(const char *device, const char *password, Error **errp)
@@ -723,6 +733,7 @@ int do_change_block(Monitor *mon, const char *device,
BlockDriverState *bs;
BlockDriver *drv = NULL;
int bdrv_flags;
+ Error *err = NULL;
bs = bdrv_find(device);
if (!bs) {
@@ -736,7 +747,10 @@ int do_change_block(Monitor *mon, const char *device,
return -1;
}
}
- if (eject_device(mon, bs, 0) < 0) {
+ eject_device(bs, 0, &err);
+ if (error_is_set(&err)) {
+ qerror_report_err(err);
+ error_free(err);
return -1;
}
bdrv_flags = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;
--
1.7.8.2.325.g247f9.dirty
- [Qemu-devel] [PATCH v1 00/10]: QAPI conversions round 4, Luiz Capitulino, 2012/01/09
- [Qemu-devel] [PATCH 01/10] vnc: Simplify vnc_display_password(), Luiz Capitulino, 2012/01/09
- [Qemu-devel] [PATCH 02/10] qapi: Convert set_password, Luiz Capitulino, 2012/01/09
- [Qemu-devel] [PATCH 04/10] block: eject_device(): Use error_set(),
Luiz Capitulino <=
- [Qemu-devel] [PATCH 05/10] qapi: Convert eject, Luiz Capitulino, 2012/01/09
- [Qemu-devel] [PATCH 03/10] qapi: Convert expire_password, Luiz Capitulino, 2012/01/09
- [Qemu-devel] [PATCH 06/10] monitor: expose readline state, Luiz Capitulino, 2012/01/09
- [Qemu-devel] [PATCH 07/10] qapi: Introduce change-vnc-password, Luiz Capitulino, 2012/01/09
- [Qemu-devel] [PATCH 10/10] qapi: Convert block_set_io_throttle, Luiz Capitulino, 2012/01/09
- [Qemu-devel] [PATCH 08/10] qerror: Extend QERR_DEVICE_ENCRYPTED, Luiz Capitulino, 2012/01/09
- [Qemu-devel] [PATCH 09/10] qapi: Convert change, Luiz Capitulino, 2012/01/09