[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 33/42] qemu-file: add writable socket QEMUFile
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 33/42] qemu-file: add writable socket QEMUFile |
Date: |
Fri, 22 Feb 2013 17:36:39 +0100 |
Reviewed-by: Orit Wasserman <address@hidden>
Reviewed-by: Juan Quintela <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/migration/qemu-file.h | 2 +-
migration-tcp.c | 2 +-
migration-unix.c | 2 +-
savevm.c | 33 +++++++++++++++++++++++++++++++--
4 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index 987e719..25e8461 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -76,7 +76,7 @@ typedef struct QEMUFileOps {
QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops);
QEMUFile *qemu_fopen(const char *filename, const char *mode);
QEMUFile *qemu_fdopen(int fd, const char *mode);
-QEMUFile *qemu_fopen_socket(int fd);
+QEMUFile *qemu_fopen_socket(int fd, const char *mode);
QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
int qemu_get_fd(QEMUFile *f);
int qemu_fclose(QEMUFile *f);
diff --git a/migration-tcp.c b/migration-tcp.c
index e78a296..7d975b5 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -95,7 +95,7 @@ static void tcp_accept_incoming_migration(void *opaque)
goto out;
}
- f = qemu_fopen_socket(c);
+ f = qemu_fopen_socket(c, "rb");
if (f == NULL) {
fprintf(stderr, "could not qemu_fopen socket\n");
goto out;
diff --git a/migration-unix.c b/migration-unix.c
index 218835a..4693b43 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -95,7 +95,7 @@ static void unix_accept_incoming_migration(void *opaque)
goto out;
}
- f = qemu_fopen_socket(c);
+ f = qemu_fopen_socket(c, "rb");
if (f == NULL) {
fprintf(stderr, "could not qemu_fopen socket\n");
goto out;
diff --git a/savevm.c b/savevm.c
index 6d6f1f1..76c88c7 100644
--- a/savevm.c
+++ b/savevm.c
@@ -198,6 +198,18 @@ static int socket_get_buffer(void *opaque, uint8_t *buf,
int64_t pos, int size)
return len;
}
+static int socket_put_buffer(void *opaque, const uint8_t *buf, int64_t pos,
int size)
+{
+ QEMUFileSocket *s = opaque;
+ ssize_t len;
+
+ len = qemu_send_full(s->fd, buf, size, 0);
+ if (len < size) {
+ len = -socket_error();
+ }
+ return len;
+}
+
static int socket_close(void *opaque)
{
QEMUFileSocket *s = opaque;
@@ -369,12 +381,29 @@ static const QEMUFileOps socket_read_ops = {
.close = socket_close
};
-QEMUFile *qemu_fopen_socket(int fd)
+static const QEMUFileOps socket_write_ops = {
+ .get_fd = socket_get_fd,
+ .put_buffer = socket_put_buffer,
+ .close = socket_close
+};
+
+QEMUFile *qemu_fopen_socket(int fd, const char *mode)
{
QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket));
+ if (mode == NULL ||
+ (mode[0] != 'r' && mode[0] != 'w') ||
+ mode[1] != 'b' || mode[2] != 0) {
+ fprintf(stderr, "qemu_fopen: Argument validity check failed\n");
+ return NULL;
+ }
+
s->fd = fd;
- s->file = qemu_fopen_ops(s, &socket_read_ops);
+ if (mode[0] == 'w') {
+ s->file = qemu_fopen_ops(s, &socket_write_ops);
+ } else {
+ s->file = qemu_fopen_ops(s, &socket_read_ops);
+ }
return s->file;
}
--
1.8.1.2
- [Qemu-devel] [PATCH 40/42] migration: move contents of migration_close to migrate_fd_cleanup, (continued)
- [Qemu-devel] [PATCH 40/42] migration: move contents of migration_close to migrate_fd_cleanup, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 42/42] migration: inline migrate_fd_close, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 41/42] migration: eliminate s->migration_file, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 15/42] migration: cleanup migration (including thread) in the iothread, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 31/42] qemu-file: fsync a writable stdio QEMUFile, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 17/42] block-migration: small preparatory changes for locking, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 37/42] migration: use qemu_ftell to compute bandwidth, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 35/42] migration: use QEMUFile for migration channel lifetime, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 07/42] migration: use qemu_file_set_error to pass error codes back to qemu_savevm_state, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 29/42] migration: use qemu_file_rate_limit consistently, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 33/42] qemu-file: add writable socket QEMUFile,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 30/42] migration: merge qemu_popen_cmd with qemu_popen, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 19/42] block-migration: add lock, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 36/42] migration: use QEMUFile for writing outgoing migration data, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 32/42] qemu-file: check exit status when closing a pipe QEMUFile, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 10/42] migration: use qemu_file_set_error, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 38/42] migration: small changes around rate-limiting, Paolo Bonzini, 2013/02/22
- [Qemu-devel] [PATCH 34/42] qemu-file: simplify and export qemu_ftell, Paolo Bonzini, 2013/02/22