All of lore.kernel.org
 help / color / mirror / Atom feed
From: serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org
To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org,
	ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org,
	lxc-devel-cunTk1MwBs9qMoObBWhMNEqPaTDuhLve2LY78lusg7I@public.gmane.org,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org,
	tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org
Subject: [PATCH 5/8] kernfs: define kernfs_node_dentry
Date: Fri, 29 Jan 2016 02:54:08 -0600	[thread overview]
Message-ID: <1454057651-23959-6-git-send-email-serge.hallyn__17262.2901424349$1454057701$gmane$org@ubuntu.com> (raw)
In-Reply-To: <1454057651-23959-1-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>

From: Aditya Kali <adityakali-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>

Add a new kernfs api is added to lookup the dentry for a particular
kernfs path.

Signed-off-by: Aditya Kali <adityakali-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Serge E. Hallyn <serge.hallyn-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Acked-by: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
---
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
	20160104 - kernfs_node_dentry: lock inode for lookup_one_len()
---
 fs/kernfs/mount.c      |   69 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/kernfs.h |    2 ++
 2 files changed, 71 insertions(+)

diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index 8eaf417..074bb8b 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,74 @@ 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);
+		mutex_lock(&d_inode(dentry)->i_mutex);
+		dtmp = lookup_one_len(kntmp->name, dentry, strlen(kntmp->name));
+		mutex_unlock(&d_inode(dentry)->i_mutex);
+		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

  parent reply	other threads:[~2016-01-29  8:54 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-29  8:54 CGroup Namespaces (v10) serge.hallyn
2016-01-29  8:54 ` serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54 ` [PATCH 1/8] kernfs: Add API to generate relative kernfs path serge.hallyn
2016-01-29  8:54   ` serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54 ` [PATCH 2/8] sched: new clone flag CLONE_NEWCGROUP for cgroup namespace serge.hallyn
2016-01-29  8:54   ` serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54 ` [PATCH 3/8] cgroup: introduce cgroup namespaces serge.hallyn
2016-01-29  8:54   ` serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
     [not found] ` <1454057651-23959-1-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2016-01-29  8:54   ` [PATCH 1/8] kernfs: Add API to generate relative kernfs path serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54   ` [PATCH 2/8] sched: new clone flag CLONE_NEWCGROUP for cgroup namespace serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54   ` [PATCH 3/8] cgroup: introduce cgroup namespaces serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54   ` [PATCH 4/8] cgroup: cgroup namespace setns support serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54     ` serge.hallyn
2016-01-29  8:54   ` serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA [this message]
2016-01-29  8:54   ` [PATCH 6/8] cgroup: mount cgroupns-root when inside non-init cgroupns serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54   ` [PATCH 7/8] cgroup: Add documentation for cgroup namespaces serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54   ` [PATCH 8/8] Add FS_USERNS_FLAG to cgroup fs serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-31 17:48   ` [PATCH] selftests/cgroupns: new test for cgroup namespaces Alban Crequy
2016-01-31 17:48     ` Alban Crequy
2016-02-10 17:48     ` Serge E. Hallyn
2016-02-10 17:48       ` Serge E. Hallyn
     [not found]     ` <1454262492-6480-1-git-send-email-alban-lYLaGTFnO9sWenYVfaLwtA@public.gmane.org>
2016-02-10 17:48       ` Serge E. Hallyn
2016-02-11 23:18   ` [lxc-devel] CGroup Namespaces (v10) Alban Crequy
2016-02-26 13:18   ` Alban Crequy
2016-01-29  8:54 ` [PATCH 5/8] kernfs: define kernfs_node_dentry serge.hallyn
2016-01-29  8:54   ` serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54 ` [PATCH 6/8] cgroup: mount cgroupns-root when inside non-init cgroupns serge.hallyn
2016-01-29  8:54   ` serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54 ` [PATCH 7/8] cgroup: Add documentation for cgroup namespaces serge.hallyn
2016-01-29  8:54   ` serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-29  8:54 ` [PATCH 8/8] Add FS_USERNS_FLAG to cgroup fs serge.hallyn
2016-02-16 18:05   ` Tejun Heo
2016-02-16 18:05     ` Tejun Heo
     [not found]   ` <1454057651-23959-9-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2016-02-16 18:05     ` Tejun Heo
2016-02-11 23:18 ` [lxc-devel] CGroup Namespaces (v10) Alban Crequy
2016-02-11 23:18   ` Alban Crequy
     [not found]   ` <CAMXgnP6eSQjsuPXdrbaHytujVSkizPd4cJJQwQcuSCLAgVcYJw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-02-12 16:09     ` Tejun Heo
2016-02-12 16:09       ` Tejun Heo
     [not found]       ` <20160212160906.GG3741-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2016-02-12 23:22         ` Serge E. Hallyn
2016-02-12 23:22       ` Serge E. Hallyn
2016-02-12 23:22         ` Serge E. Hallyn
     [not found]         ` <20160212232221.GA31062-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2016-02-15 21:17           ` Tejun Heo
2016-02-15 21:17         ` Tejun Heo
2016-02-15 21:17           ` Tejun Heo
     [not found]           ` <20160215211705.GQ3965-piEFEHQLUPpN0TnZuCh8vA@public.gmane.org>
2016-02-15 21:20             ` Tejun Heo
2016-02-15 21:20           ` Tejun Heo
2016-02-15 21:20             ` Tejun Heo
2016-02-26 13:18 ` Alban Crequy
2016-02-26 13:18   ` Alban Crequy
2016-02-26 22:47   ` Serge Hallyn
2016-02-26 22:47     ` Serge Hallyn
     [not found]   ` <CAMXgnP4Wss0ctx7mHzD0WHL4+-fC59iLZNkYONE5pAeHYr18+A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-02-26 22:47     ` Serge Hallyn
  -- strict thread matches above, loose matches on Subject: below --
2016-01-04 19:54 CGroup Namespaces (v9) serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
     [not found] ` <1451937294-22589-1-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2016-01-04 19:54   ` [PATCH 5/8] kernfs: define kernfs_node_dentry serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-01-04 19:54     ` serge.hallyn
2015-12-23  4:23 CGroup Namespaces (v8) serge.hallyn
     [not found] ` <1450844609-9194-1-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2015-12-23  4:23   ` [PATCH 5/8] kernfs: define kernfs_node_dentry serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2015-12-23  4:23     ` serge.hallyn
2015-12-23 16:25     ` Tejun Heo
2015-12-23 16:25       ` Tejun Heo
     [not found]       ` <20151223162515.GI5003-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2015-12-23 16:51         ` Greg KH
2015-12-23 16:51           ` Greg KH
     [not found]     ` <1450844609-9194-6-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2015-12-23 16:25       ` Tejun Heo
2015-12-09 19:28 CGroup Namespaces (v7) serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
     [not found] ` <1449689341-28742-1-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2015-12-09 19:28   ` [PATCH 5/8] kernfs: define kernfs_node_dentry serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2015-12-09 19:28     ` serge.hallyn

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='1454057651-23959-6-git-send-email-serge.hallyn__17262.2901424349$1454057701$gmane$org@ubuntu.com' \
    --to=serge.hallyn-gewih/nmzzlqt0dzr+alfa@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lxc-devel-cunTk1MwBs9qMoObBWhMNEqPaTDuhLve2LY78lusg7I@public.gmane.org \
    --cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.