[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/8] migration-local: add send_pipefd()
From: |
Lei Li |
Subject: |
[Qemu-devel] [PATCH 3/8] migration-local: add send_pipefd() |
Date: |
Wed, 25 Sep 2013 22:32:43 +0800 |
This patch adds send_pipefd() to pass the pipe file descriptor
to destination process.
Signed-off-by: Lei Li <address@hidden>
---
include/migration/qemu-file.h | 1 +
migration-local.c | 57 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index 39ad0bd..5fad65f 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -101,6 +101,7 @@ 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 send_pipefd(int sockfd, int pipefd);
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 d90b2ff..3875b27 100644
--- a/migration-local.c
+++ b/migration-local.c
@@ -132,3 +132,60 @@ QEMUFile *qemu_fopen_pipe(int pipefd, const char *mode)
return s->file;
}
+
+union MsgControl {
+ struct cmsghdr cmsg;
+ char control[CMSG_SPACE(sizeof(int))];
+};
+
+/*
+ * Pass a pipe file descriptor to another process.
+ *
+ * Return negative value If pipefd < 0. Return 0 on
+ * success.
+ *
+ */
+
+int send_pipefd(int sockfd, int pipefd)
+{
+ struct cmsghdr *cmsg;
+ struct iovec iov[1];
+ struct msghdr msg;
+ union MsgControl msg_control;
+
+ char msbuf[1] = { 0x01 };
+ int ret;
+
+ iov[0].iov_base = msbuf;
+ iov[0].iov_len = sizeof(msbuf);
+
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+
+ if (pipefd < 0) {
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+ /* Negative status means error */
+ msbuf[0] = pipefd;
+ } else {
+ msg.msg_control = &msg_control;
+ msg.msg_controllen = sizeof(msg_control);
+
+ cmsg = &msg_control.cmsg;
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(pipefd));
+
+ /* The pipefd to be passed */
+ memcpy(CMSG_DATA(cmsg), &pipefd, sizeof(pipefd));
+ }
+
+ do {
+ ret = sendmsg(sockfd, &msg, 0);
+ } while (ret < 0 && errno == EINTR);
+
+ if (ret < 0) {
+ return ret;
+ }
+ return 0;
+}
--
1.7.7.6
- [Qemu-devel] [PATCH 0/8 RFC] migration: Introduce side channel for RAM, Lei Li, 2013/09/25
- [Qemu-devel] [PATCH 1/8] migration-local: add pipe protocol for QEMUFileOps, Lei Li, 2013/09/25
- [Qemu-devel] [PATCH 3/8] migration-local: add send_pipefd(),
Lei Li <=
- [Qemu-devel] [PATCH 5/8] QAPI: introduce magration capability unix_page_flipping, Lei Li, 2013/09/25
- [Qemu-devel] [PATCH 4/8] migration-local: add recv_pipefd(), Lei Li, 2013/09/25
- [Qemu-devel] [PATCH 6/8] migration: add migrate_unix_page_flipping(), Lei Li, 2013/09/25
- [Qemu-devel] [PATCH 7/8] migration-unix: side channel support on unix outgoing, Lei Li, 2013/09/25
- [Qemu-devel] [PATCH 8/8] migration-unix: side channel support on unix incoming, Lei Li, 2013/09/25
- [Qemu-devel] [PATCH 2/8] migration-loca: add qemu_fopen_pipe(), Lei Li, 2013/09/25
- Re: [Qemu-devel] [PATCH 0/8 RFC] migration: Introduce side channel for RAM, Paolo Bonzini, 2013/09/25