Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1297245 > unrolled thread
| Started by | serge.hallyn@ubuntu.com |
|---|---|
| First post | 2015-12-23 05:30 +0100 |
| Last post | 2015-12-23 18:00 +0100 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 5/8] kernfs: define kernfs_node_dentry serge.hallyn@ubuntu.com - 2015-12-23 05:30 +0100
Re: [PATCH 5/8] kernfs: define kernfs_node_dentry Tejun Heo <tj@kernel.org> - 2015-12-23 17:30 +0100
Re: [PATCH 5/8] kernfs: define kernfs_node_dentry Greg KH <gregkh@linuxfoundation.org> - 2015-12-23 18:00 +0100
| From | serge.hallyn@ubuntu.com |
|---|---|
| Date | 2015-12-23 05:30 +0100 |
| Subject | [PATCH 5/8] kernfs: define kernfs_node_dentry |
| Message-ID | <qIJdN-4TG-19@gated-at.bofh.it> |
From: Aditya Kali <adityakali@google.com>
Add a new kernfs api is added to lookup the dentry for a particular
kernfs path.
Signed-off-by: Aditya Kali <adityakali@google.com>
Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com>
---
Changelog:
20151116 - Don't allow user namespaces to bind new subsystems
20151118 - postpone the FS_USERNS_MOUNT flag until the
last patch, until we can convince ourselves it
is safe.
20151207 - Switch to walking up the kernfs path from kn root.
20151208 - Split out the kernfs change
- Style changes
- Switch from pr_crit to WARN_ON
- Reorder arguments to kernfs_obtain_root
- rename kernfs_obtain_root to kernfs_node_dentry
---
fs/kernfs/mount.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/kernfs.h | 2 ++
2 files changed, 69 insertions(+)
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index 8eaf417..7224296 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -14,6 +14,7 @@
#include <linux/magic.h>
#include <linux/slab.h>
#include <linux/pagemap.h>
+#include <linux/namei.h>
#include "kernfs-internal.h"
@@ -62,6 +63,72 @@ struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)
return NULL;
}
+/*
+ * find the next ancestor in the path down to @child, where @parent was the
+ * ancestor whose descendant we want to find.
+ *
+ * Say the path is /a/b/c/d. @child is d, @parent is NULL. We return the root
+ * node. If @parent is b, then we return the node for c.
+ * Passing in d as @parent is not ok.
+ */
+static struct kernfs_node *
+find_next_ancestor(struct kernfs_node *child, struct kernfs_node *parent)
+{
+ if (child == parent) {
+ pr_crit_once("BUG in find_next_ancestor: called with parent == child");
+ return NULL;
+ }
+
+ while (child->parent != parent) {
+ if (!child->parent)
+ return NULL;
+ child = child->parent;
+ }
+
+ return child;
+}
+
+/**
+ * kernfs_node_dentry - get a dentry for the given kernfs_node
+ * @kn: kernfs_node for which a dentry is needed
+ * @sb: the kernfs super_block
+ */
+struct dentry *kernfs_node_dentry(struct kernfs_node *kn,
+ struct super_block *sb)
+{
+ struct dentry *dentry;
+ struct kernfs_node *knparent = NULL;
+
+ BUG_ON(sb->s_op != &kernfs_sops);
+
+ dentry = dget(sb->s_root);
+
+ /* Check if this is the root kernfs_node */
+ if (!kn->parent)
+ return dentry;
+
+ knparent = find_next_ancestor(kn, NULL);
+ if (WARN_ON(!knparent))
+ return ERR_PTR(-EINVAL);
+
+ do {
+ struct dentry *dtmp;
+ struct kernfs_node *kntmp;
+
+ if (kn == knparent)
+ return dentry;
+ kntmp = find_next_ancestor(kn, knparent);
+ if (WARN_ON(!kntmp))
+ return ERR_PTR(-EINVAL);
+ dtmp = lookup_one_len(kntmp->name, dentry, strlen(kntmp->name));
+ dput(dentry);
+ if (IS_ERR(dtmp))
+ return dtmp;
+ knparent = kntmp;
+ dentry = dtmp;
+ } while (1);
+}
+
static int kernfs_fill_super(struct super_block *sb, unsigned long magic)
{
struct kernfs_super_info *info = kernfs_info(sb);
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index 716bfde..c06c442 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -284,6 +284,8 @@ struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry);
struct kernfs_root *kernfs_root_from_sb(struct super_block *sb);
struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn);
+struct dentry *kernfs_node_dentry(struct kernfs_node *kn,
+ struct super_block *sb);
struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops,
unsigned int flags, void *priv);
void kernfs_destroy_root(struct kernfs_root *root);
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Tejun Heo <tj@kernel.org> |
|---|---|
| Date | 2015-12-23 17:30 +0100 |
| Message-ID | <qIUsy-3wT-19@gated-at.bofh.it> |
| In reply to | #1297245 |
On Tue, Dec 22, 2015 at 10:23:26PM -0600, serge.hallyn@ubuntu.com wrote: > From: Aditya Kali <adityakali@google.com> > > Add a new kernfs api is added to lookup the dentry for a particular > kernfs path. > > Signed-off-by: Aditya Kali <adityakali@google.com> > Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com> Greg, this is the other kernfs change in the series. Can I route this through the cgroup tree with other changes? Thanks. -- tejun -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Greg KH <gregkh@linuxfoundation.org> |
|---|---|
| Date | 2015-12-23 18:00 +0100 |
| Message-ID | <qIUVA-3GD-9@gated-at.bofh.it> |
| In reply to | #1297531 |
On Wed, Dec 23, 2015 at 11:25:15AM -0500, Tejun Heo wrote: > On Tue, Dec 22, 2015 at 10:23:26PM -0600, serge.hallyn@ubuntu.com wrote: > > From: Aditya Kali <adityakali@google.com> > > > > Add a new kernfs api is added to lookup the dentry for a particular > > kernfs path. > > > > Signed-off-by: Aditya Kali <adityakali@google.com> > > Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com> > > Greg, this is the other kernfs change in the series. Can I route this > through the cgroup tree with other changes? Yes, please do. Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web