From patchwork Tue Oct 22 03:25:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 285335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B5E722C014D for ; Tue, 22 Oct 2013 14:30:48 +1100 (EST) Received: from localhost ([::1]:42782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VYSgA-0004Z9-Rm for incoming@patchwork.ozlabs.org; Mon, 21 Oct 2013 23:30:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47243) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VYSbp-0005HN-Fc for qemu-devel@nongnu.org; Mon, 21 Oct 2013 23:26:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VYSbg-0004XK-Il for qemu-devel@nongnu.org; Mon, 21 Oct 2013 23:26:17 -0400 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:42884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VYSbf-0004X7-U0 for qemu-devel@nongnu.org; Mon, 21 Oct 2013 23:26:08 -0400 Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 22 Oct 2013 08:56:06 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp02.in.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 22 Oct 2013 08:56:04 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id C9552394003F for ; Tue, 22 Oct 2013 08:55:43 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r9M3Q1tS48693368 for ; Tue, 22 Oct 2013 08:56:01 +0530 Received: from d28av04.in.ibm.com (localhost [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r9M3Q3QI023168 for ; Tue, 22 Oct 2013 08:56:03 +0530 Received: from localhost.cn.ibm.com ([9.115.122.43]) by d28av04.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r9M3PhTX022250; Tue, 22 Oct 2013 08:56:02 +0530 From: Lei Li To: qemu-devel@nongnu.org Date: Tue, 22 Oct 2013 11:25:31 +0800 Message-Id: <1382412341-1173-8-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1382412341-1173-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1382412341-1173-1-git-send-email-lilei@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13102203-5816-0000-0000-00000A7B1602 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.2 Cc: aarcange@redhat.com, aliguori@us.ibm.com, Lei Li , quintela@redhat.com, mdroth@linux.vnet.ibm.com, mrhines@linux.vnet.ibm.com, lagarcia@br.ibm.com, pbonzini@redhat.com, rcj@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 07/17] migration-local: add send_pipefd() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds send_pipefd() to pass the pipe file descriptor to destination process. Signed-off-by: Lei Li --- migration-local.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/migration-local.c b/migration-local.c index 6214ff9..f2871d8 100644 --- a/migration-local.c +++ b/migration-local.c @@ -165,3 +165,56 @@ 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; + + union { + struct cmsghdr cm; + char control[CMSG_SPACE(sizeof(int))]; + } control_un; + struct cmsghdr *cmptr; + char req[1] = { 0x01 }; + + if (pipefd < 0) { + msg.msg_control = NULL; + msg.msg_controllen = 0; + /* Negative status means error */ + req[0] = pipefd; + } else { + 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; +}