From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0pCt-0006yL-VG for qemu-devel@nongnu.org; Wed, 08 Jan 2014 04:13:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W0pCk-0008CA-QV for qemu-devel@nongnu.org; Wed, 08 Jan 2014 04:13:47 -0500 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:43269) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0pCg-00088p-IO for qemu-devel@nongnu.org; Wed, 08 Jan 2014 04:13:38 -0500 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 8 Jan 2014 14:43:23 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 62368394002D for ; Wed, 8 Jan 2014 14:43:21 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s089DDI049873000 for ; Wed, 8 Jan 2014 14:43:13 +0530 Received: from d28av01.in.ibm.com (localhost [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s089DJGR015551 for ; Wed, 8 Jan 2014 14:43:19 +0530 From: Lei Li Date: Wed, 8 Jan 2014 17:12:56 +0800 Message-Id: <1389172376-30636-7-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1389172376-30636-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1389172376-30636-1-git-send-email-lilei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 6/6] migration-local: replace send_pipefd with qemu_send_with_fd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, mohan@in.ibm.com, Lei Li Signed-off-by: Lei Li --- migration-local.c | 52 +++------------------------------------------------- 1 files changed, 3 insertions(+), 49 deletions(-) diff --git a/migration-local.c b/migration-local.c index ce4c070..c01ba06 100644 --- a/migration-local.c +++ b/migration-local.c @@ -26,6 +26,7 @@ #include "sysemu/sysemu.h" #include "block/block.h" #include "qemu/sockets.h" +#include "qemu/fd-exchange.h" #include "migration/block.h" #include "qemu/thread.h" #include "qmp-commands.h" @@ -169,8 +170,6 @@ static int qemu_local_close(void *opaque) return 0; } -static int send_pipefd(int sockfd, int pipefd); - static size_t qemu_local_save_ram(QEMUFile *f, void *opaque, MemoryRegion *mr, ram_addr_t offset, size_t size, int *bytes_sent) @@ -179,13 +178,14 @@ static size_t qemu_local_save_ram(QEMUFile *f, void *opaque, ram_addr_t current_addr = mr->ram_addr + offset; void *ram_addr; ssize_t ret; + char req[1] = { 0x01 }; if (s->unix_page_flipping) { qemu_put_be64(s->file, current_addr | RAM_SAVE_FLAG_HOOK); qemu_fflush(s->file); if (!s->pipefd_passed) { - ret = send_pipefd(s->sockfd, s->pipefd[0]); + ret = qemu_send_with_fd(s->sockfd, s->pipefd[0], &req, sizeof(req)); if (ret < 0) { fprintf(stderr, "failed to pass PIPE\n"); return ret; @@ -342,49 +342,3 @@ fail: g_free(s); return NULL; } - - -/* - * Pass a pipe file descriptor to another process. - * - * Return negative value If pipefd < 0. Return 0 on - * success. - * - */ -static int send_pipefd(int sockfd, int pipefd) -{ - struct msghdr msg; - struct iovec iov[1]; - ssize_t ret; - char req[1] = { 0x01 }; - - 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); - - cmptr = CMSG_FIRSTHDR(&msg); - cmptr->cmsg_len = CMSG_LEN(sizeof(int)); - cmptr->cmsg_level = SOL_SOCKET; - cmptr->cmsg_type = SCM_RIGHTS; - *((int *) CMSG_DATA(cmptr)) = pipefd; - - 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; - - ret = sendmsg(sockfd, &msg, 0); - if (ret <= 0) { - DPRINTF("sendmsg error: %s\n", strerror(errno)); - } - - return ret; -} -- 1.7.7.6