From patchwork Mon Nov 4 11:26:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Kai_M=C3=A4kisara_=28Kolumbus=29?= X-Patchwork-Id: 13861254 Received: from fgw20-4.mail.saunalahti.fi (fgw20-4.mail.saunalahti.fi [62.142.5.107]) (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 00A171BD508 for ; Mon, 4 Nov 2024 11:26:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.107 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730719622; cv=none; b=Bdx8LrEN1dEthmn2R8pq/W7DhUQv8O5/Qe4dw1bwycy4sDee6IaITiOHEeOYBdjSpRXS/UE9jCB9FqAX52PJ15vYuuKtPywvrNshcu0XjyR3Y7vRmXoiB/FgcYLcDgwTMjOETZV+5Waz3YPU2DhYkSkA84hAp5UKdv6bQAH8+OQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730719622; c=relaxed/simple; bh=qNzIxubdyAACSSilP/41diGh8Aysnz2bQLFS4wC42WI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t9Xc2KWQiXDCag+NXRrycMILgIoR3qvz+f+pPErvA19rC7UeLZ965GzmdFLM5vXbJBgvjQ2Nev52QmDRhQzGTqrYJd6eHXZb/0C3+Jbbntu1Z+0fcTsvydadV59Sg3CkrCXTElrf2F/k16UAAYg99ZGOt4ZySBmsKPW/teybiX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kolumbus.fi; spf=pass smtp.mailfrom=kolumbus.fi; dkim=pass (2048-bit key) header.d=kolumbus.fi header.i=@kolumbus.fi header.b=Yh+yoosl; arc=none smtp.client-ip=62.142.5.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kolumbus.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kolumbus.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kolumbus.fi header.i=@kolumbus.fi header.b="Yh+yoosl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolumbus.fi; s=elisa1; h=content-transfer-encoding:content-type:mime-version:references:in-reply-to: message-id:date:subject:cc:to:from:from:to:cc:reply-to:subject:date: in-reply-to:references:list-archive:list-subscribe:list-unsubscribe: content-type:content-transfer-encoding:message-id; bh=zizDeVnse5oSJr33n52Uku2c2fducfcyOLo7vJwdlL4=; b=Yh+yoosl87Aa08pmZkwfGxUEnUpwiA4PQmLV9OKsEdjyMBYyq4hTmfJa1yzgT2QC/KSrH7/lZTG5d iAZlSa0Bo0uKFwqo1TNgwWuI0qi2pID2IS6WnyLUa4uOMmgwL8vMcZSvRdbfGWGSLi0YIBxqYARFbT pKPisijgcoIXA3Ntw2ambAqHh0B+1+nAyU7ttEfGzHON+wca2Q8ZlSavC2bSYqz3xvpxnL/chrtRc7 1CjrV/YmmFJsNIo9SFFMLWfwNaexYII29R7YuFfodN3nxdJf7UH58+p+0/wL7WckiMzvPJNYBk1O9C QXpGTmZYrPS6kENXTFwErNBAlGx6wyA== Received: from kaipn1.makisara.private (85-156-116-90.elisa-laajakaista.fi [85.156.116.90]) by fgw21.mail.saunalahti.fi (Halon) with ESMTPSA id b255fdd0-9a9f-11ef-8872-005056bdd08f; Mon, 04 Nov 2024 13:26:55 +0200 (EET) From: =?utf-8?q?Kai_M=C3=A4kisara?= To: linux-scsi@vger.kernel.org, jmeneghi@redhat.com Cc: martin.petersen@oracle.com, James.Bottomley@HansenPartnership.com, loberman@redhat.com, =?utf-8?q?Kai_M=C3=A4kisara?= Subject: [PATCH 1/2] scsi: st: Don't modify unknown block number in MTIOCGET Date: Mon, 4 Nov 2024 13:26:22 +0200 Message-ID: <20241104112623.2675-2-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104112623.2675-1-Kai.Makisara@kolumbus.fi> References: <20241104112623.2675-1-Kai.Makisara@kolumbus.fi> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Struct mtget field mt_blkno -1 means it is unknown. Don't add anything to it. Signed-off-by: Kai Mäkisara Reviewed-by: John Meneghini Tested-by: John Meneghini --- drivers/scsi/st.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index beb88f25dbb9..8d27e6caf027 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -3756,7 +3756,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); mt_status.mt_blkno = STps->drv_block; mt_status.mt_fileno = STps->drv_file; - if (STp->block_size != 0) { + if (STp->block_size != 0 && mt_status.mt_blkno >= 0) { if (STps->rw == ST_WRITING) mt_status.mt_blkno += (STp->buffer)->buffer_bytes / STp->block_size; From patchwork Mon Nov 4 11:26:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Kai_M=C3=A4kisara_=28Kolumbus=29?= X-Patchwork-Id: 13861255 Received: from fgw23-4.mail.saunalahti.fi (fgw23-4.mail.saunalahti.fi [62.142.5.110]) (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 163CA1B21B0 for ; Mon, 4 Nov 2024 11:27:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730719634; cv=none; b=P6HV7YqXUGmUqZm4vo2gIcYwXQu/+DbmxOrTTw4cZuODFeYwOlILxwMVs3yIwGlkUCGgcvZDuyzm5uzVzO+B8L71eCa/pecHkqLKrqIlar8OhN3itQnjgxKIw1N/kK3usuMp9FUG/rpXc8TggjTZjpajA3uIeOOgsDb5PYlcKKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730719634; c=relaxed/simple; bh=EKzcOqXkev1HDdDEvFYEpziVWcbrNvF2MvGzf3tmk70=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TB5YpT+AWbyxRoslWETI28V7lAHg/V/y1NOftZBJuLsmT1cCXJSgPqCLL212pQviCrD5quXpw7euSCgZJx/F/DVl7p0Bm/y3W5D4ajU3C/NH2aZP2OnhVna1TrDpezdbrcKUfq78wwkQFr1QZPFhLriTK4wzlCxPK4TcntMECsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kolumbus.fi; spf=pass smtp.mailfrom=kolumbus.fi; dkim=pass (2048-bit key) header.d=kolumbus.fi header.i=@kolumbus.fi header.b=q1j4hI0h; arc=none smtp.client-ip=62.142.5.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kolumbus.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kolumbus.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kolumbus.fi header.i=@kolumbus.fi header.b="q1j4hI0h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolumbus.fi; s=elisa1; h=content-transfer-encoding:content-type:mime-version:references:in-reply-to: message-id:date:subject:cc:to:from:from:to:cc:reply-to:subject:date: in-reply-to:references:list-archive:list-subscribe:list-unsubscribe: content-type:content-transfer-encoding:message-id; bh=pNtiOEFbYepsFznXLFUZugf4Oedsf9UkzgKJFcnhwEs=; b=q1j4hI0hNrRvUgSUwbUs0GRRRD43OGBEXuXgeOxcVoUauebHAkTRpi/1DUcSMp3AjkDDosY8QQnUt 8k4NtRpS++gLvkDc7CfaojFsaWBTYLJcjVYk8Svl3i9WIW0qm0jSqG0zxZGty5UgxNrkVEl+atgJZ0 B4C0SD2UW5XVY10Npy3Gg7cnmhoHBgj/TNDJ6gUCa3w0DhJqfpkJ5wRPeyUIwQeP5n54oEW6YMz0wE 6bQ/svKU74NhHtCkS2anXmyW5+lM51lsBUaFG3YOnCj8oVjhX3qyhz5HGOACByetIEpaLWQbpnXfU9 hVTImLbLARta1scmSp70r3u2Zst8e9w== Received: from kaipn1.makisara.private (85-156-116-90.elisa-laajakaista.fi [85.156.116.90]) by fgw21.mail.saunalahti.fi (Halon) with ESMTPSA id b4e4e09f-9a9f-11ef-8872-005056bdd08f; Mon, 04 Nov 2024 13:26:59 +0200 (EET) From: =?utf-8?q?Kai_M=C3=A4kisara?= To: linux-scsi@vger.kernel.org, jmeneghi@redhat.com Cc: martin.petersen@oracle.com, James.Bottomley@HansenPartnership.com, loberman@redhat.com, =?utf-8?q?Kai_M=C3=A4kisara?= Subject: [PATCH 2/2] scsi: st: Add MTIOCGET and MTLOAD to ioctls allowed after device reset Date: Mon, 4 Nov 2024 13:26:23 +0200 Message-ID: <20241104112623.2675-3-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104112623.2675-1-Kai.Makisara@kolumbus.fi> References: <20241104112623.2675-1-Kai.Makisara@kolumbus.fi> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: John Meneghini Tested-by: John Meneghini --- 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 8d27e6caf027..c9038284bc89 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -3506,6 +3506,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; @@ -3619,6 +3620,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 && @@ -3732,17 +3734,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)) {