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. > > Test for an SG device (e.g. /dev/sg0) by ensuring that all of the > following holds: > > - 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) >= 0 && S_ISCHR(st.st_mode)) { > + DPRINTF("SG device found: type=%d, version=%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. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature