dump: Show custom message for ENOSPC
PATCH 1/1 dump: Show custom message for ENOSPC
This patch intends to make a more specific message for when the system has not enough space to save guest memory.
--- dump.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
dump.c +8 -1
@@ -106,6 +106,9 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque) written_size =qemu_write_full (s->fd, buf, size);if (written_size != size) { +if (errno ==ENOSPC ) { +return -ENOSPC ; + }return -1 ; }
@@ -364,7 +367,11 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp) ret =fd_write_vmcore (buf, length, s);if (ret <0 ) { -error_setg (errp,"dump: failed to save memory" ); +if (ret == -ENOSPC ) { +error_setg (errp,"dump: not enough space to save memory" ); + }else { +error_setg (errp,"dump: failed to save memory" ); + } }else { s->written_size += length; }
Signature · 1 line
2.14.1
Hi Yasmin,
Quoted 15 lines · Yasmin Beatriz
This patch intends to make a more specific message for when the system has not enough space to save guest memory.
Reported-by [email protected]Cc Jose Ricardo Ziviani <[email protected]>Signed-off-by Yasmin Beatriz <[email protected]>--- dump.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)dump.c +0
-0
dump.c static int fd_write_vmcore(const void *buf, size_t size, void *opaque) · line 111
Quoted 6 lines
dump.c +3
-0@@ -106,6 +106,9 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque) written_size =qemu_write_full (s->fd, buf, size);if (written_size != size) { +if (errno ==ENOSPC ) { +return -ENOSPC ; + }
You can do like this:
if (written_size != size) {+ return -errno;
+ }
Everyone is checking for a negative "ret" to see if an error occurred in qemu_write_full. There is no negative errno AFAIK, so you can spare one "if" clause there and still check for -ENOSPC down there.
It might be worth checking if this code can't be baked into qemu_write_full too.
Thanks,
Daniel
Quoted 16 lines
dump.c +5
-1return -1 ; }@@ -364,7 +367,11 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp) ret =fd_write_vmcore (buf, length, s);if (ret <0 ) { -error_setg (errp,"dump: failed to save memory" ); +if (ret == -ENOSPC ) { +error_setg (errp,"dump: not enough space to save memory" ); + }else { +error_setg (errp,"dump: failed to save memory" ); + } }else { s->written_size += length; }
Hi, Yasmin.
Congratulations on your first patch!
Quoted 25 lines · Yasmin Beatriz
This patch intends to make a more specific message for when the system has not enough space to save guest memory.
Reported-by [email protected]Cc Jose Ricardo Ziviani <[email protected]>Signed-off-by Yasmin Beatriz <[email protected]>--- dump.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)dump.c +3
-0@@ -106,6 +106,9 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque) written_size =qemu_write_full (s->fd, buf, size);if (written_size != size) { +if (errno ==ENOSPC ) { +return -ENOSPC ; + }return -1 ; }
dump.c static void write_data(DumpState *s, void *buf, int length, Error **errp) · line 374
Quoted 9 lines
dump.c +5
-1@@ -364,7 +367,11 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp) ret =fd_write_vmcore (buf, length, s);if (ret <0 ) { -error_setg (errp,"dump: failed to save memory" ); +if (ret == -ENOSPC ) { +error_setg (errp,"dump: not enough space to save memory" ); + }else { +error_setg (errp,"dump: failed to save memory" ); + }
If fd_write_vmcore() returned -errno, as Daniel Barboza suggested, it could be used in error_setg_errno(). Something like this:
dump.c +0 -0
@@ -106,7 +106,7 @@ static int fd_write_vmcore(const void *buf, size_t
size, void *opaque)
written_size = qemu_write_full(s->fd, buf, size);
if (written_size != size) {
- return -1;
+ return -errno;
}
return 0;@@ -364,7 +364,7 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp)
ret = fd_write_vmcore(buf, length, s);
if (ret < 0) {
- error_setg(errp, "dump: failed to save memory");
+ error_setg_errno(errp, ret, "dump: failed to save memory");
} else {
s->written_size += length;
}With this, other reasons of errno would also be considered, not only ENOSPC.
Cheers
Murilo
Quoted 15 lines · Yasmin Beatriz
This patch intends to make a more specific message for when the system has not enough space to save guest memory.
Reported-by [email protected]Cc Jose Ricardo Ziviani <[email protected]>Signed-off-by Yasmin Beatriz <[email protected]>--- dump.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)dump.c +0
-0
dump.c static int fd_write_vmcore(const void *buf, size_t size, void *opaque) · line 112
Quoted 7 lines
dump.c +3
-0@@ -106,6 +106,9 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque) written_size =qemu_write_full (s->fd, buf, size);if (written_size != size) { +if (errno ==ENOSPC ) { +return -ENOSPC ; + }return -1 ;
Mixing a return of -1 and negative errno is ugly (as -1 is indistinguishable from -EPERM on many, but not all, operating systems). If you need to distinguish between different error types, then return negative errno in all places.
dump.c static void write_data(DumpState *s, void *buf, int length, Error **errp) · line 367
Quoted 7 lines
dump.c +0
-1}@@ -364,7 +367,11 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp) ret =fd_write_vmcore (buf, length, s);if (ret <0 ) { -error_setg (errp,"dump: failed to save memory" );
Or, if you really want better error messages, it might make sense to push errp setting down into fd_write_vmcore() (all callers have to be updated).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org