From nobody@FreeBSD.org  Fri Mar 25 02:01:42 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 0D7AF106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 25 Mar 2011 02:01:42 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id F1EC58FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 25 Mar 2011 02:01:41 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p2P21fEU048444
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 25 Mar 2011 02:01:41 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p2P21fZf048443;
	Fri, 25 Mar 2011 02:01:41 GMT
	(envelope-from nobody)
Message-Id: <201103250201.p2P21fZf048443@red.freebsd.org>
Date: Fri, 25 Mar 2011 02:01:41 GMT
From: KOIE Hidetaka <koie@suri.co.jp>
To: freebsd-gnats-submit@FreeBSD.org
Subject: CD tray is not locked even if using /dev/adc0.
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         155925
>Category:       misc
>Synopsis:       CD tray is not locked even if using /dev/adc0.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 25 02:10:10 UTC 2011
>Closed-Date:    Sun Nov 20 18:53:57 UTC 2011
>Last-Modified:  Sun Nov 20 18:53:57 UTC 2011
>Originator:     KOIE Hidetaka
>Release:        9.0-CURRENT
>Organization:
surigiken
>Environment:
FreeBSD guriandgura 9.0-CURRENT FreeBSD 9.0-CURRENT #0 r219849+1716dd734afd,ver-hg,nice-powerd: Tue Mar 22 08:39:13 JST 2011     root@guriandgura:/usr/obj/usr/src/sys/GURIANDGURA  amd64
>Description:
while using CD/DVD, a drive tray is not locked.
if a filesystem is mounted with readwrite, ejecting is breaking.

>How-To-Repeat:
mount_cd9660 /dev/acd0 /mnt
cdcontrol eject cdrom

or

zpool import dvdram
cdcontrol eject cdrom

>Fix:


>Release-Note:
>Audit-Trail:

From: Alexander Best <arundel@freebsd.org>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: misc/155925: CD tray is not locked even if using /dev/adc0.
Date: Fri, 25 Mar 2011 10:47:13 +0000

 this issue is not limited to acd. using cdcontrol -f /dev/cd gives the same
 behavior.
 
 plus camcontrol eject cd0 also ejects a mounted cd.
 
 cheers.
 alex
 
 -- 
 a13x

From: Jaakko Heinonen <jh@FreeBSD.org>
To: Alexander Best <arundel@freebsd.org>, koie@suri.co.jp
Cc: bug-followup@FreeBSD.org
Subject: Re: misc/155925: CD tray is not locked even if using /dev/adc0.
Date: Sat, 26 Mar 2011 19:10:55 +0200

 On 2011-03-25, Alexander Best wrote:
 >  this issue is not limited to acd. using cdcontrol -f /dev/cd gives the same
 >  behavior.
 
 I think this is because cdcontrol(1) first issues the CDIOCALLOW ioctl
 to unlock the tray. Does this patch fix your problem?
 
 	http://www.saunalahti.fi/~jh3/patches/cdcontrol-no-CDIOCALLOW.diff
 
 I am inclined to think that the behavior is intentional.
 
 -- 
 Jaakko

From: Alexander Best <arundel@freebsd.org>
To: Jaakko Heinonen <jh@FreeBSD.org>
Cc: koie@suri.co.jp, bug-followup@FreeBSD.org
Subject: Re: misc/155925: CD tray is not locked even if using /dev/adc0.
Date: Sat, 26 Mar 2011 18:27:02 +0000

 On Sat Mar 26 11, Jaakko Heinonen wrote:
 > On 2011-03-25, Alexander Best wrote:
 > >  this issue is not limited to acd. using cdcontrol -f /dev/cd gives the same
 > >  behavior.
 > 
 > I think this is because cdcontrol(1) first issues the CDIOCALLOW ioctl
 > to unlock the tray. Does this patch fix your problem?
 > 
 > 	http://www.saunalahti.fi/~jh3/patches/cdcontrol-no-CDIOCALLOW.diff
 > 
 > I am inclined to think that the behavior is intentional.
 
 i think the actual issue is not cdcontrol(1) so much, as CDIOCALLOW itself.
 looking at this PR:
 
 http://www.freebsd.org/cgi/query-pr.cgi?pr=125139
 
 shouldn't CDIOCALLOW and CDIOCPREVENT have the same busy checks like CDIOCEJECT
 (as pointed out in the PR)?
 
 i haven't tested your patch, but i think it works. CDIOCEJECT checks the ref
 count. without the CDIOCALLOW and a ref count >= 1 the cd won't be ejected.
 
 i'm not sure whether CDIOCALLOW and CDIOCPREVENT should stay the way they are
 or not. making them dependent on the ref count won't allow ejecting a CD at
 all. this might cause problems if or some reason the ref count cannot be set
 to 0. e. g. unmounting a broken CD/DVD might fail. i'm not sure if umount -f
 will always suceeded, so we might not be able to reduce the ref count to 0 in
 certain situations.
 
 if in fact CDIOCALLOW/CDIOCPREVENT should work regardless of the ref count i
 think your patch is good to go. here are the other places CDIOCALLOW is being
 used:
 
 otaku% grep -r CDIOCALLOW *
 share/man/man4/cd.4:.It Dv CDIOCALLOW
 sys/cam/scsi/scsi_cd.c:	case CDIOCALLOW:
 sys/dev/ata/atapi-cd.c:    case CDIOCALLOW:
 sys/dev/mcd/mcd.c:	case CDIOCALLOW:
 sys/dev/scd/scd.c:	case CDIOCALLOW:
 sys/sys/cdio.h:#define	CDIOCALLOW	_IO('c',26)
 usr.sbin/cdcontrol/cdcontrol.c:		(void) ioctl (fd, CDIOCALLOW);
 usr.sbin/cdcontrol/cdcontrol.c:		(void) ioctl (fd, CDIOCALLOW);
 usr.sbin/cdcontrol/cdcontrol.c:		(void) ioctl (fd, CDIOCALLOW);
 usr.sbin/sysinstall/cdrom.c:		ioctl(fd, CDIOCALLOW);
 
 cheers.
 alex
 
 > 
 > -- 
 > Jaakko
 
 -- 
 a13x

