Subject: Cloning bdev/cdev devices, step one
To: None <>
From: Jason R Thorpe <>
List: tech-kern
Date: 07/05/2000 17:01:11
Hi folks...

I'm needing to add support for cloning bdev/cdev devices soon, and
also for another sort of semi-cloning device, similar to the network
pseudo-device cloning stuff I did recently.  Both are going to require
some sort of change to the devsw routines, and I think I've come up with
one that will work for both.

Essentially, for all the routines that take a `dev_t' argument now, I
want to change them to take a `struct vnode *' instead.  specinfo will
be augmented to include an opaque cookie (void *si_devcookie) which will
be available as `vp->v_devcookie' similar to how `vp->v_rdev' is available.

Instead of the dev_t argument, device open routines will get the device
from vp->v_rdev, and take appropriate action.  For devices like a regular
disk, it would be something like:

fooopen(struct vnode *vp, int oflags, int devtype, struct proc *p)
	struct foo_softc *sc;
	int unit = DISKUNIT(vp->v_rdev);

	if (unit >= foo_cd.cd_ndevs ||
	    (sc = foo_cd.cd_devs[unit]) == NULL)
		return (ENXIO);


	/* Open was successful! */
	vp->v_devcookie = sc;
	return (0);

fooread(struct vnode *vp, struct uio *uio, int ioflag)
	struct foo_softc = vp->v_devcookie;


	return (0);


This would then allow something like the ccd, raid, or vnd devices
to allocate the softc structure in the ioctl routine when the device
is actually configured, and free the softc when the device is

The drawback is that it (obviously) requires a lot of changes to various
parts of the kernel... although I think many of them can be done

Anway, this is just a rough sketch of the idea right now... any comments?

        -- Jason R. Thorpe <>