qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [PATCH v4 5/5] raw-posix: Introduce hdev_is_sg()


From: Eric Blake
Subject: Re: [Qemu-block] [PATCH v4 5/5] raw-posix: Introduce hdev_is_sg()
Date: Thu, 18 Jun 2015 14:16:43 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]