On 2/20/22 09:56, Douglas Gilbert wrote: > On 2022-02-19 17:46, Martin K. Petersen wrote: >> >> Douglas, >> >>> What should the sd driver do when it gets the error in the subject >>> line? Try again, and again, and again, and again ...? >>> >>> sd 2:0:1:0: [sdb] Unaligned partial completion (resid=3584, sector_sz=4096) >>> sd 2:0:1:0: [sdb] tag#407 CDB: Read(16) 88 00 00 00 00 00 00 00 00 00 00 00 00 01 00 >>> >>> Not very productive, IMO. Perhaps, after say 3 retries getting the >>> _same_ resid, it might rescan that disk. There is a big hint in the >>> logged data shown above: trying to READ 1 block (sector_sz=4096) and >>> getting a resid of 3584. So it got back 512 bytes (again and again >>> ...). The disk isn't mounted so perhaps it is being prepared. And >>> maybe that preparation involved a MODE SELECT which changed the LB >>> size in its block descriptor, prior to a FORMAT UNIT. >> >> The kernel doesn't inspect passthrough commands to track whether an >> application is doing MODE SELECT or FORMAT UNIT. The burden is generally >> on the application to do the right thing. > > No, of course not. But the kernel should inspect all UAs especially the one > that says: CAPACITY DATA HAS CHANGED ! > >> I'm assuming we're trying to read the partition table. Did the device >> somehow get closed between the MODE SELECT and the FORMAT UNIT? > > Nope, look up "format corrupt" state in SBC, there is a asc/ascq code for > that, and it was _not_ reported in this case. The disk was fine after those > two commands, it was sd or the scsi mid-level that didn't observe the UAs, > hence the snafu. Sending a READ command after a CAPACITY DATA HAS CHANGE > UA is "undefined behaviour" as the say in the C/C++ spec. > > Also more and more settings in SCSI *** are giving the option to return an > error (even MEDIUM ERROR) if the initiator is reading a block that has never > been written. So if the sd driver is looking for a partition table (LBA 0 ?) > then you have a chicken and egg problem that retrying will not solve. It is not the scsi driver looking for partitions. This is generic block layer code rescanning the partition table together with disk revalidate after the bdev is closed. The disk revalidate should have caught the change in LBA size, so it may be that the partition scan is before revalidate instead of after... That would need checking. >>> Another issue with that error message: what does "unaligned" mean in >>> this context? Surely it is superfluous and "Partial completion" is >>> more accurate (unless the resid is negative). >> >> The "unaligned" term comes from ZBC. > > The sd driver should take its lead from SBC, not ZBC. It was observed in the past that some HBAs (Broadcom I think it was) returned a resid not aligned to the LBA size with 4Kn disks, making it impossible to restart the command to process the reminder of the data. This problem was especially apparent with ZBC disks writes. So unaligned here is not just for ZBC disks. > > Doug Gilbert > > > *** for example, FORMAT UNIT (FFMT=2) > -- Damien Le Moal Western Digital Research