NetBSD Problem Report #30288

From pavel.cahyna@st.mff.cuni.cz  Fri May 20 11:02:35 2005
Return-Path: <pavel.cahyna@st.mff.cuni.cz>
Received: from mail.casablanca.cz (mail.casablanca.cz [82.208.31.182])
	by narn.netbsd.org (Postfix) with ESMTP id EE47A63B104
	for <gnats-bugs@gnats.netbsd.org>; Fri, 20 May 2005 11:02:34 +0000 (UTC)
Message-Id: <1116587682.0@pc.martani.n2.repy.czf>
Date: Fri, 20 May 2005 11:14:42 -0000
From: "Pavel Cahyna" <pavel.cahyna@st.mff.cuni.cz>
To: "gnats bugs" <gnats-bugs@netbsd.org>
Subject: eject and raw SCSI access to a CDROM drive don't work when the medium is bad
X-Send-Pr-Version: gtk-send-pr 0.4 
X-GNATS-Notify:

>Number:         30288
>Category:       kern
>Synopsis:       eject and raw SCSI access to a CDROM drive don't work when the medium is bad
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bouyer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 20 11:03:00 +0000 2005
>Closed-Date:    Wed Jul 06 14:29:12 +0000 2005
>Last-Modified:  Thu Apr 27 20:40:01 +0000 2006
>Originator:     Pavel Cahyna
>Release:        NetBSD 3.0_BETA i386
>Organization:
>Environment:


System: NetBSD 3.0_BETA (GENERIC) #0: Sat May  7 08:05:37 UTC 2005
	jmc@faith.netbsd.org:/home/builds/ab/netbsd-3/i386/200505060000Z-obj/home/builds/ab/netbsd-3/src/sys/arch/i386/compile/GENERIC



>Description:


When there is an unreadable CD-RW medium in my SCSI CD drive, even the tools
that don't access the medium don't work.  For example scsictl:
$ scsictl cd1 identify                                        
scsictl: cd1: Device not configured

or eject:
$ eject cd1
eject: open: /dev/rcd1d: Device not configured

When I attempt to do this, the kernel prints:
cd1(ahc1:0:5:0):  Check Condition on CDB: 0x25 00 00 00 00 00 00 00 00 00
    SENSE KEY:  Not Ready
     ASC/ASCQ:  Cannot Read Medium - Incompatible Format

When there is a good medium, scsictl works normally:
$ scsictl cd1 identify 
/dev/rcd1d: scsibus0 target 5 lun 0 <YAMAHA, CRW6416S, 1.0c>

eject too.

The problem is also present in 2.0_BETA and I remember similar problems with
a PD optical drive with NetBSD 1.6 .

relevant lines from my dmesg:

ahc1 at pci0 dev 11 function 0: Adaptec 2940 Ultra SCSI adapter
ahc1: interrupting at irq 5
ahc1: aic7880: Ultra Wide Channel A, SCSI Id=7, 16/253 SCBs
scsibus0 at ahc1: 16 targets, 8 luns per target
scsibus0: waiting 2 seconds for devices to settle...
cd1 at scsibus0 target 5 lun 0: <YAMAHA, CRW6416S, 1.0c> cdrom removable
cd1: sync (100.00ns offset 15), 8-bit (10.000MB/s) transfers



>How-To-Repeat:


see above.


>Fix:


Unknown. Somehow always allow to access the raw device? 
Or introduce another device node for the necessary IOCTLs instead of the raw device?


>Release-Note:

>Audit-Trail:
From: Manuel Bouyer <bouyer@antioche.lip6.fr>
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@NetBSD.org, gnats-admin@NetBSD.org,
	netbsd-bugs@NetBSD.org
