From patchwork Mon Nov 25 14:02:58 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: 13884927 Received: from fgw21-4.mail.saunalahti.fi (fgw21-4.mail.saunalahti.fi [62.142.5.108]) (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 BC31A376E0 for ; Mon, 25 Nov 2024 14:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732543421; cv=none; b=HvpklxwkDCTNR/irnmcanj6eIdTf2pA1K2W8DxVsaolIvt+qq+o8sSogVHQU0eSzhaGNVwwHFuxaRBaxH/WmVMLqTm2zGFOkNXB7ZXksfJiJrb6XTzhtjb/9i55VopU8D8TW1am2NDZB4JbOYW5Cl1NGmr2av2oCipuc4P0Y4Ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732543421; c=relaxed/simple; bh=xdVsFpk78aVyLxBrTCMaTBWrqjHFfXeYjpqnbg2DY+k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qsE8P3Ruri8BobY8qX4HSWvWR0HGizvRlZziDMTD+/s8c2FdiUGKwUQ3MRddgBC4h1JnSAXQyVDpqutK/XBHneeVeU2AZXvGZ7sAWrX3O7Swd7KOsm1TDrXP6R4XcLT2C7VGJyFDL3TnAScSm9FE8T7zT3edUX+vu+AQAyLMijE= 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=tfX8VrEw; arc=none smtp.client-ip=62.142.5.108 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="tfX8VrEw" 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=qM72bWVvmIeEbt3irAHb3j16yFGCfq336oGxPw2oDZE=; b=tfX8VrEw8lSC+0WobCWOu2N40BFcP5KtDwRufA+lXdaxqFcUiruvk4aKFw0l1bZKaKZAC936acVZ4 sjTa86Qi0jQ8iX9diDduOIbYhpmuQ8G84tGJ7n9Uxj9XmUU5bsGnf1rEn/HHFDUEdperDYZUkIpFyR PCV4MEeBysJ7PaqOpL7rg1tVxcVL0mXLeurHSTeoptakTaH32EooatdWWZvIirRjKnYu88VBRTNc+8 ZvEEOfUKsmVnnX5PH6+g/lehMb1u5aERmbDsMs4t11dWFqHnffal+/YSMt94W5jYThiqSAS/utR69m FsrI7ExGxGHP+QepxdEwKaEjDoN3fhA== 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 0135e6dc-ab36-11ef-8882-005056bdd08f; Mon, 25 Nov 2024 16:03:10 +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/4] scsi: st: Restore some drive settings after reset Date: Mon, 25 Nov 2024 16:02:58 +0200 Message-ID: <20241125140301.3912-2-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125140301.3912-1-Kai.Makisara@kolumbus.fi> References: <20241125140301.3912-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 Reviewed-by: John Meneghini Tested-by: John Meneghini --- drivers/scsi/st.c | 26 +++++++++++++++++++++----- drivers/scsi/st.h | 2 ++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index e8ef27d7ef61..a0667a0ae4c9 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; } } @@ -2925,14 +2924,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); @@ -3631,9 +3633,23 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) retval = (-EIO); goto out; } - reset_state(STp); - /* remove this when the midlevel properly clears was_reset */ - STp->device->was_reset = 0; + reset_state(STp); /* Clears pos_unknown */ + + /* 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 7a68eaba7e81..2105c6a5b458 100644 --- a/drivers/scsi/st.h +++ b/drivers/scsi/st.h @@ -165,12 +165,14 @@ 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 */ unsigned char inited; unsigned char cleaning_req; /* cleaning requested? */ int block_size; + int changed_blksize; int min_block; int max_block; int recover_count; /* From tape opening */ From patchwork Mon Nov 25 14:02:59 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: 13884928 Received: from fgw21-4.mail.saunalahti.fi (fgw21-4.mail.saunalahti.fi [62.142.5.108]) (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 7292A376E0 for ; Mon, 25 Nov 2024 14:03:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732543425; cv=none; b=h8zteG/BFllZ1XQc8COZ8Jt9HYIisyPZ/Wjef5PmSQjq6BICejHrTWdvSvOOk3wsjZ/PxoMPJlRlBhSM4+SneE4ZRpE8S3nl16sq5p6jN5Don+iK/PBMB68/9yTeTHMtntVCwK+zUnh6DwfLcDki7Zm/eM7eIdSl6uuZ23AZG74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732543425; c=relaxed/simple; bh=KM0+gSVYcVSbV98eFilQZSlBUj4LlQl8rZ1uc7YDnmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y5Vh20yCwDDZ0wANeHjANGEQ7fhxQVsNuQwImV5KQt7utt2+XfdLDSA81BVIOpaLHmZgL7ONKha+BSlC1TvXXXIKErFsJwH2S4VD/fKLgeRcelD6CA99bmW9KN3zriuL2Xg8yShG3qE6bpXuBxx1Vx7+ThKUYfyErcml76+9A5A= 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=DehU1BUq; arc=none smtp.client-ip=62.142.5.108 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="DehU1BUq" 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=Hr0qlNYospOGJ1FTldS39b0lMVvrLazIGwPQNi2ZC5c=; b=DehU1BUqjia7pdel89zxyDro3gzatst4ei8M7QXhrc8jlJWHVQflD2r2U8H9TYrvonZPs7O/r+YMB /lzQxL5qgiAvjuqEg6Vn2+Ecz6BJQ9eH9bPP/o/CWrFD4K+BEMvadjsL9x44xeS0JOYBdECO+PyCki eNVJYSW0wL1clGrIzJx+snJPGcY3BhEbfKgAmzV42EliGt3L3PhnTsb7ecD2JMKColbCBQee4ZKBmf 6T85IzJlIqbP/uEl3AJZliK3vQqOMMS0uHMlDUq4vsDE1oYWiYwp1wIG4tzlB2qFr+MhVPCuxSj/S+ +YGV/wB6IkVRJ8DTV6mcXWT1unIzZOQ== 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 044dcc28-ab36-11ef-8882-005056bdd08f; Mon, 25 Nov 2024 16:03:16 +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/4] scsi: scsi_error: Add counters for New Media and Power On/Reset UNIT ATTENTIONs Date: Mon, 25 Nov 2024 16:02:59 +0200 Message-ID: <20241125140301.3912-3-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125140301.3912-1-Kai.Makisara@kolumbus.fi> References: <20241125140301.3912-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 using the scsi_get_ua_new_media_ctr() and scsi_get_ua_por_ctr() macros (argument pointer to the scsi_device struct). Signed-off-by: Kai Mäkisara --- drivers/scsi/scsi_error.c | 12 ++++++++++++ include/scsi/scsi_device.h | 9 +++++++++ 2 files changed, 21 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..b184a5efc27e 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 */ + unsigned char ua_new_media_ctr; /* Counter for New Media UNIT ATTENTIONs */ + unsigned char 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 */ @@ -684,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 Nov 25 14:03:00 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: 13884926 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 92485376E0 for ; Mon, 25 Nov 2024 14:03:27 +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=1732543411; cv=none; b=bZnnmZyIwSLLUHPZs8NUfD3Yz1ajOOx6o/JhERt769B0dgFTww+ZwcOxFzU+Xh0AxJGYJaFa/6qRr+fl3tewkfLE4iCEYeB/kupDDkd6UzhBalwX/6I70wnhnQAjb0Y3ZI7Y/wLEwBwEJpys2lLdtpLXfMM+w+aeR1OgnY9PrSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732543411; c=relaxed/simple; bh=8MEwmFiTo7rjB+NGx5umIcQHlacB3w2MExmzilxAQ1Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cuqQSMI5J6kM69vVASWbq0xteocSP+wM5BtV/NAIF69h5gQliUHFYLJjt/ljvKqtt7DrNfS9c3nNXz+npUSPRAewsZN3qxjn0rWACj0PzF6Cqe4Q+99o/moV+joP41YAO+u9NH7WdgquafDIjvW1tQvMzJA83dERGLFCj3b+9jI= 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=w/Wmtq98; 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="w/Wmtq98" 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=CCuEaY1I75CVu4/J/xAMzSkf6Fn2artCV/2R6lhlYWQ=; b=w/Wmtq980wUa254ld7SjzoVDJbB8kqkxc5GYnRM7Ogr/Q+VBq1aqRLZF2z8ewoeZghvBBMQ/BdGKK sD3Jh35OLXfEslh74VQs74xna2nS4vUMQW/EjSaHWT5qlOJqtXRSUBlGIzw2lZX//mroS+wA1hJyb9 7aBr3GOWXjPypYKwW8OaATUPZTAuZXZ0hnm8SX8Sdb4Y9bNs5XuCW0YjhdG/8A1ZmKFsPK4rZPbj1D 3v0H/+NHesWKfhffWEv1eEHGnbo5mLwUz59i4U74INxIG8SCffSc8O/2jJzs380vIhuJD8ay192s60 ez5zjrqXWVxnX7oa34rIEDkb07aAS0A== 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 05da4e4f-ab36-11ef-8882-005056bdd08f; Mon, 25 Nov 2024 16:03:18 +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/4] scsi: st: Modify st.c to use the new scsi_error counters Date: Mon, 25 Nov 2024 16:03:00 +0200 Message-ID: <20241125140301.3912-4-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125140301.3912-1-Kai.Makisara@kolumbus.fi> References: <20241125140301.3912-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. Remove use of the was_reset flag in struct scsi_device. Signed-off-by: Kai Mäkisara --- drivers/scsi/st.c | 28 +++++++++++++++++++++++++--- drivers/scsi/st.h | 4 ++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index a0667a0ae4c9..ad86dfbc8919 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; @@ -4394,6 +4413,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 2105c6a5b458..47b0e31b7828 100644 --- a/drivers/scsi/st.h +++ b/drivers/scsi/st.h @@ -178,6 +178,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; From patchwork Mon Nov 25 14:03:01 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: 13884941 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 C6E5E192B7F for ; Mon, 25 Nov 2024 14:03:49 +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=1732543432; cv=none; b=dAEGTzerhLiAoNBTY+lM4jGscgt28AvcN1zIJ1Pye53QMzHgeZdrbg2HefZxixOOlXMmZ6Z3E18VAnA5d8YkNAKFQOWBRHDq1jglKIWsIuM4Gs2UN9N4zRM8eUd9qCmG60J2w6D0n4oPmDBP6szNvAZKUMTjpvVUc1hYVXMVBIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732543432; c=relaxed/simple; bh=3Go/PZyu/K4D4xKrpApeeRJrQZXrkB71scXFvQZQDOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FB+7E7MfPaKpGfhM+A+ROznEOXwEY7I+Z9Usng0+ix/vfCH8Bu+8M3tY47zPlTckKgiKsQ6BuGx7gffcvMuT0pxb/EGOaWJSF6/ZLghDLzmcMGmkhcblXKTGEDVHMvdPdlhZokGMNUVs7DtfHwzJpiFBonkfTKt0dbg4qD13Wg4= 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=Lcm8r229; 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="Lcm8r229" 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=NeqVt7amgvIxmptxFb8tKAWnqzkJFXJev23JSQNq7aw=; b=Lcm8r229ixtrKrKborSvcEAVWeBY4FNnC/gubLuM9fefkH9EOzmC2e6C1NezVDWIM3eu4KNNGItuY qbBT4C5t3DygPLTYHmR8wb1ARnx9H9KKsZQL5ucfkYekRJYvD/C9U6Q86QQ0+J0BlVBoeIJz5TtGa/ R9DlSviSRd61wWgujXrJYccfs5wSkOGUTeUeNNIULthKL7DCq+SK727fvXotOeaEgYti5KCsYiKnPo 91wF/g1sGiGQGyWWxeD5yORR08IojGcAFRUv90jXkyEazKwXCd2WmNngtXTIam+I2A2NAzWTG2MzTG kxE2vS3ZrHPLBUqzvvw2pWvVORue5TQ== 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 0837c1a6-ab36-11ef-8882-005056bdd08f; Mon, 25 Nov 2024 16:03:22 +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 4/4] scsi: st: Add sysfs file reset_blocked Date: Mon, 25 Nov 2024 16:03:01 +0200 Message-ID: <20241125140301.3912-5-Kai.Makisara@kolumbus.fi> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125140301.3912-1-Kai.Makisara@kolumbus.fi> References: <20241125140301.3912-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 ad86dfbc8919..0e6a87f1f47f 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -4697,6 +4697,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 */ /** @@ -4881,6 +4899,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, };