Lkm: Last Block Written to Device

LKM: Last block written to device

The Linux kernel provides several different tracing toolkits; the blktrace tools were designed specifically for block devices. The blkparse(1) tool will parse the output of the blktrace(8) utility. (At least Ubuntu has these packaged in the blktrace package; I expect other distributions to be similar.) The bklparse(1) tool can give you the sector information.

Documentation/trace/events.txt describes another tracing mechanism -- one that could allow you to follow the block:block_bio_complete event, which includes the sector information. This won't require installing the bkltrace toolkit but I'll (sheepishly) admit that I don't know where to read the trace log.

Creating entry in /proc from LKM

In .read and .write callbacks, it is usually needed to update loff_t *pos before return.
If your module has read or written count bytes, increment *pos by that amount.

Besides that, note that when .read callback returns 0, it indicates an EOF. If it never returns 0, the system will loop indefinitely trying to "read the file to the end" when you cat the file. That is why returning 1 the first time and then 0 worked.

How to communicate between LKM and pthread?

Yes. Possible.

LKM need to intimate the user space once the interrupt is occurred in your case.

In ISR, a fifo kind of mechanism can be used to notify to user space. Where as a thread(say pthread) is in blocked read on that fifo can start processing once the LKM writes in to it.

Linux Kernel Module/IOCTL: inappropriate ioctl for device

Okay. So. Here's the solution.

In Linux kernel 2.6.x the declaration for _ioctl calls changed from

static long wait_ioctl(struct inode *, struct file *, unsigned int, unsigned long);

To:

static long wait_ioctl(struct file *, unsigned int, unsigned long);

The fix is thus:

...
static long wait_ioctl(struct file *, unsigned int, unsigned long);
...
static long wait_ioctl(struct file *file, unsigned int cmd, unsigned long sub_cmd){
if(_IOC_TYPE(cmd) != WAIT_DEVICE_MAGIC){
printk(KERN_INFO "[wait device] invalid magic number: %u:%u:%u", _IOC_TYPE(cmd), cmd, WAIT_DEVICE_MAGIC);
return -ENOTTY;
}
....


Related Topics



Leave a reply



Submit