2017-11-05 14:15:13 +00:00
|
|
|
# mod_hello
|
|
|
|
|
2017-11-05 14:50:18 +00:00
|
|
|
|
|
|
|
## building
|
|
|
|
|
|
|
|
```shell
|
|
|
|
make all
|
|
|
|
```
|
|
|
|
|
|
|
|
This produces `./helloctl/helloctl` binary for talking to the `mod_hello` over
|
|
|
|
ioctl through `/dev/helloctl`, as well as `./mod_hello.ko` kernel module
|
|
|
|
itself.
|
|
|
|
|
|
|
|
|
|
|
|
## Testing
|
|
|
|
|
|
|
|
### Host
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$> make build
|
|
|
|
$> sudo insmod ./mod_hello.ko
|
|
|
|
$> sudo dmesg | tail
|
|
|
|
[ 1679.566426] [mod_hello] pid: 8418, comm: insmod
|
|
|
|
[ 1679.566427] [mod_hello] module loaded.
|
|
|
|
[ 1679.566428] [mod_hello] looking up 'files'
|
|
|
|
[ 1679.574011] [mod_hello] files 0xffffffff87e57e40
|
|
|
|
[ 1679.574013] [mod_hello] files (0xffffffff87e57e40): usage
|
|
|
|
[ 1679.579120] [mod_hello] fib of 0 and 1 (up to 10000000): 8644293272739028509 (in only 5 jiffies)
|
|
|
|
$> sudo ./helloctl/helloctl
|
|
|
|
$> sudo dmesg | tail -1
|
|
|
|
[ 1734.248270] [mod_hello] received command: 1
|
|
|
|
```
|
|
|
|
|
|
|
|
### Container
|
|
|
|
|
|
|
|
Running ioctl's inside containers is a little tricky.
|
|
|
|
Assuming we've already `insmod` the module above:
|
|
|
|
|
|
|
|
```shell
|
2017-11-05 16:31:16 +00:00
|
|
|
sudo docker run -it --rm -v $(pwd)/helloctl/helloctl:/usr/bin/helloctl:ro -v /dev/helloctl:/dev/helloctl:ro fedora /usr/bin/helloctl
|
2017-11-05 14:50:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
You'll get a failure `Could not open /dev/helloctl`
|
|
|
|
|
|
|
|
```shell
|
2017-11-05 16:31:16 +00:00
|
|
|
sudo docker run -it --rm -v $(pwd)/helloctl/helloctl:/usr/bin/helloctl:ro -v /dev/helloctl:/dev/helloctl:ro --privileged fedora /usr/bin/helloctl
|
2017-11-05 14:50:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Now `dmesg | tail` will reflect the command ran successfully.
|
|
|
|
|
|
|
|
### cleanup
|
|
|
|
|
|
|
|
```shell
|
|
|
|
make clean
|
|
|
|
sudo rmmod mod_hello
|
|
|
|
```
|