From owner-freebsd-current@FreeBSD.ORG Sun Feb 15 04:08:18 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 94B5816A4CF for ; Sun, 15 Feb 2004 04:08:18 -0800 (PST) Received: from critter.freebsd.dk (critter.freebsd.dk [212.242.86.163]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B1DD43D1F for ; Sun, 15 Feb 2004 04:08:18 -0800 (PST) (envelope-from phk@phk.freebsd.dk) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.12.10/8.12.10) with ESMTP id i1FC8HhM013193 for ; Sun, 15 Feb 2004 13:08:17 +0100 (CET) (envelope-from phk@phk.freebsd.dk) To: current@freebsd.org From: Poul-Henning Kamp Date: Sun, 15 Feb 2004 13:08:17 +0100 Message-ID: <13192.1076846897@critter.freebsd.dk> Subject: HEADSUP: The bigger cdevsw/dev_t picture X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Feb 2004 12:08:18 -0000 You have seen me throw a number of kilopatches out for review/test in the last week, and there is a couple more forthcoming. This is my big ugly "dev_t refcount" source-tree being decomposed into self-contained bites which hopefully makes review/test easier. I am finalizing a mechanical patch which flips the sense of the "D_NOGIANT" flag to become "D_NEEDGIANT", this will also go out for review today I think. The final bit of this package of patches will be a tiny patch which goes over all makedev(9) and udev2dev(9) users in the tree and convert them to the new world order where they only succeed if a dev_t was already created with make_dev(). At that point I will release the integrated mega-patch for your convenience. This entire load of patches will be committed in rapid order followed by a bump to __FreeBSD_version, probably next weekend. When that has settled down a bit, I will send the meaty part of the dev_t reference counting patch in review. Background: All this comes about because of device driver unloading. To be able to tell that we can safely unload a device driver, we need to be sure that a thread has not just entered the drivers open() routine but not yet done anything useful there. To be able to check this, we need to have a sort of reference counts on dev_t. The way this gets implemented is that struct cdevsw{} presented to make_dev() will get put on a linked list, and all dev_t's created against that cdevsw{} will be hung off a list from the cdevsw{}. the dev_t will grow a reference count field and functions to grab/release a reference will be added. When destroy_dev() is called, the dev_t is removed from the list of the cdevsw{} and added to the dead_cdevsw{} list, and when its reference count decreases to zero, it can be released/recycled. To unload a device driver, after doing any private EBUSY checks, the unload code will check if any dev_t's hang off the cdevsw{}, and if this is not the case, the driver can safely be unloaded. (safely with respect to it's cdevsw that is). -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.