From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7Onf-0000bM-J9 for qemu-devel@nongnu.org; Tue, 23 Jun 2015 10:03:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z7Onb-0006zJ-L0 for qemu-devel@nongnu.org; Tue, 23 Jun 2015 10:03:43 -0400 Date: Tue, 23 Jun 2015 15:03:30 +0100 From: Stefan Hajnoczi Message-ID: <20150623140330.GD31481@stefanha-thinkpad.redhat.com> References: <1435056300-14924-1-git-send-email-dimara@arrikto.com> <1435056300-14924-6-git-send-email-dimara@arrikto.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="GyRA7555PLgSTuth" Content-Disposition: inline In-Reply-To: <1435056300-14924-6-git-send-email-dimara@arrikto.com> Subject: Re: [Qemu-devel] [PATCH v5 5/5] raw-posix: Introduce hdev_is_sg() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Dimitris Aragiorgis Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org --GyRA7555PLgSTuth Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jun 23, 2015 at 01:45:00PM +0300, Dimitris Aragiorgis wrote: > +static bool hdev_is_sg(BlockDriverState *bs) > +{ > + > +#if defined(__linux__) > + > + struct stat st; > + struct sg_scsi_id scsiid; > + int sg_version; > + > + if (stat(bs->filename, &st) >= 0 && S_ISCHR(st.st_mode) && > + !bdrv_ioctl(bs, SG_GET_VERSION_NUM, &sg_version) && > + !bdrv_ioctl(bs, SG_GET_SCSI_ID, &scsiid)) { > + DPRINTF("SG device found: type=%d, version=%d\n", > + scsiid.scsi_type, sg_version); > + return true; > + } If you respin this series, please use fstat() instead of stat() since we already have the file descriptor open. That ensures the stat is really for the same file as the one we already have open (it avoids the race condition). I don't see a practical danger in using stat() for the time being: Reviewed-by: Stefan Hajnoczi --GyRA7555PLgSTuth Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJViWcyAAoJEJykq7OBq3PIOqsH/R2SlaNPR99ex4hrLEzLJZdU Sf6bvQeTsAIYfL/02Mpi3SwlYZi7VOCedQWDM9MFDHtIPxk430H5TywVLGO4PkPP IvrZS6ZD8nfgJrcjRdAKXHMZmE6XdqK25iKYusxxYcAicqDIHX7RikAuPmmTCaJ2 fdZ0y7lUBUtrtG19PhvmfsLakUXdBcqxRfO2qsJRCg1KBocAnFCn0r+TzLfPAAOV QbVIUQldRGgNnpHJPQAty5wINQKjV27mxkmnxjf55POeWsV1UKxWsDAGWpL4tcaE k8h0ROU/G8QeQEoBfpXP/OhP1nkJVewHyRZSwDn74RHPbzsHzyakgeC/6HBblks= =HcJG -----END PGP SIGNATURE----- --GyRA7555PLgSTuth--