On 29/09/2023 18:51, Bart Van Assche wrote:
On 9/29/23 03:27, John Garry wrote:> + if (pos % atomic_write_unit_min_bytes)
> + return false;
See later rules.
> + if (iov_iter_count(iter) % atomic_write_unit_min_bytes)
> + return false;
For SCSI, there is an atomic write granularity, which dictates atomic_write_unit_min_bytes. So here we need to ensure that the length is a multiple of this value.
> + if (!is_power_of_2(iov_iter_count(iter)))
> + return false;
This rule comes from FS block alignment and NVMe atomic boundary.
FSes (XFS) have discontiguous extents. We need to ensure that an atomic write does not cross discontiguous extents. To do this we ensure extent length and alignment and limit atomic_write_unit_max_bytes to that.
For NVMe, an atomic write boundary is a boundary in LBA space which an atomic write should not cross. We limit atomic_write_unit_max_bytes such that it is evenly divisible into this atomic write boundary.
To ensure that the write does not cross these alignment boundaries we say that it must be naturally aligned and a power-of-2 in length.
We may be able to relax this rule but I am not sure it buys us anything - typically we want to be writing a 64KB block aligned to 64KB, for example.