mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>
Subject: [PATCH 2/4] fs: tftp: cache dentries for some time
Date: Thu, 07 Nov 2024 08:23:31 +0100	[thread overview]
Message-ID: <20241107-fs-tftp-v1-2-39d7e1cff418@pengutronix.de> (raw)
In-Reply-To: <20241107-fs-tftp-v1-0-39d7e1cff418@pengutronix.de>

For TFTP we always returned invalid in the d_revalidate op. This has
the effect that we always look on the server if a file still exists, but
has also the effect that we initiate multiple tftp connections when we
want to transfer a file.

This patch introduces a grace time of two seconds in which a dentry will
be valid before looking it up on the server again. Two seconds is long
enough for not initiating multiple TFTP connections when transferring a
file and also short enough that changes on the server will be recognized
by barebox.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/tftp.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 56 insertions(+), 2 deletions(-)

diff --git a/fs/tftp.c b/fs/tftp.c
index c6edc9969f..cc9c4ab1f7 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -130,6 +130,16 @@ struct tftp_priv {
 	IPaddr_t server;
 };
 
+struct tftp_inode {
+	struct inode inode;
+	u64 time;
+};
+
+static struct tftp_inode *to_tftp_inode(struct inode *inode)
+{
+	return container_of(inode, struct tftp_inode, inode);
+}
+
 static inline bool is_block_before(uint16_t a, uint16_t b)
 {
 	return (int16_t)(b - a) > 0;
@@ -939,10 +949,14 @@ static struct inode *tftp_get_inode(struct super_block *sb, const struct inode *
                                      umode_t mode)
 {
 	struct inode *inode = new_inode(sb);
+	struct tftp_inode *node;
 
 	if (!inode)
 		return NULL;
 
+	node = to_tftp_inode(inode);
+	node->time = get_time_ns();
+
 	inode->i_ino = get_next_ino();
 	inode->i_mode = mode;
 
@@ -1015,7 +1029,47 @@ static const struct inode_operations tftp_dir_inode_operations =
 	.create = tftp_create,
 };
 
-static const struct super_operations tftp_ops;
+static struct inode *tftp_alloc_inode(struct super_block *sb)
+{
+	struct tftp_inode *node;
+
+	node = xzalloc(sizeof(*node));
+	if (!node)
+		return NULL;
+
+	return &node->inode;
+}
+
+static void tftp_destroy_inode(struct inode *inode)
+{
+	struct tftp_inode *node = to_tftp_inode(inode);
+
+	free(node);
+}
+
+static const struct super_operations tftp_ops = {
+	.alloc_inode = tftp_alloc_inode,
+	.destroy_inode = tftp_destroy_inode,
+};
+
+static int tftp_lookup_revalidate(struct dentry *dentry, unsigned int flags)
+{
+	struct tftp_inode *node;
+
+	if (!dentry->d_inode)
+		return 0;
+
+	node = to_tftp_inode(dentry->d_inode);
+
+	if (is_timeout(node->time, 2 * SECOND))
+		return 0;
+
+	return 1;
+}
+
+static const struct dentry_operations tftp_dentry_operations = {
+	.d_revalidate = tftp_lookup_revalidate,
+};
 
 static int tftp_probe(struct device *dev)
 {
@@ -1034,7 +1088,7 @@ static int tftp_probe(struct device *dev)
 	}
 
 	sb->s_op = &tftp_ops;
-	sb->s_d_op = &no_revalidate_d_ops;
+	sb->s_d_op = &tftp_dentry_operations;
 
 	inode = tftp_get_inode(sb, NULL, S_IFDIR);
 	sb->s_root = d_make_root(inode);

-- 
2.39.5




  parent reply	other threads:[~2024-11-07  8:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07  7:23 [PATCH 0/4] some fs/tftp updates Sascha Hauer
2024-11-07  7:23 ` [PATCH 1/4] fs: open loopback device before using it Sascha Hauer
2024-11-07  7:23 ` Sascha Hauer [this message]
2024-11-07  7:23 ` [PATCH 3/4] fs: kill invalid dentries Sascha Hauer
2024-11-07  7:23 ` [PATCH 4/4] fs: tftp: Set default window size to 1 Sascha Hauer
2024-11-08 13:26 ` [PATCH 0/4] some fs/tftp updates Sascha Hauer

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=20241107-fs-tftp-v1-2-39d7e1cff418@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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