From: KOIE Hidetaka (=?iso-2022-jp?B?GyRCOHE5PjFRTjQhdz90TX01OzgmGyhC?=)
 <koie@suri.co.jp>
To: jh@FreeBSD.org
Cc: arundel@freebsd.org, bug-followup@FreeBSD.org
Subject: Re: misc/155925: CD tray is not locked even if using /dev/adc0.
Date: Mon, 28 Mar 2011 11:05:33 +0900 (JST)

   Message-Id: <20110326171054.GA1528@a91-153-123-205.elisa-laajakaista..
   Date:       Sat, 26 Mar 2011 19:10:55 +0200
   From:       Jaakko Heinonen <jh@FreeBSD.org>
   Subject:    Re: misc/155925: CD tray is not locked even if using /de..
 
   | On 2011-03-25, Alexander Best wrote:
   | >  this issue is not limited to acd. using cdcontrol -f /dev/cd gives the same
   | >  behavior.
   | 
   | I think this is because cdcontrol(1) first issues the CDIOCALLOW ioctl
   | to unlock the tray. Does this patch fix your problem?
   | 
   | 	http://www.saunalahti.fi/~jh3/patches/cdcontrol-no-CDIOCALLOW.diff
   | 
   | I am inclined to think that the behavior is intentional.
   | 
   | -- 
   | Jaakko
 
 I apply this patch and try:
 % /usr/obj/usr/src/usr.sbin/cdcontrol/cdcontrol eject
 cdcontrol: Input/output error
 
 ok, buk pushing the eject button still ejects a tray...
 
 --
 KOIE Hidetaka / koie@suri.co.jp / SURIGIKEN Co.,LTD.

From: Jaakko Heinonen <jh@FreeBSD.org>
To: KOIE Hidetaka <koie@suri.co.jp>
Cc: arundel@freebsd.org, bug-followup@FreeBSD.org
Subject: Re: misc/155925: CD tray is not locked even if using /dev/adc0.
Date: Mon, 28 Mar 2011 18:23:30 +0300

 On 2011-03-28, KOIE Hidetaka wrote:
 > I apply this patch and try:
 > % /usr/obj/usr/src/usr.sbin/cdcontrol/cdcontrol eject
 > cdcontrol: Input/output error
 > 
 > ok, buk pushing the eject button still ejects a tray...
 
 Thanks for testing. Could you try if the latest patch in PR kern/125139
 helps?
 
 -- 
 Jaakko

From: KOIE Hidetaka (=?iso-2022-jp?B?GyRCOHE5PjFRTjQhdz90TX01OzgmGyhC?=)
 <koie@suri.co.jp>
To: jh@FreeBSD.org
Cc: arundel@freebsd.org, bug-followup@FreeBSD.org
Subject: Re: misc/155925: CD tray is not locked even if using /dev/adc0.
Date: Tue, 29 Mar 2011 09:20:14 +0900 (JST)

   Message-Id: <20110328152329.GA1526@a91-153-123-205.elisa-laajakaista..
   Date:       Mon, 28 Mar 2011 18:23:30 +0300
   From:       Jaakko Heinonen <jh@FreeBSD.org>
   Subject:    Re: misc/155925: CD tray is not locked even if using /de..
 
   | On 2011-03-28, KOIE Hidetaka wrote:
   | > I apply this patch and try:
   | > % /usr/obj/usr/src/usr.sbin/cdcontrol/cdcontrol eject
   | > cdcontrol: Input/output error
   | > 
   | > ok, buk pushing the eject button still ejects a tray...
   | 
   | Thanks for testing. Could you try if the latest patch in PR kern/125139
   | helps?
   | 
   | -- 
   | Jaakko
 
 I try "patch-2.diff".
 note: a hunk for acd_modevent() is already applied in the current source.
 
 case1 (using patched cdcontrol):
 # mount_cd9660 /dev/acd0 /mnt
 # push the eject button -> no action
 # /usr/obj/usr/src/usr.sbin/cdcontrol/cdcontrol eject
 cdcontrol: Input/output error
 # /usr/obj/usr/src/usr.sbin/cdcontrol/cdcontrol eject
 cdcontrol: Input/output error
 # push the eject button -> ejected
 
 case 2 (using plain cdcontrol):
 # mount_cd9660 /dev/acd0 /mnt
 # /usr/sbin/cdcontrol eject -> ejected
 
 --
 KOIE Hidetaka / koie@suri.co.jp / SURIGIKEN Co.,LTD.
State-Changed-From-To: open->closed 
State-Changed-By: arundel 
State-Changed-When: Sun Nov 20 18:50:50 UTC 2011 
State-Changed-Why:  
This problem report appears to describe the very same issue that are being 
discussed in kern/125139. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=155925 
>Unformatted:
