From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWaUm-0005WL-SN for qemu-devel@nongnu.org; Mon, 21 May 2012 17:50:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SWaUk-0005wU-Ux for qemu-devel@nongnu.org; Mon, 21 May 2012 17:50:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64891) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWaUk-0005w9-NC for qemu-devel@nongnu.org; Mon, 21 May 2012 17:50:26 -0400 Message-ID: <4FBAB899.6010407@redhat.com> Date: Mon, 21 May 2012 15:50:17 -0600 From: Eric Blake MIME-Version: 1.0 References: <1337631598-30639-1-git-send-email-coreyb@linux.vnet.ibm.com> <1337631598-30639-4-git-send-email-coreyb@linux.vnet.ibm.com> In-Reply-To: <1337631598-30639-4-git-send-email-coreyb@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigBAFEDF4A1CE470ED85C78B5B" Subject: Re: [Qemu-devel] [RFC PATCH 3/4] block: Enable QEMU to retrieve passed fd before attempting open List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corey Bryant Cc: kwolf@redhat.com, libvir-list@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigBAFEDF4A1CE470ED85C78B5B Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 05/21/2012 02:19 PM, Corey Bryant wrote: > With this patch, when QEMU needs to "open" a file, it will first > check to see if a matching filename/fd pair were passed via the > -filefd command line option or the getfd_file monitor command. > If a match is found, QEMU will use the passed fd and will not > attempt to open the file. Otherwise, if a match is not found, > QEMU will attempt to open the file on it's own. >=20 > Signed-off-by: Corey Bryant > +int file_open(const char *filename, int flags, mode_t mode) > +{ > + int fd; > + > +#ifdef _WIN32 > + return qemu_open(filename, flags, mode); > +#else Would it be any easier to write: #ifndef _WIN32 qemu_get_fd_file() stuff #endif return qemu_open() so that you aren't repeating the return line? > + fd =3D qemu_get_fd_file(filename, false); > + if (fd !=3D -1) { > + return dup(fd); Why are you dup'ing the fd? That just sounds like a way to leak fds. Remember, the existing 'getfd' monitor command doesn't dup things - it either gets consumed by a successful use of the named fd, or it remains open on failure and the user can close it by calling 'closefd'. Or, if you are intentionally allowing the user to reuse the fd for more than one qemu open instance, you need to document this point. What happens if qemu wants O_WRONLY or O_RDWR access, but the user passed in an fd with only O_RDONLY access? --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigBAFEDF4A1CE470ED85C78B5B 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/ iQEcBAEBCAAGBQJPuriZAAoJEKeha0olJ0NqKHcH/jdI0/EDRJ0nopW1ApB74GqZ /F4uJyqJSUwjBzImcLIiKEHwUcGchmc8vq6+vziVCUeQ2s/t0b8dL//Nzn+/TN0I 41RH01495mOCvYznO/SlrmByAcudwn3XpWVGEg/CA2Bdzg9RzDJhOuLIar6vgk5L l2RwLwL5OjI9Mcm5slEXyCt/LLiatKbXJr1y9W6jp/JOOqIUP1to1OcRSU2T1Th7 3JjF2v8ymMJcEJLr8LRZDZ82Rrmy5zGzyxuDVDFNnfwl2aEzcJVUbWUgB9MjTUll wwovt0qKdgeQ3saPzEujVWl2DaayAKzkTPhYWn39LHmtQp59pFtD+w6tOBZctps= =4TLz -----END PGP SIGNATURE----- --------------enigBAFEDF4A1CE470ED85C78B5B--