From nobody@FreeBSD.org  Wed Jan 21 07:53:29 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 3BEA716A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 21 Jan 2004 07:53:29 -0800 (PST)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id CB43643D1D
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 21 Jan 2004 07:53:27 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.10/8.12.10) with ESMTP id i0LFrPdL094974
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 21 Jan 2004 07:53:25 -0800 (PST)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.10/8.12.10/Submit) id i0LFrPGi094973;
	Wed, 21 Jan 2004 07:53:25 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200401211553.i0LFrPGi094973@www.freebsd.org>
Date: Wed, 21 Jan 2004 07:53:25 -0800 (PST)
From: Jim Bauer <jfbauer@nfr.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Unable to open CDROM tray if boot_cdrom is in loader.conf
X-Send-Pr-Version: www-2.0

>Number:         61677
>Category:       kern
>Synopsis:       Unable to open CDROM tray if boot_cdrom is in loader.conf
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          suspended
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 21 08:00:23 PST 2004
>Closed-Date:    
>Last-Modified:  Sat Mar 01 20:26:23 UTC 2008
>Originator:     Jim Bauer
>Release:        4.8-RELEASE
>Organization:
NFR Security Inc
>Environment:
FreeBSD gyro.nidlab.nfr.net 4.8-RELEASE FreeBSD 4.8-RELEASE
#4: Mon Jan  5 12:47:40 EST 2004
jfbauer@gyro.nidlab.nfr.net:/home/jfbauer/freebsd_48_src/sys/compile/JFB  i386
>Description:
If loader.conf contains: boot_cdrom="YES" (the value is unimportant, just the existence seems to matter) but you don't actually boot from the CDROM drive (because it does not contain a CD) then the cdrom tray will remain locked.

As the system boots, the kernel will try to mount the CDROM trying 3 different CD devices.  All will fail as there is no CD in any cdrom drive.  The kernel will then fallback and mount the root FS from the hard disk.

Once the system is up and running you can login and see that nothing is mounted from the (empty) cdrom drive, but the eject command (CDIOCEJECT ioctl) will return EBUSY.  Also, pressing the eject button on the drive will fail to open the tray.

It looks like the mount attempt is not fully cleaning up and leaving the device in a busy state.


>How-To-Repeat:
1) Place this in your loader.conf file: boot_cdrom="YES"
2) Make sure there is no CD in the drive
3) Reboot (the kernel will attempt to mount the CD, fail and mount hard disk as usual)
4) Try to open the CD tray via either the eject command or the pressing the eject button on the cd drive.  Both will fail to open the tray.

>Fix:
This patch seem to fix the problem.

diff -u -r1.1.1.1 cd9660_vfsops.c
--- isofs/cd9660/cd9660_vfsops.c        11 Apr 2003 00:34:55 -0000      1.1.1.1
+++ isofs/cd9660/cd9660_vfsops.c        20 Jan 2004 20:46:31 -0000
@@ -163,7 +163,7 @@
        error = VOP_OPEN(rootvp, FREAD, FSCRED, p);
        VOP_UNLOCK(rootvp, 0, p);
        if (error)
-               return (error);
+               goto err;
 
        args.ssector = iso_get_ssector(rootdev, p);
 
@@ -173,10 +173,15 @@
                printf("iso_mountroot(): using session at block %d\n",
                       args.ssector);
        if ((error = iso_mountfs(rootvp, mp, p, &args)) != 0)
-               return (error);
+               goto err;
 
        (void)cd9660_statfs(mp, &mp->mnt_stat, p);
        return (0);
+
+    err:
+       /* Undo the addalias() called from bdevvp() */
+       delalias(rootvp, rootdev);
+       return error;
 }
 
 /*
Index: kern/vfs_subr.c
===================================================================
diff -u -r1.1.1.1 vfs_subr.c
--- kern/vfs_subr.c     11 Apr 2003 00:34:56 -0000      1.1.1.1
+++ kern/vfs_subr.c     20 Jan 2004 20:46:31 -0000
@@ -1481,6 +1481,22 @@
 }
 
 /*
+ * Remove an alias created by addalias()
+ */
+void
+delalias(nvp, dev)
+       struct vnode *nvp;
+        dev_t dev;
+{
+       if (nvp->v_type != VBLK && nvp->v_type != VCHR)
+               panic("delalias on non-special vnode");
+
+       simple_lock(&spechash_slock);
+       SLIST_REMOVE(&dev->si_hlist, nvp, vnode, v_specnext);
+        simple_unlock(&spechash_slock);
+}
+
+/*
  * Grab a particular vnode from the free list, increment its
  * reference count and lock it. The vnode lock bit is set if the
  * vnode is being eliminated in vgone. The process is awakened


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->josef 
Responsible-Changed-By: josef 
Responsible-Changed-When: Mon May 24 14:58:47 PDT 2004 
Responsible-Changed-Why:  
i'll handle this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=61677 
State-Changed-From-To: open->feedback 
State-Changed-By: josef 
State-Changed-When: Tue Jun 1 11:23:00 PDT 2004 
State-Changed-Why:  
I modified the patch, have some open questions, asked 
author for feedback. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=61677 
Responsible-Changed-From-To: josef->freebsd-bugs 
Responsible-Changed-By: josef 
Responsible-Changed-When: Wed Oct 13 22:14:50 GMT 2004 
Responsible-Changed-Why:  
Throw this one back into the pool. 
I am working on other areas now. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=61677 
State-Changed-From-To: feedback->suspended 
State-Changed-By: linimon 
State-Changed-When: Sat Mar 1 20:25:39 UTC 2008 
State-Changed-Why:  
Although feedback has not been received, it may be that the patch is 
still valid. 

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