I created a very simple device mapper device like in the code below. It just prints "Reading test device" whenever a read is performed on the device, and similarly it prints "Writing test device" when a write is performed.
If I now create the device, write to it and then check dmesg
I see "Writing test device", and then about 40 - 50 logs "Reading test device".
My question is if anyone knows the reason why so many reads are performed on a simple write? Or is something wrong in my code?
static int test_map(struct dm_target *ti, struct bio *bio)
{
switch (bio_op(bio)) {
case REQ_OP_READ:
printk("Reading from test device.");
break;
case REQ_OP_WRITE:
printk("Writing to test device.");
break;
default:
return DM_MAPIO_KILL;
}
bio_endio(bio);
return DM_MAPIO_SUBMITTED;
}
I figured this is the only helpful code to show