Date: Sun, 17 Feb 2008 22:24:57 +0100 From: Ed Schouten <ed@fxq.nl> To: freebsd-arch@freebsd.org Subject: Device minor number uniqueness Message-ID: <20080217212457.GX1340@hoeg.nl>
next in thread | raw e-mail | index | archive | help
--va9XEZk9/dJ5GUjX Content-Type: multipart/mixed; boundary="vM12nk/63StVgfqY" Content-Disposition: inline --vM12nk/63StVgfqY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, This week I was looking at the ttycreate() function in tty.c. As you can see, it generates unique numbers and passes them to make_dev() to make sure each TTY device node has its own number. The manual page has a rather brief description of the `minor' argument of make_dev(): The cdev returned by make_dev() and make_dev_alias() has two fields, si_drv1 and si_drv2, that are available to store state. Both fields a= re of type void *. These are designed to replace the minor argument to make_dev(). I discovered you get a panic when you call make_dev() multiple times with the same minor number, because newdev() always walks down the device list to return an existing device which shares the same minor number. After digging into some more source code, it turns out a lot of drivers use minor number to store device numbers and such, but there is no real reason why we should enforce drivers to use unique minor numbers. Because we cannot change this behaviour at once, I'm proposing the following patch, which adds a new flag called D_MULTIMINOR. This flag allows you to create multiple devices that share the same minor number. This way there is no need for creating your own unrhdr to hold some kind of free list. --=20 Ed Schouten <ed@fxq.nl> WWW: http://g-rave.nl/ --vM12nk/63StVgfqY Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="make_dev.diff" Content-Transfer-Encoding: quoted-printable =3D=3D=3D=3D //depot/user/ed/mpsafetty/sys/kern/kern_conf.c#3 - /home/ed/p4= /mpsafetty/sys/kern/kern_conf.c =3D=3D=3D=3D @@ -458,10 +458,12 @@ =20 mtx_assert(&devmtx, MA_OWNED); udev =3D y; - LIST_FOREACH(si2, &csw->d_devs, si_list) { - if (si2->si_drv0 =3D=3D udev) { - dev_free_devlocked(si); - return (si2); + if (!(csw->d_flags & D_MULTIMINOR)) { + LIST_FOREACH(si2, &csw->d_devs, si_list) { + if (si2->si_drv0 =3D=3D udev) { + dev_free_devlocked(si); + return (si2); + } } } si->si_drv0 =3D udev; =3D=3D=3D=3D //depot/user/ed/mpsafetty/sys/sys/conf.h#3 - /home/ed/p4/mpsaf= etty/sys/sys/conf.h =3D=3D=3D=3D @@ -171,6 +171,7 @@ #define D_MMAP_ANON 0x00100000 /* special treatment in vm_mmap.c */ #define D_PSEUDO 0x00200000 /* make_dev() can return NULL */ #define D_NEEDGIANT 0x00400000 /* driver want Giant */ +#define D_MULTIMINOR 0x00800000 /* don't track minor numbers */ =20 /* * Version numbers. --vM12nk/63StVgfqY-- --va9XEZk9/dJ5GUjX Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (FreeBSD) iEYEARECAAYFAke4pigACgkQ52SDGA2eCwXR6wCff1IHRNanZ/QP0utNXpAVkFPF UEMAnR2SNtGWau6WpcLyX30zI98F26F3 =OzuT -----END PGP SIGNATURE----- --va9XEZk9/dJ5GUjX--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080217212457.GX1340>