[PATCH 2/4] fs/buffer: parse IOCB_DONTCACHE flag in block_write_begin()

Yangtao Li posted 4 patches 3 months, 1 week ago
[PATCH 2/4] fs/buffer: parse IOCB_DONTCACHE flag in block_write_begin()
Posted by Yangtao Li 3 months, 1 week ago
When iocb flags passes IOCB_DONTCACHE, use FGP_DONTCACHE mode to get folio.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/buffer.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index f2b7b30a76ca..0ed80b62feea 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2251,11 +2251,14 @@ int block_write_begin(struct kiocb *iocb, struct address_space *mapping, loff_t
 		unsigned len, struct folio **foliop, get_block_t *get_block)
 {
 	pgoff_t index = pos >> PAGE_SHIFT;
+	fgf_t fgp = FGP_WRITEBEGIN;
 	struct folio *folio;
 	int status;
 
-	folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
-			mapping_gfp_mask(mapping));
+	if (iocb->ki_flags & IOCB_DONTCACHE)
+		fgp |= FGP_DONTCACHE;
+
+	folio = __filemap_get_folio(mapping, index, fgp, mapping_gfp_mask(mapping));
 	if (IS_ERR(folio))
 		return PTR_ERR(folio);
 
-- 
2.48.1
Re: [PATCH 2/4] fs/buffer: parse IOCB_DONTCACHE flag in block_write_begin()
Posted by Viacheslav Dubeyko 3 months ago
On Thu, 2025-06-26 at 11:30 -0600, Yangtao Li wrote:
> When iocb flags passes IOCB_DONTCACHE, use FGP_DONTCACHE mode to get
> folio.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>  fs/buffer.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/buffer.c b/fs/buffer.c
> index f2b7b30a76ca..0ed80b62feea 100644
> --- a/fs/buffer.c
> +++ b/fs/buffer.c
> @@ -2251,11 +2251,14 @@ int block_write_begin(struct kiocb *iocb,
> struct address_space *mapping, loff_t
>  		unsigned len, struct folio **foliop, get_block_t
> *get_block)
>  {
>  	pgoff_t index = pos >> PAGE_SHIFT;
> +	fgf_t fgp = FGP_WRITEBEGIN;
>  	struct folio *folio;
>  	int status;
>  
> -	folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
> -			mapping_gfp_mask(mapping));
> +	if (iocb->ki_flags & IOCB_DONTCACHE)
> +		fgp |= FGP_DONTCACHE;
> +
> +	folio = __filemap_get_folio(mapping, index, fgp,
> mapping_gfp_mask(mapping));
>  	if (IS_ERR(folio))
>  		return PTR_ERR(folio);
>  

Correct me if I am wrong. As far as I can see, the first patch depends
from  second one. It means that if somebody applies the first patch
but, somehow, don't apply the second one, then nobody will be able to
compile the kernel code. Am I correct?

Why do we need to make this modification and, then, touch other file
systems? What the justification of this? Why do we need to make this
modification at the first place?

Thanks,
Slava.