Page MenuHomeFreeBSD

bcache should support reads shorter than sector size
ClosedPublic

Authored by tsoome on May 20 2016, 3:37 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 25 2024, 6:45 PM
Unknown Object (File)
Dec 22 2023, 11:17 PM
Unknown Object (File)
Nov 12 2023, 9:55 AM
Unknown Object (File)
Nov 8 2023, 5:49 AM
Unknown Object (File)
Nov 6 2023, 1:46 PM
Unknown Object (File)
Nov 5 2023, 9:55 AM
Unknown Object (File)
Nov 5 2023, 8:59 AM
Unknown Object (File)
Oct 9 2023, 8:53 AM

Details

Summary

dosfs (fat file systems) can perform reads for few bytes, bcache should support such reads.

Test Plan

browsing/reading dosfs from loader.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

tsoome retitled this revision from to bcache should support reads shorter than sector size.
tsoome updated this object.
tsoome edited the test plan for this revision. (Show Details)

I don't think the message matches the diff?

The diff appears to truncate bcopied data for reads where some of the trailing blocks were not populated in to the cache with dv_strategy.

I.e., this appears to fix a logic bug that previously existed in the "check how much data can we copy" code, but does not appear to have anything to do with msdosfs or fragments.

In D6475#137183, @cem wrote:

I don't think the message matches the diff?

The diff appears to truncate bcopied data for reads where some of the trailing blocks were not populated in to the cache with dv_strategy.

I.e., this appears to fix a logic bug that previously existed in the "check how much data can we copy" code, but does not appear to have anything to do with msdosfs or fragments.

I guess the wording is not the best one, true:D but actually it has everything to do about the dosfs, because that one is the only consumer issuing the custom size reads (well, except if someone will write such code on purpose). And this is the reason why the tests did not reveal the problem till yesterday when I was working with fat32.

I think perhaps more fitting description would be that bcache read is corrupting memory by reading more data than requested - which is exactly what happens with reads from dosfs with size < 512 bytes.

Yes, that wording is better.

Still, I don't understand how this case happens. nblk is simply size / bcache_blksize, rounded up to 1; i is at most nblk; how can it possibly be the case that size > i * bcache_blksize (unless dv_strategy failed to read some blocks or we hit end of disk)? How does FAT affect this?

In the size < 512 case, assuming bcache_blksize is 512, size > 1 * 512 will not be true because size is less than 512.

In D6475#137196, @cem wrote:

Yes, that wording is better.

Still, I don't understand how this case happens. nblk is simply size / bcache_blksize, rounded up to 1; i is at most nblk; how can it possibly be the case that size > i * bcache_blksize (unless dv_strategy failed to read some blocks or we hit end of disk)? How does FAT affect this?

FAT affects it by issuing < 512B reads *and* with exact buffer for such reads.

if size < 512, we will have nblk 1, yes, so the code did fill the return buffer with 512 bytes. Also, unfortunately, writing past buffer end by 512 - size bytes *if* the provided buffer was allocated for exactly size bytes; also as an side effect, the while(size) loop in bcache_strategy() will fail to terminate, because the amount of data read is reported back 512 and the value of size in bcache_strategy() got wrapped.. Essentially the issue is, bcache code was ok for n*512 byte reads, with this patch it should be also ok for n byte reads. Well, as much as reading dosfs is working, we can pretty much say it is ok for N byte reads.

cem added a reviewer: cem.

Oh, I was missing the removed line before. Doh! Now the change makes sense.

This is essentially size = MIN(size, i * bcache_blksize). Okay.

This revision is now accepted and ready to land.May 20 2016, 5:26 PM
This revision was automatically updated to reflect the committed changes.