From patchwork Thu Jun 14 15:55:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Bryant X-Patchwork-Id: 164956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CA1EAB6FBC for ; Fri, 15 Jun 2012 01:55:04 +1000 (EST) Received: from localhost ([::1]:45964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfCNy-00040N-PI for incoming@patchwork.ozlabs.org; Thu, 14 Jun 2012 11:55:02 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfCNO-0002WE-Ti for qemu-devel@nongnu.org; Thu, 14 Jun 2012 11:54:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SfCNJ-0003YO-PI for qemu-devel@nongnu.org; Thu, 14 Jun 2012 11:54:26 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:37518) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfCNJ-0003XJ-Il for qemu-devel@nongnu.org; Thu, 14 Jun 2012 11:54:21 -0400 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 14 Jun 2012 09:54:16 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 14 Jun 2012 09:54:13 -0600 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 97E513E40049 for ; Thu, 14 Jun 2012 15:54:11 +0000 (WET) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q5EFs7ja175558 for ; Thu, 14 Jun 2012 09:54:07 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q5EFs6aF022691 for ; Thu, 14 Jun 2012 09:54:06 -0600 Received: from localhost ([9.80.103.203]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q5EFs5If022634; Thu, 14 Jun 2012 09:54:06 -0600 From: Corey Bryant To: qemu-devel@nongnu.org Date: Thu, 14 Jun 2012 11:55:02 -0400 Message-Id: <1339689305-27031-3-git-send-email-coreyb@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.2 In-Reply-To: <1339689305-27031-1-git-send-email-coreyb@linux.vnet.ibm.com> References: <1339689305-27031-1-git-send-email-coreyb@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12061415-7408-0000-0000-000005DA8D6A X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.110.158 Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, libvir-list@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, eblake@redhat.com Subject: [Qemu-devel] [PATCH v3 2/5] qapi: Add pass-fd QMP command 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 the pass-fd QMP command using the QAPI framework. Like the getfd command, it is used to pass a file descriptor via SCM_RIGHTS. However, the pass-fd command also returns the received file descriptor, which is a difference in behavior from the getfd command, which returns nothing. The closefd command can be used to close a file descriptor that was passed with the pass-fd command. Note that when using getfd or pass-fd, there are some commands (e.g. migrate with fd:name) that implicitly close the named fd. When this is not the case, closefd must be used to avoid fd leaks. Signed-off-by: Corey Bryant --- v2: -Introduce new QMP command to pass/return fd (lcapitulino@redhat.com) -Use passfd as command name (berrange@redhat.com) v3: -Use pass-fd as command name (lcapitulino@redhat.com) -Fail pass-fd if fdname already exists (lcapitulino@redhat.com) -Add notes to QMP command describing behavior in more detail (lcapitulino@redhat.com, eblake@redhat.com) -Add note about fd leakage (eblake@redhat.com) monitor.c | 33 +++++++++++++++++++++++++++++++++ qapi-schema.json | 19 +++++++++++++++++++ qmp-commands.hx | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/monitor.c b/monitor.c index 1a7f7e7..6d99368 100644 --- a/monitor.c +++ b/monitor.c @@ -2182,6 +2182,39 @@ static void do_inject_mce(Monitor *mon, const QDict *qdict) } #endif +int64_t qmp_pass_fd(const char *fdname, Error **errp) +{ + mon_fd_t *monfd; + int fd; + + fd = qemu_chr_fe_get_msgfd(cur_mon->chr); + if (fd == -1) { + error_set(errp, QERR_FD_NOT_SUPPLIED); + return -1; + } + + if (qemu_isdigit(fdname[0])) { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname", + "a name not starting with a digit"); + return -1; + } + + QLIST_FOREACH(monfd, &cur_mon->fds, next) { + if (strcmp(monfd->name, fdname) == 0) { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname", + "a name that does not already exist"); + return -1; + } + } + + monfd = g_malloc0(sizeof(mon_fd_t)); + monfd->name = g_strdup(fdname); + monfd->fd = fd; + + QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next); + return fd; +} + void qmp_getfd(const char *fdname, Error **errp) { mon_fd_t *monfd; diff --git a/qapi-schema.json b/qapi-schema.json index 26a6b84..ed99f23 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1864,6 +1864,25 @@ { 'command': 'netdev_del', 'data': {'id': 'str'} } ## +# @pass-fd: +# +# Pass a file descriptor via SCM rights and assign it a name +# +# @fdname: file descriptor name +# +# Returns: The QEMU file descriptor that was received +# If file descriptor was not received, FdNotSupplied +# If @fdname is not valid, InvalidParameterType +# +# Since: 1.2.0 +# +# Notes: If @fdname already exists, the command will fail. +# The 'closefd' command can be used to explicitly close the +# file descriptor when it is no longer needed. +## +{ 'command': 'pass-fd', 'data': {'fdname': 'str'}, 'returns': 'int' } + +## # @getfd: # # Receive a file descriptor via SCM rights and assign it a name diff --git a/qmp-commands.hx b/qmp-commands.hx index e3cf3c5..c039947 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -869,6 +869,40 @@ Example: EQMP { + .name = "pass-fd", + .args_type = "fdname:s", + .params = "pass-fd name", + .help = "pass a file descriptor via SCM rights and assign it a name", + .mhandler.cmd_new = qmp_marshal_input_pass_fd, + }, + +SQMP +pass-fd +------- + +Pass a file descriptor via SCM rights and assign it a name. + +Arguments: + +- "fdname": file descriptor name (json-string) + +Return a json-int with the QEMU file descriptor that was received. + +Example: + +-> { "execute": "pass-fd", "arguments": { "fdname": "fd1" } } +<- { "return": 42 } + +Notes: + +(1) If the name specified by the "fdname" argument already exists, + the command will fail. +(2) The 'closefd' command can be used to explicitly close the file + descriptor when it is no longer needed. + +EQMP + + { .name = "getfd", .args_type = "fdname:s", .params = "getfd name",