scsi: scsi_ioctl: Factor SG_IO handling into a helper

Split the SG_IO handler from the main scsi_ioctl() routine.

Link: https://lore.kernel.org/r/20210724072033.1284840-24-hch@lst.de
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Christoph Hellwig 2021-07-24 09:20:32 +02:00 коммит произвёл Martin K. Petersen
Родитель 2102a5cc12
Коммит b2123d3b09
1 изменённых файлов: 19 добавлений и 16 удалений

Просмотреть файл

@ -864,6 +864,23 @@ static int scsi_cdrom_send_packet(struct request_queue *q,
return err; return err;
} }
static int scsi_ioctl_sg_io(struct request_queue *q, struct gendisk *disk,
fmode_t mode, void __user *argp)
{
struct sg_io_hdr hdr;
int error;
error = get_sg_io_hdr(&hdr, argp);
if (error)
return error;
error = sg_io(q, disk, &hdr, mode);
if (error == -EFAULT)
return error;
if (put_sg_io_hdr(&hdr, argp))
return -EFAULT;
return 0;
}
/** /**
* scsi_ioctl - Dispatch ioctl to scsi device * scsi_ioctl - Dispatch ioctl to scsi device
* @sdev: scsi device receiving ioctl * @sdev: scsi device receiving ioctl
@ -881,7 +898,6 @@ int scsi_ioctl(struct scsi_device *sdev, struct gendisk *disk, fmode_t mode,
{ {
struct request_queue *q = sdev->request_queue; struct request_queue *q = sdev->request_queue;
struct scsi_sense_hdr sense_hdr; struct scsi_sense_hdr sense_hdr;
int error;
/* Check for deprecated ioctls ... all the ioctls which don't /* Check for deprecated ioctls ... all the ioctls which don't
* follow the new unique numbering scheme are deprecated */ * follow the new unique numbering scheme are deprecated */
@ -912,21 +928,8 @@ int scsi_ioctl(struct scsi_device *sdev, struct gendisk *disk, fmode_t mode,
return sg_set_reserved_size(q, arg); return sg_set_reserved_size(q, arg);
case SG_EMULATED_HOST: case SG_EMULATED_HOST:
return sg_emulated_host(q, arg); return sg_emulated_host(q, arg);
case SG_IO: { case SG_IO:
struct sg_io_hdr hdr; return scsi_ioctl_sg_io(q, disk, mode, arg);
error = get_sg_io_hdr(&hdr, arg);
if (error)
return error;
error = sg_io(q, disk, &hdr, mode);
if (error == -EFAULT)
return error;
if (put_sg_io_hdr(&hdr, arg))
return -EFAULT;
return 0;
}
case SCSI_IOCTL_SEND_COMMAND: case SCSI_IOCTL_SEND_COMMAND:
return sg_scsi_ioctl(q, disk, mode, arg); return sg_scsi_ioctl(q, disk, mode, arg);
case CDROM_SEND_PACKET: case CDROM_SEND_PACKET: