[PATCH 2/4] fs: tftp: cache dentries for some time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux