Bug 155925

Summary: CD tray is not locked even if using /dev/adc0.
Product: Base System Reporter: KOIE Hidetaka <koie>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 9.0-CURRENT   
Hardware: Any   
OS: Any   

Description KOIE Hidetaka 2011-03-25 02:10:10 UTC
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
Comment 1 Alexander Best freebsd_committer freebsd_triage 2011-03-25 10:47:13 UTC
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
Comment 2 Jaakko Heinonen freebsd_committer freebsd_triage 2011-03-26 17:10:55 UTC
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
Comment 3 Alexander Best freebsd_committer freebsd_triage 2011-03-26 18:27:02 UTC
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
Comment 4 KOIE Hidetaka 2011-03-28 03:05:33 UTC
  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.
Comment 5 Jaakko Heinonen freebsd_committer freebsd_triage 2011-03-28 16:23:30 UTC
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
Comment 6 KOIE Hidetaka 2011-03-29 01:20:14 UTC
  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.
Comment 7 Alexander Best freebsd_committer freebsd_triage 2011-11-20 18:50:50 UTC
State Changed
From-To: open->closed

This problem report appears to describe the very same issue that are being 
discussed in kern/125139.