From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: dhowells@redhat.com, linux-cachefs@redhat.com
Cc: linux-kernel@vger.kernel.org, xiang@kernel.org
Subject: [PATCH RFC 9/9] cachefiles: cull content map file on cull
Date: Tue, 2 Aug 2022 11:03:42 +0800 [thread overview]
Message-ID: <20220802030342.46302-10-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20220802030342.46302-1-jefflexu@linux.alibaba.com>
Also hole punch the backing content map file when the backing object
gets culled.
When cacehfilesd is going to cull a whole directory, the whole
directory will be moved to the graveyard and then cacehfilesd itself
will remove all files under the directory one by one. Since each
sub-directory under one volume maintains one backing content map file,
cacehfilesd already works well with this bitmap-based mechanism and
doesn't need any refactoring.
Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
fs/cachefiles/content-map.c | 37 +++++++++++++++++++++++++++++++++++++
fs/cachefiles/internal.h | 4 ++++
fs/cachefiles/namei.c | 4 ++++
fs/cachefiles/xattr.c | 17 +++++++++++++++++
4 files changed, 62 insertions(+)
diff --git a/fs/cachefiles/content-map.c b/fs/cachefiles/content-map.c
index 360c59b06670..5584a0182df9 100644
--- a/fs/cachefiles/content-map.c
+++ b/fs/cachefiles/content-map.c
@@ -294,3 +294,40 @@ void cachefiles_shorten_content_map(struct cachefiles_object *object,
out:
read_unlock_bh(&object->content_map_lock);
}
+
+int cachefiles_cull_content_map(struct cachefiles_cache *cache,
+ struct dentry *dir, struct dentry *victim)
+{
+ struct dentry *map;
+ struct file *map_file;
+ size_t content_map_size = 0;
+ loff_t content_map_off = 0;
+ struct path path;
+ int ret;
+
+ if (!d_is_reg(victim))
+ return 0;
+
+ ret = cachefiles_get_content_info(victim, &content_map_size, &content_map_off);
+ if (ret || !content_map_size)
+ return ret;
+
+ map = lookup_positive_unlocked("Map", dir, strlen("Map"));
+ if (IS_ERR(map))
+ return PTR_ERR(map);
+
+ path.mnt = cache->mnt;
+ path.dentry = map;
+ map_file = open_with_fake_path(&path, O_RDWR | O_LARGEFILE,
+ d_backing_inode(map), cache->cache_cred);
+ if (IS_ERR(map_file)) {
+ dput(map);
+ return PTR_ERR(map_file);
+ }
+
+ ret = vfs_fallocate(map_file, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+ content_map_off, content_map_size);
+
+ fput(map_file);
+ return ret;
+}
diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
index 7747f99f00c1..9c36631ee051 100644
--- a/fs/cachefiles/internal.h
+++ b/fs/cachefiles/internal.h
@@ -190,6 +190,8 @@ extern loff_t cachefiles_find_next_hole(struct cachefiles_object *object,
extern void cachefiles_invalidate_content_map(struct cachefiles_object *object);
extern void cachefiles_shorten_content_map(struct cachefiles_object *object,
loff_t new_size);
+extern int cachefiles_cull_content_map(struct cachefiles_cache *cache,
+ struct dentry *dir, struct dentry *victim);
/*
* daemon.c
@@ -384,6 +386,8 @@ extern int cachefiles_remove_object_xattr(struct cachefiles_cache *cache,
extern void cachefiles_prepare_to_write(struct fscache_cookie *cookie);
extern bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume);
extern int cachefiles_check_volume_xattr(struct cachefiles_volume *volume);
+extern int cachefiles_get_content_info(struct dentry *dentry,
+ size_t *content_map_size, loff_t *content_map_off);
/*
* Error handling
diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index f5e1ec1d9445..79c759468ab3 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -923,6 +923,10 @@ int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
if (ret < 0)
goto error_unlock;
+ ret = cachefiles_cull_content_map(cache, dir, victim);
+ if (ret < 0)
+ goto error;
+
ret = cachefiles_bury_object(cache, NULL, dir, victim,
FSCACHE_OBJECT_WAS_CULLED);
if (ret < 0)
diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
index 05ac6b70787a..b7091c8e4262 100644
--- a/fs/cachefiles/xattr.c
+++ b/fs/cachefiles/xattr.c
@@ -283,3 +283,20 @@ int cachefiles_check_volume_xattr(struct cachefiles_volume *volume)
_leave(" = %d", ret);
return ret;
}
+
+int cachefiles_get_content_info(struct dentry *dentry, size_t *content_map_size,
+ loff_t *content_map_off)
+{
+ struct cachefiles_xattr buf;
+ ssize_t xlen, tlen = sizeof(buf);
+
+ xlen = vfs_getxattr(&init_user_ns, dentry, cachefiles_xattr_cache, &buf, tlen);
+ if (xlen != tlen)
+ return -ESTALE;
+
+ if (buf.content == CACHEFILES_CONTENT_MAP) {
+ *content_map_off = be64_to_cpu(buf.content_map_off);
+ *content_map_size = be64_to_cpu(buf.content_map_size);
+ }
+ return 0;
+}
--
2.27.0
prev parent reply other threads:[~2022-08-02 3:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 3:03 [RFC PATCH 0/9] cachefiles: content map Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 1/9] cachefiles: improve FSCACHE_COOKIE_NO_DATA_TO_READ optimization Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 2/9] cachefiles: add content map file helpers Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 3/9] cachefiles: allocate per-subdir content map files Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 4/9] cachefiles: alloc/load/save content map Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 5/9] cachefiles: mark content map on write to the backing file Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 6/9] cachefiles: check content map on read/write Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 7/9] cachefiles: free content map on invalidate Jingbo Xu
2022-08-02 3:03 ` [PATCH RFC 8/9] cachefiles: resize content map on resize Jingbo Xu
2022-08-02 3:03 ` Jingbo Xu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220802030342.46302-10-jefflexu@linux.alibaba.com \
--to=jefflexu@linux.alibaba.com \
--cc=dhowells@redhat.com \
--cc=linux-cachefs@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®