Skip to content

Commit 6e9d677

Browse files
author
Ewan D. Milne
committed
scsi: st: Add MTIOCGET and MTLOAD to ioctls allowed after device reset
JIRA: https://issues.redhat.com/browse/RHEL-124946 Upstream Status: From upstream linux mainline Most drives rewind the tape when the device is reset. Reading and writing are not allowed until something is done to make the tape position match the user's expectation (e.g., rewind the tape). Add MTIOCGET and MTLOAD to operations allowed after reset. MTIOCGET is modified to not touch the tape if pos_unknown is non-zero. The tape location is known after MTLOAD. Signed-off-by: Kai Mäkisara <Kai.Makisara@kolumbus.fi> Link: https://bugzilla.kernel.org/show_bug.cgi?id=219419#c14 Link: https://lore.kernel.org/r/20241106095723.63254-3-Kai.Makisara@kolumbus.fi Reviewed-by: John Meneghini <jmeneghi@redhat.com> Tested-by: John Meneghini <jmeneghi@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> (cherry picked from commit 0b120ed) Signed-off-by: Ewan D. Milne <emilne@redhat.com>
1 parent 4c41743 commit 6e9d677

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

drivers/scsi/st.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,6 +3528,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
35283528
int i, cmd_nr, cmd_type, bt;
35293529
int retval = 0;
35303530
unsigned int blk;
3531+
bool cmd_mtiocget;
35313532
struct scsi_tape *STp = file->private_data;
35323533
struct st_modedef *STm;
35333534
struct st_partstat *STps;
@@ -3641,6 +3642,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
36413642
*/
36423643
if (mtc.mt_op != MTREW &&
36433644
mtc.mt_op != MTOFFL &&
3645+
mtc.mt_op != MTLOAD &&
36443646
mtc.mt_op != MTRETEN &&
36453647
mtc.mt_op != MTERASE &&
36463648
mtc.mt_op != MTSEEK &&
@@ -3768,17 +3770,28 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
37683770
goto out;
37693771
}
37703772

3773+
cmd_mtiocget = cmd_type == _IOC_TYPE(MTIOCGET) && cmd_nr == _IOC_NR(MTIOCGET);
3774+
37713775
if ((i = flush_buffer(STp, 0)) < 0) {
3772-
retval = i;
3773-
goto out;
3774-
}
3775-
if (STp->can_partitions &&
3776-
(i = switch_partition(STp)) < 0) {
3777-
retval = i;
3778-
goto out;
3776+
if (cmd_mtiocget && STp->pos_unknown) {
3777+
/* flush fails -> modify status accordingly */
3778+
reset_state(STp);
3779+
STp->pos_unknown = 1;
3780+
} else { /* return error */
3781+
retval = i;
3782+
goto out;
3783+
}
3784+
} else { /* flush_buffer succeeds */
3785+
if (STp->can_partitions) {
3786+
i = switch_partition(STp);
3787+
if (i < 0) {
3788+
retval = i;
3789+
goto out;
3790+
}
3791+
}
37793792
}
37803793

3781-
if (cmd_type == _IOC_TYPE(MTIOCGET) && cmd_nr == _IOC_NR(MTIOCGET)) {
3794+
if (cmd_mtiocget) {
37823795
struct mtget mt_status;
37833796

37843797
if (_IOC_SIZE(cmd_in) != sizeof(struct mtget)) {

0 commit comments

Comments
 (0)