[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 08/17] migration-local: add recv_pipefd()
From: |
Lei Li |
Subject: |
[Qemu-devel] [PATCH 08/17] migration-local: add recv_pipefd() |
Date: |
Tue, 22 Oct 2013 11:25:32 +0800 |
This patch adds recv_pipefd() to receive the pipe file descriptor
that passed by source process.
Signed-off-by: Lei Li <address@hidden>
---
migration-local.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/migration-local.c b/migration-local.c
index f2871d8..ed0ae6c 100644
--- a/migration-local.c
+++ b/migration-local.c
@@ -218,3 +218,67 @@ static int send_pipefd(int sockfd, int pipefd)
return ret;
}
+
+/*
+ * Receive a pipe file descriptor from a source process
+ * via unix socket.
+ *
+ * Return negative value if there has been an recvmsg error or
+ * no fd to be received. Return 0 if the connection closed by
+ * source. Return file descriptor on success.
+ *
+ */
+static int recv_pipefd(int sockfd)
+{
+ struct msghdr msg;
+ struct iovec iov[1];
+ ssize_t n;
+ int pipefd = -1;
+ char req[1];
+
+ union {
+ struct cmsghdr cm;
+ char control[CMSG_SPACE(sizeof(int))];
+ } control_un;
+ struct cmsghdr *cmptr;
+
+ msg.msg_control = control_un.control;
+ msg.msg_controllen = sizeof(control_un.control);
+
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+
+ iov[0].iov_base = req;
+ iov[0].iov_len = sizeof(req);
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+
+ if ( (n = recvmsg(sockfd, &msg, 0)) <= 0) {
+ fprintf(stderr, "recvmsg error: %s\n", strerror(errno));
+ return n;
+ }
+
+ /* req 0x01 means there is a file descriptor to receive */
+ if (req[0] != 0x01) {
+ return pipefd;
+ }
+
+ if ( (cmptr = CMSG_FIRSTHDR(&msg)) != NULL &&
+ cmptr->cmsg_len == CMSG_LEN(sizeof(int))) {
+ if (cmptr->cmsg_level != SOL_SOCKET) {
+ DPRINTF(stderr, "control level != SOL_SOCKET\n");
+ return pipefd;
+ } else if (cmptr->cmsg_type != SCM_RIGHTS) {
+ DPRINTF(stderr, "control type != SCM_RIGHTS\n");
+ return pipefd;
+ }
+ /* The pipe file descriptor to be received */
+ pipefd = *((int *) CMSG_DATA(cmptr));
+ DPRINTF("pipefd received successfully: %d\n", pipefd);
+ } else {
+ /* Descriptor was not passed */
+ DPRINTF(stderr, "pipefd was not passed\n");
+ }
+
+ return pipefd;
+}
--
1.7.7.6
- Re: [Qemu-devel] [PATCH 02/17] QAPI: introduce magration capability unix_page_flipping, (continued)
- [Qemu-devel] [PATCH 03/17] migration: add migrate_unix_page_flipping(), Lei Li, 2013/10/21
- [Qemu-devel] [PATCH 04/17] qmp-command.hx: add missing docs for migration capabilites, Lei Li, 2013/10/21
- [Qemu-devel] [PATCH 05/17] migration-local: add QEMUFileLocal with socket based QEMUFile, Lei Li, 2013/10/21
- [Qemu-devel] [PATCH 06/17] migration-local: introduce qemu_fopen_socket_local(), Lei Li, 2013/10/21
- [Qemu-devel] [PATCH 07/17] migration-local: add send_pipefd(), Lei Li, 2013/10/21
- [Qemu-devel] [PATCH 08/17] migration-local: add recv_pipefd(),
Lei Li <=
- [Qemu-devel] [PATCH 09/17] migration-local: override before_ram_iterate to send pipefd, Lei Li, 2013/10/21
[Qemu-devel] [PATCH 10/17] migration-local: override save_page for page transmit, Lei Li, 2013/10/21
[Qemu-devel] [PATCH 11/17] savevm: adjust ram_control_save_page for page flipping, Lei Li, 2013/10/21
[Qemu-devel] [PATCH 12/17] migration-local: override hook_ram_load, Lei Li, 2013/10/21