linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zizhi Wo <wozizhi@huawei.com>
To: <netfs@lists.linux.dev>, <dhowells@redhat.com>, <jlayton@kernel.org>
Cc: <hsiangkao@linux.alibaba.com>, <jefflexu@linux.alibaba.com>,
	<zhujia.zj@bytedance.com>, <linux-erofs@lists.ozlabs.org>,
	<linux-fsdevel@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<wozizhi@huawei.com>, <libaokun1@huawei.com>,
	<yangerkun@huawei.com>, <houtao1@huawei.com>,
	<yukuai3@huawei.com>
Subject: [PATCH 4/8] cachefiles: Clear invalid cache data in advance
Date: Wed, 21 Aug 2024 10:42:57 +0800	[thread overview]
Message-ID: <20240821024301.1058918-5-wozizhi@huawei.com> (raw)
In-Reply-To: <20240821024301.1058918-1-wozizhi@huawei.com>

In the current on-demand loading scenario, when umount is called, the
cachefiles_commit_tmpfile() is invoked. When checking the inode
corresponding to object->file is inconsistent with the dentry,
cachefiles_unlink() is called to perform cleanup to prevent invalid data
from occupying space.

The above operation does not apply to the first mount, because the cache
dentry generated by the first mount must be negative. Moreover, there is no
need to clear it during the first umount because this part of the data may
be reusable in the future. But the problem is that, the clean operation can
currently only be called through cachefiles_withdraw_cookie(), in other
words the redundant data does not cleaned until the second umount. This
means that during the second mount, the old cache data generated from the
first mount still occupies space. So if the user does not manually clean up
the previous cache before the next mount, it may return insufficient space
during the second mount phase.

This patch adds an additional cleanup process in the cachefiles_open_file()
function. When the auxdata check fails, the remaining old cache data is no
longer needed, the file and dentry corresponding to the object are also
put. As there is no need to clear it until umount, we can directly clear it
during the mount process.

Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
---
 fs/cachefiles/namei.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index f53977169db4..70b0b3477085 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -542,7 +542,7 @@ static bool cachefiles_create_file(struct cachefiles_object *object)
  * stale.
  */
 static bool cachefiles_open_file(struct cachefiles_object *object,
-				 struct dentry *dentry)
+				 struct dentry *dir, struct dentry *dentry)
 {
 	struct cachefiles_cache *cache = object->volume->cache;
 	struct file *file;
@@ -601,10 +601,18 @@ static bool cachefiles_open_file(struct cachefiles_object *object,
 check_failed:
 	fscache_cookie_lookup_negative(object->cookie);
 	cachefiles_unmark_inode_in_use(object, file);
-	fput(file);
-	dput(dentry);
-	if (ret == -ESTALE)
+	__fput_sync(file);
+	if (ret == -ESTALE) {
+		/* When the auxdata check fails, the remaining old cache data
+		 * is no longer needed, and we will clear it here first.
+		 */
+		inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
+		cachefiles_unlink(cache, object, dir, dentry, FSCACHE_OBJECT_IS_STALE);
+		inode_unlock(d_inode(dir));
+		dput(dentry);
 		return cachefiles_create_file(object);
+	}
+	dput(dentry);
 	return false;
 
 error_fput:
@@ -654,7 +662,7 @@ bool cachefiles_look_up_object(struct cachefiles_object *object)
 		goto new_file;
 	}
 
-	if (!cachefiles_open_file(object, dentry))
+	if (!cachefiles_open_file(object, fan, dentry))
 		return false;
 
 	_leave(" = t [%lu]", file_inode(object->file)->i_ino);
-- 
2.39.2


  parent reply	other threads:[~2024-08-21  2:47 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-21  2:42 [PATCH 0/8] netfs/cachefiles: Some bugfixes Zizhi Wo
2024-08-21  2:42 ` [PATCH 1/8] cachefiles: Fix incorrect block calculations in __cachefiles_prepare_write() Zizhi Wo
2024-08-21  2:42 ` [PATCH 2/8] cachefiles: Fix incorrect length return value in cachefiles_ondemand_fd_write_iter() Zizhi Wo
2024-08-21  2:42 ` [PATCH 3/8] cachefiles: Fix missing pos updates " Zizhi Wo
2024-08-21  2:42 ` Zizhi Wo [this message]
2024-08-21  2:42 ` [PATCH 5/8] cachefiles: Clean up in cachefiles_commit_tmpfile() Zizhi Wo
2024-08-21  2:42 ` [PATCH 6/8] cachefiles: Modify inappropriate error return value in cachefiles_daemon_secctx() Zizhi Wo
2024-08-21  2:43 ` [PATCH 7/8] cachefiles: Fix NULL pointer dereference in object->file Zizhi Wo
2024-08-21  2:43 ` [PATCH 8/8] netfs/fscache: Add a memory barrier for FSCACHE_VOLUME_CREATING Zizhi Wo
2024-10-10  3:08 ` [PATCH 0/8] netfs/cachefiles: Some bugfixes Zizhi Wo
2024-10-10  3:31   ` Gao Xiang
2024-10-10  4:08     ` Zizhi Wo
2024-10-10 10:34 ` [PATCH 1/8] cachefiles: Fix incorrect block calculations in __cachefiles_prepare_write() David Howells
2024-10-10 11:11   ` Zizhi Wo
2024-10-10 11:36   ` David Howells
2024-10-10 12:17     ` Zizhi Wo
2024-10-10 13:15     ` Zizhi Wo
2024-10-10 11:16 ` [PATCH 4/8] cachefiles: Clear invalid cache data in advance David Howells
2024-10-10 11:23 ` [PATCH 5/8] cachefiles: Clean up in cachefiles_commit_tmpfile() David Howells
2024-10-10 11:24 ` [PATCH 8/8] netfs/fscache: Add a memory barrier for FSCACHE_VOLUME_CREATING David Howells
2024-10-10 11:26 ` [PATCH 7/8] cachefiles: Fix NULL pointer dereference in object->file David Howells
2024-10-10 12:04   ` Zizhi Wo
2024-10-10 14:52   ` David Howells
2024-10-11  1:31     ` Zizhi Wo
2024-10-10 11:26 ` [PATCH 3/8] cachefiles: Fix missing pos updates in cachefiles_ondemand_fd_write_iter() David Howells
2024-10-10 11:31 ` [PATCH 6/8] cachefiles: Modify inappropriate error return value in cachefiles_daemon_secctx() David Howells
2024-10-10 11:47   ` Zizhi Wo

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=20240821024301.1058918-5-wozizhi@huawei.com \
    --to=wozizhi@huawei.com \
    --cc=dhowells@redhat.com \
    --cc=houtao1@huawei.com \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=jefflexu@linux.alibaba.com \
    --cc=jlayton@kernel.org \
    --cc=libaokun1@huawei.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netfs@lists.linux.dev \
    --cc=yangerkun@huawei.com \
    --cc=yukuai3@huawei.com \
    --cc=zhujia.zj@bytedance.com \
    /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;
as well as URLs for NNTP newsgroup(s).