From: Corey Bryant <coreyb@linux.vnet.ibm.com>
To: Eric Blake <eblake@redhat.com>
Cc: kwolf@redhat.com, libvir-list@redhat.com, aliguori@us.ibm.com,
qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [RFC PATCH 3/4] block: Enable QEMU to retrieve passed fd before attempting open
Date: Tue, 22 May 2012 10:06:14 -0400 [thread overview]
Message-ID: <4FBB9D56.3010605@linux.vnet.ibm.com> (raw)
In-Reply-To: <4FBAB899.6010407@redhat.com>
On 05/21/2012 05:50 PM, Eric Blake wrote:
> On 05/21/2012 02:19 PM, Corey Bryant wrote:
>> With this patch, when QEMU needs to "open" a file, it will first
>> check to see if a matching filename/fd pair were passed via the
>> -filefd command line option or the getfd_file monitor command.
>> If a match is found, QEMU will use the passed fd and will not
>> attempt to open the file. Otherwise, if a match is not found,
>> QEMU will attempt to open the file on it's own.
>>
>> Signed-off-by: Corey Bryant<coreyb@linux.vnet.ibm.com>
>
>> +int file_open(const char *filename, int flags, mode_t mode)
>> +{
>> + int fd;
>> +
>> +#ifdef _WIN32
>> + return qemu_open(filename, flags, mode);
>> +#else
>
> Would it be any easier to write:
>
> #ifndef _WIN32
> qemu_get_fd_file() stuff
> #endif
> return qemu_open()
>
> so that you aren't repeating the return line?
>
Yes that's easier. Thanks for the suggestion!
>
>> + fd = qemu_get_fd_file(filename, false);
>> + if (fd != -1) {
>> + return dup(fd);
>
> Why are you dup'ing the fd? That just sounds like a way to leak fds.
> Remember, the existing 'getfd' monitor command doesn't dup things - it
> either gets consumed by a successful use of the named fd, or it remains
> open on failure and the user can close it by calling 'closefd'.
The way it works now is that the fd/filename pairs that are passed in
(either through -filefd or getfd_file) will persist on the option and
monitor structures. In other words, when we find a match for a filename
on the monitor structure, we don't delete it from the struct. We leave
it there in case we need to open the file again.
So we dup the fd and let QEMU use the new fd as if it opened it itself.
This allows QEMU to close the fd on its own, and if it needs to
re-open the fd, it can dup it again.
>
> Or, if you are intentionally allowing the user to reuse the fd for more
> than one qemu open instance, you need to document this point.
Ok, yes. I'll document this.
>
> What happens if qemu wants O_WRONLY or O_RDWR access, but the user
> passed in an fd with only O_RDONLY access?
This is an area of concern for me. And it's an area where Anthony's
call-back approach was much simpler because it passed the open flags
directly from QEMU to libvirt.
I don't think these flags can be set through fcntl(F_SETFL). So I think
they have to be set on the open() by the managing application. The
problem is that, today, QEMU will open a single file several different
times on initialization alone (reading cow headers and what not), and
the open flags vary on these open calls. The difference with the new
approach in this patch series is that the fd from a single open call is
re-used for each of the "opens".
--
Regards,
Corey
next prev parent reply other threads:[~2012-05-22 14:16 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-21 20:19 [Qemu-devel] [RFC PATCH 0/4] block: file descriptor passing using -filefd and getfd_file Corey Bryant
2012-05-21 20:19 ` [Qemu-devel] [RFC PATCH 1/4] qemu-options: Add -filefd command line option Corey Bryant
2012-05-21 21:40 ` Eric Blake
2012-05-22 13:25 ` Corey Bryant
2012-05-22 13:38 ` Kevin Wolf
2012-05-22 14:26 ` Stefan Hajnoczi
2012-05-22 14:39 ` Kevin Wolf
2012-05-21 20:19 ` [Qemu-devel] [RFC PATCH 2/4] qmp/hmp: Add getfd_file monitor command Corey Bryant
2012-05-21 21:48 ` Eric Blake
2012-05-22 13:37 ` Corey Bryant
2012-05-22 9:18 ` Stefan Hajnoczi
2012-05-22 14:13 ` Corey Bryant
2012-05-22 19:06 ` Luiz Capitulino
2012-05-22 20:02 ` Corey Bryant
2012-05-22 20:26 ` Luiz Capitulino
2012-05-22 22:34 ` Corey Bryant
2012-05-23 13:33 ` Luiz Capitulino
2012-05-23 13:45 ` Corey Bryant
2012-05-21 20:19 ` [Qemu-devel] [RFC PATCH 3/4] block: Enable QEMU to retrieve passed fd before attempting open Corey Bryant
2012-05-21 21:50 ` Eric Blake
2012-05-22 14:06 ` Corey Bryant [this message]
2012-05-21 20:19 ` [Qemu-devel] [RFC PATCH 4/4] Example -filefd and getfd_file server Corey Bryant
2012-05-22 8:18 ` [Qemu-devel] [RFC PATCH 0/4] block: file descriptor passing using -filefd and getfd_file Kevin Wolf
2012-05-22 12:02 ` Eric Blake
2012-05-22 12:08 ` Kevin Wolf
2012-05-22 14:30 ` Corey Bryant
2012-05-22 14:45 ` Kevin Wolf
2012-05-22 15:01 ` Eric Blake
2012-05-22 15:24 ` Kevin Wolf
2012-05-22 15:29 ` Corey Bryant
2012-05-22 15:39 ` Kevin Wolf
2012-05-22 16:02 ` Corey Bryant
2012-05-22 16:15 ` Eric Blake
2012-05-22 17:17 ` Corey Bryant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FBB9D56.3010605@linux.vnet.ibm.com \
--to=coreyb@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=libvir-list@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).