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 v4 2/4] scsi: st: Record the tape position after a successful MTLOAD
Date: Tue, 29 Sep 2026 15:28:19 -0400 [thread overview]
Message-ID: <20260929192821.997675-3-loberman@redhat.com> (raw)
In-Reply-To: <20260929192821.997675-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, reset the partition and the state of all
partitions, as the new-session path in check_tape() does: partition 0,
position at BOT, EOF state cleared and no pending write. Otherwise the
driver may still record the previous partition, so that a later MTSETPART
to that partition is not performed; a read after loading at EOD fails
with EIO; and a partition left in the ST_WRITING state by a partition
switch in read() or write() makes st_flush() write a filemark at the
beginning of partition 0 when the device is closed.
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>
---
v4: reset the state of all partitions after the load, as a new session
does; a stale ST_WRITING state made st_flush() write a filemark at
BOT of partition 0 (Sashiko). Reproduced on an IBM LTO-5: write in
partition 0, MTSETPART 1, read(), MTLOAD, close.
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 | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 6e5e6f6..aa4d2ce 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -2686,6 +2686,30 @@ 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 and the partition state
+ * would be left as before the load. Reset them as a
+ * new session does, for all partitions: a stale
+ * ST_WRITING state would make st_flush() write a
+ * filemark at the beginning of partition 0.
+ */
+ if (retval == CHKRES_READY) {
+ int i;
+
+ STp->partition = STp->new_partition = 0;
+ for (i = 0; i < ST_NBR_PARTITIONS; i++) {
+ STps = &(STp->ps[i]);
+ STps->rw = ST_IDLE;
+ STps->eof = ST_NOEOF;
+ STps->at_sm = 0;
+ STps->last_block_valid = 0;
+ STps->drv_block = 0;
+ STps->drv_file = 0;
+ }
+ }
if (retval > 0)
retval = 0;
}
--
2.43.0
next prev parent reply other threads:[~2026-09-29 19:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 19:28 [PATCH v4 0/4] scsi: st: Restore drive settings and state after reset and MTLOAD Laurence Oberman
2026-09-29 19:28 ` [PATCH v4 1/4] scsi: st: Restore changed drive settings after reset also for MTLOAD and MTRETEN Laurence Oberman
2026-09-29 19:28 ` Laurence Oberman [this message]
2026-09-29 19:28 ` [PATCH v4 3/4] scsi: st: Restore the drive buffering mode after reset Laurence Oberman
2026-09-29 19:28 ` [PATCH v4 4/4] scsi: st: Relock the door after a reset Laurence Oberman
2026-09-30 15:58 ` [PATCH v4 0/4] scsi: st: Restore drive settings and state after reset and MTLOAD "Kai Mäkisara (Kolumbus)"
2026-10-03 14:36 ` Martin K. Petersen (Oracle)
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=20260929192821.997675-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