From: Laurence Oberman <loberman@redhat.com>
To: "David Jeffery" <djeffery@redhat.com>,
"Kai Mäkisara" <Kai.Makisara@kolumbus.fi>,
linux-scsi@vger.kernel.org
Subject: Re: [PATCH 1/2] st: separate st-unique ioctl handling from scsi common ioctl handling
Date: Wed, 05 Nov 2025 09:43:20 -0500 [thread overview]
Message-ID: <8fc9581aadc868f0caa54484980a40e6f53ea0c0.camel@redhat.com> (raw)
In-Reply-To: <20251104154709.6436-1-djeffery@redhat.com>
On Tue, 2025-11-04 at 10:46 -0500, David Jeffery wrote:
> 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>
> ---
>
> drivers/scsi/st.c | 85 ++++++++++++++++++++++++++++++++++-----------
> --
> 1 file changed, 62 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> index 74a6830b7ed8..87f0e303fdd6 100644
> --- a/drivers/scsi/st.c
> +++ b/drivers/scsi/st.c
> @@ -3526,8 +3526,60 @@ static int partition_tape(struct scsi_tape
> *STp, int size)
> out:
> return result;
> }
> -\f
>
> +/*
> + * Handles any extra state needed for ioctls which are not st-
> specific.
> + * Called with the scsi_tape lock held, released before return
> + */
> +static long st_common_ioctl(struct scsi_tape *STp, struct st_modedef
> *STm,
> + struct file *file, unsigned int cmd_in,
> + unsigned long arg)
> +{
> + int i, retval = 0;
> +
> + if (!STm->defined) {
> + retval = -ENXIO;
> + goto out;
> + }
> +
> + if ((i = flush_buffer(STp, 0)) < 0) {
> + retval = i;
> + goto out;
> + } else { /* flush_buffer succeeds */
> + if (STp->can_partitions) {
> + i = switch_partition(STp);
> + if (i < 0) {
> + retval = i;
> + goto out;
> + }
> + }
> + }
> + mutex_unlock(&STp->lock);
> +
> + switch (cmd_in) {
> + case SG_IO:
> + case SCSI_IOCTL_SEND_COMMAND:
> + case CDROM_SEND_PACKET:
> + if (!capable(CAP_SYS_RAWIO))
> + return -EPERM;
> + break;
> + default:
> + break;
> + }
> +
> + retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE,
> + cmd_in, (void __user *)arg);
> + if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) {
> + /* unload */
> + STp->rew_at_close = 0;
> + STp->ready = ST_NO_TAPE;
> + }
> +
> + return retval;
> +out:
> + mutex_unlock(&STp->lock);
> + return retval;
> +}
>
> /* The ioctl command */
> 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)
> if (retval)
> goto out;
>
> + switch(cmd_in) {
> + case MTIOCPOS:
> + case MTIOCGET:
> + case MTIOCTOP:
> + break;
> + default:
> + return st_common_ioctl(STp, STm, file, cmd_in, arg);
> + }
> +
> cmd_type = _IOC_TYPE(cmd_in);
> cmd_nr = _IOC_NR(cmd_in);
>
> @@ -3876,29 +3937,7 @@ static long st_ioctl(struct file *file,
> unsigned int cmd_in, unsigned long arg)
> }
> mt_pos.mt_blkno = blk;
> retval = put_user_mtpos(p, &mt_pos);
> - goto out;
> - }
> - mutex_unlock(&STp->lock);
> -
> - switch (cmd_in) {
> - case SG_IO:
> - case SCSI_IOCTL_SEND_COMMAND:
> - case CDROM_SEND_PACKET:
> - if (!capable(CAP_SYS_RAWIO))
> - return -EPERM;
> - break;
> - default:
> - break;
> }
> -
> - retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE,
> cmd_in, p);
> - if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) {
> - /* unload */
> - STp->rew_at_close = 0;
> - STp->ready = ST_NO_TAPE;
> - }
> - return retval;
> -
> out:
> mutex_unlock(&STp->lock);
> return retval;
For the series:
Reviewed by: Laurence Oberman <loberman@redhat.com>
Many hours of testing done here folks, this looks to be solid and fixes
all our prior issues.
next prev parent reply other threads:[~2025-11-05 14:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 15:46 [PATCH 1/2] st: separate st-unique ioctl handling from scsi common ioctl handling David Jeffery
2025-11-04 15:46 ` [PATCH 2/2] st: skip buffer flush for information ioctls David Jeffery
2025-11-05 14:40 ` "Kai Mäkisara (Kolumbus)"
2025-11-05 17:34 ` John Meneghini
2025-11-08 17:22 ` Martin K. Petersen
2025-11-05 14:38 ` [PATCH 1/2] st: separate st-unique ioctl handling from scsi common ioctl handling "Kai Mäkisara (Kolumbus)"
2025-11-05 14:43 ` Laurence Oberman [this message]
2025-11-05 15:56 ` John Meneghini
2025-11-08 17:22 ` Martin K. Petersen
2025-11-13 2:46 ` Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8fc9581aadc868f0caa54484980a40e6f53ea0c0.camel@redhat.com \
--to=loberman@redhat.com \
--cc=Kai.Makisara@kolumbus.fi \
--cc=djeffery@redhat.com \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox