From: Laurence Oberman <loberman@redhat.com>
To: linux-scsi@vger.kernel.org
Cc: "Martin K . Petersen" <mkp@kernel.org>,
"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>,
Kai Makisara <Kai.Makisara@kolumbus.fi>,
John Meneghini <jmeneghi@redhat.com>,
emilne@redhat.com, bgurney@redhat.com
Subject: [PATCH v3 2/4] scsi: st: Record the tape position after a successful MTLOAD
Date: Tue, 29 Sep 2026 13:18:11 -0400 [thread overview]
Message-ID: <20260929171813.844733-3-loberman@redhat.com> (raw)
In-Reply-To: <20260929171813.844733-1-loberman@redhat.com>
Commit 0b120edb37dc ("scsi: st: Add MTIOCGET and MTLOAD to ioctls allowed
after device reset") allows MTLOAD to clear the reset condition because
the tape location is known after MTLOAD. But the driver does not record
it: reset_state() sets the file and block numbers to -1, and
do_load_unload() leaves them there. check_tape() sets them to 0 only for
a new session, which requires a new-medium unit attention. Drives that
do not report one when the medium was already loaded (seen with IBM LTO
drives) keep reporting file/block -1 in MTIOCGET and no BOT, although the
tape is at the beginning.
After a successful load, set the partition to 0, the position to BOT and
reset the EOF state, as the new-session path in check_tape() and MTREW
do. Otherwise the driver may still record the previous partition, so
that a later MTSETPART to that partition is not performed, and a read
after loading at EOD fails with EIO.
Fixes: 0b120edb37dc ("scsi: st: Add MTIOCGET and MTLOAD to ioctls allowed after device reset")
Suggested-by: Kai Mäkisara <Kai.Makisara@kolumbus.fi>
Assisted-by: Claude sashiko
Signed-off-by: Laurence Oberman <loberman@redhat.com>
---
v3: set the partition to 0 for all partitions, not only when the current
partition is 0 (Kai Mäkisara).
v2: also reset the EOF state after the load, as MTREW does (Sashiko).
drivers/scsi/st.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 0a4263bef9cb..e5b2e2d4872d 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -2686,6 +2686,22 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod
else {
STp->rew_at_close = STp->autorew_dev;
retval = check_tape(STp, filp);
+ /*
+ * LOAD leaves the medium at the beginning of partition
+ * 0. check_tape() records that only for a new session;
+ * without a new-medium unit attention (the medium was
+ * already loaded) the partition, position and EOF state
+ * would be left as before the load. Set them as a new
+ * session and MTREW do.
+ */
+ if (retval == CHKRES_READY) {
+ STp->partition = STp->new_partition = 0;
+ STps = &(STp->ps[0]);
+ STps->drv_file = STps->drv_block = 0;
+ STps->eof = ST_NOEOF;
+ STps->at_sm = 0;
+ STps->last_block_valid = 0;
+ }
if (retval > 0)
retval = 0;
}
--
2.55.0
next prev parent reply other threads:[~2026-09-29 17:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 17:18 [PATCH v3 0/4] scsi: st: Restore drive settings and state after reset and MTLOAD Laurence Oberman
2026-09-29 17:18 ` [PATCH v3 1/4] scsi: st: Restore changed drive settings after reset also for MTLOAD and MTRETEN Laurence Oberman
2026-09-29 17:33 ` sashiko-bot
2026-09-29 17:45 ` Laurence Oberman
2026-09-29 17:18 ` Laurence Oberman [this message]
2026-09-29 17:41 ` [PATCH v3 2/4] scsi: st: Record the tape position after a successful MTLOAD sashiko-bot
2026-09-29 18:16 ` Laurence Oberman
2026-09-29 17:18 ` [PATCH v3 3/4] scsi: st: Restore the drive buffering mode after reset Laurence Oberman
2026-09-29 17:18 ` [PATCH v3 4/4] scsi: st: Relock the door after a reset Laurence Oberman
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=20260929171813.844733-3-loberman@redhat.com \
--to=loberman@redhat.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=Kai.Makisara@kolumbus.fi \
--cc=bgurney@redhat.com \
--cc=emilne@redhat.com \
--cc=jmeneghi@redhat.com \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@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