From patchwork Fri Oct 5 18:07: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: 189560 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 B93932C0040 for ; Sat, 6 Oct 2012 04:09:57 +1000 (EST) Received: from localhost ([::1]:55449 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TKCLT-0007Ab-ME for incoming@patchwork.ozlabs.org; Fri, 05 Oct 2012 14:09:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TKCKX-0004ZQ-Ec for qemu-devel@nongnu.org; Fri, 05 Oct 2012 14:08:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TKCKV-0004UX-Gt for qemu-devel@nongnu.org; Fri, 05 Oct 2012 14:08:57 -0400 Received: from e4.ny.us.ibm.com ([32.97.182.144]:46572) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TKCKV-0004QV-D1 for qemu-devel@nongnu.org; Fri, 05 Oct 2012 14:08:55 -0400 Received: from /spool/local by e4.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 5 Oct 2012 14:08:32 -0400 Received: from d01relay03.pok.ibm.com (9.56.227.235) by e4.ny.us.ibm.com (192.168.1.104) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 5 Oct 2012 14:08:29 -0400 Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q95I8SsO150654 for ; Fri, 5 Oct 2012 14:08:28 -0400 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q95I8Seh002176 for ; Fri, 5 Oct 2012 14:08:28 -0400 Received: from localhost ([9.80.102.135]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q95I8Rua002140; Fri, 5 Oct 2012 14:08:27 -0400 From: Corey Bryant To: qemu-devel@nongnu.org Date: Fri, 5 Oct 2012 14:07:05 -0400 Message-Id: <1349460425-30601-5-git-send-email-coreyb@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1349460425-30601-1-git-send-email-coreyb@linux.vnet.ibm.com> References: <1349460425-30601-1-git-send-email-coreyb@linux.vnet.ibm.com> x-cbid: 12100518-3534-0000-0000-00000D7C537A X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.182.144 Cc: libvir-list@redhat.com, kwolf@redhat.com, Corey Bryant , eblake@redhat.com Subject: [Qemu-devel] [PATCH 4/4] blockdev: Process -drive fd and opaque options 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 When an fd, and optionally opaque, are passed with -drive, they are added to an automatically generated fd set. The file name is also generated in the form of "/dev/fdset/nnn", where nnn is the fd set ID. 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 --- blockdev.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5f18dfa..cf348c6 100644 --- a/blockdev.c +++ b/blockdev.c @@ -281,6 +281,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) const char *file = NULL; const char *serial; const char *mediastr = ""; + const char *opaque = NULL; BlockInterfaceType type; enum { MEDIA_DISK, MEDIA_CDROM } media; int bus_id, unit_id; @@ -297,6 +298,10 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) int snapshot = 0; bool copy_on_read; int ret; + int fd; + char filename[32]; + AddfdInfo *fdinfo = NULL; + Error *errp = NULL; translation = BIOS_ATA_TRANSLATION_AUTO; media = MEDIA_DISK; @@ -315,6 +320,8 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) copy_on_read = qemu_opt_get_bool(opts, "copy-on-read", false); file = qemu_opt_get(opts, "file"); + fd = qemu_opt_get_number(opts, "fd", -1); + opaque = qemu_opt_get(opts, "opaque"); serial = qemu_opt_get(opts, "serial"); if ((buf = qemu_opt_get(opts, "if")) != NULL) { @@ -575,9 +582,35 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) default: abort(); } - if (!file || !*file) { - return dinfo; + + if (file && fd != -1) { + error_report("file cannot be used with fd"); + goto err; + } + + if (opaque && fd == -1) { + error_report("opaque cannot be specified without fd"); + goto err; + } + + if ((!file || !*file)) { + if (fd != -1) { + /* add the fd, and optionally opaque, to an fd set */ + fdinfo = monitor_fdset_add_fd(fd, false, -1, opaque ? true : false, + opaque, &errp); + if (fdinfo == NULL) { + goto err; + } + + /* set file name to /dev/fdset/nnn */ + snprintf(filename, sizeof(filename), "/dev/fdset/%" PRId64, + fdinfo->fdset_id); + file = filename; + } else { + return dinfo; + } } + if (snapshot) { /* always use cache=unsafe with snapshot */ bdrv_flags &= ~BDRV_O_CACHE_MASK; @@ -625,6 +658,9 @@ err: g_free(dinfo->id); QTAILQ_REMOVE(&drives, dinfo, next); g_free(dinfo); + if (fdinfo) { + qmp_remove_fd(fdinfo->fdset_id, true, fdinfo->fd, &errp); + } return NULL; }