Skip to contentSkip to conversation

cachefiles: set HAVE_DATA only after successful writes

PATCH New Yichong Chen 1 participant 1 message Aug 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cachefiles: set HAVE_DATA only after successful writes

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")
---
 fs/cachefiles/io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/cachefiles/io.c +2 -1
index 9540ec25b3cb..0f94ec2aa5c8 100644
@@ -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);
Signature · 1 line
2.51.0