Subject: Re: kern/30288: eject and raw SCSI access to a CDROM drive don't work when the medium is bad
Date: Fri, 20 May 2005 13:31:49 +0200

 --6TrnltStXW4iwmi0
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline

 On Fri, May 20, 2005 at 11:03:00AM +0000, Pavel Cahyna wrote:
 > >Description:
 > 
 > 
 > When there is an unreadable CD-RW medium in my SCSI CD drive, even the tools
 > that don't access the medium don't work.  For example scsictl:
 > $ scsictl cd1 identify                                        
 > scsictl: cd1: Device not configured
 > 
 > or eject:
 > $ eject cd1
 > eject: open: /dev/rcd1d: Device not configured
 > 
 > When I attempt to do this, the kernel prints:
 > cd1(ahc1:0:5:0):  Check Condition on CDB: 0x25 00 00 00 00 00 00 00 00 00
 >     SENSE KEY:  Not Ready
 >      ASC/ASCQ:  Cannot Read Medium - Incompatible Format
 > 
 > When there is a good medium, scsictl works normally:
 > $ scsictl cd1 identify 
 > /dev/rcd1d: scsibus0 target 5 lun 0 <YAMAHA, CRW6416S, 1.0c>
 > 
 > eject too.
 > [...]
 > >Fix:
 > 
 > 
 > Unknown. Somehow always allow to access the raw device? 

 Yes, this is how it should work. Can you try the (untested) patch attached ?

 -- 
 Manuel Bouyer <bouyer@antioche.eu.org>
      NetBSD: 26 ans d'experience feront toujours la difference
 --

 --6TrnltStXW4iwmi0
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=diff

 Index: cd.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/scsipi/cd.c,v
 retrieving revision 1.222
 diff -u -r1.222 cd.c
 --- cd.c	25 Apr 2005 17:52:30 -0000	1.222
 +++ cd.c	20 May 2005 11:29:47 -0000
 @@ -348,6 +348,7 @@
  	struct scsipi_adapter *adapt;
  	int unit, part;
  	int error;
 +	int rawpart;

  	unit = CDUNIT(dev);
  	if (unit >= cd_cd.cd_ndevs)
 @@ -375,20 +376,21 @@
  	if ((error = lockmgr(&cd->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
  		goto bad4;

 +	rawpart = (part == RAW_PART && fmt == S_IFCHR);
  	if ((periph->periph_flags & PERIPH_OPEN) != 0) {
  		/*
  		 * If any partition is open, but the disk has been invalidated,
  		 * disallow further opens.
  		 */
  		if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0 &&
 -			(part != RAW_PART || fmt != S_IFCHR )) {
 +			!rawpart) {
  			error = EIO;
  			goto bad3;
  		}
  	} else {
  		int silent;

 -		if (part == RAW_PART && fmt == S_IFCHR)
 +		if (rawpart)
  			silent = XS_CTL_SILENT;
  		else
  			silent = 0;
 @@ -420,7 +422,7 @@
  			}
  		}
  		if (error) {
 -			if (silent)
 +			if (rawpart)
  				goto out;
  			goto bad3;
  		}
 @@ -432,17 +434,21 @@
  		    XS_CTL_IGNORE_ILLEGAL_REQUEST | XS_CTL_IGNORE_MEDIA_CHANGE);
  		SC_DEBUG(periph, SCSIPI_DB1,
  		    ("cdopen: scsipi_prevent, error=%d\n", error));
 -		if (error)
 +		if (error) {
 +			if (rawpart)
 +				goto out;
  			goto bad;
 +		}

  		if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0) {
 -			periph->periph_flags |= PERIPH_MEDIA_LOADED;
 -
  			/* Load the physical device parameters. */
  			if (cd_get_parms(cd, 0) != 0) {
 +				if (rawpart)
 +					goto out;
  				error = ENXIO;
 -				goto bad2;
 +				goto bad;
  			}
 +			periph->periph_flags |= PERIPH_MEDIA_LOADED;
  			SC_DEBUG(periph, SCSIPI_DB3, ("Params loaded "));

  			/* Fabricate a disk label. */
 @@ -475,7 +481,6 @@
  	lockmgr(&cd->sc_lock, LK_RELEASE, NULL);
  	return (0);

 -bad2:
  	periph->periph_flags &= ~PERIPH_MEDIA_LOADED;

  bad:

 --6TrnltStXW4iwmi0--

Responsible-Changed-From-To: kern-bug-people->bouyer
Responsible-Changed-By: bouyer@netbsd.org
Responsible-Changed-When: Fri, 20 May 2005 11:33:00 +0000
Responsible-Changed-Why:
I'll handle this


State-Changed-From-To: open->feedback
State-Changed-By: bouyer@netbsd.org
State-Changed-When: Fri, 20 May 2005 11:33:00 +0000
State-Changed-Why:
I sent a patch


From: Pavel Cahyna <pcah8322@artax.karlin.mff.cuni.cz>
To: bouyer@netbsd.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org
Subject: Re: kern/30288
Date: Sat, 2 Jul 2005 22:03:30 +0200

 On Fri, May 20, 2005 at 11:33:00AM +0000, bouyer@netbsd.org wrote:
 > Synopsis: eject and raw SCSI access to a CDROM drive don't work when the medium is bad
 > State-Changed-From-To: open->feedback
 > State-Changed-By: bouyer@netbsd.org
 > State-Changed-When: Fri, 20 May 2005 11:33:00 +0000
 > State-Changed-Why:
 > I sent a patch

 Hello,

 thanks, I applied your patch to 3.99.3 sources, compiled a XEN0 kernel and
 it works!

 the messages
 cd1(ahc0:0:5:0):  Check Condition on CDB: 0x25 00 00 00 00 00 00 00 00 00
     SENSE KEY:  Not Ready
      ASC/ASCQ:  Cannot Read Medium - Incompatible Format
 still appear, but eject and scsictl work as expected!

State-Changed-From-To: feedback->closed
State-Changed-By: bouyer@netbsd.org
State-Changed-When: Wed, 06 Jul 2005 14:29:12 +0000
State-Changed-Why:
Patch commited, will request pullup in a few days.
Thanks for the PR !


From: Manuel Bouyer <bouyer@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/30288 CVS commit: src/sys/dev/scsipi
Date: Wed,  6 Jul 2005 14:28:39 +0000 (UTC)

 Module Name:	src
 Committed By:	bouyer
 Date:		Wed Jul  6 14:28:39 UTC 2005

 Modified Files:
 	src/sys/dev/scsipi: cd.c

 Log Message:
 Always allow open() on the raw partition to succeed, even if any of the
 SCSI command in cdopen() fails. Fix PR kern/30288 by Pavel Cahyna.


 To generate a diff of this commit:
 cvs rdiff -r1.223 -r1.224 src/sys/dev/scsipi/cd.c

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

From: Matthias Scheler <tron@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/30288 CVS commit: [netbsd-3] src/sys/dev/scsipi
Date: Thu, 27 Apr 2006 20:37:42 +0000 (UTC)

 Module Name:	src
 Committed By:	tron
 Date:		Thu Apr 27 20:37:42 UTC 2006

 Modified Files:
 	src/sys/dev/scsipi [netbsd-3]: cd.c

 Log Message:
 Pull up following revision(s) (requested by pavel in ticket #1290):
 	sys/dev/scsipi/cd.c: revision 1.224
 Always allow open() on the raw partition to succeed, even if any of the
 SCSI command in cdopen() fails. Fix PR kern/30288 by Pavel Cahyna.


 To generate a diff of this commit:
 cvs rdiff -r1.220.2.1 -r1.220.2.2 src/sys/dev/scsipi/cd.c

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

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.