From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58434) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOwwR-0002dS-UR for qemu-devel@nongnu.org; Thu, 18 Oct 2012 16:43:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOwwQ-0005Sm-K3 for qemu-devel@nongnu.org; Thu, 18 Oct 2012 16:43:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12594) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOwwQ-0005S7-BW for qemu-devel@nongnu.org; Thu, 18 Oct 2012 16:43:42 -0400 Message-ID: <508069F5.1000005@redhat.com> Date: Thu, 18 Oct 2012 14:43:33 -0600 From: Eric Blake MIME-Version: 1.0 References: <1350587974-6378-1-git-send-email-coreyb@linux.vnet.ibm.com> <1350587974-6378-5-git-send-email-coreyb@linux.vnet.ibm.com> In-Reply-To: <1350587974-6378-5-git-send-email-coreyb@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigB48633A1ECD20B717417006B" Subject: Re: [Qemu-devel] [PATCH v4 4/4] qemu-config: Add new -add-fd command line option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corey Bryant Cc: kwolf@redhat.com, libvir-list@redhat.com, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigB48633A1ECD20B717417006B Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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. >=20 > This can be combined with commands such as -drive to link file > descriptors in an fd set to a drive: >=20 > qemu-kvm -add-fd fd=3D3,set=3D2,opaque=3D"rdwr:/path/to/file" > -add-fd fd=3D4,set=3D2,opaque=3D"rdonly:/path/to/file" > -drive file=3D/dev/fdset/2,index=3D0,media=3Ddisk >=20 > This example adds dups of fds 3 and 4, and the accompanying opaque > strings to the fd set with ID=3D2. 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. >=20 > Signed-off-by: Corey Bryant > + > + 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 --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigB48633A1ECD20B717417006B Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iQEcBAEBCAAGBQJQgGn1AAoJEKeha0olJ0NqeNEH/AiR0ELHgeclk6FZY5t3NyBx 1twFuUbQGaLlZlKHzSTe31vFqXUQQF2tGueYzOrm4/GxQ0Z7hQB1Ssmgs0ylDGwf hxxwbkQ/ZRMIPfMTa5kmBMa5Dkjl1gGPH854u0LFU/Tng04fVK+ERhliALrJydJE WapPklRgk8RcPiPeXEv44A3OvCbcZgE+jSCqXNKKjTEzX4LQcOCjCvNRFcxOq+Ak /jytkvuJfVwOzP/dTH2WZLLlPGUpeSbm1P0tc+LC1XGgU2GXX8y8KcwNrqEJHksx gxXJjC9JUfD4r+DgLFP3DEn2TFTMy6s1BJ7dJ77OwpsQIU/iOBD5FmMCxRaXyQM= =SSZy -----END PGP SIGNATURE----- --------------enigB48633A1ECD20B717417006B--