From mboxrd@z Thu Jan 1 00:00:00 1970 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 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 From: Corey Bryant Date: Fri, 5 Oct 2012 14:07:05 -0400 Message-Id: <1349460425-30601-5-git-send-email-coreyb@linux.vnet.ibm.com> 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> Subject: [Qemu-devel] [PATCH 4/4] blockdev: Process -drive fd and opaque options List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: libvir-list@redhat.com, kwolf@redhat.com, Corey Bryant , eblake@redhat.com 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; } -- 1.7.11.4