From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5gF2-0007Tr-CC for qemu-devel@nongnu.org; Thu, 18 Jun 2015 16:16:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5gF1-0004W9-9s for qemu-devel@nongnu.org; Thu, 18 Jun 2015 16:16:52 -0400 Message-ID: <5583272B.2010600@redhat.com> Date: Thu, 18 Jun 2015 14:16:43 -0600 From: Eric Blake MIME-Version: 1.0 References: <1432115859-11413-1-git-send-email-dimara@arrikto.com> <1432115859-11413-6-git-send-email-dimara@arrikto.com> In-Reply-To: <1432115859-11413-6-git-send-email-dimara@arrikto.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="It5XBqmuN47fm314HfMUtqSII876URkAV" Subject: Re: [Qemu-devel] [PATCH v4 5/5] raw-posix: Introduce hdev_is_sg() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Dimitris Aragiorgis , qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --It5XBqmuN47fm314HfMUtqSII876URkAV Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05/20/2015 03:57 AM, Dimitris Aragiorgis wrote: > Until now, an SG device was identified only by checking if its path > started with "/dev/sg". Then, hdev_open() set bs->sg accordingly. > This is very fragile, e.g. it fails with symlinks or relative paths. > We should rely on the actual properties of the device instead of the > specified file path. >=20 > Test for an SG device (e.g. /dev/sg0) by ensuring that all of the > following holds: >=20 > - The device supports the SG_GET_VERSION_NUM ioctl > - The device supports the SG_GET_SCSI_ID ioctl > - The specified file name corresponds to a character device I'd check stat first. ioctl's on the wrong device type might have unexpected side effects. > +static int hdev_is_sg(BlockDriverState *bs) > +{ > + > +#if defined(__linux__) > + > + struct stat st; > + struct sg_scsi_id scsiid; > + int sg_version; > + > + if (!bdrv_ioctl(bs, SG_GET_VERSION_NUM, &sg_version) && > + !bdrv_ioctl(bs, SG_GET_SCSI_ID, &scsiid) && > + stat(bs->filename, &st) >=3D 0 && S_ISCHR(st.st_mode)) { > + DPRINTF("SG device found: type=3D%d, version=3D%d\n", > + scsiid.scsi_type, sg_version); > + return 1; > + } > + > +#endif > + > + return 0; Make this return 'bool', using 'true' and 'false'. We require a C99 compiler, after all. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --It5XBqmuN47fm314HfMUtqSII876URkAV Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVgycrAAoJEKeha0olJ0Nq2XAH/2dqywzIIZox0WBuqcDC7e6R IYWBbwRzlNPRFCu9uTwfJryUdc+iy8hxH1CPaebVHCNE6NDAI/fxhUrBRMX4LeRj JC7tHIvWNEo8uHleP34e7uG3CXP7m7KeRE0Y5w799GvA0EQwldfyjkdhsJZmIlm1 BC0yuxVsYKHo92J52ijdQ+onpIcg1Mz+njm5TQRPOwmnYX3tjWpqFs6UuRGLamFC kKmh/1WeBCTTleL8P4NyR3/vdlzPbXGtN/Y5IpndQ/aG36Jii6sBOCVmDrdN0o3+ HvE0BnZcFS4U6tiUVlGPjmFvc4NVSk078fKANoug9/Lafd8fCRy5KPvIb2EJQKM= =7wlV -----END PGP SIGNATURE----- --It5XBqmuN47fm314HfMUtqSII876URkAV--