'How to edit a bio write request

I'm writing a device-mapper which has to edit incoming writes, for example: Incoming bio request contains a biovec with a page full of 0s, and I want to change it to all 1s.

I tried using bvec_kmap_local() to get the page address, and then I can read the data and if needed adjust it using memcpy or similar. Initial tests seemed to work, but if I execute things like mkfs on the created dm, I get a lot of segmentation faults. I narrowed down the problem that this only happens if I actually write something to the mapped page. However, I see no reason why it should cause this fault as I (after checking probably 100 times) don't access invalid memory. I'm wondering if my method of editing the write is actually correct?

Thanks! I can provide way more information if needed



Solution 1:[1]

So apparently you're not supposed to edit the pages of a bio request, since write submitters (like file systems) expect their data buffers not to be modified. Instead, you should create a new one with the page you want it to be, and submit it.

Solution 2:[2]

As you are using then on this.storage.get("city"), this.city has not been set yet when you call this.cdp.getCityData(this.city). Just use await properly.

Also, some basic tips:

  • if(a == b){...} else if(a != b){...} is essentially just if(a == b){...}else{...}
  • if(condition){value = true}else{value = false} is essentially just value = condition

async ionViewWillEnter() {
    try
    {
        this.city = await this.storage.get("city");
        this.hidden = this.city == null;
    }
    catch (error)
    {
        alert("Error accessing storage.")
    }

    this.cdp.getCityData(this.city).subscribe(data =>
    {
        this.cityData = data;

        this.capital = data[0].capital.toString().toLowerCase();
        this.cityLowerCase = this.city.toLowerCase();

        this.showHeader(this.cityLowerCase, this.capital);

    });
}

showHeader(a: string, b: string) {
    this.hiddenTwo = a != b;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jasper
Solution 2 Ricky Mo