Skip to content

Commit b37d70c

Browse files
David Jefferymartinkpetersen
authored andcommitted
scsi: st: Separate st-unique ioctl handling from SCSI common ioctl handling
The st ioctl function currently interleaves code for handling various st specific ioctls with parts of code needed for handling ioctls common to all SCSI devices. Separate out st's code for the common ioctls into a more manageable, separate function. Signed-off-by: David Jeffery <djeffery@redhat.com> Tested-by: Laurence Oberman <loberman@redhat.com> Acked-by: Kai Mäkisara <kai.makisara@kolumbus.fi> Reviewed-by: John Meneghini <jmeneghi@redhat.com> Tested-by: John Meneghini <jmeneghi@redhat.com> Link: https://patch.msgid.link/20251104154709.6436-1-djeffery@redhat.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent ad4716a commit b37d70c

1 file changed

Lines changed: 62 additions & 23 deletions

File tree

drivers/scsi/st.c

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,8 +3526,60 @@ static int partition_tape(struct scsi_tape *STp, int size)
35263526
out:
35273527
return result;
35283528
}
3529-
35303529

3530+
/*
3531+
* Handles any extra state needed for ioctls which are not st-specific.
3532+
* Called with the scsi_tape lock held, released before return
3533+
*/
3534+
static long st_common_ioctl(struct scsi_tape *STp, struct st_modedef *STm,
3535+
struct file *file, unsigned int cmd_in,
3536+
unsigned long arg)
3537+
{
3538+
int i, retval = 0;
3539+
3540+
if (!STm->defined) {
3541+
retval = -ENXIO;
3542+
goto out;
3543+
}
3544+
3545+
if ((i = flush_buffer(STp, 0)) < 0) {
3546+
retval = i;
3547+
goto out;
3548+
} else { /* flush_buffer succeeds */
3549+
if (STp->can_partitions) {
3550+
i = switch_partition(STp);
3551+
if (i < 0) {
3552+
retval = i;
3553+
goto out;
3554+
}
3555+
}
3556+
}
3557+
mutex_unlock(&STp->lock);
3558+
3559+
switch (cmd_in) {
3560+
case SG_IO:
3561+
case SCSI_IOCTL_SEND_COMMAND:
3562+
case CDROM_SEND_PACKET:
3563+
if (!capable(CAP_SYS_RAWIO))
3564+
return -EPERM;
3565+
break;
3566+
default:
3567+
break;
3568+
}
3569+
3570+
retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE,
3571+
cmd_in, (void __user *)arg);
3572+
if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) {
3573+
/* unload */
3574+
STp->rew_at_close = 0;
3575+
STp->ready = ST_NO_TAPE;
3576+
}
3577+
3578+
return retval;
3579+
out:
3580+
mutex_unlock(&STp->lock);
3581+
return retval;
3582+
}
35313583

35323584
/* The ioctl command */
35333585
static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
@@ -3565,6 +3617,15 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
35653617
if (retval)
35663618
goto out;
35673619

3620+
switch (cmd_in) {
3621+
case MTIOCPOS:
3622+
case MTIOCGET:
3623+
case MTIOCTOP:
3624+
break;
3625+
default:
3626+
return st_common_ioctl(STp, STm, file, cmd_in, arg);
3627+
}
3628+
35683629
cmd_type = _IOC_TYPE(cmd_in);
35693630
cmd_nr = _IOC_NR(cmd_in);
35703631

@@ -3876,29 +3937,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
38763937
}
38773938
mt_pos.mt_blkno = blk;
38783939
retval = put_user_mtpos(p, &mt_pos);
3879-
goto out;
38803940
}
3881-
mutex_unlock(&STp->lock);
3882-
3883-
switch (cmd_in) {
3884-
case SG_IO:
3885-
case SCSI_IOCTL_SEND_COMMAND:
3886-
case CDROM_SEND_PACKET:
3887-
if (!capable(CAP_SYS_RAWIO))
3888-
return -EPERM;
3889-
break;
3890-
default:
3891-
break;
3892-
}
3893-
3894-
retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE, cmd_in, p);
3895-
if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) {
3896-
/* unload */
3897-
STp->rew_at_close = 0;
3898-
STp->ready = ST_NO_TAPE;
3899-
}
3900-
return retval;
3901-
39023941
out:
39033942
mutex_unlock(&STp->lock);
39043943
return retval;

0 commit comments

Comments
 (0)