bio-integrity: use hardware sectors instead of block layer sectors
Subsystems (2)
PATCH 1/1 bio-integrity: use hardware sectors instead of block layer sectors
Smatch tagged this code as suspicious because we never use the "nr_sectors" variable. Looking at the code, I think we did intend to use "nr_sectors" instead of "sectors" when we call bio_integrity_mark_tail().
The difference between "sectors" and "nr_sectors" is that "sectors" is in terms of 512 byte sectors and "nr_sectors" is in terms of hardware sectors. They are only different for 4k sector devices.
---
I'm only guessing as to the intent and I can't test this myself. Please handle with care.
fs/bio-integrity.c +1 -1
@@ -676,7 +676,7 @@ void bio_integrity_trim(struct bio *bio, unsigned int offset, nr_sectors =bio_integrity_hw_sectors (bi, sectors); bip->bip_sector = bip->bip_sector + offset;bio_integrity_mark_head (bip, offset * bi->tuple_size); -bio_integrity_mark_tail (bip, sectors * bi->tuple_size); +bio_integrity_mark_tail (bip, nr_sectors * bi->tuple_size); }EXPORT_SYMBOL (bio_integrity_trim);
Quoted 8 lines · Dan Carpenter
Smatch tagged this code as suspicious because we never use the "
nr_sectors" variable. Looking at the code, I think we did intend to use "nr_sectors" instead of "sectors" when we callbio_integrity_mark_tail().The difference between "sectors" and "
nr_sectors" is that "sectors" is in terms of 512 byte sectors and "nr_sectors" is in terms of hardware sectors. They are only different for 4k sector devices.
That code is so asking for the variable to be called "hw_sectors".
-- Jamie
PATCH v2 1/1 bio-integrity: use hardware sectors instead of block layer sectors
In reply to Dan CarpenterSmatch tagged this code as suspicious because we never use the "nr_sectors" variable. Looking at the code, we did intend to use "nr_sectors" instead of "sectors" when we call bio_integrity_mark_tail().
The difference between "sectors" and "nr_sectors" is that "sectors" is in terms of 512 byte sectors and "nr_sectors" is in terms of hardware sectors. They are only different for 4k sector devices.
Also I changed the name because as Jamie Lokier points out, "that code is so asking for the variable to be called 'hw_sectors'."
fs/bio-integrity.c +3 -3
@@ -667,16 +667,16 @@ void bio_integrity_trim(struct bio *bio, unsigned int offset, {struct bio_integrity_payload *bip = bio->bi_integrity;struct blk_integrity *bi =bdev_get_integrity (bio->bi_bdev); -unsigned int nr_sectors; +unsigned int hw_sectors;BUG_ON (bip =NULL );BUG_ON (bi =NULL );BUG_ON (!bio_flagged (bio,BIO_CLONED )); - nr_sectors =bio_integrity_hw_sectors (bi, sectors); + hw_sectors =bio_integrity_hw_sectors (bi, sectors); bip->bip_sector = bip->bip_sector + offset;bio_integrity_mark_head (bip, offset * bi->tuple_size); -bio_integrity_mark_tail (bip, sectors * bi->tuple_size); +bio_integrity_mark_tail (bip, hw_sectors * bi->tuple_size); }EXPORT_SYMBOL (bio_integrity_trim);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Dan" = Dan Carpenter <[email protected]> writes:
Dan,
This one bitrotted in my mailbox for a while because it conflicted with something else I was working on and then it slipped through the cracks. Sorry about that.
Dan> The difference between "sectors" and "nr_sectors" is that "sectors" Dan> is in terms of 512 byte sectors and "nr_sectors" is in terms of Dan> hardware sectors. They are only different for 4k sector devices.
Dan> Also I changed the name because as Jamie Lokier points out, "that Dan> code is so asking for the variable to be called 'hw_sectors'."
The change is obviously functionally correct. But I object to the notion of hw_sectors. The 1:1 mapping of DIF tuples and logical blocks is even going away in SBC3. So let's not perpetuate that.
I have a patch in my queue that gets rid of all the hw_sector references in the integrity code. I'll make sure to include your fix.
So thanks for spotting this. I obviously haven't tested PI drives with a 4KB logical block size in combination with device mapper...
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Hi,
Quoted 9 lines · Martin K. Petersen
The change is obviously functionally correct. But I object to the notion of
hw_sectors. The 1:1 mapping of DIF tuples and logical blocks is even going away in SBC3. So let's not perpetuate that.I have a patch in my queue that gets rid of all the
hw_sectorreferences in the integrity code. I'll make sure to include your fix.So thanks for spotting this. I obviously haven't tested PI drives with a 4KB logical block size in combination with device mapper...
I'm just curious: did anything come of this? Nowadays gcc 4.6 warns about the same unused nr_sector var smatch warned about, so new readers are coming to the same question of why this function doesn't use hardware sectors.