From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ShMIU-0003DG-Dq for qemu-devel@nongnu.org; Wed, 20 Jun 2012 10:54:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ShMIO-0000Fu-4A for qemu-devel@nongnu.org; Wed, 20 Jun 2012 10:54:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43313) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ShMIN-0000FR-Rw for qemu-devel@nongnu.org; Wed, 20 Jun 2012 10:54:12 -0400 Message-ID: <4FE1E3FF.50702@redhat.com> Date: Wed, 20 Jun 2012 08:53:51 -0600 From: Eric Blake 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> In-Reply-To: <4FE1D09F.8070704@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigA2381044DFF422813C8B0236" 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: Corey Bryant 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 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigA2381044DFF422813C8B0236 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 06/20/2012 07:31 AM, Corey Bryant wrote: >=20 > 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. >=20 > 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. --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigA2381044DFF422813C8B0236 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://enigmail.mozdev.org/ iQEcBAEBCAAGBQJP4eP/AAoJEKeha0olJ0NqzHYIAJLqyfF6zKncxAm/tfx10oNH XQpRXjWpUhacngyjTg2IgqspxGxWF6Yo5a9JmS8JblvlyoeFm8IWUeExuyKO2HKj g57KUc0LXQsl13Nig0j0NIf9d3B5hylpSg8aq8xp3BXIVRFgl1Je3RLb4H6kJs8G p0yCBM627fmcYQ62eDzAwJvb9wZlYBhM26grpNKhGV+wH6XIB0SzMMZI9ZAEfo/P vv8Ie5+sfgV8mGLDhByfElM07vL/tfQEcBGzLPANt+vdFUWB7sQz3zUI2PIstxvi 7ZjcidAX9QMrcUwtyu1fsE5QyTMQPv1o8D6Aphzv3IZuOYbHaWC1QfLg7ULODT8= =MaTW -----END PGP SIGNATURE----- --------------enigA2381044DFF422813C8B0236--