* [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures
@ 2013-06-07 19:52 Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 1/9] error: add error_setg_file_open() helper Luiz Capitulino
` (8 more replies)
0 siblings, 9 replies; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-07 19:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru
Today 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)
Luiz Capitulino (9):
error: add error_setg_file_open() helper
rng-random: use error_setg_file_open()
block: bdrv_reopen_prepare(): 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()
qerror: drop QERR_OPEN_FILE_FAILED macro
backends/rng-random.c | 3 +--
block.c | 3 +--
block/mirror.c | 2 +-
blockdev.c | 6 +++---
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, 20 insertions(+), 15 deletions(-)
--
1.8.1.4
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 1/9] error: add error_setg_file_open() helper
2013-06-07 19:52 [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
@ 2013-06-07 19:52 ` Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 2/9] rng-random: use error_setg_file_open() Luiz Capitulino
` (7 subsequent siblings)
8 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-07 19:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
include/qapi/error.h | 5 +++++
util/error.c | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/include/qapi/error.h b/include/qapi/error.h
index 5cd2f0c..ffd1cea 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -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.
*/
diff --git a/util/error.c b/util/error.c
index 519f6b6..53b0435 100644
--- a/util/error.c
+++ b/util/error.c
@@ -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;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 2/9] rng-random: use error_setg_file_open()
2013-06-07 19:52 [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 1/9] error: add error_setg_file_open() helper Luiz Capitulino
@ 2013-06-07 19:52 ` Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): " Luiz Capitulino
` (6 subsequent siblings)
8 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-07 19:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
backends/rng-random.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/backends/rng-random.c b/backends/rng-random.c
index 830360c..68dfc8a 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -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);
}
}
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): use error_setg_file_open()
2013-06-07 19:52 [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 1/9] error: add error_setg_file_open() helper Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 2/9] rng-random: use error_setg_file_open() Luiz Capitulino
@ 2013-06-07 19:52 ` Luiz Capitulino
2013-06-10 8:39 ` Stefan Hajnoczi
2013-06-10 8:43 ` Stefan Hajnoczi
2013-06-07 19:52 ` [Qemu-devel] [PATCH 4/9] block: mirror_complete(): " Luiz Capitulino
` (5 subsequent siblings)
8 siblings, 2 replies; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-07 19:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
block.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/block.c b/block.c
index 79ad33d..c78f152 100644
--- a/block.c
+++ b/block.c
@@ -1291,8 +1291,7 @@ 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_file_open(errp, errno, reopen_state->bs->filename);
}
goto error;
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 4/9] block: mirror_complete(): use error_setg_file_open()
2013-06-07 19:52 [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
` (2 preceding siblings ...)
2013-06-07 19:52 ` [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): " Luiz Capitulino
@ 2013-06-07 19:52 ` Luiz Capitulino
2013-06-10 8:44 ` Stefan Hajnoczi
2013-06-07 19:52 ` [Qemu-devel] [PATCH 5/9] blockdev: " Luiz Capitulino
` (4 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-07 19:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
block/mirror.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/mirror.c b/block/mirror.c
index 8b07dec..89d531d 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -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, errno, backing_filename);
return;
}
if (!s->synced) {
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 5/9] blockdev: use error_setg_file_open()
2013-06-07 19:52 [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
` (3 preceding siblings ...)
2013-06-07 19:52 ` [Qemu-devel] [PATCH 4/9] block: mirror_complete(): " Luiz Capitulino
@ 2013-06-07 19:52 ` Luiz Capitulino
2013-06-10 8:45 ` Stefan Hajnoczi
2013-06-07 19:52 ` [Qemu-devel] [PATCH 6/9] cpus: " Luiz Capitulino
` (3 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-07 19:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
blockdev.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 9937311..c09adba 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -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, errno, new_image_file);
}
}
@@ -1063,7 +1063,7 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
const char *password, Error **errp)
{
if (bdrv_open(bs, filename, NULL, bdrv_flags, drv) < 0) {
- error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+ error_setg_file_open(errp, errno, filename);
return;
}
@@ -1483,7 +1483,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, errno, target);
return;
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 6/9] cpus: use error_setg_file_open()
2013-06-07 19:52 [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
` (4 preceding siblings ...)
2013-06-07 19:52 ` [Qemu-devel] [PATCH 5/9] blockdev: " Luiz Capitulino
@ 2013-06-07 19:52 ` Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 7/9] dump: qmp_dump_guest_memory(): " Luiz Capitulino
` (2 subsequent siblings)
8 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-07 19:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
cpus.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cpus.c b/cpus.c
index c232265..c8bc8ad 100644
--- a/cpus.c
+++ b/cpus.c
@@ -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;
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 7/9] dump: qmp_dump_guest_memory(): use error_setg_file_open()
2013-06-07 19:52 [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
` (5 preceding siblings ...)
2013-06-07 19:52 ` [Qemu-devel] [PATCH 6/9] cpus: " Luiz Capitulino
@ 2013-06-07 19:52 ` Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 8/9] savevm: qmp_xen_save_devices_state(): " Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 9/9] qerror: drop QERR_OPEN_FILE_FAILED macro Luiz Capitulino
8 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-07 19:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
dump.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dump.c b/dump.c
index c0d3da5..28fd296 100644
--- a/dump.c
+++ b/dump.c
@@ -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;
}
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 8/9] savevm: qmp_xen_save_devices_state(): use error_setg_file_open()
2013-06-07 19:52 [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
` (6 preceding siblings ...)
2013-06-07 19:52 ` [Qemu-devel] [PATCH 7/9] dump: qmp_dump_guest_memory(): " Luiz Capitulino
@ 2013-06-07 19:52 ` Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 9/9] qerror: drop QERR_OPEN_FILE_FAILED macro Luiz Capitulino
8 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-07 19:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
savevm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/savevm.c b/savevm.c
index 2ce439f..ff5ece6 100644
--- a/savevm.c
+++ b/savevm.c
@@ -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);
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 9/9] qerror: drop QERR_OPEN_FILE_FAILED macro
2013-06-07 19:52 [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
` (7 preceding siblings ...)
2013-06-07 19:52 ` [Qemu-devel] [PATCH 8/9] savevm: qmp_xen_save_devices_state(): " Luiz Capitulino
@ 2013-06-07 19:52 ` Luiz Capitulino
8 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-07 19:52 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru
Not used since the last commit.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
include/qapi/qmp/qerror.h | 3 ---
1 file changed, 3 deletions(-)
diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h
index 6c0a18d..c30c2f6 100644
--- a/include/qapi/qmp/qerror.h
+++ b/include/qapi/qmp/qerror.h
@@ -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"
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): use error_setg_file_open()
2013-06-07 19:52 ` [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): " Luiz Capitulino
@ 2013-06-10 8:39 ` Stefan Hajnoczi
2013-06-10 8:43 ` Stefan Hajnoczi
1 sibling, 0 replies; 20+ messages in thread
From: Stefan Hajnoczi @ 2013-06-10 8:39 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: kwolf, qemu-devel, armbru
On Fri, Jun 07, 2013 at 03:52:29PM -0400, Luiz Capitulino wrote:
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
> block.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/block.c b/block.c
> index 79ad33d..c78f152 100644
> --- a/block.c
> +++ b/block.c
> @@ -1291,8 +1291,7 @@ 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_file_open(errp, errno, reopen_state->bs->filename);
s/errno/-ret/
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): use error_setg_file_open()
2013-06-07 19:52 ` [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): " Luiz Capitulino
2013-06-10 8:39 ` Stefan Hajnoczi
@ 2013-06-10 8:43 ` Stefan Hajnoczi
2013-06-10 13:21 ` Luiz Capitulino
1 sibling, 1 reply; 20+ messages in thread
From: Stefan Hajnoczi @ 2013-06-10 8:43 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: kwolf, qemu-devel, armbru
On Fri, Jun 07, 2013 at 03:52:29PM -0400, Luiz Capitulino wrote:
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
> block.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/block.c b/block.c
> index 79ad33d..c78f152 100644
> --- a/block.c
> +++ b/block.c
> @@ -1291,8 +1291,7 @@ 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_file_open(errp, errno, reopen_state->bs->filename);
Looking closer, my suggestion was wrong too.
I think QERR_OPEN_FILE_FAILED is simply the wrong error here. We don't
know that the error occurred when trying to open a file.
errno does not necessarily contain the error value!
Stefan
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 4/9] block: mirror_complete(): use error_setg_file_open()
2013-06-07 19:52 ` [Qemu-devel] [PATCH 4/9] block: mirror_complete(): " Luiz Capitulino
@ 2013-06-10 8:44 ` Stefan Hajnoczi
0 siblings, 0 replies; 20+ messages in thread
From: Stefan Hajnoczi @ 2013-06-10 8:44 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: kwolf, qemu-devel, armbru
On Fri, Jun 07, 2013 at 03:52:30PM -0400, Luiz Capitulino wrote:
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
> block/mirror.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block/mirror.c b/block/mirror.c
> index 8b07dec..89d531d 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -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, errno, backing_filename);
s/errno/-ret/
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 5/9] blockdev: use error_setg_file_open()
2013-06-07 19:52 ` [Qemu-devel] [PATCH 5/9] blockdev: " Luiz Capitulino
@ 2013-06-10 8:45 ` Stefan Hajnoczi
2013-06-10 13:25 ` Luiz Capitulino
0 siblings, 1 reply; 20+ messages in thread
From: Stefan Hajnoczi @ 2013-06-10 8:45 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: kwolf, qemu-devel, armbru
On Fri, Jun 07, 2013 at 03:52:31PM -0400, Luiz Capitulino wrote:
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
> blockdev.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
s/errno/-ret/g
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): use error_setg_file_open()
2013-06-10 8:43 ` Stefan Hajnoczi
@ 2013-06-10 13:21 ` Luiz Capitulino
2013-06-10 13:54 ` Kevin Wolf
0 siblings, 1 reply; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-10 13:21 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: kwolf, qemu-devel, armbru
On Mon, 10 Jun 2013 10:43:47 +0200
Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Fri, Jun 07, 2013 at 03:52:29PM -0400, Luiz Capitulino wrote:
> > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > ---
> > block.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/block.c b/block.c
> > index 79ad33d..c78f152 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -1291,8 +1291,7 @@ 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_file_open(errp, errno, reopen_state->bs->filename);
>
> Looking closer, my suggestion was wrong too.
>
> I think QERR_OPEN_FILE_FAILED is simply the wrong error here. We don't
> know that the error occurred when trying to open a file.
Right.
> errno does not necessarily contain the error value!
There are two ways to fix it (and they're not mutually exclusive):
1. We could review all bdrv_reopen_prepare() methods and make sure they
set errno on failure
2. We set errno=0 before calling the bdrv_reopen_prepare() method and if
there's an error and if errno != 0 we use it, otherwise we set a generic
"failed to prepare to reopen image" error
Option 1 goes a bit beyond the time I'd like to spent on this series.
Option 2 is quite reasonable.
What do you think?
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 5/9] blockdev: use error_setg_file_open()
2013-06-10 8:45 ` Stefan Hajnoczi
@ 2013-06-10 13:25 ` Luiz Capitulino
0 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-10 13:25 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: kwolf, qemu-devel, armbru
On Mon, 10 Jun 2013 10:45:23 +0200
Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Fri, Jun 07, 2013 at 03:52:31PM -0400, Luiz Capitulino wrote:
> > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > ---
> > blockdev.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
>
> s/errno/-ret/g
I'll fix this and double check the other patches.
Thanks for reviewing Stefan!
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): use error_setg_file_open()
2013-06-10 13:21 ` Luiz Capitulino
@ 2013-06-10 13:54 ` Kevin Wolf
2013-06-10 14:02 ` Luiz Capitulino
0 siblings, 1 reply; 20+ messages in thread
From: Kevin Wolf @ 2013-06-10 13:54 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: Stefan Hajnoczi, qemu-devel, armbru
Am 10.06.2013 um 15:21 hat Luiz Capitulino geschrieben:
> On Mon, 10 Jun 2013 10:43:47 +0200
> Stefan Hajnoczi <stefanha@gmail.com> wrote:
>
> > On Fri, Jun 07, 2013 at 03:52:29PM -0400, Luiz Capitulino wrote:
> > > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > > ---
> > > block.c | 3 +--
> > > 1 file changed, 1 insertion(+), 2 deletions(-)
> > >
> > > diff --git a/block.c b/block.c
> > > index 79ad33d..c78f152 100644
> > > --- a/block.c
> > > +++ b/block.c
> > > @@ -1291,8 +1291,7 @@ 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_file_open(errp, errno, reopen_state->bs->filename);
> >
> > Looking closer, my suggestion was wrong too.
> >
> > I think QERR_OPEN_FILE_FAILED is simply the wrong error here. We don't
> > know that the error occurred when trying to open a file.
>
> Right.
>
> > errno does not necessarily contain the error value!
>
> There are two ways to fix it (and they're not mutually exclusive):
>
> 1. We could review all bdrv_reopen_prepare() methods and make sure they
> set errno on failure
>
> 2. We set errno=0 before calling the bdrv_reopen_prepare() method and if
> there's an error and if errno != 0 we use it, otherwise we set a generic
> "failed to prepare to reopen image" error
>
> Option 1 goes a bit beyond the time I'd like to spent on this series.
> Option 2 is quite reasonable.
>
> What do you think?
errno is definitely not reliable here and won't be. You must use -ret if
you want a meaningful error message.
I think Stefan's point was more that "Could not open" might not be the
right message for a reopen, so we'd have to use error_setg_errno()
directly with a different message here, like "Could not prepare reopen
for '%s'".
The _real_ solution, of course, is to make bdrv_prepare_reopen() a void
function and always set errp when something goes wrong.
Kevin
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): use error_setg_file_open()
2013-06-10 13:54 ` Kevin Wolf
@ 2013-06-10 14:02 ` Luiz Capitulino
2013-06-10 14:06 ` Kevin Wolf
0 siblings, 1 reply; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-10 14:02 UTC (permalink / raw)
To: Kevin Wolf; +Cc: Stefan Hajnoczi, qemu-devel, armbru
On Mon, 10 Jun 2013 15:54:10 +0200
Kevin Wolf <kwolf@redhat.com> wrote:
> Am 10.06.2013 um 15:21 hat Luiz Capitulino geschrieben:
> > On Mon, 10 Jun 2013 10:43:47 +0200
> > Stefan Hajnoczi <stefanha@gmail.com> wrote:
> >
> > > On Fri, Jun 07, 2013 at 03:52:29PM -0400, Luiz Capitulino wrote:
> > > > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > > > ---
> > > > block.c | 3 +--
> > > > 1 file changed, 1 insertion(+), 2 deletions(-)
> > > >
> > > > diff --git a/block.c b/block.c
> > > > index 79ad33d..c78f152 100644
> > > > --- a/block.c
> > > > +++ b/block.c
> > > > @@ -1291,8 +1291,7 @@ 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_file_open(errp, errno, reopen_state->bs->filename);
> > >
> > > Looking closer, my suggestion was wrong too.
> > >
> > > I think QERR_OPEN_FILE_FAILED is simply the wrong error here. We don't
> > > know that the error occurred when trying to open a file.
> >
> > Right.
> >
> > > errno does not necessarily contain the error value!
> >
> > There are two ways to fix it (and they're not mutually exclusive):
> >
> > 1. We could review all bdrv_reopen_prepare() methods and make sure they
> > set errno on failure
> >
> > 2. We set errno=0 before calling the bdrv_reopen_prepare() method and if
> > there's an error and if errno != 0 we use it, otherwise we set a generic
> > "failed to prepare to reopen image" error
> >
> > Option 1 goes a bit beyond the time I'd like to spent on this series.
> > Option 2 is quite reasonable.
> >
> > What do you think?
>
> errno is definitely not reliable here and won't be. You must use -ret if
> you want a meaningful error message.
>
> I think Stefan's point was more that "Could not open" might not be the
> right message for a reopen, so we'd have to use error_setg_errno()
> directly with a different message here, like "Could not prepare reopen
> for '%s'".
Ok, but Stefan also said that -ret is not reliable. And after quickly
checking the code I see he's right, as there are methods that return -1.
I think the safest thing to do is to have a generic error message for
for this now and in the future we should propagate errp or return -errno.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): use error_setg_file_open()
2013-06-10 14:02 ` Luiz Capitulino
@ 2013-06-10 14:06 ` Kevin Wolf
0 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-10 14:06 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: Stefan Hajnoczi, qemu-devel, armbru
Am 10.06.2013 um 16:02 hat Luiz Capitulino geschrieben:
> On Mon, 10 Jun 2013 15:54:10 +0200
> Kevin Wolf <kwolf@redhat.com> wrote:
>
> > Am 10.06.2013 um 15:21 hat Luiz Capitulino geschrieben:
> > > On Mon, 10 Jun 2013 10:43:47 +0200
> > > Stefan Hajnoczi <stefanha@gmail.com> wrote:
> > >
> > > > On Fri, Jun 07, 2013 at 03:52:29PM -0400, Luiz Capitulino wrote:
> > > > > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > > > > ---
> > > > > block.c | 3 +--
> > > > > 1 file changed, 1 insertion(+), 2 deletions(-)
> > > > >
> > > > > diff --git a/block.c b/block.c
> > > > > index 79ad33d..c78f152 100644
> > > > > --- a/block.c
> > > > > +++ b/block.c
> > > > > @@ -1291,8 +1291,7 @@ 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_file_open(errp, errno, reopen_state->bs->filename);
> > > >
> > > > Looking closer, my suggestion was wrong too.
> > > >
> > > > I think QERR_OPEN_FILE_FAILED is simply the wrong error here. We don't
> > > > know that the error occurred when trying to open a file.
> > >
> > > Right.
> > >
> > > > errno does not necessarily contain the error value!
> > >
> > > There are two ways to fix it (and they're not mutually exclusive):
> > >
> > > 1. We could review all bdrv_reopen_prepare() methods and make sure they
> > > set errno on failure
> > >
> > > 2. We set errno=0 before calling the bdrv_reopen_prepare() method and if
> > > there's an error and if errno != 0 we use it, otherwise we set a generic
> > > "failed to prepare to reopen image" error
> > >
> > > Option 1 goes a bit beyond the time I'd like to spent on this series.
> > > Option 2 is quite reasonable.
> > >
> > > What do you think?
> >
> > errno is definitely not reliable here and won't be. You must use -ret if
> > you want a meaningful error message.
> >
> > I think Stefan's point was more that "Could not open" might not be the
> > right message for a reopen, so we'd have to use error_setg_errno()
> > directly with a different message here, like "Could not prepare reopen
> > for '%s'".
>
> Ok, but Stefan also said that -ret is not reliable. And after quickly
> checking the code I see he's right, as there are methods that return -1.
>
> I think the safest thing to do is to have a generic error message for
> for this now and in the future we should propagate errp or return -errno.
Ah, yes. I agree, let's make it error_setg() without errno for now.
Kevin
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 2/9] rng-random: use error_setg_file_open()
2013-06-10 17:02 [Qemu-devel] [PATCH v2 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
@ 2013-06-10 17:02 ` Luiz Capitulino
0 siblings, 0 replies; 20+ messages in thread
From: Luiz Capitulino @ 2013-06-10 17:02 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, armbru, stefanha
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
backends/rng-random.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/backends/rng-random.c b/backends/rng-random.c
index 830360c..68dfc8a 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -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);
}
}
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
end of thread, other threads:[~2013-06-10 17:02 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-07 19:52 [Qemu-devel] [PATCH 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 1/9] error: add error_setg_file_open() helper Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 2/9] rng-random: use error_setg_file_open() Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 3/9] block: bdrv_reopen_prepare(): " Luiz Capitulino
2013-06-10 8:39 ` Stefan Hajnoczi
2013-06-10 8:43 ` Stefan Hajnoczi
2013-06-10 13:21 ` Luiz Capitulino
2013-06-10 13:54 ` Kevin Wolf
2013-06-10 14:02 ` Luiz Capitulino
2013-06-10 14:06 ` Kevin Wolf
2013-06-07 19:52 ` [Qemu-devel] [PATCH 4/9] block: mirror_complete(): " Luiz Capitulino
2013-06-10 8:44 ` Stefan Hajnoczi
2013-06-07 19:52 ` [Qemu-devel] [PATCH 5/9] blockdev: " Luiz Capitulino
2013-06-10 8:45 ` Stefan Hajnoczi
2013-06-10 13:25 ` Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 6/9] cpus: " Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 7/9] dump: qmp_dump_guest_memory(): " Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 8/9] savevm: qmp_xen_save_devices_state(): " Luiz Capitulino
2013-06-07 19:52 ` [Qemu-devel] [PATCH 9/9] qerror: drop QERR_OPEN_FILE_FAILED macro Luiz Capitulino
-- strict thread matches above, loose matches on Subject: below --
2013-06-10 17:02 [Qemu-devel] [PATCH v2 0/9] QMP/HMP: add error reason to open failures Luiz Capitulino
2013-06-10 17:02 ` [Qemu-devel] [PATCH 2/9] rng-random: use error_setg_file_open() Luiz Capitulino
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).