[PATCH v3 06/10] chardev/char: Allow partial writes in qemu_chr_write()

Philippe Mathieu-Daudé posted 10 patches 2 days, 6 hours ago
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Alistair Francis <alistair@alistair23.me>, Peter Maydell <peter.maydell@linaro.org>, Palmer Dabbelt <palmer@dabbelt.com>, "Alex Bennée" <alex.bennee@linaro.org>
[PATCH v3 06/10] chardev/char: Allow partial writes in qemu_chr_write()
Posted by Philippe Mathieu-Daudé 2 days, 6 hours ago
If qemu_chr_write_buffer() returned an error, but could
write some characters, return the number of character
written. Otherwise frontends able to recover and resume
writes re-write the partial chars already written.

Cc: qemu-stable@nongnu.org
Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 chardev/char.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/chardev/char.c b/chardev/char.c
index 105b0d53184..7931f4e0832 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -186,6 +186,11 @@ int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all)
 
     res = qemu_chr_write_buffer(s, buf, len, &offset, write_all);
 
+    if (!write_all && res < 0 && offset == 0) {
+        /* Allow partial writes */
+        return res;
+    }
+
     if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
         replay_char_write_event_save(res, offset);
     }
-- 
2.51.0