From patchwork Wed Oct 10 14:20:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Bryant X-Patchwork-Id: 190652 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 1F4D82C007B for ; Thu, 11 Oct 2012 01:26:36 +1100 (EST) Received: from localhost ([::1]:57474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLxF4-0006Cb-8N for incoming@patchwork.ozlabs.org; Wed, 10 Oct 2012 10:26:34 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLxEm-00060L-Sy for qemu-devel@nongnu.org; Wed, 10 Oct 2012 10:26:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TLxEd-000256-1e for qemu-devel@nongnu.org; Wed, 10 Oct 2012 10:26:16 -0400 Received: from e5.ny.us.ibm.com ([32.97.182.145]:35765) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLxEc-000250-TD for qemu-devel@nongnu.org; Wed, 10 Oct 2012 10:26:06 -0400 Received: from /spool/local by e5.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Oct 2012 10:26:05 -0400 Received: from d01relay02.pok.ibm.com (9.56.227.234) by e5.ny.us.ibm.com (192.168.1.105) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 10 Oct 2012 10:21:31 -0400 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9AELDh5169240 for ; Wed, 10 Oct 2012 10:21:14 -0400 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9AEKG1A024357 for ; Wed, 10 Oct 2012 08:20:16 -0600 Received: from localhost ([9.80.100.186]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q9AEKEQf024143; Wed, 10 Oct 2012 08:20:15 -0600 From: Corey Bryant To: qemu-devel@nongnu.org Date: Wed, 10 Oct 2012 10:20:05 -0400 Message-Id: <1349878805-16352-4-git-send-email-coreyb@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1349878805-16352-1-git-send-email-coreyb@linux.vnet.ibm.com> References: <1349878805-16352-1-git-send-email-coreyb@linux.vnet.ibm.com> x-cbid: 12101014-5930-0000-0000-00000CF20A8C X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.182.145 Cc: kwolf@redhat.com, libvir-list@redhat.com, Corey Bryant Subject: [Qemu-devel] [PATCH v2 3/3] qemu-config: Add new -add-fd command line option 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 option can be used for passing file descriptors on the command line. It mirrors the existing add-fd QMP command which allows an fd to be passed to QEMU via SCM_RIGHTS and added to an fd set. This can be combined with commands such as -drive to link file descriptors in an fd set to a drive: qemu-kvm -add-fd fd=4,set=2,opaque="rdwr:/path/to/file" -add-fd fd=5,set=2,opaque="rdonly:/path/to/file" -drive file=/dev/fdset/2,index=0,media=disk This example adds fds 4 and 5, and the accompanying opaque strings to the fd set with ID=2. qemu_open() already knows how to handle a filename of this format. qemu_open() searches the corresponding fd set for an fd and when it finds a match, QEMU goes on to use a dup of that fd just like it would have used an fd that it opened itself. Signed-off-by: Corey Bryant --- v2: - The -add-fd option is new in v2 (eblake@redhat.com) qemu-config.c | 22 ++++++++++++++++++++++ qemu-options.hx | 35 +++++++++++++++++++++++++++++++++++ vl.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) diff --git a/qemu-config.c b/qemu-config.c index cd1ec21..0bd67ca 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -653,6 +653,27 @@ QemuOptsList qemu_boot_opts = { }, }; +static QemuOptsList qemu_add_fd_opts = { + .name = "add-fd", + .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head), + .desc = { + { + .name = "fd", + .type = QEMU_OPT_NUMBER, + .help = "file descriptor to add to fd set", + },{ + .name = "set", + .type = QEMU_OPT_NUMBER, + .help = "ID of the fd set to add fd to", + },{ + .name = "opaque", + .type = QEMU_OPT_STRING, + .help = "free-form string used to describe fd", + }, + { /* end of list */ } + }, +}; + static QemuOptsList *vm_config_groups[32] = { &qemu_drive_opts, &qemu_chardev_opts, @@ -669,6 +690,7 @@ static QemuOptsList *vm_config_groups[32] = { &qemu_boot_opts, &qemu_iscsi_opts, &qemu_sandbox_opts, + &qemu_add_fd_opts, NULL, }; diff --git a/qemu-options.hx b/qemu-options.hx index 7d97f96..884fcb6 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -257,6 +257,14 @@ qemu-system-i386 -drive file=file,index=2,media=disk qemu-system-i386 -drive file=file,index=3,media=disk @end example +You can open an image using pre-opened file descriptors from an fd set: +@example +qemu-system-i386 +-add-fd fd=4,set=2,opaque="rdwr:/path/to/file" +-add-fd fd=5,set=2,opaque="rdonly:/path/to/file" +-drive file=/dev/fdset/2,index=0,media=disk +@end example + You can connect a CDROM to the slave of ide0: @example qemu-system-i386 -drive file=file,if=ide,index=1,media=cdrom @@ -289,6 +297,33 @@ qemu-system-i386 -hda a -hdb b @end example ETEXI +DEF("add-fd", HAS_ARG, QEMU_OPTION_add_fd, + "-add-fd fd=fd,set=set[,opaque=opaque]\n" + " Add 'fd' to fd 'set'\n", QEMU_ARCH_ALL) +STEXI +@item -add-fd fd=@var{fd},set=@var{set}[,opaque=@var{opaque}] +@findex -add-fd + +Add a file descriptor to an fd set. Valid options are: + +@table @option +@item fd=@var{fd} +This option defines the file descriptor that is to be added to the fd set. +@item set=@var{set} +This option defines the ID of the fd set to add the file descriptor to. +@item opaque=@var{opaque} +This option defines a free-form string that can be used to describe @var{fd}. +@end table + +You can open an image using pre-opened file descriptors from an fd set: +@example +qemu-system-i386 +-add-fd fd=4,set=2,opaque="rdwr:/path/to/file" +-add-fd fd=5,set=2,opaque="rdonly:/path/to/file" +-drive file=/dev/fdset/2,index=0,media=disk +@end example +ETEXI + DEF("set", HAS_ARG, QEMU_OPTION_set, "-set group.id.arg=value\n" " set parameter for item of type \n" diff --git a/vl.c b/vl.c index 8d305ca..0265712 100644 --- a/vl.c +++ b/vl.c @@ -790,6 +790,33 @@ static int parse_sandbox(QemuOpts *opts, void *opaque) return 0; } +static int parse_add_fd(QemuOpts *opts, void *opaque) +{ + int fd; + int64_t fdset_id; + const char *fd_opaque = NULL; + + fd = qemu_opt_get_number(opts, "fd", -1); + fdset_id = qemu_opt_get_number(opts, "set", -1); + fd_opaque = qemu_opt_get(opts, "opaque"); + + if (fd == -1) { + qerror_report(ERROR_CLASS_GENERIC_ERROR, "fd option is required"); + return -1; + } + + if (fdset_id == -1) { + qerror_report(ERROR_CLASS_GENERIC_ERROR, "set option is required"); + return -1; + } + + /* add the fd, and optionally the opaque string, to the fd set */ + monitor_fdset_add_fd(fd, true, fdset_id, fd_opaque ? true : false, + fd_opaque); + + return 0; +} + /***********************************************************/ /* QEMU Block devices */ @@ -3299,6 +3326,11 @@ int main(int argc, char **argv, char **envp) exit(0); } break; + case QEMU_OPTION_add_fd: + opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0); + if (!opts) { + exit(0); + } default: os_parse_cmd_args(popt->index, optarg); } @@ -3310,6 +3342,10 @@ int main(int argc, char **argv, char **envp) exit(1); } + if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) { + exit(1); + } + if (machine == NULL) { fprintf(stderr, "No machine found.\n"); exit(1);