block: Cleanups around error reporting
cover block: Cleanups around error reporting
Markus Armbruster (4):
blockdev: Give find_block_job() an Error ** parameter
blockdev: Eliminate silly QERR_BLOCK_JOB_NOT_ACTIVE macro
block: New bdrv_add_key(), convert monitor to use it
block: Eliminate silly QERR_ macros used for encryption keys
block.c | 31 +++++++++++++++++++++++++++++++ blockdev.c | 44 +++++++++++--------------------------------- include/block/block.h | 1 + include/qapi/qmp/qerror.h | 9 --------- monitor.c | 16 +++++++++++----- qmp.c | 8 ++++---- 6 files changed, 58 insertions(+), 51 deletions(-)
Signature · 1 line
1.9.3
PATCH 1/4 blockdev: Give find_block_job() an Error ** parameter
When find_block_job() fails, all its callers build the same Error object. Build it in find_block_job() instead.
--- blockdev.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
blockdev.c +8 -11
@@ -2653,7 +2653,8 @@ out: }/* Get the block job for a given device name and acquire its AioContext */ -static BlockJob *find_block_job (const char *device,AioContext **aio_context) +static BlockJob *find_block_job (const char *device,AioContext **aio_context, +Error **errp) {BlockDriverState *bs;
@@ -2673,6 +2674,7 @@ static BlockJob *find_block_job(const char *device, AioContext **aio_context)return bs->job; notfound: +error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device); *aio_context =NULL ;return NULL ; }
@@ -2680,10 +2682,9 @@ notfound:void qmp_block_job_set_speed (const char *device,int64_t speed,Error **errp) {AioContext *aio_context; -BlockJob *job =find_block_job (device, &aio_context); +BlockJob *job =find_block_job (device, &aio_context, errp);if (!job) { -error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device);return ; }
@@ -2695,10 +2696,9 @@ void qmp_block_job_cancel(const char *device, bool has_force, bool force, Error **errp) { AioContext *aio_context; -BlockJob *job =find_block_job (device, &aio_context); +BlockJob *job =find_block_job (device, &aio_context, errp);if (!job) { -error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device);return ; }
@@ -2721,10 +2721,9 @@ out:void qmp_block_job_pause (const char *device,Error **errp) {AioContext *aio_context; -BlockJob *job =find_block_job (device, &aio_context); +BlockJob *job =find_block_job (device, &aio_context, errp);if (!job) { -error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device);return ; }
@@ -2736,10 +2735,9 @@ void qmp_block_job_pause(const char *device, Error **errp)void qmp_block_job_resume (const char *device,Error **errp) {AioContext *aio_context; -BlockJob *job =find_block_job (device, &aio_context); +BlockJob *job =find_block_job (device, &aio_context, errp);if (!job) { -error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device);return ; }
@@ -2751,10 +2749,9 @@ void qmp_block_job_resume(const char *device, Error **errp)void qmp_block_job_complete (const char *device,Error **errp) {AioContext *aio_context; -BlockJob *job =find_block_job (device, &aio_context); +BlockJob *job =find_block_job (device, &aio_context, errp);if (!job) { -error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device);return ; }
Signature · 1 line
1.9.3
PATCH 2/4 blockdev: Eliminate silly QERR_BLOCK_JOB_NOT_ACTIVE macro
In reply to Markus ArmbrusterFrom: Markus Armbruster <[email protected]>
The QERR_ macros are leftovers from the days of "rich" error objects. They're used with error_set() and qerror_report(), and expand into the first *two* arguments. This trickiness has become pointless. Clean this one up.
--- blockdev.c | 3 ++- include/qapi/qmp/qerror.h | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-)
blockdev.c +2 -1
@@ -2674,7 +2674,8 @@ static BlockJob *find_block_job(const char *device, AioContext **aio_context,return bs->job; notfound: -error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device); +error_set (errp,ERROR_CLASS_DEVICE_NOT_ACTIVE , +"No active block job on device '%s'" , device); *aio_context =NULL ;return NULL ; }
include/qapi/qmp/qerror.h +0 -3
@@ -37,9 +37,6 @@ void qerror_report_err(Error *err);#define QERR_BASE_NOT_FOUND \ ERROR_CLASS_GENERIC_ERROR, "Base '%s' not found" -#define QERR_BLOCK_JOB_NOT_ACTIVE \ - ERROR_CLASS_DEVICE_NOT_ACTIVE, "No active block job on device '%s'" -#define QERR_BLOCK_JOB_NOT_READY \ ERROR_CLASS_GENERIC_ERROR, "The active block job for device '%s' cannot be completed"
Signature · 1 line
1.9.3
PATCH 3/4 block: New bdrv_add_key(), convert monitor to use it
In reply to Markus Armbruster--- block.c | 29 +++++++++++++++++++++++++++++ blockdev.c | 24 ++---------------------- include/block/block.h | 1 + monitor.c | 16 +++++++++++----- qmp.c | 8 ++++---- 5 files changed, 47 insertions(+), 31 deletions(-)
block.c +29 -0
@@ -3722,6 +3722,35 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)return ret; } +/* +* Provide an encryption key for @bs. +* If @key is non-null: +* If @bs is not encrypted, fail. +* Else if the key is invalid, fail. +* Else set @bs's key to @key, replacing the existing key, if any. +* If @key is null: +* If @bs is encrypted and still lacks a key, fail. +* Else do nothing. +* On failure, store an error object through @errp if non-null. +*/ +void bdrv_add_key (BlockDriverState *bs,const char *key,Error **errp) +{ +if (key) { +if (!bdrv_is_encrypted (bs)) { +error_set (errp,QERR_DEVICE_NOT_ENCRYPTED , +bdrv_get_device_name (bs)); + }else if (bdrv_set_key (bs, key) <0 ) { +error_set (errp,QERR_INVALID_PASSWORD ); + } + }else { +if (bdrv_key_required (bs)) { +error_set (errp,QERR_DEVICE_ENCRYPTED , +bdrv_get_device_name (bs), +bdrv_get_encrypted_filename (bs)); + } + } +} +const char *bdrv_get_format_name (BlockDriverState *bs) {return bs->drv ? bs->drv->format_name :NULL ;
blockdev.c +2 -22
@@ -1793,7 +1793,6 @@ void qmp_block_passwd(bool has_device, const char *device,Error *local_err =NULL ;BlockDriverState *bs;AioContext *aio_context; -int err; bs = bdrv_lookup_bs(has_device ? device : NULL, has_node_name ? node_name : NULL,
@@ -1806,16 +1805,8 @@ void qmp_block_passwd(bool has_device, const char *device, aio_context =bdrv_get_aio_context (bs);aio_context_acquire (aio_context); - err =bdrv_set_key (bs, password); -if (err == -EINVAL ) { -error_set (errp,QERR_DEVICE_NOT_ENCRYPTED ,bdrv_get_device_name (bs)); - goto out; - }else if (err <0 ) { -error_set (errp,QERR_INVALID_PASSWORD ); - goto out; - } +bdrv_add_key (bs, password, errp); -out:aio_context_release (aio_context); }
@@ -1833,18 +1824,7 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,return ; } -if (bdrv_key_required (bs)) { -if (password) { -if (bdrv_set_key (bs, password) <0 ) { -error_set (errp,QERR_INVALID_PASSWORD ); - } - }else { -error_set (errp,QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), -bdrv_get_encrypted_filename (bs)); - } - }else if (password) { -error_set (errp,QERR_DEVICE_NOT_ENCRYPTED ,bdrv_get_device_name (bs)); - } +bdrv_add_key (bs, password, errp); } void qmp_change_blockdev(const char *device, const char *filename,
include/block/block.h +1 -0
@@ -378,6 +378,7 @@ BlockDriverState *bdrv_next(BlockDriverState *bs);int bdrv_is_encrypted (BlockDriverState *bs);int bdrv_key_required (BlockDriverState *bs);int bdrv_set_key (BlockDriverState *bs,const char *key); +void bdrv_add_key (BlockDriverState *bs,const char *key,Error **errp);int bdrv_query_missing_keys (void );void bdrv_iterate_format (void (*it)(void *opaque,const char *name),void *opaque);
monitor.c +11 -5
@@ -5366,9 +5366,12 @@ static void bdrv_password_cb(void *opaque, const char *password,Monitor *mon = opaque;BlockDriverState *bs = readline_opaque;int ret =0 ; +Error *local_err =NULL ; -if (bdrv_set_key (bs, password) !=0 ) { -monitor_printf (mon,"invalid password\n" ); +bdrv_add_key (bs, password, &local_err); +if (local_err) { +monitor_printf (mon,"%s\n" ,error_get_pretty (local_err)); +error_free (local_err); ret = -EPERM ; }if (mon->password_completion_cb)
@@ -5386,17 +5389,20 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, BlockCompletionFunc *completion_cb, void *opaque) { +Error *local_err =NULL ;int err; -if (!bdrv_key_required (bs)) { +bdrv_add_key (bs,NULL , &local_err); +if (!local_err) {if (completion_cb)completion_cb (opaque,0 );return 0 ; } +/* Need a key for @bs */ +if (monitor_ctrl_mode (mon)) { -qerror_report (QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), -bdrv_get_encrypted_filename (bs)); +qerror_report_err (local_err);return -1 ; }
qmp.c +4 -4
@@ -150,6 +150,7 @@ SpiceInfo *qmp_query_spice(Error **errp)void qmp_cont (Error **errp) { +Error *local_err =NULL ;BlockDriverState *bs;if (runstate_needs_reset ()) {
@@ -163,10 +164,9 @@ void qmp_cont(Error **errp)bdrv_iostatus_reset (bs); }for (bs =bdrv_next (NULL ); bs; bs =bdrv_next (bs)) { -if (bdrv_key_required (bs)) { -error_set (errp,QERR_DEVICE_ENCRYPTED , -bdrv_get_device_name (bs), -bdrv_get_encrypted_filename (bs)); +bdrv_add_key (bs,NULL , &local_err); +if (local_err) { +error_propagate (errp, local_err);return ; } }
Signature · 1 line
1.9.3
PATCH 4/4 block: Eliminate silly QERR_ macros used for encryption keys
In reply to Markus ArmbrusterThe QERR_ macros are leftovers from the days of "rich" error objects. They're used with error_set() and qerror_report(), and expand into the first *two* arguments. This trickiness has become pointless. Clean up QERR_DEVICE_ENCRYPTED and QERR_DEVICE_NOT_ENCRYPTED.
--- block.c | 6 ++++-- include/qapi/qmp/qerror.h | 6 ------ 2 files changed, 4 insertions(+), 8 deletions(-)
block.c +4 -2
@@ -3737,14 +3737,16 @@ void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) {if (key) {if (!bdrv_is_encrypted (bs)) { -error_set (errp,QERR_DEVICE_NOT_ENCRYPTED , +error_set (errp,ERROR_CLASS_GENERIC_ERROR , +"Device '%s' is not encrypted" ,bdrv_get_device_name (bs)); }else if (bdrv_set_key (bs, key) <0 ) {error_set (errp,QERR_INVALID_PASSWORD ); } }else {if (bdrv_key_required (bs)) { -error_set (errp,QERR_DEVICE_ENCRYPTED , +error_set (errp,ERROR_CLASS_DEVICE_ENCRYPTED , +"'%s' (%s) is encrypted" ,bdrv_get_device_name (bs),bdrv_get_encrypted_filename (bs)); }
include/qapi/qmp/qerror.h +0 -6
@@ -52,9 +52,6 @@ void qerror_report_err(Error *err);#define QERR_COMMAND_NOT_FOUND \ ERROR_CLASS_COMMAND_NOT_FOUND, "The command %s has not been found" -#define QERR_DEVICE_ENCRYPTED \ - ERROR_CLASS_DEVICE_ENCRYPTED, "'%s' (%s) is encrypted" -#define QERR_DEVICE_HAS_NO_MEDIUM \ ERROR_CLASS_GENERIC_ERROR, "Device '%s' has no medium"
@@ -73,9 +70,6 @@ void qerror_report_err(Error *err);#define QERR_DEVICE_NOT_ACTIVE \ ERROR_CLASS_DEVICE_NOT_ACTIVE, "No %s device has been activated" -#define QERR_DEVICE_NOT_ENCRYPTED \ - ERROR_CLASS_GENERIC_ERROR, "Device '%s' is not encrypted" -#define QERR_DEVICE_NOT_FOUND \ ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found"
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 4/4] block: Eliminate silly QERR_ macros used for encryption keys
Am 14.01.2015 um 15:31 hat Markus Armbruster geschrieben:
Quoted 16 lines
The
QERR_macros are leftovers from the days of "rich" error objects. They're used witherror_set()andqerror_report(), and expand into the first *two* arguments. This trickiness has become pointless. Clean upQERR_DEVICE_ENCRYPTEDandQERR_DEVICE_NOT_ENCRYPTED.Signed-off-by Markus Armbruster <[email protected]>--- block.c | 6 ++++-- include/qapi/qmp/qerror.h | 6 ------ 2 files changed, 4 insertions(+), 8 deletions(-)block.c +0
-0
block.c void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) · line 3742
Quoted 7 lines
block.c +2
-1@@ -3737,14 +3737,16 @@ void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) {if (key) {if (!bdrv_is_encrypted (bs)) { -error_set (errp,QERR_DEVICE_NOT_ENCRYPTED , +error_set (errp,ERROR_CLASS_GENERIC_ERROR , +"Device '%s' is not encrypted" ,bdrv_get_device_name (bs));
Why not error_setg()?
Kevin
Re: [Qemu-devel] [PATCH 4/4] block: Eliminate silly QERR_ macros used for encryption keys
Quoted 12 lines · Kevin Wolf
Am 14.01.2015 um 15:31 hat Markus Armbruster geschrieben:
Quoted 11 lines
The
QERR_macros are leftovers from the days of "rich" error objects. They're used witherror_set()andqerror_report(), and expand into the first *two* arguments. This trickiness has become pointless. Clean upQERR_DEVICE_ENCRYPTEDandQERR_DEVICE_NOT_ENCRYPTED.Signed-off-by Markus Armbruster <[email protected]>--- block.c | 6 ++++-- include/qapi/qmp/qerror.h | 6 ------ 2 files changed, 4 insertions(+), 8 deletions(-)
Quoted 14 lines
block.c void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) · line 3742
Quoted 12 lines
block.c +2
-1@@ -3737,14 +3737,16 @@ void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) {if (key) {if (!bdrv_is_encrypted (bs)) { -error_set (errp,QERR_DEVICE_NOT_ENCRYPTED , +error_set (errp,ERROR_CLASS_GENERIC_ERROR , +"Device '%s' is not encrypted" ,bdrv_get_device_name (bs));Why not
error_setg()?
Because I forgot? I'll respin unless you prefer to fix it up on commit.
Re: [Qemu-devel] [PATCH 4/4] block: Eliminate silly QERR_ macros used for encryption keys
Am 15.01.2015 um 13:40 hat Markus Armbruster geschrieben:
Quoted 29 lines
Quoted 12 lines · Kevin Wolf
Am 14.01.2015 um 15:31 hat Markus Armbruster geschrieben:
Quoted 11 lines
The
QERR_macros are leftovers from the days of "rich" error objects. They're used witherror_set()andqerror_report(), and expand into the first *two* arguments. This trickiness has become pointless. Clean upQERR_DEVICE_ENCRYPTEDandQERR_DEVICE_NOT_ENCRYPTED.Signed-off-by Markus Armbruster <[email protected]>--- block.c | 6 ++++-- include/qapi/qmp/qerror.h | 6 ------ 2 files changed, 4 insertions(+), 8 deletions(-)Quoted 14 lines
block.c void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) · line 3742
Quoted 12 lines
block.c +2
-1@@ -3737,14 +3737,16 @@ void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) {if (key) {if (!bdrv_is_encrypted (bs)) { -error_set (errp,QERR_DEVICE_NOT_ENCRYPTED , +error_set (errp,ERROR_CLASS_GENERIC_ERROR , +"Device '%s' is not encrypted" ,bdrv_get_device_name (bs));Why not
error_setg()?
Quoted 1 line
Because I forgot? I'll respin unless you prefer to fix it up on commit.
I would fix it on commit, but it's Stefan's week, so whatever he prefers.
Kevin
Quoted 5 lines · Markus Armbruster
Markus Armbruster (4):
blockdev: Givefind_block_job()an Error ** parameter
blockdev: Eliminate sillyQERR_BLOCK_JOB_NOT_ACTIVEmacro
block: Newbdrv_add_key(), convert monitor to use it
block: Eliminate sillyQERR_macros used for encryption keys
Quoted 9 lines
block.c | 31 +++++++++++++++++++++++++++++++ blockdev.c | 44 +++++++++++--------------------------------- include/block/block.h | 1 + include/qapi/qmp/qerror.h | 9 --------- monitor.c | 16 +++++++++++----- qmp.c | 8 ++++---- 6 files changed, 58 insertions(+), 51 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org