- add qemu_file_fd() for later use - drop qemu_stdio_fd Now qemu_file_fd() replaces qemu_stdio_fd(). - savevm/QEMUFileSocket: drop duplicated member fd fd is already stored in QEMUFile so drop duplicated member QEMUFileSocket::fd. - remove QEMUFileSocket Signed-off-by: Isaku Yamahata <yamahata@xxxxxxxxxxxxx> --- migration-exec.c | 4 ++-- migration-fd.c | 2 +- qemu-file.h | 2 +- savevm.c | 40 +++++++++++++++++++--------------------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/migration-exec.c b/migration-exec.c index 6c97db9..95e9779 100644 --- a/migration-exec.c +++ b/migration-exec.c @@ -98,7 +98,7 @@ static void exec_accept_incoming_migration(void *opaque) QEMUFile *f = opaque; process_incoming_migration(f); - qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); + qemu_set_fd_handler2(qemu_file_fd(f), NULL, NULL, NULL, NULL); qemu_fclose(f); } @@ -113,7 +113,7 @@ int exec_start_incoming_migration(const char *command) return -errno; } - qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, + qemu_set_fd_handler2(qemu_file_fd(f), NULL, exec_accept_incoming_migration, NULL, f); return 0; diff --git a/migration-fd.c b/migration-fd.c index 7335167..b3c54e5 100644 --- a/migration-fd.c +++ b/migration-fd.c @@ -104,7 +104,7 @@ static void fd_accept_incoming_migration(void *opaque) QEMUFile *f = opaque; process_incoming_migration(f); - qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); + qemu_set_fd_handler2(qemu_file_fd(f), NULL, NULL, NULL, NULL); qemu_fclose(f); } diff --git a/qemu-file.h b/qemu-file.h index 9b6dd08..bc222dc 100644 --- a/qemu-file.h +++ b/qemu-file.h @@ -70,7 +70,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode); QEMUFile *qemu_fopen_socket(int fd); QEMUFile *qemu_popen(FILE *popen_file, const char *mode); QEMUFile *qemu_popen_cmd(const char *command, const char *mode); -int qemu_stdio_fd(QEMUFile *f); +int qemu_file_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); int qemu_fflush(QEMUFile *f); void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); diff --git a/savevm.c b/savevm.c index 0c7af43..e24041b 100644 --- a/savevm.c +++ b/savevm.c @@ -178,6 +178,7 @@ struct QEMUFile { uint8_t buf[IO_BUF_SIZE]; int last_error; + int fd; /* -1 means fd isn't associated */ }; typedef struct QEMUFileStdio @@ -186,19 +187,18 @@ typedef struct QEMUFileStdio QEMUFile *file; } QEMUFileStdio; -typedef struct QEMUFileSocket +typedef struct QEMUFileFD { - int fd; QEMUFile *file; -} QEMUFileSocket; +} QEMUFileFD; static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) { - QEMUFileSocket *s = opaque; + QEMUFileFD *s = opaque; ssize_t len; do { - len = qemu_recv(s->fd, buf, size, 0); + len = qemu_recv(s->file->fd, buf, size, 0); } while (len == -1 && socket_error() == EINTR); if (len == -1) @@ -207,9 +207,9 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) return len; } -static int socket_close(void *opaque) +static int fd_close(void *opaque) { - QEMUFileSocket *s = opaque; + QEMUFileFD *s = opaque; g_free(s); return 0; } @@ -276,6 +276,7 @@ QEMUFile *qemu_popen(FILE *stdio_file, const char *mode) s->file = qemu_fopen_ops(s, stdio_put_buffer, NULL, stdio_pclose, NULL, NULL, NULL); } + s->file->fd = fileno(stdio_file); return s->file; } @@ -291,17 +292,6 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode) return qemu_popen(popen_file, mode); } -int qemu_stdio_fd(QEMUFile *f) -{ - QEMUFileStdio *p; - int fd; - - p = (QEMUFileStdio *)f->opaque; - fd = fileno(p->stdio_file); - - return fd; -} - QEMUFile *qemu_fdopen(int fd, const char *mode) { QEMUFileStdio *s; @@ -325,6 +315,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode) s->file = qemu_fopen_ops(s, stdio_put_buffer, NULL, stdio_fclose, NULL, NULL, NULL); } + s->file->fd = fd; return s->file; fail: @@ -334,11 +325,11 @@ fail: QEMUFile *qemu_fopen_socket(int fd) { - QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket)); + QEMUFileFD *s = g_malloc0(sizeof(QEMUFileFD)); - s->fd = fd; - s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, + s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, fd_close, NULL, NULL, NULL); + s->file->fd = fd; return s->file; } @@ -381,6 +372,7 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode) s->file = qemu_fopen_ops(s, NULL, file_get_buffer, stdio_fclose, NULL, NULL, NULL); } + s->file->fd = fileno(s->stdio_file); return s->file; fail: g_free(s); @@ -431,10 +423,16 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, f->set_rate_limit = set_rate_limit; f->get_rate_limit = get_rate_limit; f->is_write = 0; + f->fd = -1; return f; } +int qemu_file_fd(QEMUFile *f) +{ + return f->fd; +} + int qemu_file_get_error(QEMUFile *f) { return f->last_error; -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html