Re: Dynamic modules
On Mon, 4 May 2015, Kamil Rytarowski wrote: 3. Is it possible to automatically create a device file in /dev from a module? Not really, at least not from a loaded kernel module. On the other hand, modules are also applicable to rump environments, and you _can_ dynamically create the /dev entry (in a rump'd file system, of course). For an example, please have a look at src/sys/rump/dev/lib/libsysmon/sysmon_component.c 4. What is the best way to extract the major from devsw_attach call in case we let it to automatically generate the major? For now I'm using printf(9) and I'm checking dmesg(8). This gives me an output for mknod(8) with an appropriate value. You could always create a sysctl and make the return values from devsw_attach() available to user-land. BTW, devsw_attach() doesn't automatically generate the major. It does a lookup in the majors table. If there is no entry in the table, you get an error. (At least, that's how I read that code. If I've misinterpreted, I'd be happy to have someone explain how it really works!) - | Paul Goyette | PGP Key fingerprint: | E-mail addresses: | | (Retired)| FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com| | Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org | -
re: Dynamic modules
BTW, devsw_attach() doesn't automatically generate the major. It does a lookup in the majors table. If there is no entry in the table, you get an error. see eg this line in devsw_attach(): newptr = kmem_zalloc(new * DEVSWCONV_SIZE, KM_NOSLEEP); for what happens when the entry isn't found. err, and this doesn't generate a major. the function itself needs you to pass them in, so your idea of hard coding is as good as any today. .mrg.
re: Dynamic modules
3. Is it possible to automatically create a device file in /dev from a module? Not really, at least not from a loaded kernel module. sure you can. ipfilter was doing this back with LKMs in the 90s :-) BTW, devsw_attach() doesn't automatically generate the major. It does a lookup in the majors table. If there is no entry in the table, you get an error. see eg this line in devsw_attach(): newptr = kmem_zalloc(new * DEVSWCONV_SIZE, KM_NOSLEEP); for what happens when the entry isn't found. .mrg.
re: Dynamic modules
matthew green writes: BTW, devsw_attach() doesn't automatically generate the major. It does a lookup in the majors table. If there is no entry in the table, you get an error. see eg this line in devsw_attach(): newptr = kmem_zalloc(new * DEVSWCONV_SIZE, KM_NOSLEEP); for what happens when the entry isn't found. err, and this doesn't generate a major. the function itself needs you to pass them in, so your idea of hard coding is as good as any today. as Jared points out, it does work, and you can see that this happens in [bc]devsw_attach().
Re: Dynamic modules
Sent: Monday, May 04, 2015 at 11:39 AM From: Paul Goyette p...@vps1.whooppee.com To: Kamil Rytarowski n...@gmx.com Cc: tech-kern@netbsd.org Subject: Re: Dynamic modules On Mon, 4 May 2015, Kamil Rytarowski wrote: 3. Is it possible to automatically create a device file in /dev from a module? Not really, at least not from a loaded kernel module. I see. On the other hand, modules are also applicable to rump environments, and you _can_ dynamically create the /dev entry (in a rump'd file system, of course). For an example, please have a look at src/sys/rump/dev/lib/libsysmon/sysmon_component.c Interesting note! 4. What is the best way to extract the major from devsw_attach call in case we let it to automatically generate the major? For now I'm using printf(9) and I'm checking dmesg(8). This gives me an output for mknod(8) with an appropriate value. You could always create a sysctl and make the return values from devsw_attach() available to user-land. BTW, devsw_attach() doesn't automatically generate the major. It does a lookup in the majors table. If there is no entry in the table, you get an error. (At least, that's how I read that code. If I've misinterpreted, I'd be happy to have someone explain how it really works!) I see, so there is no good mechanism for something called by me automatic major pickup. So my best try is to choose the major number and hard-code it in the module. Thanks!