[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v8 17/54] Return path: socket_writev_buffer: Block e
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v8 17/54] Return path: socket_writev_buffer: Block even on non-blocking fd's |
Date: |
Tue, 29 Sep 2015 09:37:41 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
The destination sets the fd to non-blocking on incoming migrations;
this also affects the return path from the destination, and thus we
need to make sure we can safely write to the return path.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
Reviewed-by: Amit Shah <address@hidden>
---
migration/qemu-file-unix.c | 42 +++++++++++++++++++++++++++++++++++++-----
1 file changed, 37 insertions(+), 5 deletions(-)
diff --git a/migration/qemu-file-unix.c b/migration/qemu-file-unix.c
index dd463ff..4bf050f 100644
--- a/migration/qemu-file-unix.c
+++ b/migration/qemu-file-unix.c
@@ -22,6 +22,7 @@
* THE SOFTWARE.
*/
#include "qemu-common.h"
+#include "qemu/error-report.h"
#include "qemu/iov.h"
#include "qemu/sockets.h"
#include "block/coroutine.h"
@@ -39,12 +40,43 @@ static ssize_t socket_writev_buffer(void *opaque, struct
iovec *iov, int iovcnt,
QEMUFileSocket *s = opaque;
ssize_t len;
ssize_t size = iov_size(iov, iovcnt);
+ ssize_t offset = 0;
+ int err;
- len = iov_send(s->fd, iov, iovcnt, 0, size);
- if (len < size) {
- len = -socket_error();
- }
- return len;
+ while (size > 0) {
+ len = iov_send(s->fd, iov, iovcnt, offset, size);
+
+ if (len > 0) {
+ size -= len;
+ offset += len;
+ }
+
+ if (size > 0) {
+ err = socket_error();
+
+ if (err != EAGAIN && err != EWOULDBLOCK) {
+ error_report("socket_writev_buffer: Got err=%d for (%zd/%zd)",
+ err, size, len);
+ /*
+ * If I've already sent some but only just got the error, I
+ * could return the amount validly sent so far and wait for the
+ * next call to report the error, but I'd rather flag the error
+ * immediately.
+ */
+ return -err;
+ }
+
+ /* Emulate blocking */
+ GPollFD pfd;
+
+ pfd.fd = s->fd;
+ pfd.events = G_IO_OUT | G_IO_ERR;
+ pfd.revents = 0;
+ g_poll(&pfd, 1 /* 1 fd */, -1 /* no timeout */);
+ }
+ }
+
+ return offset;
}
static int socket_get_fd(void *opaque)
--
2.5.0
- [Qemu-devel] [PATCH v8 08/54] Add wrapper for setting blocking status on a QEMUFile, (continued)
- [Qemu-devel] [PATCH v8 08/54] Add wrapper for setting blocking status on a QEMUFile, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 09/54] Add QEMU_MADV_NOHUGEPAGE, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 10/54] migration/ram.c: Use RAMBlock rather than MemoryRegion, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 11/54] ram_debug_dump_bitmap: Dump a migration bitmap as text, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 12/54] migrate_init: Call from savevm, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 13/54] Move dirty page search state into separate structure, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 14/54] ram_find_and_save_block: Split out the finding, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 15/54] Rename save_live_complete to save_live_complete_precopy, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 17/54] Return path: socket_writev_buffer: Block even on non-blocking fd's,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v8 16/54] Return path: Open a return path on QEMUFile for sockets, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 18/54] Migration commands, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 19/54] Return path: Control commands, Dr. David Alan Gilbert (git), 2015/10/01
- [Qemu-devel] [PATCH v8 20/54] Return path: Send responses from destination to source, Dr. David Alan Gilbert (git), 2015/10/01