Add qemu_fopen_pipe() to open QEMUFileOps pipe_write_ops and
pipe_read_ops introduced for pipe protocol.

Signed-off-by: Lei Li <li...@linux.vnet.ibm.com>
---
 include/migration/qemu-file.h |    2 ++
 migration-local.c             |   20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index 0f757fb..39ad0bd 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -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_pipe(int sockfd, const char *mode);
+
 int qemu_get_fd(QEMUFile *f);
 int qemu_fclose(QEMUFile *f);
 int64_t qemu_ftell(QEMUFile *f);
diff --git a/migration-local.c b/migration-local.c
index 1fb62b6..d90b2ff 100644
--- a/migration-local.c
+++ b/migration-local.c
@@ -112,3 +112,23 @@ static const QEMUFileOps pipe_write_ops = {
     //.save_page  = qemu_local_save_ram,
     .close      = qemu_local_close
 };
+
+QEMUFile *qemu_fopen_pipe(int pipefd, const char *mode)
+{
+    QEMUFilePipe *s;
+
+    if (qemu_file_mode_is_not_valid(mode)) {
+        return NULL;
+    }
+
+    s = g_malloc0(sizeof(QEMUFilePipe));
+    s->pipefd = pipefd;
+
+    if (mode[0] == 'w') {
+        s->file = qemu_fopen_ops(s, &pipe_write_ops);
+    } else {
+        s->file = qemu_fopen_ops(s, &pipe_read_ops);
+    }
+
+    return s->file;
+}
-- 
1.7.7.6


Reply via email to