sg ioengine's alignment check fails for 528 /4224
Please acknowledge the following before creating a ticket
- I have read the GitHub issues section of REPORTING-BUGS.
Bug: sg ioengine's alignment check in fio_sgio_prep() (engines/sg.c) uses io_u->xfer_buflen & (sd->bs - 1) to validate block alignment. This is only correct when sd->bs is a power of two. For SCSI devices formatted with non-power-of-two logical block sizes (SAS T10 DIF/PI drives commonly use 520/524/528/4224-byte sectors), this bitmask produces incorrect results.
Environment: RHEL9, ppc64le, fio-3.42-148-g6bc57
Reproduction: Device formatted 528-byte logical blocks (confirmed via sg_readcap -l, and independently confirmed via strace that fio's own READ CAPACITY(10) call correctly retrieves block length=528):
fio --name=test --filename=/dev/sgN --ioengine=sg --rw=randrw --bs=528 --iodepth=1 --runtime=5 --time_based
→ fails with "read/write not sector aligned" even though bs exactly equals the device's real logical block length.
Same device with bs=4224 (8× the real block length) succeeds, and 528 & 527 = 512 (nonzero) vs 4224 & 527 = 0 shows the check is bit-pattern dependent rather than a true modulo test — e.g. 3*528=1584 & 527 = 512 also incorrectly fails despite being a valid multiple of the block size.
Fix: change the bitmask to a real modulo:
c
- if (io_u->xfer_buflen & (sd->bs - 1)) {
- if (io_u->xfer_buflen % sd->bs) {
Confirmed fixed locally: previously-failing bs=528 and bs=4224 cases against 528-byte and 4224-byte native SAS drives both now complete cleanly with real I/O.
Source: axboe/fio