On Fri, Jun 27, 2025 at 06:03:09PM +0100, Matthew Wilcox wrote:
> On Fri, Jun 27, 2025 at 11:03:13AM +0000, 陈涛涛 Taotao Chen wrote:
> > +++ b/fs/ext4/inode.c
> > @@ -1270,6 +1270,9 @@ static int ext4_write_begin(const struct kiocb *iocb,
> >     if (unlikely(ret))
> >             return ret;
> >  
> > +   if (iocb->ki_flags & IOCB_DONTCACHE)
> > +           fgp |= FGP_DONTCACHE;
> 
> I think this needs to be:
> 
>       if (iocb && iocb->ki_flags & IOCB_DONTCACHE)
> 
> because it's legit to call write_begin with a NULL argument.  The
> 'file' was always an optional argument, and we should preserve that
> optionality with this transformation.

write_begin and write_end are only callbacks through helpers called
by the file system.  So if the file system never passes a NULL
file/kiocb it doesn't need to check for it.

> I wonder if it's worth abstracting some of this boilerplate.  Something
> like:
> 
> struct folio *write_begin_get_folio(iocb, mapping, index, len)
> {
>       fgf_t fgflags = FGP_WRITEBEGIN;
> 
>       if (iocb && iocb->ki_flags & IOCB_DONTCACHE)
>               fgflags |= FGP_DONTCACHE;
>       fgflags |= fgf_set_order(len);
> 
>       return __filemap_get_folio(mapping, index, fgflags,
>                       mapping_gfp_mask(mapping));
> }

But this helper still seems useful.

Reply via email to