From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOxmB-0004lq-OY for qemu-devel@nongnu.org; Thu, 18 Oct 2012 17:37:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOxmA-0007Kq-HM for qemu-devel@nongnu.org; Thu, 18 Oct 2012 17:37:11 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:34413) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOxmA-0007Kk-D8 for qemu-devel@nongnu.org; Thu, 18 Oct 2012 17:37:10 -0400 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 Oct 2012 17:37:09 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 1A41BC90042 for ; Thu, 18 Oct 2012 17:37:07 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9ILb6Rc116996 for ; Thu, 18 Oct 2012 17:37:06 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9ILb6J6028346 for ; Thu, 18 Oct 2012 18:37:06 -0300 Message-ID: <50807681.5060301@linux.vnet.ibm.com> Date: Thu, 18 Oct 2012 17:37:05 -0400 From: Corey Bryant 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> <508069F5.1000005@redhat.com> In-Reply-To: <508069F5.1000005@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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: Eric Blake Cc: kwolf@redhat.com, libvir-list@redhat.com, qemu-devel@nongnu.org On 10/18/2012 04:43 PM, Eric Blake wrote: > 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 > >> + >> + 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. Yep it works for both cases. I have to admit I stumbled into this at first and then decided to leave it this way since it worked. :) > > 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. I agree, a comment would be useful. Maybe Kevin can add if this series gets pushed? > > Series: > Reviewed-by: Eric Blake > Thanks for reviewing! -- Regards, Corey Bryant