@@ -99,6 +99,8 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode);
QEMUFile *qemu_fdopen(int fd, const char *mode);
QEMUFile *qemu_fopen_socket(int fd, const char *mode);
QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
+QEMUFile *qemu_fopen_socket_local(int sockfd, const char *mode);
+
int qemu_get_fd(QEMUFile *f);
int qemu_fclose(QEMUFile *f);
int64_t qemu_ftell(QEMUFile *f);
@@ -105,6 +105,12 @@ static int qemu_local_close(void *opaque)
QEMUFileLocal *s = opaque;
closesocket(s->sockfd);
+
+ if (s->unix_page_flipping) {
+ close(s->pipefd[0]);
+ close(s->pipefd[1]);
+ }
+
g_free(s);
return 0;
@@ -121,3 +127,43 @@ static const QEMUFileOps pipe_write_ops = {
.writev_buffer = qemu_local_writev_buffer,
.close = qemu_local_close,
};
+
+QEMUFile *qemu_fopen_socket_local(int sockfd, const char *mode)
+{
+ QEMUFileLocal *s;
+ int pipefd[2];
+
+ if (qemu_file_mode_is_not_valid(mode)) {
+ return NULL;
+ }
+
+ s = g_malloc0(sizeof(QEMUFileLocal));
+ s->sockfd = sockfd;
+
+ if (migrate_unix_page_flipping()) {
+ s->unix_page_flipping = 1;
+ }
+
+ if (mode[0] == 'w') {
+ if (s->unix_page_flipping) {
+ if (pipe(pipefd) < 0) {
+ fprintf(stderr, "failed to create PIPE\n");
+ goto fail;
+ }
+
+ s->pipefd[0] = pipefd[0];
+ s->pipefd[1] = pipefd[1];
+ }
+
+ qemu_set_block(s->sockfd);
+ s->file = qemu_fopen_ops(s, &pipe_write_ops);
+ } else {
+ s->file = qemu_fopen_ops(s, &pipe_read_ops);
+ }
+
+ return s->file;
+
+fail:
+ g_free(s);
+ return NULL;
+}
Add qemu_fopen_socket_local() to open QEMUFileLocal introduced earlier. It will create a pipe in write mode if unix_page_flipping is enabled, adjust qemu_local_close() to close pipe as well. Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com> --- include/migration/qemu-file.h | 2 + migration-local.c | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 0 deletions(-)