On Wed, 2019-08-07 at 13:42 +0200, Douglas Gilbert wrote:
> Add support for the sg v4 interface based on struct sg_io_v4 found
> in include/uapi/linux/bsg.h and only previously supported by the
> bsg driver. Add ioctl(SG_IOSUBMIT) and ioctl(SG_IORECEIVE) for
> async (non-blocking) usage of the sg v4 interface. Do not accept
> the v3 interface with these ioctls. Do not accept the v4
> interface with this driver's existing write() and read()
> system calls.
> 
> For sync (blocking) usage expand the existing ioctl(SG_IO)
> to additionally accept the sg v4 interface object.

First the meta comments:

Since this is effectively a new interface for sg, we're not constrained
by what happened before.  Specifically, we don't want to support the
read/write interface for v4, that should remain only for legacy v3.

We're already discussing what the correct async interface should look
like, I won't comment on the IOSUBMIT/IORECEIVE parts.

Given that we want to unify the v4 code paths, I think this:
 
> @@ -1293,15 +1528,25 @@ sg_ctl_sg_io(struct file *filp, struct
> sg_device *sdp, struct sg_fd *sfp,
>               return res;
>       if (copy_from_user(h3p, p, SZ_SG_IO_HDR))
>               return -EFAULT;
> -     if (h3p->interface_id == 'S')
> -             res = sg_submit(filp, sfp, h3p, true, &srp);
> -     else
> +     if (h3p->interface_id == 'Q') {
> +             /* copy in rest of sg_io_v4 object */
> +             if (copy_from_user(hu8arr + SZ_SG_IO_HDR,
> +                                ((u8 __user *)p) + SZ_SG_IO_HDR,
> +                                SZ_SG_IO_V4 - SZ_SG_IO_HDR))
> +                     return -EFAULT;
> +             res = sg_v4_submit(filp, sfp, p, h4p, true, &srp);

Can simply become

if (h3p->interface_id == 'Q')
        return bsg_sg_io(sdp->request_queue, filp->file_mode, p);

And all the duplicate code could then be eliminated.  Of course, we
have to export bsg_sg_io, but that should be a trivial addition.

James


Reply via email to