[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220802030342.46302-8-jefflexu@linux.alibaba.com>
Date: Tue, 2 Aug 2022 11:03:40 +0800
From: Jingbo Xu <jefflexu@...ux.alibaba.com>
To: dhowells@...hat.com, linux-cachefs@...hat.com
Cc: linux-kernel@...r.kernel.org, xiang@...nel.org
Subject: [PATCH RFC 7/9] cachefiles: free content map on invalidate
Free the content map when the cached file is invalidated. Also hole
punch the backing content map file if any.
Signed-off-by: Jingbo Xu <jefflexu@...ux.alibaba.com>
---
fs/cachefiles/content-map.c | 21 +++++++++++++++++++++
fs/cachefiles/interface.c | 1 +
fs/cachefiles/internal.h | 1 +
3 files changed, 23 insertions(+)
diff --git a/fs/cachefiles/content-map.c b/fs/cachefiles/content-map.c
index 949ec5d9e4c9..b73a109844ca 100644
--- a/fs/cachefiles/content-map.c
+++ b/fs/cachefiles/content-map.c
@@ -250,3 +250,24 @@ loff_t cachefiles_find_next_hole(struct cachefiles_object *object,
return min_t(loff_t, result * CACHEFILES_GRAN_SIZE,
object->cookie->object_size);
}
+
+void cachefiles_invalidate_content_map(struct cachefiles_object *object)
+{
+ struct file *file = object->volume->content_map[(u8)object->cookie->key_hash];
+
+ if (object->content_info != CACHEFILES_CONTENT_MAP)
+ return;
+
+ write_lock_bh(&object->content_map_lock);
+ free_pages((unsigned long)object->content_map,
+ get_order(object->content_map_size));
+ object->content_map = NULL;
+ object->content_map_size = 0;
+
+ if (object->content_map_off != CACHEFILES_CONTENT_MAP_OFF_INVAL) {
+ vfs_fallocate(file, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+ object->content_map_off, object->content_map_size);
+ object->content_map_off = CACHEFILES_CONTENT_MAP_OFF_INVAL;
+ }
+ write_unlock_bh(&object->content_map_lock);
+}
diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index 4cfbdc87b635..f87b9a665d85 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -409,6 +409,7 @@ static bool cachefiles_invalidate_cookie(struct fscache_cookie *cookie)
old_file = object->file;
object->file = new_file;
+ cachefiles_invalidate_content_map(object);
object->content_info = CACHEFILES_CONTENT_NO_DATA;
set_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags);
set_bit(FSCACHE_COOKIE_NEEDS_UPDATE, &object->cookie->flags);
diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
index 506700809a6d..c674c4e42529 100644
--- a/fs/cachefiles/internal.h
+++ b/fs/cachefiles/internal.h
@@ -187,6 +187,7 @@ extern loff_t cachefiles_find_next_granule(struct cachefiles_object *object,
loff_t start);
extern loff_t cachefiles_find_next_hole(struct cachefiles_object *object,
loff_t start);
+extern void cachefiles_invalidate_content_map(struct cachefiles_object *object);
/*
* daemon.c
--
2.27.0
Powered by blists - more mailing lists