From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46B70216387; Wed, 4 Dec 2024 17:02:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733331722; cv=none; b=SDm2sj6qRV9ZkbteYKF7aIFL3GiKCC8alDynAM6AlRR5j8KclHInhvpMzTwAfKgEROAvN55uriEt34Wl++Gu1xKakmmT3hCBh6tyLMRFjtdlE1GKi9m3AA9jkIvLxJky5BulbvmPIDnMzDN60ULpZS+8ZFSIP/Q2qEmtaXk8yHc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733331722; c=relaxed/simple; bh=hLAim6cf/YyZaUrOGNzlYX9enQI+ULwRAtTjPIMCBqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YECQ96PFkay77a2dnNCOjHqmzOLWC4+5w6+qgFCOkAe8kaAxaD4yQO0Cl+KsKr1j6rCGGVA8oVx5iOBNCj9SAES1/jpcbpU1ICUOR9Bs/ihXVajbb3oVKr1MzuUbZx0rj22DqwXp6kxWfcyq0TeDo+SPgb+L0XdSrx0fb9Br3SU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nGb6bp9j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nGb6bp9j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCF76C4CECD; Wed, 4 Dec 2024 17:02:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733331721; bh=hLAim6cf/YyZaUrOGNzlYX9enQI+ULwRAtTjPIMCBqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nGb6bp9jc36oW4UJQRRiP1srxK3QjhCal0+b8Lj08SiN46VSTGGWJfNmysN3qCh34 gPX9Q63Q0jaSJaJOFY8Vz9iDbwv5Yqi/B5/tNd1Zt11zQs5TwAO9BT8a4PX2fqFf59 qSOCoYXGCtO7VKzqyWc8FilhHebSLVUFF3oC4nZkcSTizGiAgGqedFdcapPdZcxBt/ FS8QouXqnrNvKZ5xr26bWtxsi5aAf9N6PHUCQj3nsBdonpwWhw8fU4Vc/IQ8CHitqv DMbtGlfgKelT3BL4nREg9Znqb4+0kBaN1UnaG43bEQnqYDgnAfUXTAua0nsv0Nnuv6 Nn1JpWgMwXu0w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Kai=20M=C3=A4kisara?= , John Meneghini , "Martin K . Petersen" , Sasha Levin , James.Bottomley@HansenPartnership.com, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 18/24] scsi: st: Add MTIOCGET and MTLOAD to ioctls allowed after device reset Date: Wed, 4 Dec 2024 10:49:38 -0500 Message-ID: <20241204155003.2213733-18-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204155003.2213733-1-sashal@kernel.org> References: <20241204155003.2213733-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.63 Content-Transfer-Encoding: 8bit From: Kai Mäkisara [ Upstream commit 0b120edb37dc9dd8ca82893d386922eb6b16f860 ] 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 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 Tested-by: John Meneghini Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/st.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index 1537f4a9347f9..4e872f2559d13 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -3507,6 +3507,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) int i, cmd_nr, cmd_type, bt; int retval = 0; unsigned int blk; + bool cmd_mtiocget; struct scsi_tape *STp = file->private_data; struct st_modedef *STm; struct st_partstat *STps; @@ -3620,6 +3621,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) */ if (mtc.mt_op != MTREW && mtc.mt_op != MTOFFL && + mtc.mt_op != MTLOAD && mtc.mt_op != MTRETEN && mtc.mt_op != MTERASE && mtc.mt_op != MTSEEK && @@ -3733,17 +3735,28 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) goto out; } + cmd_mtiocget = cmd_type == _IOC_TYPE(MTIOCGET) && cmd_nr == _IOC_NR(MTIOCGET); + if ((i = flush_buffer(STp, 0)) < 0) { - retval = i; - goto out; - } - if (STp->can_partitions && - (i = switch_partition(STp)) < 0) { - retval = i; - goto out; + if (cmd_mtiocget && STp->pos_unknown) { + /* flush fails -> modify status accordingly */ + reset_state(STp); + STp->pos_unknown = 1; + } else { /* return error */ + retval = i; + goto out; + } + } else { /* flush_buffer succeeds */ + if (STp->can_partitions) { + i = switch_partition(STp); + if (i < 0) { + retval = i; + goto out; + } + } } - if (cmd_type == _IOC_TYPE(MTIOCGET) && cmd_nr == _IOC_NR(MTIOCGET)) { + if (cmd_mtiocget) { struct mtget mt_status; if (_IOC_SIZE(cmd_in) != sizeof(struct mtget)) { -- 2.43.0