From owner-freebsd-bugs@FreeBSD.ORG Sat Sep 22 06:20:01 2007 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B194916A41A for ; Sat, 22 Sep 2007 06:20:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 9694513C455 for ; Sat, 22 Sep 2007 06:20:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.1/8.14.1) with ESMTP id l8M6K1kU067849 for ; Sat, 22 Sep 2007 06:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.1/8.14.1/Submit) id l8M6K1hb067848; Sat, 22 Sep 2007 06:20:01 GMT (envelope-from gnats) Resent-Date: Sat, 22 Sep 2007 06:20:01 GMT Resent-Message-Id: <200709220620.l8M6K1hb067848@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Eugene Grosbein Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C723C16A420 for ; Sat, 22 Sep 2007 06:13:27 +0000 (UTC) (envelope-from eugen@grosbein.pp.ru) Received: from grosbein.pp.ru (grgw.svzserv.kemerovo.su [213.184.64.166]) by mx1.freebsd.org (Postfix) with ESMTP id 1816A13C459 for ; Sat, 22 Sep 2007 06:13:26 +0000 (UTC) (envelope-from eugen@grosbein.pp.ru) Received: from grosbein.pp.ru (localhost [127.0.0.1]) by grosbein.pp.ru (8.14.1/8.14.1) with ESMTP id l8M6DP09002459 for ; Sat, 22 Sep 2007 14:13:25 +0800 (KRAST) (envelope-from eugen@grosbein.pp.ru) Received: (from eugen@localhost) by grosbein.pp.ru (8.14.1/8.14.1/Submit) id l8M6DPGw002458; Sat, 22 Sep 2007 14:13:25 +0800 (KRAST) (envelope-from eugen) Message-Id: <200709220613.l8M6DPGw002458@grosbein.pp.ru> Date: Sat, 22 Sep 2007 14:13:25 +0800 (KRAST) From: Eugene Grosbein To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: kern/116539: [fdc] fdc(4) marks /dev/fd0 device busy when it should not, so does not allow to kldunload fdc.ko X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Eugene Grosbein List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Sep 2007 06:20:01 -0000 >Number: 116539 >Category: kern >Synopsis: [fdc] fdc(4) marks /dev/fd0 device busy when it should not, so does not allow to kldunload fdc.ko >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Sep 22 06:20:00 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Eugene Grosbein >Release: FreeBSD 6.2-STABLE i386 >Organization: Svyaz-Service JSC >Environment: System: FreeBSD grosbein.pp.ru 6.2-STABLE FreeBSD 6.2-STABLE #2: Sun Sep 16 16:54:23 KRAST 2007 eu@grosbein.pp.ru:/home/obj/usr/local/src/sys/DADV i386 >Description: Any access to /dev/fd0 results in call to device_busy(fd->dev) and should entail appropriate device_unbusy(fd->dev). However, an attempt to write access to write-protected floppy leads to device_busy(fd->dev) without corresponding device_unbusy(fd->dev). This locks fdc.ko from unloading. >How-To-Repeat: Boot kernel without fdc(4) compiled-in. Load fdc(4) by means of loader or kldload having write-protected floppy in the drive when fdc(4) initializes. Do: echo -n >/dev/fd0 You'll get 'Read-only file system' error and will not be allowed to unload fdc.ko after that. One may use following patch to see what happens inside kernel. You should 'debug.fdc.debugflags=64' in the /boot/loader.conf to see what happens. You can also try 'debug.fdc.debugflags=320' to enable this patch's ability to force device unlocking for such case but this is not correct solution. It will unbusy device in cases where it should not: device is mounted read-only and an attempt to open it for writing is performed. The patch will call device_unbusy(fd->dev) allowing to unload fdc.ko while device is still mounted. I do not know correct solution. --- sys/dev/fdc/fdc.c.orig 2007-09-15 16:53:23.000000000 +0800 +++ sys/dev/fdc/fdc.c 2007-09-16 16:26:07.000000000 +0800 @@ -1389,6 +1393,8 @@ ae = e + pp->ace; if (ar == 0 && aw == 0 && ae == 0) { + if (debugflags & 0x40) + device_printf(fdc->fdc_dev, "marked not busy\n"); device_unbusy(fd->dev); return (0); } @@ -1404,11 +1410,20 @@ fd->flags &= ~FD_NEWDISK; mtx_unlock(&fdc->fdc_mtx); } + if (debugflags & 0x40) + device_printf(fdc->fdc_dev, "marked busy\n"); device_busy(fd->dev); } - if (w > 0 && (fd->flags & FD_WP)) + if (w > 0 && (fd->flags & FD_WP)) { + if ((debugflags & 0x100) && + (device_get_state(fd->dev) == DS_BUSY)) { + if (debugflags & 0x40) + device_printf(fdc->fdc_dev, "marked not busy\n"); + device_unbusy(fd->dev); + } return (EROFS); + } pp->sectorsize = fd->sectorsize; pp->stripesize = fd->ft->heads * fd->ft->sectrac * fd->sectorsize; @@ -1749,6 +1764,7 @@ fdc = device_get_softc(dev); fdc->fdc_dev = dev; + TUNABLE_INT_FETCH("debug.fdc.debugflags", &debugflags); error = fdc_initial_reset(dev, fdc); if (error) { device_printf(dev, "does not respond\n"); >Fix: Unknown. >Release-Note: >Audit-Trail: >Unformatted: