CVS commit: [netbsd-7] src/sys/dev/scsipi

2019-03-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Mar  7 16:49:10 UTC 2019

Modified Files:
src/sys/dev/scsipi [netbsd-7]: files.scsipi st.c

Log Message:
Pull up following revision(s) (requested by kardel in ticket #1682):

sys/dev/scsipi/st.c: revision 1.236 (patch)
sys/dev/scsipi/st.c: revision 1.237
sys/dev/scsipi/files.scsipi: revision 1.42

Fix PR kern/53949:
Fix inconsistent/incomplete file mark handling to conform again
to mtio(4) at close(2) time. This was necessary as the PREVENT/ALLOW
bracket was reduced from a whole mount session to cover only the
open(2)/close(2) time on ~2002-03-22. The rationale was to allow
robots and humans to change the media during a mount session.

Unfortunately this lead to file marks being written to potentially other
media at the beginning on drives that used the two file marks as EOM
pattern. In order for that to happen the media had to be removed after
data and at most one file mark had been written before removal.

The mount error message has been clarified and a warning about
potential data/file mark lossage on UNIT ATTENTION
during an active mount session with unfinished file marks has been
added.

While there, fix, but disable the commented SUN compatibility to write
final file marks by opening and immediately closing the device
in O_WRONLY mode. That code has not been working since around 1998.

It can now be enabled with options ST_SUNCOMPAT.

Additionally debug output coverage has been extended.

Correct printing type of b_blkno (int64_t) in st.c

Fixes build with kUBSan on NetBSD/i386.

Fix, but disable the commented SUN compatibility in st.c to write
final file marks by opening and immediately closing the device
in O_WRONLY mode. That code has not been working since around 1998.
It can now be enabled with options ST_SUNCOMPAT.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.41.138.1 src/sys/dev/scsipi/files.scsipi
cvs rdiff -u -r1.226 -r1.226.2.1 src/sys/dev/scsipi/st.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/files.scsipi
diff -u src/sys/dev/scsipi/files.scsipi:1.41 src/sys/dev/scsipi/files.scsipi:1.41.138.1
--- src/sys/dev/scsipi/files.scsipi:1.41	Sun Dec 11 12:23:50 2005
+++ src/sys/dev/scsipi/files.scsipi	Thu Mar  7 16:49:10 2019
@@ -1,11 +1,12 @@
-#	$NetBSD: files.scsipi,v 1.41 2005/12/11 12:23:50 christos Exp $
+#	$NetBSD: files.scsipi,v 1.41.138.1 2019/03/07 16:49:10 martin Exp $
 #
 # Config file and device description for machine-independent SCSI code.
 # Included by ports that need it.  Ports that use it must provide
 # their own "major" declarations for the appropriate devices.
 
 defflag	opt_scsi.h		SCSIVERBOSE ST_ENABLE_EARLYWARN
-SES_ENABLE_PASSTHROUGH SCSI_OLD_NOINQUIRY
+ST_SUNCOMPAT SES_ENABLE_PASSTHROUGH
+SCSI_OLD_NOINQUIRY
 defparam opt_scsi.h		ST_MOUNT_DELAY SDRETRIES SD_IO_TIMEOUT
 
 defflag	opt_scsipi_debug.h	SCSIPI_DEBUG

Index: src/sys/dev/scsipi/st.c
diff -u src/sys/dev/scsipi/st.c:1.226 src/sys/dev/scsipi/st.c:1.226.2.1
--- src/sys/dev/scsipi/st.c:1.226	Sun Aug 10 16:44:36 2014
+++ src/sys/dev/scsipi/st.c	Thu Mar  7 16:49:10 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: st.c,v 1.226 2014/08/10 16:44:36 tls Exp $ */
+/*	$NetBSD: st.c,v 1.226.2.1 2019/03/07 16:49:10 martin Exp $ */
 
 /*-
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.226 2014/08/10 16:44:36 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.226.2.1 2019/03/07 16:49:10 martin Exp $");
 
 #include "opt_scsi.h"
 
@@ -605,6 +605,30 @@ stopen(dev_t dev, int flags, int mode, s
 		 */
 		if ((st->flags & ST_MOUNTED) || ST_MOUNT_DELAY == 0 ||
 		(st->mt_key != SKEY_NOT_READY)) {
+			device_printf(st->sc_dev,
+  "mount error (sense key=%d) - "
+  "terminating mount session\n",
+  st->mt_key);
+			/*
+			 * the following should not trigger unless
+			 * something serious happened while the device
+			 * was open (PREVENT MEDIUM REMOVAL in effect)
+			 */
+			if (st->flags & ST_WRITTEN &&
+			st->mt_key == SKEY_UNIT_ATTENTION) {
+/*
+ * device / media state may have changed
+ * refrain from writing missing file marks
+ * onto potentially newly inserted/formatted
+ * media (e. g. emergency EJECT/RESET/etc.)
+ */
+st->flags &= ~(ST_WRITTEN|ST_FM_WRITTEN);
+
+device_printf(st->sc_dev,
+"CAUTION: file marks/data may be missing"
+" - ASC = 0x%02x, ASCQ = 0x%02x\n",
+	  st->asc, st->ascq);
+			}
 			goto bad;
 		}
 
@@ -713,15 +737,30 @@ stclose(dev_t dev, int flags, int mode, 
 	 */
 
 	stxx = st->flags & (ST_WRITTEN | ST_FM_WRITTEN);
-	if (((flags & FWRITE) && stxx == ST_WRITTEN) ||
-	((flags & O_ACCMODE) == FWRITE && stxx == 0)) {
-		int nm;
+	if ((flags & FWRITE) != 0) {
+		int nm 

CVS commit: [netbsd-7] src/sys/dev/scsipi

2015-03-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Mar 26 16:09:52 UTC 2015

Modified Files:
src/sys/dev/scsipi [netbsd-7]: scsipi_base.c

Log Message:
Pull up the following revisions, requested by christos in #644:

sys/dev/scsipi/scsipi_base.c1.161 - 1.164

Use size for the size argument of memcmp, not the result of a compare.

PR/49054: Add a quirk for the ES-6600 RAID controller which does not do
INQUIRY3 properly. Unfortunately looking at the length does not solve
the problem since other devices send greater lengths too.

src is too big these days to tolerate superfluous apostrophes.  It's
its, people!

PR/49054: Uwe Toenjes: Some RAID controllers return more bytes in the
scsi 3 inquiry command than expected by the size of the scsi 3 inquiry
packet. This can be detected by looking at the additional_length field
returned by the scsi 2 inquiry. If that's the case, avoid doing the
scsi 3 inquiry because we can't handle the extra bytes later.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.160.2.1 src/sys/dev/scsipi/scsipi_base.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsipi_base.c
diff -u src/sys/dev/scsipi/scsipi_base.c:1.160 src/sys/dev/scsipi/scsipi_base.c:1.160.2.1
--- src/sys/dev/scsipi/scsipi_base.c:1.160	Sun Jul 13 17:12:23 2014
+++ src/sys/dev/scsipi/scsipi_base.c	Thu Mar 26 16:09:52 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipi_base.c,v 1.160 2014/07/13 17:12:23 dholland Exp $	*/
+/*	$NetBSD: scsipi_base.c,v 1.160.2.1 2015/03/26 16:09:52 martin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: scsipi_base.c,v 1.160 2014/07/13 17:12:23 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: scsipi_base.c,v 1.160.2.1 2015/03/26 16:09:52 martin Exp $);
 
 #include opt_scsi.h
 
@@ -808,7 +808,7 @@ scsipi_interpret_sense(struct scsipi_xfe
 #endif
 
 	/*
-	 * If the periph has it's own error handler, call it first.
+	 * If the periph has its own error handler, call it first.
 	 * If it returns a legit error value, return that, otherwise
 	 * it wants us to continue with normal error processing.
 	 */
@@ -1044,6 +1044,28 @@ scsipi_test_unit_ready(struct scsipi_per
 	retries, 1, NULL, flags));
 }
 
+static const struct scsipi_inquiry3_pattern {
+	const char vendor[8];
+	const char product[16];
+	const char revision[4];
+} scsipi_inquiry3_quirk[] = {
+	{ ES-6600 , ,  },
+};
+
+static int
+scsipi_inquiry3_ok(const struct scsipi_inquiry_data *ib)
+{
+	for (size_t i = 0; i  __arraycount(scsipi_inquiry3_quirk); i++) {
+		const struct scsipi_inquiry3_pattern *q =
+		scsipi_inquiry3_quirk[i];
+#define MATCH(field) \
+(q-field[0] ? memcmp(ib-field, q-field, sizeof(ib-field)) == 0 : 1)
+		if (MATCH(vendor)  MATCH(product)  MATCH(revision))
+			return 0;
+	}
+	return 1;
+}
+
 /*
  * scsipi_inquire:
  *
@@ -1064,7 +1086,7 @@ scsipi_inquire(struct scsipi_periph *per
 
 	/*
 	 * If we request more data than the device can provide, it SHOULD just
-	 * return a short reponse.  However, some devices error with an
+	 * return a short response.  However, some devices error with an
 	 * ILLEGAL REQUEST sense code, and yet others have even more special
 	 * failture modes (such as the GL641USB flash adapter, which goes loony
 	 * and sends corrupted CRCs).  To work around this, and to bring our
@@ -1081,6 +1103,7 @@ scsipi_inquire(struct scsipi_periph *per
 	1, NULL, flags | XS_CTL_DATA_IN);
 	if (!error 
 	inqbuf-additional_length  SCSIPI_INQUIRY_LENGTH_SCSI2 - 4) {
+	if (scsipi_inquiry3_ok(inqbuf)) {
 #if 0
 printf(inquire: addlen=%d, retrying\n, inqbuf-additional_length);
 #endif
@@ -1091,6 +1114,7 @@ printf(inquire: addlen=%d, retrying\n,
 #if 0
 printf(inquire: error=%d\n, error);
 #endif
+	}
 	}
 
 #ifdef SCSI_OLD_NOINQUIRY
@@ -2445,7 +2469,7 @@ scsipi_sync_factor_to_freq(int factor)
 
 #ifdef SCSIPI_DEBUG
 /*
- * Given a scsipi_xfer, dump the request, in all it's glory
+ * Given a scsipi_xfer, dump the request, in all its glory
  */
 void
 show_scsipi_xs(struct scsipi_xfer *xs)