[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 4/4] qemu-config: Add new -add-fd command lin
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v4 4/4] qemu-config: Add new -add-fd command line option |
Date: |
Thu, 18 Oct 2012 14:43:33 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121009 Thunderbird/16.0 |
On 10/18/2012 01:19 PM, Corey Bryant wrote:
> 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=3,set=2,opaque="rdwr:/path/to/file"
> -add-fd fd=4,set=2,opaque="rdonly:/path/to/file"
> -drive file=/dev/fdset/2,index=0,media=disk
>
> This example adds dups of fds 3 and 4, 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 <address@hidden>
> +
> + if (fcntl(fd, F_GETFD) & FD_CLOEXEC) {
> + qerror_report(ERROR_CLASS_GENERIC_ERROR,
> + "fd is not valid or already in use");
> + return -1;
> + }
Hmm, I was about to call you on the fact that you didn't check whether
fcntl() succeeded; but then realized that in the failure case it is
required by POSIX to return -1 which happens to include the FD_CLOEXEC
bit, so you actually ended up with a sneaky optimization that does the
right thing for both open and closed fds.
Perhaps a comment in the code is warranted (after all, it is not
immediately apparent from reading just this if statement why it works);
maybe "/* All fds inherited across exec() necessarily have FD_CLOEXEC
clear, while qemu sets FD_CLOEXEC on all other fds opened from command
line arguments */". But I'm not going to require a v5 just for a
comment addition.
Series:
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake address@hidden +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
[Qemu-devel] [PATCH v4 3/4] monitor: Prevent removing fd from set during init, Corey Bryant, 2012/10/18
[Qemu-devel] [PATCH v4 2/4] monitor: Enable adding an inherited fd to an fd set, Corey Bryant, 2012/10/18