Re: [PATCH RFC] ext4: never fall back to buffered I/O for atomic direct writes

From: Ojaswin Mujoo

Date: Tue Sep 15 2026 - 03:37:01 EST


On Sun, Sep 13, 2026 at 07:18:37PM -0400, Tal Zussman wrote:
> On 9/10/26 6:58 AM, Jan Kara wrote:
> > I agree your patch makes things better but I have a question: are short
> > writes (even 0) allowed for atomic writes? I don't think so as far as my
> > understanding of atomic writes goes (and based on what I could find in the
> > code). But after your change we'd just return short write (including ret ==
> > 0) now which doesn't look ideal and also doesn't match your "so any future
> > bug yields an error rather than a torn write with a WARN()" description. So
> > as a futureproofing I'd maybe suggest just:
> >
> > if (WARN_ON_ONCE(iocb->ki_flags & IOCB_ATOMIC && ret >= 0 &&
> > iov_iter_count(from)))
> > ret = -EIO; /* or maybe -ENOPROTOOPT??? */
> >
> > before the fallback to buffered IO as a more robust solution.
> >
>
> Short writes shouldn't be allowed, so this is definitely better in terms of
> future-proofing. I'll do this with EIO but with the if (WARN_ON_ONCE())
> inside the existing ret and iov_iter_count() check to avoid duplicating the
> checks.

Hi Tal, Jan,

AFAICR the WARN_ON was mostly precautionary as we ensure in the dio path
that a during submission we ensure a write will not tear else we return
an error. Sure we can go with Jan's suggestion but I think either ways,
if we hit that WARN_ON at that point we have already torn the write so
it is actually a BUG in the sense that we have not honored the
RWF_ATOMIC contract, but hopefully that will not happen.

>
> It looks like Sashiko also found a pre-existing issue where an atomic request
> can be done non-atomically [1]. I'll see if I can reproduce it and add a fix
> as a second patch in v2.

Looking at Sashiko's comment, it does seem like a valid issue. A simple
test would be to create an inode with inline data after mounting with -o
inline_data which should force ext4_should_use_dio() to return false.

Return,
ojaswin

>
> Thanks,
> Tal


>
> [1] https://sashiko.dev/#/patchset/20260909-ext4-atomic-no-fallback-v1-1-5a6b9539c002%40columbia.edu?part=1
>
>