From patchwork Mon Jan 20 19:49:22 2025 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: 858866 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 777041EF085 for ; Mon, 20 Jan 2025 19:51:11 +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=1737402673; cv=none; b=IR4fZM2BbvIPcvWepxRJ5dPdvu86tVIFErX98DNU9s+g2NRc4oLMqClwypMn4Oytsflw1U7sZu6GNOc2vDth8EUHe35lOImRk/MMLV1p+lbEwoG1A96C3aW1w+DUevHyVWmkitHJi+WYyvdkRqwcW/6tb15CxIp/sIb29FsGTF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737402673; c=relaxed/simple; bh=BxJtxA0ocbWGpF7eL92eK1av5tZ18fN41vYn18Qnc1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pJDNrEKJjSy6KarhPzsX/8Ejkv4oDZZj9LPK3w7Nr7PbBTr1MbxMRd/xeuzKjFV1f+EeiJI5NgRuFIcPFpn/EdAkiqvCbpb0TS/O0a9hr2N/sVTCoNt1A4mCoVkGQkcpdpWEwwAIz3Ajcv57NjlyOIuGJnMSXjM8MXAe41kaX/s= 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=vuji8/kk; 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="vuji8/kk" 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=eWu3ct2L5/P9RrxqM90AHc/6t3KnyCl838geYRAmh3o=; b=vuji8/kkpjcA9svZnnx4VDkuCfkB2Ov6mSlpiye1bM9aHvhcyYWJCp1J36ZZiTWtTflM/TbNvHtX5 XN+lDlCoNPRzhIvz+av8iKOdp9BmC5g5VdtVHY0lUZId0JPhR9dNByImTa/CunaRdlRD3B+yK3M2WP lzqQ0mgoSGYAHIC8Vyr3MWMH7lwprCu6R8blD3b55qPPpXRA9SWsb9hO26iwhg8KIaxNPH/2SVI8Ty xoQFN2OU764fjXTSK/c5HQ+NbXE8UWx6q2KFGHPJvqdZU5zd6F1/NMX7Apunbd0+DIsZ2N8zhZ6H+n 5wzPJRqH51ZPYkiL4WS7pDYKce0b9dg== 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 bc456bcc-d767-11ef-88a3-005056bdd08f; Mon, 20 Jan 2025 21:50:01 +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 v3 1/4] scsi: st: Restore some drive settings after reset Date: Mon, 20 Jan 2025 21:49:22 +0200 Message-ID: <20250120194925.44432-2-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120194925.44432-1-Kai.Makisara@kolumbus.fi> References: <20250120194925.44432-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 Some of the allowed operations put the tape into a known position to continue operation assuming only the tape position has changed. But reset sets partition, density and block size to drive default values. These should be restored to the values before reset. Normally the current block size and density are stored by the drive. If the settings have been changed, the changed values have to be saved by the driver across reset. Signed-off-by: Kai Mäkisara --- drivers/scsi/st.c | 24 +++++++++++++++++++++--- drivers/scsi/st.h | 2 ++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index ebbd50ec0cda..0fc9afe60862 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -952,7 +952,6 @@ static void reset_state(struct scsi_tape *STp) STp->partition = find_partition(STp); if (STp->partition < 0) STp->partition = 0; - STp->new_partition = STp->partition; } } @@ -2930,14 +2929,17 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon if (cmd_in == MTSETDENSITY) { (STp->buffer)->b_data[4] = arg; STp->density_changed = 1; /* At least we tried ;-) */ + STp->changed_density = arg; } else if (cmd_in == SET_DENS_AND_BLK) (STp->buffer)->b_data[4] = arg >> 24; else (STp->buffer)->b_data[4] = STp->density; if (cmd_in == MTSETBLK || cmd_in == SET_DENS_AND_BLK) { ltmp = arg & MT_ST_BLKSIZE_MASK; - if (cmd_in == MTSETBLK) + if (cmd_in == MTSETBLK) { STp->blksize_changed = 1; /* At least we tried ;-) */ + STp->changed_blksize = arg; + } } else ltmp = STp->block_size; (STp->buffer)->b_data[9] = (ltmp >> 16); @@ -3636,9 +3638,25 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) retval = (-EIO); goto out; } - reset_state(STp); + reset_state(STp); /* Clears pos_unknown */ /* remove this when the midlevel properly clears was_reset */ STp->device->was_reset = 0; + + /* Fix the device settings after reset, ignore errors */ + if (mtc.mt_op == MTREW || mtc.mt_op == MTSEEK || + mtc.mt_op == MTEOM) { + if (STp->can_partitions) { + /* STp->new_partition contains the + * latest partition set + */ + STp->partition = 0; + switch_partition(STp); + } + if (STp->density_changed) + st_int_ioctl(STp, MTSETDENSITY, STp->changed_density); + if (STp->blksize_changed) + st_int_ioctl(STp, MTSETBLK, STp->changed_blksize); + } } if (mtc.mt_op != MTNOP && mtc.mt_op != MTSETBLK && diff --git a/drivers/scsi/st.h b/drivers/scsi/st.h index 1aaaf5369a40..6d31b894ee84 100644 --- a/drivers/scsi/st.h +++ b/drivers/scsi/st.h @@ -165,6 +165,7 @@ struct scsi_tape { unsigned char compression_changed; unsigned char drv_buffer; unsigned char density; + unsigned char changed_density; unsigned char door_locked; unsigned char autorew_dev; /* auto-rewind device */ unsigned char rew_at_close; /* rewind necessary at close */ @@ -172,6 +173,7 @@ struct scsi_tape { unsigned char cleaning_req; /* cleaning requested? */ unsigned char first_tur; /* first TEST UNIT READY */ int block_size; + int changed_blksize; int min_block; int max_block; int recover_count; /* From tape opening */ From patchwork Mon Jan 20 19:49:23 2025 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: 859348 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 EFDD31F03E2 for ; Mon, 20 Jan 2025 19:51:18 +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=1737402680; cv=none; b=SMPBReMuaJEEsgdPEEJwvvm2adblB+cAiRQYk6OsQ77SI2yzWsrCNX1pZaElOzz0I51n+LBcQCBrtY3WLnmiuJjFiUkvM0I9hzCAFyCnUG1lbMWFPcQeYi0Ka5KJIpEiNO6NJR7QybJuAXt0D/SjEOLK19BXR5/DIPAyWRn4KFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737402680; c=relaxed/simple; bh=BCulJklyaVilXsUyQlDwxUFa+2ea6FdqbSLucPGG1xY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ecCNxk/IFfRgeB/ZOAXapKAqZNa/7gXAK8e36b8uBUhwtHtPC51IUE2MaHLLZJxDC1TP72XyIPrn8muCTk97/jeZ9AIxJHjvxaTQQZc1Su2+t3pRkiCxdClPTSdqH6DOHCiifaKl1K/K48OGaVd/Qs4iEZ1vj6Aea6G1caWJ43I= 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=GGQ93oQY; 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="GGQ93oQY" 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=J7gvWeXf9JaeEwT3helUnwbyKeFTP/imC3PMdengEN8=; b=GGQ93oQYcJRgAC2cGpWaoYMS5BwVI4tPQTfU5QgTzo3Ly0gQJ5Q9VAz8xgE5QvJLuion8yb1XRP2E E2O24kguMgbhG8G5T/8H7G8d5I9BfSorX8ySw80K5K+ovuqh/UglndObIXagONC6CZ00AFb2QTuWjD RdULf/iWVepfc42FcTVtGsLvffRZwwbUpK5IKfzwyMGt9e6l8ZQI35Dfs5YukkYVY1YQDzeQ1PHQPD MuRFB9fOElN1q/EW8CUR96qsLAoqNYJejiskId0lwvvtvNQQWsJK3FYRIkxseIXB09H1pJR9EMFFvK znasC3HzWpbjJeoDmE+Ymek10BJJbZA== 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 be1e9af9-d767-11ef-88a3-005056bdd08f; Mon, 20 Jan 2025 21:50:04 +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 v3 2/4] scsi: scsi_error: Add counters for New Media and Power On/Reset UNIT ATTENTIONs Date: Mon, 20 Jan 2025 21:49:23 +0200 Message-ID: <20250120194925.44432-3-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120194925.44432-1-Kai.Makisara@kolumbus.fi> References: <20250120194925.44432-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 The purpose of the counters is to enable all ULDs attached to a device to find out that a New Media or/and Power On/Reset Unit Attentions has/have been set, even if another ULD catches the Unit Attention as response to a SCSI command. The ULDs can read the counters and see if the values have changed from the previous check. Signed-off-by: Kai Mäkisara --- drivers/scsi/scsi_error.c | 12 ++++++++++++ include/scsi/scsi_device.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 10154d78e336..6ef0711c4ec3 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -547,6 +547,18 @@ enum scsi_disposition scsi_check_sense(struct scsi_cmnd *scmd) scsi_report_sense(sdev, &sshdr); + if (sshdr.sense_key == UNIT_ATTENTION) { + /* + * increment the counters for Power on/Reset or New Media so + * that all ULDs interested in these can see that those have + * happened, even if someone else gets the sense data. + */ + if (sshdr.asc == 0x28) + scmd->device->ua_new_media_ctr++; + else if (sshdr.asc == 0x29) + scmd->device->ua_por_ctr++; + } + if (scsi_sense_is_deferred(&sshdr)) return NEEDS_RETRY; diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 9c540f5468eb..f5c0f07a053a 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -247,6 +247,9 @@ struct scsi_device { unsigned int queue_stopped; /* request queue is quiesced */ bool offline_already; /* Device offline message logged */ + u16 ua_new_media_ctr; /* Counter for New Media UNIT ATTENTIONs */ + u16 ua_por_ctr; /* Counter for Power On / Reset UAs */ + atomic_t disk_events_disable_depth; /* disable depth for disk events */ DECLARE_BITMAP(supported_events, SDEV_EVT_MAXBITS); /* supported events */ From patchwork Mon Jan 20 19:49:24 2025 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: 859350 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 E172A1EEA51 for ; Mon, 20 Jan 2025 19:50:18 +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=1737402622; cv=none; b=a2wgGZuMKvWGSURJG9QA9u24KCLuBREqpjN7T1REh65LpOwa7Uv6PCNGC6G2SCuOVjyNhHxnJH7v2Gxqg+0fRmdNEWatnGbFa91Zjv3vZNSrSKLstVjvJTeIU4maU2HVfK06VYWVsRGi5ZEwsBJURCFTBsrxR1yatyC6pfKw76Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737402622; c=relaxed/simple; bh=iGHb7QYGM/qKY0kNKWyNlbWXLhzUWbd9VfPi8yK8EuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PXosAz6ATSkJIgnnpBBiYZuErvLy1WnphyBkCUJ2XLggWJ0zYA3a4WnC8i+8GRufNjXdbNNmrVx++ULscIJ/tpjdS877NYgYhEz56GRDMtR9+ySK50+RhfMSs6RURM9FCS/uiSW1cfuXHjffi2Jyc4qjWmzadykQwQDh0Pl4jZY= 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=PTZvIExw; 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="PTZvIExw" 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=fOxipktNqCrigYZ7B5hPT1lw2rZhoRC3OXaHW10XMDU=; b=PTZvIExwseunHDuzrNXu1GyIQIEDbm4J+FCI7O5+JJdOTPn99LxUvLgw+hVNoimLxc9Diz2WzsXQk 2zHN8CJ3A76+dCuq0c97K8Bc79U6316EeHYHehX8Dj1NsOLBM9Ke6wUkr8fmPmniowRytcFwboSkRp izIMMQ2bZXknE3C1lXAQHSk0REU8fEEh0HyvIQ/1foztzsTNF7JJMEO+sz8J5HIBoIjHPcEVdh5oMH 2xKfEP6iq30p3bw5Crhu4gcHcf0XIZ0trdNNempkFGyTuxRgKVaawziklBjOIsFxtGSIU/ZE2yWLSF apgOx1xfvLTYihC9UbkRJGFXbIzR/CA== 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 c126253c-d767-11ef-88a3-005056bdd08f; Mon, 20 Jan 2025 21:50:09 +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 v3 3/4] scsi: st: scsi_device: Modify st.c to use the new scsi_error counters Date: Mon, 20 Jan 2025 21:49:24 +0200 Message-ID: <20250120194925.44432-4-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120194925.44432-1-Kai.Makisara@kolumbus.fi> References: <20250120194925.44432-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 Compare the stored values of por_ctr and new_media_ctr against the values in the device struct. In case of mismatch, the Unit Attention corresponding to the counter has happened. This is a safeguard against another ULD catching the Unit Attention sense data. Macros scsi_get_ua_new_media_ctr and scsi_get_ua_por_ctr are added to read the current values of the counters. Signed-off-by: Kai Mäkisara --- drivers/scsi/st.c | 30 +++++++++++++++++++++++++----- drivers/scsi/st.h | 4 ++++ include/scsi/scsi_device.h | 6 ++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index 0fc9afe60862..6ec1cfeb92ff 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -163,9 +163,11 @@ static const char *st_formats[] = { static int debugging = DEBUG; +/* Setting these non-zero may risk recognizing resets */ #define MAX_RETRIES 0 #define MAX_WRITE_RETRIES 0 #define MAX_READY_RETRIES 0 + #define NO_TAPE NOT_READY #define ST_TIMEOUT (900 * HZ) @@ -357,10 +359,18 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) { int result = SRpnt->result; u8 scode; + unsigned int ctr; DEB(const char *stp;) char *name = STp->name; struct st_cmdstatus *cmdstatp; + ctr = scsi_get_ua_por_ctr(STp->device); + if (ctr != STp->por_ctr) { + STp->por_ctr = ctr; + STp->pos_unknown = 1; /* ASC => power on / reset */ + st_printk(KERN_WARNING, STp, "Power on/reset recognized."); + } + if (!result) return 0; @@ -413,10 +423,11 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) if (cmdstatp->have_sense && cmdstatp->sense_hdr.asc == 0 && cmdstatp->sense_hdr.ascq == 0x17) STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */ - if (cmdstatp->have_sense && scode == UNIT_ATTENTION && cmdstatp->sense_hdr.asc == 0x29) + if (cmdstatp->have_sense && scode == UNIT_ATTENTION && + cmdstatp->sense_hdr.asc == 0x29 && !STp->pos_unknown) { STp->pos_unknown = 1; /* ASC => power on / reset */ - - STp->pos_unknown |= STp->device->was_reset; + st_printk(KERN_WARNING, STp, "Power on/reset recognized."); + } if (cmdstatp->have_sense && scode == RECOVERED_ERROR @@ -968,6 +979,7 @@ static int test_ready(struct scsi_tape *STp, int do_wait) { int attentions, waits, max_wait, scode; int retval = CHKRES_READY, new_session = 0; + unsigned int ctr; unsigned char cmd[MAX_COMMAND_SIZE]; struct st_request *SRpnt = NULL; struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; @@ -1024,6 +1036,13 @@ static int test_ready(struct scsi_tape *STp, int do_wait) } } + ctr = scsi_get_ua_new_media_ctr(STp->device); + if (ctr != STp->new_media_ctr) { + STp->new_media_ctr = ctr; + new_session = 1; + DEBC_printk(STp, "New tape session."); + } + retval = (STp->buffer)->syscall_result; if (!retval) retval = new_session ? CHKRES_NEW_SESSION : CHKRES_READY; @@ -3639,8 +3658,6 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) goto out; } reset_state(STp); /* Clears pos_unknown */ - /* remove this when the midlevel properly clears was_reset */ - STp->device->was_reset = 0; /* Fix the device settings after reset, ignore errors */ if (mtc.mt_op == MTREW || mtc.mt_op == MTSEEK || @@ -4402,6 +4419,9 @@ static int st_probe(struct device *dev) goto out_idr_remove; } + tpnt->new_media_ctr = scsi_get_ua_new_media_ctr(SDp); + tpnt->por_ctr = scsi_get_ua_por_ctr(SDp); + dev_set_drvdata(dev, tpnt); diff --git a/drivers/scsi/st.h b/drivers/scsi/st.h index 6d31b894ee84..0d7c4b8c2c8a 100644 --- a/drivers/scsi/st.h +++ b/drivers/scsi/st.h @@ -179,6 +179,10 @@ struct scsi_tape { int recover_count; /* From tape opening */ int recover_reg; /* From last status call */ + /* The saved values of midlevel counters */ + unsigned int new_media_ctr; + unsigned int por_ctr; + #if DEBUG unsigned char write_pending; int nbr_finished; diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index f5c0f07a053a..013018608370 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -687,6 +687,12 @@ static inline int scsi_device_busy(struct scsi_device *sdev) return sbitmap_weight(&sdev->budget_map); } +/* Macros to access the UNIT ATTENTION counters */ +#define scsi_get_ua_new_media_ctr(sdev) \ + ((const unsigned int)(sdev->ua_new_media_ctr)) +#define scsi_get_ua_por_ctr(sdev) \ + ((const unsigned int)(sdev->ua_por_ctr)) + #define MODULE_ALIAS_SCSI_DEVICE(type) \ MODULE_ALIAS("scsi:t-" __stringify(type) "*") #define SCSI_DEVICE_MODALIAS_FMT "scsi:t-0x%02x" From patchwork Mon Jan 20 19:49:25 2025 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: 858867 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 8997F1EEA51 for ; Mon, 20 Jan 2025 19:50:24 +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=1737402627; cv=none; b=DOWgnBNa86CcXRhck1Jok+PFTyCPpygcuXEUbaRAEctNhiioR63BZVj7QQGIvbFoMcJ1i13bTsvtSR21o9cJTsZIW4r4LO3XrV1RxN+Z9yuEqumZuRIHkh0DS5zdMf/uvpwtOv54tClTTtC/Cb1es4IPVA7COkaFNT2bVk9lhi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737402627; c=relaxed/simple; bh=KABGlaX7rMXucBqJq+MIXlqOLNLFyeYLI92Yrw0NLq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CDOjuC2HLiOlw5TkK1QsQiGnMP563oO5a6IrLnJa7GTgfIYi3Hhd8K3WBvjhD18M2mp1RX2pTMGYakeTkVPuGB02tn7kbAw3tX/Ls2Vjv8GikF2HH5ghprrpJx4OHUAnHhccsJDzc5FGYJ87Id6kXqX2l+ooMBpFyv2WNYIc+ZU= 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=F6Bf9wgS; 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="F6Bf9wgS" 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=DtYdyyTFdl4qm+eN09b6vGlwUwXQ5lNR8Cz7Z4xR+JE=; b=F6Bf9wgSG3582uNDNDl/lJrM9AOAUSRJ6OLp9b+59J43Wq9PF2UmCNxIHkkasqbC3lsXh44+gRsCa Xy4jz5oQ2WixSojiQKNbNgSHOIqyEk6c6QEpKXJ7QZpwkh8bNTbaTVE5bmyjqHbJcY6wApcXyqdFt8 6vTiElvajYAKtqJPiPEoE4z9aACEgsqy1FQPfvRnsGV0ExTrk4YkCKOFluSf29H+r2LWu1jMPFcHGN gm+rMky85KdYKR7qNElPjhoshc1CQCUpHz3QsojmpgIQk2sN0EpZOu3kvh216NeYU2UgUeRNueasWQ lh2aCDeWhj9EYrwa9n/o06Oet6wtPLQ== 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 c3568288-d767-11ef-88a3-005056bdd08f; Mon, 20 Jan 2025 21:50:13 +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 v3 4/4] scsi: st: Add sysfs file reset_blocked Date: Mon, 20 Jan 2025 21:49:25 +0200 Message-ID: <20250120194925.44432-5-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120194925.44432-1-Kai.Makisara@kolumbus.fi> References: <20250120194925.44432-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 If the value read from the file is 1, reads and writes from/to the device are blocked because the tape position may not match user's expectation (tape rewound after device reset). Signed-off-by: Kai Mäkisara --- Documentation/scsi/st.rst | 5 +++++ drivers/scsi/st.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Documentation/scsi/st.rst b/Documentation/scsi/st.rst index d3b28c28d74c..2209f03faad3 100644 --- a/Documentation/scsi/st.rst +++ b/Documentation/scsi/st.rst @@ -157,6 +157,11 @@ enabled driver and mode options. The value in the file is a bit mask where the bit definitions are the same as those used with MTSETDRVBUFFER in setting the options. +Each directory contains the entry 'reset_blocked'. If this value is one, +reading and writing to the device is blocked after device reset. Most +devices rewind the tape after reset and the writes/read don't access the +tape position the user expects. + A link named 'tape' is made from the SCSI device directory to the class directory corresponding to the mode 0 auto-rewind device (e.g., st0). diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index 6ec1cfeb92ff..e4fda0954004 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -4703,6 +4703,24 @@ options_show(struct device *dev, struct device_attribute *attr, char *buf) } static DEVICE_ATTR_RO(options); +/** + * reset_blocked_show - Value 1 indicates that reads, writes, etc. are blocked + * because a device reset has occurred and no operation positioning the tape + * has been issued. + * @dev: struct device + * @attr: attribute structure + * @buf: buffer to return formatted data in + */ +static ssize_t reset_blocked_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct st_modedef *STm = dev_get_drvdata(dev); + struct scsi_tape *STp = STm->tape; + + return sprintf(buf, "%d", STp->pos_unknown); +} +static DEVICE_ATTR_RO(reset_blocked); + /* Support for tape stats */ /** @@ -4887,6 +4905,7 @@ static struct attribute *st_dev_attrs[] = { &dev_attr_default_density.attr, &dev_attr_default_compression.attr, &dev_attr_options.attr, + &dev_attr_reset_blocked.attr, NULL, };