QMP/HMP: add error reason to open failures
v2 cover QMP/HMP: add error reason to open failures
I was surprised to find out that we still have old users of QERR_OPEN_FILE_FAILED that print errors like:
(qemu) dump-guest-memory -p /lkmads/foo
Could not open '/lkmads/foo'
(qemu)
This series converts all those users to a new helper called error_setg_file_open(), which adds error reason to open failures:
(qemu) dump-guest-memory -p /sfmdkjf/foo
Could not open '/sfmdkjf/foo': No such file or directory (qemu)
v2
- bdrv_reopen_prepare(): use generic error message
- s/error/-ret for bdrv_open() errors
Luiz Capitulino (9):
error: add error_setg_file_open() helper
rng-random: use error_setg_file_open()
block: mirror_complete(): use error_setg_file_open()
blockdev: use error_setg_file_open()
cpus: use error_setg_file_open()
dump: qmp_dump_guest_memory(): use error_setg_file_open()
savevm: qmp_xen_save_devices_state(): use error_setg_file_open()
block: bdrv_reopen_prepare(): don't use QERR_OPEN_FILE_FAILED
qerror: drop QERR_OPEN_FILE_FAILED macro
backends/rng-random.c | 3 +-- block.c | 4 ++-- block/mirror.c | 2 +- blockdev.c | 11 +++++++---- cpus.c | 4 ++-- dump.c | 2 +- include/qapi/error.h | 5 +++++ include/qapi/qmp/qerror.h | 3 --- savevm.c | 2 +- util/error.c | 5 +++++ 10 files changed, 25 insertions(+), 16 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v2 1/9 error: add error_setg_file_open() helper
--- include/qapi/error.h | 5 +++++ util/error.c | 5 +++++ 2 files changed, 10 insertions(+)
include/qapi/error.h +5 -0
@@ -45,6 +45,11 @@ void error_set_errno(Error **err, int os_error, ErrorClass err_class, const char error_set_errno(err, os_error, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)/** +* Helper for open() errors + */ +void error_setg_file_open (Error **errp,int os_errno,const char *filename); + +/** * Returns true if an indirect pointer to an error is pointing to a valid * error object. */
util/error.c +5 -0
@@ -71,6 +71,11 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class, *errp = err; } +void error_setg_file_open (Error **errp,int os_errno,const char *filename) +{ +error_setg_errno (errp, os_errno,"Could not open '%s'" , filename); +} +Error *error_copy (const Error *err) {Error *err_new;
Signature · 1 line
1.8.1.4
PATCH v2 2/9 rng-random: use error_setg_file_open()
In reply to Luiz Capitulino--- backends/rng-random.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
backends/rng-random.c +1 -2
@@ -78,9 +78,8 @@ static void rng_random_opened(RngBackend *b, Error **errp) "filename", "a valid filename"); }else { s->fd =qemu_open (s->filename,O_RDONLY |O_NONBLOCK ); -if (s->fd ==-1 ) { -error_set (errp,QERR_OPEN_FILE_FAILED , s->filename); +error_setg_file_open (errp, errno, s->filename); } } }
Signature · 1 line
1.8.1.4
PATCH v2 3/9 block: mirror_complete(): use error_setg_file_open()
In reply to Luiz Capitulino--- block/mirror.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/mirror.c +1 -1
@@ -512,7 +512,7 @@ static void mirror_complete(BlockJob *job, Error **errp)char backing_filename[PATH_MAX ];bdrv_get_full_backing_filename (s->target, backing_filename,sizeof (backing_filename)); -error_set (errp,QERR_OPEN_FILE_FAILED , backing_filename); +error_setg_file_open (errp, -ret, backing_filename);return ; }if (!s->synced) {
Signature · 1 line
1.8.1.4
PATCH v2 4/9 blockdev: use error_setg_file_open()
In reply to Luiz Capitulino--- blockdev.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
blockdev.c +7 -4
@@ -899,7 +899,7 @@ static void external_snapshot_prepare(BlkTransactionStates *common, ret =bdrv_open (states->new_bs, new_image_file,NULL , flags |BDRV_O_NO_BACKING , drv);if (ret !=0 ) { -error_set (errp,QERR_OPEN_FILE_FAILED , new_image_file); +error_setg_file_open (errp, -ret, new_image_file); } }
@@ -1062,8 +1062,11 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename, int bdrv_flags, BlockDriver *drv, const char *password, Error **errp) { - if (bdrv_open(bs, filename, NULL, bdrv_flags, drv) < 0) { -error_set (errp ,QERR_OPEN_FILE_FAILED ,filename ); + int ret; + + ret =bdrv_open (bs, filename,NULL , bdrv_flags, drv); +if (ret <0 ) { +error_setg_file_open (errp, -ret, filename);return ; }
@@ -1483,7 +1486,7 @@ void qmp_drive_mirror(const char *device, const char *target,if (ret <0 ) {bdrv_delete (target_bs); -error_set (errp,QERR_OPEN_FILE_FAILED , target); +error_setg_file_open (errp, -ret, target);return ; }
Signature · 1 line
1.8.1.4
PATCH v2 5/9 cpus: use error_setg_file_open()
In reply to Luiz Capitulino--- cpus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
cpus.c +2 -2
@@ -1278,7 +1278,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename, f =fopen (filename,"wb" );if (!f) { -error_set (errp,QERR_OPEN_FILE_FAILED , filename); +error_setg_file_open (errp, errno, filename);return ; }
@@ -1308,7 +1308,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, f =fopen (filename,"wb" );if (!f) { -error_set (errp,QERR_OPEN_FILE_FAILED , filename); +error_setg_file_open (errp, errno, filename);return ; }
Signature · 1 line
1.8.1.4
PATCH v2 6/9 dump: qmp_dump_guest_memory(): use error_setg_file_open()
In reply to Luiz Capitulino--- dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
dump.c +1 -1
@@ -847,7 +847,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,if (strstart (file,"file:" , &p)) { fd =qemu_open (p,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY ,S_IRUSR );if (fd <0 ) { -error_set (errp,QERR_OPEN_FILE_FAILED , p); +error_setg_file_open (errp, errno, p);return ; } }
Signature · 1 line
1.8.1.4
PATCH v2 7/9 savevm: qmp_xen_save_devices_state(): use error_setg_file_open()
In reply to Luiz Capitulino--- savevm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
savevm.c +1 -1
@@ -2410,7 +2410,7 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) f =qemu_fopen (filename,"wb" );if (!f) { -error_set (errp,QERR_OPEN_FILE_FAILED , filename); +error_setg_file_open (errp, errno, filename); goto the_end; } ret =qemu_save_device_state (f);
Signature · 1 line
1.8.1.4
PATCH v2 8/9 block: bdrv_reopen_prepare(): don't use QERR_OPEN_FILE_FAILED
In reply to Luiz CapitulinoThe call to drv->bdrv_reopen_prepare() can fail due to reasons other than an open failure. Unfortunately, we can't use errno nor -ret, cause they are not always set.
Stick to a generic error message then.
--- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block.c +2 -2
@@ -1291,8 +1291,8 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,if (local_err !=NULL ) {error_propagate (errp, local_err); }else { -error_set (errp,QERR_OPEN_FILE_FAILED , - reopen_state->bs->filename); +error_setg (errp,"failed while preparing to reopen image '%s'" , + reopen_state->bs->filename); } goto error; }
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 8/9] block: bdrv_reopen_prepare(): don't use QERR_OPEN_FILE_FAILED
Am 10.06.2013 um 19:02 hat Luiz Capitulino geschrieben:
Quoted 16 lines
The call to
drv->bdrv_reopen_prepare()can fail due to reasons other than an open failure. Unfortunately, we can't use errno nor -ret, cause they are not always set.Stick to a generic error message then.
Signed-off-by Luiz Capitulino <[email protected]>--- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)block.c +0
-0
block.c int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, · line 1294
Quoted 6 lines
block.c +1
-2@@ -1291,8 +1291,8 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,if (local_err !=NULL ) {error_propagate (errp, local_err); }else { -error_set (errp,QERR_OPEN_FILE_FAILED , - reopen_state->bs->filename); + error_setg(errp, "failed while preparing to reopen image '%s'",
Please start the message with an uppercase letter like before.
Also, maybe "Failed to prepare for reopening '%s'" is better?
block.c int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, · line 1298
Quoted 4 lines
block.c +1
-0+ reopen_state->bs->filename); } goto error; }
Kevin
Re: [Qemu-devel] [PATCH 8/9] block: bdrv_reopen_prepare(): don't use QERR_OPEN_FILE_FAILED
Quoted 12 lines · On Tue, 11 Jun 2013 10:38:47 +0200 Kevin Wolf <[email protected]> wrote:
Am 10.06.2013 um 19:02 hat Luiz Capitulino geschrieben:
Quoted 11 lines
The call to
drv->bdrv_reopen_prepare()can fail due to reasons other than an open failure. Unfortunately, we can't use errno nor -ret, cause they are not always set.Stick to a generic error message then.
Signed-off-by Luiz Capitulino <[email protected]>--- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines
block.c int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, · line 1294
Quoted 11 lines
block.c +1
-2@@ -1291,8 +1291,8 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,if (local_err !=NULL ) {error_propagate (errp, local_err); }else { -error_set (errp,QERR_OPEN_FILE_FAILED , - reopen_state->bs->filename); + error_setg(errp, "failed while preparing to reopen image '%s'",Please start the message with an uppercase letter like before.
Fixed.
Quoted 1 line
Also, maybe "Failed to prepare for reopening '%s'" is better?
I have no idea :)
PATCH v2 9/9 qerror: drop QERR_OPEN_FILE_FAILED macro
In reply to Luiz CapitulinoNot used since the last commit.
--- include/qapi/qmp/qerror.h | 3 --- 1 file changed, 3 deletions(-)
include/qapi/qmp/qerror.h +0 -3
@@ -177,9 +177,6 @@ void assert_no_error(Error *err);#define QERR_NOT_SUPPORTED \ ERROR_CLASS_GENERIC_ERROR, "Not supported" -#define QERR_OPEN_FILE_FAILED \ - ERROR_CLASS_GENERIC_ERROR, "Could not open '%s'" -#define QERR_PERMISSION_DENIED \ ERROR_CLASS_GENERIC_ERROR, "Insufficient permission to perform this operation"
Signature · 1 line
1.8.1.4
Quoted 30 lines · Luiz Capitulino
I was surprised to find out that we still have old users of
QERR_OPEN_FILE_FAILEDthat print errors like:(qemu) dump-guest-memory -p /lkmads/foo
Could not open '/lkmads/foo'
(qemu)This series converts all those users to a new helper called
error_setg_file_open(), which adds error reason to open failures:(qemu) dump-guest-memory -p /sfmdkjf/foo
Could not open '/sfmdkjf/foo': No such file or directory (qemu)v2
-
bdrv_reopen_prepare(): use generic error message
- s/error/-ret forbdrv_open()errorsLuiz Capitulino (9):
error: adderror_setg_file_open()helper
rng-random: useerror_setg_file_open()
block:mirror_complete(): useerror_setg_file_open()
blockdev: useerror_setg_file_open()
cpus: useerror_setg_file_open()
dump:qmp_dump_guest_memory(): useerror_setg_file_open()
savevm:qmp_xen_save_devices_state(): useerror_setg_file_open()
block:bdrv_reopen_prepare(): don't useQERR_OPEN_FILE_FAILED
qerror: dropQERR_OPEN_FILE_FAILEDmacro
Quoted 15 lines
backends/rng-random.c | 3 +-- block.c | 4 ++-- block/mirror.c | 2 +- blockdev.c | 11 +++++++---- cpus.c | 4 ++-- dump.c | 2 +- include/qapi/error.h | 5 +++++ include/qapi/qmp/qerror.h | 3 --- savevm.c | 2 +- util/error.c | 5 +++++ 10 files changed, 25 insertions(+), 16 deletions(-)Signature · 1 line
1.8.1.4
On Mon, Jun 10, 2013 at 01:02:19PM -0400, Luiz Capitulino wrote:
I should have qualified by Reviewed-by: with "reviewed block layer changes".
Stefan
Quoted 2 lines · On Tue, 11 Jun 2013 09:44:08 +0200 Stefan Hajnoczi <[email protected]> wrote:
On Mon, Jun 10, 2013 at 01:02:19PM -0400, Luiz Capitulino wrote:
I should have qualified by Reviewed-by: with "reviewed block layer changes".
I've added it only to the block layer patches.
Am 10.06.2013 um 19:02 hat Luiz Capitulino geschrieben:
Quoted 10 lines
I was surprised to find out that we still have old users of
QERR_OPEN_FILE_FAILEDthat print errors like:(qemu) dump-guest-memory -p /lkmads/foo
Could not open '/lkmads/foo'
(qemu)This series converts all those users to a new helper called
error_setg_file_open(), which adds error reason to open failures:
Quoted 8 lines
(qemu) dump-guest-memory -p /sfmdkjf/foo
Could not open '/sfmdkjf/foo': No such file or directory (qemu)v2
-
bdrv_reopen_prepare(): use generic error message
- s/error/-ret forbdrv_open()errors
I suggested an error message change in patch 8, but I think that's minor enough that you don't have to resend the series after changing the text. So you can add: