From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0Cgq-0006nN-Ab for qemu-devel@nongnu.org; Sat, 11 Aug 2012 10:29:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T0Cgn-0001be-I7 for qemu-devel@nongnu.org; Sat, 11 Aug 2012 10:29:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50971) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0Cgn-0001bW-9s for qemu-devel@nongnu.org; Sat, 11 Aug 2012 10:29:17 -0400 Message-ID: <50266C28.6070908@redhat.com> Date: Sat, 11 Aug 2012 08:28:56 -0600 From: Eric Blake MIME-Version: 1.0 References: <1344690878-1555-1-git-send-email-coreyb@linux.vnet.ibm.com> <1344690878-1555-7-git-send-email-coreyb@linux.vnet.ibm.com> In-Reply-To: <1344690878-1555-7-git-send-email-coreyb@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig45280E1B1AD44177BDEB9D5F" Subject: Re: [Qemu-devel] [PATCH v9 6/7] block: Enable qemu_open/close to work with fd sets List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corey Bryant Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, libvir-list@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, pbonzini@redhat.com This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig45280E1B1AD44177BDEB9D5F Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 08/11/2012 07:14 AM, Corey Bryant wrote: > When qemu_open is passed a filename of the "/dev/fdset/nnn" > format (where nnn is the fdset ID), an fd with matching access > mode flags will be searched for within the specified monitor > fd set. If the fd is found, a dup of the fd will be returned > from qemu_open. >=20 > v9: > -Drop fdset refcount and check dup_fds instead. (eblake@redhat.com) > -Fix dupfd leak in qemu_dup(). (eblake@redhat.com) > -Always set O_CLOEXEC in qemu_dup(). (kwolf@redhat.com) > -Change name of qemu_dup() to qemu_dup_flags(). (kwolf@redhat.com) >=20 > @@ -87,6 +146,40 @@ int qemu_open(const char *name, int flags, ...) > int ret; > int mode =3D 0; > =20 > +#ifndef _WIN32 > + const char *fdset_id_str; > + > + /* Attempt dup of fd from fd set */ > + if (strstart(name, "/dev/fdset/", &fdset_id_str)) { > + int64_t fdset_id; > + int fd, dupfd; > + > + fdset_id =3D qemu_parse_fdset(fdset_id_str); > + if (fdset_id =3D=3D -1) { > + errno =3D EINVAL; > + return -1; > + } > + > + fd =3D monitor_fdset_get_fd(fdset_id, flags); > + if (fd =3D=3D -1) { > + return -1; > + } > + > + dupfd =3D qemu_dup_flags(fd, flags); > + if (fd =3D=3D -1) { Checking the wrong condition: s/fd/dupfd/ > + return -1; > + } > + > + ret =3D monitor_fdset_dup_fd_add(fdset_id, dupfd); > + if (ret =3D=3D -1) { > + close(dupfd); > + return -1; This function appears to promise a reasonable errno on failure. However, I don't think monitor_fdset_dup_fd_add guarantees a reasonable errno, and even if it does, close() can corrupt errno. I think that prior to returning here, you either need an explicit errno=3DENOMEM, or fix monitor_fdset_dup_fd to guarantee a nice errno, plus a save and restore of errno here. Unless no one cares about errno on failure, in which case your earlier errno=3DEINVAL can be dropped. --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enig45280E1B1AD44177BDEB9D5F 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/ iQEcBAEBCAAGBQJQJmwtAAoJEKeha0olJ0NqU0IH/0MCvmtNAL329EnLoSXSMyu/ gqWm/Ud9t6wZZKzuhW4V2kfpMBh6up1BlQzbYuHOWtYSQWP0CbDc87vI09uEFVGF 6+YbHavvS/IiZ1W9pL7/zPwR235CYqkP2mhAQSlbJMjRr6UWT33oy0F7ra/Zf3+T Nsli7TVgYKeQY3BtZtCshyS0Oj0n5dSZSzMYxFHnSgGhsRSA3fttrlBsEwvAix4i NLsLgMUZFKWxcKb4yxaxRXB750utZYGjII07fdzUbKOi0ZChrKeaTI/lFXB/hR3R GuQ6O/o6Y0bpT2/Rl9OEWOJ7lcx/MP80i0AHKXE7JlA3zr+IoJXqofvNdVaID0o= =qa/1 -----END PGP SIGNATURE----- --------------enig45280E1B1AD44177BDEB9D5F--