Re: [PATCH 10/21] block: Add fops atomic write support
From: John Garry
Date: Mon Oct 02 2023 - 06:11:42 EST
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;
+ if (iov_iter_count(iter) % atomic_write_unit_min_bytes)
+ return false;
+ if (!is_power_of_2(iov_iter_count(iter)))
+ return false;
[ ... ]
+ if (pos % iov_iter_count(iter))
+ return false;
Where do these rules come from? Is there any standard that requires
any of the above?
SCSI and NVMe have slightly different atomic writes semantics, and the
rules are created to work for both.
In addition, the rules are related to FS extent alignment.
Note that for simplicity and consistency we use the same rules for
regular files as for bdev's.
This is the coding for the rules and where they come from:
> + if (!atomic_write_unit_min_bytes)
> + return false;
If atomic_write_unit_min_bytes == 0, then we just don't support atomic
writes.
> + 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.
> + if (iov_iter_count(iter) > atomic_write_unit_max_bytes)
> + return false;
We just can't exceed this length.
> + if (pos % iov_iter_count(iter))
> + return false;
As above, ensure naturally aligned.
Thanks,
John