mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Ladislav Michl <ladis@linux-mips.org>
Subject: [PATCH 2/2] fs: devfs: implement d_revalidate hook
Date: Wed, 17 Oct 2018 10:43:53 +0200	[thread overview]
Message-ID: <20181017084353.5217-3-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20181017084353.5217-1-s.hauer@pengutronix.de>

The files in devfs can change withouut the fs layer noticing, so we
have to revalidate dentries before using them.

A failure could be triggered with:

ls /dev/nand0.root.ubi; ubiattach /dev/nand0.root; ls /dev/nand0.root.ubi

The first 'ls' would create a dentry for nand0.root.ubi with no inode
associated since it does not yet exist. 'ubiattach' then creates that
file, but the second 'ls' does not show it since the dentry is not
revalidated and thus no inode is added to that dentry. This patch
fixes this and also the opposite case when a file is removed (for
example with ubidetach).

Reported-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/devfs.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/fs/devfs.c b/fs/devfs.c
index d2b801036e..717e66c5dc 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -212,6 +212,32 @@ static const struct file_operations devfs_dir_operations;
 static const struct inode_operations devfs_dir_inode_operations;
 static const struct file_operations devfs_file_operations;
 
+static int devfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
+{
+	struct devfs_inode *dinode;
+	struct inode *inode;
+	struct cdev *cdev;
+
+	cdev = cdev_by_name(dentry->name);
+	if (!cdev)
+		return -ENOENT;
+
+	inode = d_inode(dentry);
+	if (!inode)
+		return 0;
+
+	dinode = container_of(inode, struct devfs_inode, inode);
+
+	if (dinode->cdev != cdev)
+		return 0;
+
+	return 1;
+}
+
+static const struct dentry_operations devfs_dentry_operations = {
+	.d_revalidate = devfs_lookup_revalidate,
+};
+
 static struct inode *devfs_get_inode(struct super_block *sb, const struct inode *dir,
                                      umode_t mode)
 {
@@ -290,6 +316,7 @@ static int devfs_probe(struct device_d *dev)
 	struct super_block *sb = &fsdev->sb;
 
 	sb->s_op = &devfs_ops;
+	sb->s_d_op = &devfs_dentry_operations;
 
 	inode = devfs_get_inode(sb, NULL, S_IFDIR);
 	sb->s_root = d_make_root(inode);
-- 
2.19.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2018-10-17  8:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-17  8:43 [PATCH 0/2] fs: add revalidating of dentries Sascha Hauer
2018-10-17  8:43 ` [PATCH 1/2] fs: implement d_revalidate Sascha Hauer
2018-10-17  8:43 ` Sascha Hauer [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=20181017084353.5217-3-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=ladis@linux-mips.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