* [PATCH] scsi: st: Save the visited block for the partition the drive is in
@ 2026-10-06 16:42 Laurence Oberman
2026-10-08 14:51 ` "Kai Mäkisara (Kolumbus)"
0 siblings, 1 reply; 2+ messages in thread
From: Laurence Oberman @ 2026-10-06 16:42 UTC (permalink / raw)
To: linux-scsi
Cc: Martin K . Petersen, James E . J . Bottomley, Kai Makisara,
John Meneghini, emilne, bgurney
set_location() saves the current tape location before switching
partitions, so that switch_partition() can return to it later. It reads
the location with READ POSITION but stores it in the st_partstat of
STp->partition, ignoring the partition the drive reports.
The two differ after a device reset. When the reset is recovered with
MTREW, MTSEEK or MTEOM, st_ioctl() sets STp->partition = 0 and calls
switch_partition() to return to STp->new_partition. A drive that was in
partition 1 is still there, so set_location() files the partition 1
position under partition 0. The next switch to partition 0 locates to
that block: if partition 0 holds less data, MTSETPART fails with EIO
(BLANK CHECK), otherwise the tape is silently positioned at the wrong
block.
IBM ULTRIUM-TD5 (LTO-5), LU reset in partition 1 at block 1025:
st 12:0:0:0: [st0] Visited block 1025 for partition 0 saved.
...
st 12:0:0:0: [st0] Setting block to 1025 and partition to 0.
st 12:0:0:0: [st0] Error: 402, cmd: 2b 2 0 0 0 4
st 12:0:0:0: [st0] Sense Key : Blank Check [current]
st 12:0:0:0: [st0] Add. Sense: End-of-data detected
Store the location in the st_partstat of the partition reported by READ
POSITION. With the fix:
st 12:0:0:0: [st0] Visited block 1025 for partition 1 saved.
This is a pre-existing issue. It was not caught when testing the
recent st reset series because the partition test was only run on
scsi_debug: on the LTO drive it was skipped, since can-partitions is
off in the test harness's stinit.conf, as is normal for LTO. scsi_debug
hides the problem because its emulated tape returns to the beginning of
partition 0 on an LU reset. It was found while validating a backport
of that series to RHEL 9.8, when the partition tests were run on real
hardware with can-partitions enabled. The same failure then reproduced
on unmodified RHEL 9.8 and on upstream, and the fix makes the test pass
on v7.3-rc3 and RHEL 9.8 with an LTO-5.
The harness (https://gitlab.com/loberman/tapetest, test X03) now
refuses to silently skip the partition tests on hardware.
Fixes: 7081dc75df79 ("scsi: st: Restore some drive settings after reset")
Assisted-by: Claude
Signed-off-by: Laurence Oberman <loberman@redhat.com>
---
drivers/scsi/st.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index e089d3ac063d..63ec9619d1b2 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -3246,14 +3246,20 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
partition >= ST_NBR_PARTITIONS)
return (-EINVAL);
if (partition != STp->partition) {
- if (get_location(STp, &blk, &p, 1))
+ /*
+ * Save the location for the partition the drive reports,
+ * not for STp->partition: after a reset STp->partition may
+ * not match the partition the drive is in.
+ */
+ if (get_location(STp, &blk, &p, 1) ||
+ p < 0 || p >= ST_NBR_PARTITIONS)
STps->last_block_valid = 0;
else {
- STps->last_block_valid = 1;
- STps->last_block_visited = blk;
+ STp->ps[p].last_block_valid = 1;
+ STp->ps[p].last_block_visited = blk;
DEBC_printk(STp, "Visited block %d for "
"partition %d saved.\n",
- blk, STp->partition);
+ blk, p);
}
}
base-commit: 9eaf6f9c2e50f67b7a3af1ba170a7da98201fbd5
prerequisite-patch-id: 7ff6c2a8facfef94f8d9e55d289671fc752572ec
prerequisite-patch-id: 8fc95d01ad41ddd3d884090c98b70d210ceb6b51
prerequisite-patch-id: 4fcffbe676c887709189baeb202ad2b5b58094ee
prerequisite-patch-id: 7f269b2366e79524769bca811886375d8a3e83f8
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] scsi: st: Save the visited block for the partition the drive is in
2026-10-06 16:42 [PATCH] scsi: st: Save the visited block for the partition the drive is in Laurence Oberman
@ 2026-10-08 14:51 ` "Kai Mäkisara (Kolumbus)"
0 siblings, 0 replies; 2+ messages in thread
From: "Kai Mäkisara (Kolumbus)" @ 2026-10-08 14:51 UTC (permalink / raw)
To: Laurence Oberman
Cc: linux-scsi, Martin K . Petersen, James E . J . Bottomley,
John Meneghini, emilne, bgurney
> On 6. Oct 2026, at 19.42, Laurence Oberman <loberman@redhat.com> wrote:
>
> set_location() saves the current tape location before switching
> partitions, so that switch_partition() can return to it later. It reads
> the location with READ POSITION but stores it in the st_partstat of
> STp->partition, ignoring the partition the drive reports.
>
> The two differ after a device reset. When the reset is recovered with
> MTREW, MTSEEK or MTEOM, st_ioctl() sets STp->partition = 0 and calls
> switch_partition() to return to STp->new_partition. A drive that was in
> partition 1 is still there, so set_location() files the partition 1
> position under partition 0. The next switch to partition 0 locates to
> that block: if partition 0 holds less data, MTSETPART fails with EIO
> (BLANK CHECK), otherwise the tape is silently positioned at the wrong
> block.
The analysis is correct. The elegant fix makes sure that the saved position
is a real position and does not cause an error in future.
Whether it makes sense to the user is another thing. The behaviour after
depends on the drive, its firmware, some mode settings and maybe on what
commands have been sent to the drive before reset. For instance,
the IBM LTO SCSI Reference says enigmatically:
"A logical position is established that may or may not be the same as
the position prior to the reset. Where possible, the logical position prior
to reset is maintained."
But this is one of the problems with resets that the driver can't solve
(at least not with reasonable amount of work).
Reviewed-by: Kai Mäkisara <kai.makisara@kolumbus.f <mailto:kai.makisara@kolumbus.f>>
Thanks,
Kai
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-08 14:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-06 16:42 [PATCH] scsi: st: Save the visited block for the partition the drive is in Laurence Oberman
2026-10-08 14:51 ` "Kai Mäkisara (Kolumbus)"
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox