0

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

Jasper
  • 302
  • 3
  • 11
  • You should specify the full device mapper stack and the filesystem used on the block device. – Yann Droneaud Apr 05 '22 at 14:42
  • I can't say for certain, but the reading you describe is likely due to the partition and filesystem scanning triggered by udev rules. It sounds like perhaps for your device, this process is delayed until after you write the device once? If you let it complete, it should not happen again for subsequent writes. If you log the addresses that are read, you should find that it's looking at the beginning and end of the device for partition tables and filesystem structures. – Mike Andrews Apr 05 '22 at 22:21

0 Answers0