[PATCH] cachefiles: set HAVE_DATA only after successful writes
From: Yichong Chen
Date: Thu Aug 27 2026 - 22:35:31 EST
FSCACHE_COOKIE_HAVE_DATA means that the backend stored data for the cookie.
cachefiles_write_complete() currently sets it unconditionally. This also
happens when the cache write failed.
A failed cache write should not make fscache_note_page_release() believe
that there is data to read from the cache. Set the flag only when the
write completion reports that some data was written.
Fixes: 047487c947e8 ("cachefiles: Implement the I/O routines")
Signed-off-by: Yichong Chen <chenyichong@xxxxxxxxxxxxx>
---
fs/cachefiles/io.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c
index 9540ec25b3cb..0f94ec2aa5c8 100644
--- a/fs/cachefiles/io.c
+++ b/fs/cachefiles/io.c
@@ -269,7 +269,8 @@ static void cachefiles_write_complete(struct kiocb *iocb, long ret)
cachefiles_trace_write_error);
atomic_long_sub(ki->b_writing, &object->volume->cache->b_writing);
- set_bit(FSCACHE_COOKIE_HAVE_DATA, &object->cookie->flags);
+ if (ret > 0)
+ set_bit(FSCACHE_COOKIE_HAVE_DATA, &object->cookie->flags);
if (ki->term_func)
ki->term_func(ki->term_func_priv, ret);
cachefiles_put_kiocb(ki);
--
2.51.0