From patchwork Wed Nov 6 09:57:21 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?= X-Patchwork-Id: 13864262 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 419031DBB19 for ; Wed, 6 Nov 2024 09:58:03 +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=1730887087; cv=none; b=hFEMTtzC6tv0f48MvykR7F8td8/NBeEmj2eRCZPE2xCt/FjFAvi/M48FXPlzdhY559Eg++xflDv+7JsNG7brl20nVLKGo9rzR0pqdSqehaaHVSkKnU7lYhl/ucRd2lh4I9J52FBlSz6mOtz7hgcKVE++zqQSvaM27hfGnBH7EEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887087; c=relaxed/simple; bh=l9wBaku2eNrhQlkCJ8tf1ggwj70zRo4TJotF5QWkE4I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bbAYj9HVppFof2iX1ZaxHDrLsWmycQRpY0TVSIW6HLzLJOrvDOMJ1o0UWURa87IcPP7sBTITXdTJD4XaeE6fWS671rcrcFdldvFPxqKfW+Lr228ocvI4491YCFD5N7pyAvsHwTAwGcZaWZ/EhaD8ogbdGT+ubf4DTP4GH6fO22c= 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=YdNm7XEP; 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="YdNm7XEP" 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=QAZ4jadDKxvoZ1Vq/VK15yEjhsc69wrd6OeWg15VVDY=; b=YdNm7XEP/vRXBKGMJ+PmK4LQ1N7/3gtx9dQINNRhhSBtSq9twOfAwQ8DpTwbxxGbWttEPHtlAT4dy oO6AmzdgXMl7HHzRVfH6hNC5LF6Zf9mo2w3gamvXUgwIw4P8TMtffkhUwQjT34aDMTkXb8LfD19xqu ZF6EWU6C2tQLUSpY+/X7nLFwlaay5P6xUqyp8xc7XMsRFXCxEo0WzYnZV9IKCIcSEpNPvxxn6G+ln6 YO0tpbmCJTq78hdzHS3O9eqXQxlGGyH7b+23urN+g3iydxiUczc/9pHwiWCI5qVffdYmWZfP5+kjTD P+T2fKpHRi0pSpH+3smrr3e7eYUoQjw== Received: from kaipn1.makisara.private (85-156-116-90.elisa-laajakaista.fi [85.156.116.90]) by fgw20.mail.saunalahti.fi (Halon) with ESMTPSA id 9356e484-9c25-11ef-9ac8-005056bd6ce9; Wed, 06 Nov 2024 11:57:47 +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 v2 1/3] scsi: st: Don't modify unknown block number in MTIOCGET Date: Wed, 6 Nov 2024 11:57:21 +0200 Message-ID: <20241106095723.63254-2-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106095723.63254-1-Kai.Makisara@kolumbus.fi> References: <20241106095723.63254-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 Wed Nov 6 09:57: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?= X-Patchwork-Id: 13864264 Received: from fgw22-4.mail.saunalahti.fi (fgw22-4.mail.saunalahti.fi [62.142.5.109]) (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 997581DD0FF for ; Wed, 6 Nov 2024 09:59:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.109 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887163; cv=none; b=X4kHw92Vo777EIP9iBTT81yYABadg+hVUoqKhtmbS9Jgr1MMzTt0veKWHPMcIIzJh229XsGx6/G84vqV5Fn5yVgNsMKxlOrm13C0eZ2ur7tpwmihLndubBcyQ2kSPhwbrRKeoSAkX+OYw/UzMhONWfZf1ELAlMurM32N1nEK3To= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887163; c=relaxed/simple; bh=nmHcOvT01GZAENA7MCHMQ4A2pRTqQAqR0679py1cyLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F3JKaMIVugLwWJ3oT4q/4Tep8XbjVjLuOz+blLL25EX+wcYmlEI4/zCHyhwoPKFcy3ZzuUonO5oZ/AGsJY3bMgGNVAvnJ865afMrp5I8GS3L5vVD8ZzIR7RxjJMwdGmHEMx4bzR14n2PBohkSQ7b3oW5SO0eExwbpuITEvqPwfI= 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=c8llg1/j; arc=none smtp.client-ip=62.142.5.109 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="c8llg1/j" 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=N11RRwHX+clsLwhnPodKuSOd7SrqM693Ulg6o6cTJEU=; b=c8llg1/jCpnzA+vFwMi8Z74PPxFicBvCkrekn8ZYvtjMBO+vYyo0vDxqrZPBtS/NVWOqehJC6FfQz otlD/DUSHTZBc8gcHR3SYeSfesu8yLk7qvq5tfmVIWlRGBgG3Mvu/FCn8KcXhuuRl61xkp4XjmrlbR 7zjoUiuVnCvdtHF5Xqh3OPlVUN/PmFHgjMJ15hCQ/nrzT6hopVy+4yrXEmTcGJoaCm1oJqygG5og8P rF0chzHJqXZN472TlVVbvo9YGDDJv2PPELD0RPrcWsXY1MJk1yisBus3Al26wzRbUYhQp8ACy+1UD0 WErDr5OBYvYZBlD5qm9XBLzG6HeATrQ== Received: from kaipn1.makisara.private (85-156-116-90.elisa-laajakaista.fi [85.156.116.90]) by fgw20.mail.saunalahti.fi (Halon) with ESMTPSA id 963cc97a-9c25-11ef-9ac8-005056bd6ce9; Wed, 06 Nov 2024 11:57:52 +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 v2 2/3] scsi: st: Add MTIOCGET and MTLOAD to ioctls allowed after device reset Date: Wed, 6 Nov 2024 11:57:22 +0200 Message-ID: <20241106095723.63254-3-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106095723.63254-1-Kai.Makisara@kolumbus.fi> References: <20241106095723.63254-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)) { From patchwork Wed Nov 6 09:57:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Kai_M=C3=A4kisara?= X-Patchwork-Id: 13864263 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 702FC1DD0C9 for ; Wed, 6 Nov 2024 09:58:09 +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=1730887092; cv=none; b=PbplX7x7Jz9PUZoZ156kc4ecI/NH2qLDIwhWWztGBes0edGKTW4+3emB8P8tezxpR474bRP6mL/s8oNCKExUo5xr7V1IyglnmC3xbK4XPFBOP09Whz4eqL9CEUxvSMa1WOkM4LqvwT6b8wnAf8NRJTCD3w4AMSb+Qda8MR4+O90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887092; c=relaxed/simple; bh=x40R41wS28JHaszElwyf6IwMxjE2egr5A3XtFUi/S5U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T0ICXRdURdF/I5qy3cNg2RyL+H7nuUWKdvcXijUbuwHKvKNdmmRJzjBFqb/6BhnqzVEguojWJU4OREqCCKVd5DUxV+Frnb5hjyQ3DeYK9ISYUvZNv9VT2QWih81XiQZPdcY8DGslXc37iw+gKQkm0GgXHR8HDHleKZjNA7xej2I= 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=oX8qFbln; 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="oX8qFbln" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolumbus.fi; s=elisa1; h=content-transfer-encoding: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=QDqJYncT/PdMgfRzyz2Q49vpB2LdWEH5W9QQkI2VqQY=; b=oX8qFblnb3kMOL9EVpY8oZN2AZQ6tnVpTn7ohnhDF3RSb6TAzdZIf8w7V97NIYtzUTBbRYkLCwKQe 4m2VXOl1h/8yYgFsdNaS+mOknBt1t3u6p57pERmfH2SX+VgVcW5qCnrMS9Q7Bk7DuFkuP2G3YDmdj/ KAunCj35oDDbf+KBuF6VgP/xI+kMZDY3yNaAFfyR4BdkSrQISnAPjyyjpkwejz9coapjN6dFm4AF73 nsjRmvl/5VO8Vkwr7g9SCuYrdqtgvgRWbA91D0Bd20ZFrThTwB3/K9MrRTBuy3Cf/BfB8t6l4Jpktg rm9YXwLwwVXgwmXc2YFqC7J1D/x7+1g== Received: from kaipn1.makisara.private (85-156-116-90.elisa-laajakaista.fi [85.156.116.90]) by fgw20.mail.saunalahti.fi (Halon) with ESMTPSA id 982c1968-9c25-11ef-9ac8-005056bd6ce9; Wed, 06 Nov 2024 11:57: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 v2 3/3] scsi: st: New session only when Unit Attention for new tape Date: Wed, 6 Nov 2024 11:57:23 +0200 Message-ID: <20241106095723.63254-4-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106095723.63254-1-Kai.Makisara@kolumbus.fi> References: <20241106095723.63254-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 Currently the code starts new tape session when any Unit Attention (UA) is seen when opening the device. This leads to incorrectly clearing pos_unknown when the UA is for reset. Set new session only when the UA is for a new tape. --- drivers/scsi/st.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index c9038284bc89..e8ef27d7ef61 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -991,7 +991,10 @@ static int test_ready(struct scsi_tape *STp, int do_wait) scode = cmdstatp->sense_hdr.sense_key; if (scode == UNIT_ATTENTION) { /* New media? */ - new_session = 1; + if (cmdstatp->sense_hdr.asc == 0x28) { /* New media */ + new_session = 1; + DEBC_printk(STp, "New tape session."); + } if (attentions < MAX_ATTENTIONS) { attentions++; continue;