From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ShNpa-0002K2-5X for qemu-devel@nongnu.org; Wed, 20 Jun 2012 12:32:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ShNpT-0000zo-Nh for qemu-devel@nongnu.org; Wed, 20 Jun 2012 12:32:33 -0400 Received: from e1.ny.us.ibm.com ([32.97.182.141]:54107) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ShNpT-0000zZ-J3 for qemu-devel@nongnu.org; Wed, 20 Jun 2012 12:32:27 -0400 Received: from /spool/local by e1.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Jun 2012 12:32:23 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id B05E16E81B2 for ; Wed, 20 Jun 2012 12:25:22 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q5KGPMbl172024 for ; Wed, 20 Jun 2012 12:25:22 -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 q5KGOb3Z018195 for ; Wed, 20 Jun 2012 13:24:37 -0300 Message-ID: <4FE1F943.40509@linux.vnet.ibm.com> Date: Wed, 20 Jun 2012 12:24:35 -0400 From: Corey Bryant MIME-Version: 1.0 References: <1339689305-27031-1-git-send-email-coreyb@linux.vnet.ibm.com> <4FE09EE3.9070603@redhat.com> <4FE0A15F.7070606@redhat.com> <4FE0A579.40307@redhat.com> <4FE17AE9.90205@redhat.com> <20120620083122.GC20792@redhat.com> <4FE1B308.2080100@redhat.com> <4FE1D09F.8070704@linux.vnet.ibm.com> <4FE1E3FF.50702@redhat.com> In-Reply-To: <4FE1E3FF.50702@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 0/5] file descriptor passing using pass-fd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Kevin Wolf , aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, libvir-list@redhat.com, Jeff Cody , qemu-devel@nongnu.org, Luiz Capitulino , pbonzini@redhat.com On 06/20/2012 10:53 AM, Eric Blake wrote: > On 06/20/2012 07:31 AM, Corey Bryant wrote: > >> >> It sounds like the flow would be: >> 'pass-fd drive-virtio1' of O_RDONLY fd --> guest gets fd 21 > > No -f, so qemu errors out if an fd named 'drive-virtio1' already exists; > otherwise it succeeds, and returns the fd assigned by SCM_RIGHTS as well > as adding the name to its internal list. > >> 'pass-fd -f drive-virtio1' of O_WRONLY fd --> guest gets fd 21? > > -f says to fail if 'drive-virtio1' does not already exist in the > internal list. Otherwise, this is a reopen attempt, and the fd passed > in by SCM_RIGHTS (let's assume it is 23 at this time) is then passed > through dup2() to overwrite the fd already associated with > 'drive-virtio1' (21 in this case), then the SCM_RIGHTS fd (23) is > closed. In this way, the name 'drive-virtio1' remains associated with > fd 21, but we have reopened it with different mode. At this point, code > that wants to reopen /dev/fd/21 with a new mode will see the new > permissions on the reassigned fd. And yes, it means that libvirt would > not be allowed to call 'closefd drive-virtio1' until the block device > for drive-virtio1 is no longer around, whether or not the /dev/fd/nn > reuses the fd as-is or whether it dup()s the fd to something else (say > 22) for use by the block device. > That makes sense. Thanks for the explanation. Essentially dup2(23, 21) will give fd 21 the new access mode. I assume we can go ahead and close fd 23 after the dup2? I'll go ahead and add this support in the next version of the patch series if there are no objections. -- Regards, Corey >> >> But I'm not clear as to how you would retain file descriptor 21 in the >> guest when using 'pass-fd -f drive-virtio1'. The fd is created as a >> result of passing via SCM_RIGHTS, which assigns the next available fd. >> We don't have control over what fd is assigned, do we? > > The use of -f says that 'pass-fd' uses dup2() to reuse an existing fd. >