From: "Serge E. Hallyn" <serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
To: serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org,
ebiederm-aS9lmoZGLiVWk0Htik3J/w@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,
serge-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH 2/2] mountinfo: implement show_path for kernfs and cgroup
Date: Sun, 17 Apr 2016 23:11:27 -0500 [thread overview]
Message-ID: <20160418041126.GA424@mail.hallyn.com> (raw)
In-Reply-To: <1460923472-29370-3-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
On Sun, Apr 17, 2016 at 03:04:32PM -0500, serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org wrote:
> From: Serge Hallyn <serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
>
> When showing a cgroupfs entry in mountinfo, show the
> path of the mount root dentry relative to the reader's
> cgroup namespace root.
>
> Signed-off-by: Serge Hallyn <serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
> ---
> fs/kernfs/mount.c | 14 ++++++++++++++
> include/linux/kernfs.h | 2 ++
> kernel/cgroup.c | 35 +++++++++++++++++++++++++++++++++++
> 3 files changed, 51 insertions(+)
>
> diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
> index f73541f..3b78724 100644
> --- a/fs/kernfs/mount.c
> +++ b/fs/kernfs/mount.c
> @@ -15,6 +15,7 @@
> #include <linux/slab.h>
> #include <linux/pagemap.h>
> #include <linux/namei.h>
> +#include <linux/seq_file.h>
>
> #include "kernfs-internal.h"
>
> @@ -40,6 +41,18 @@ static int kernfs_sop_show_options(struct seq_file *sf, struct dentry *dentry)
> return 0;
> }
>
> +static int kernfs_sop_show_path(struct seq_file *sf, struct dentry *dentry)
> +{
> + struct kernfs_node *node = dentry->d_fsdata;
> + struct kernfs_root *root = kernfs_root(node);
> + struct kernfs_syscall_ops *scops = root->syscall_ops;
> +
> + if (scops && scops->show_path)
> + return scops->show_path(sf, node, root);
> +
> + return seq_dentry(sf, dentry, " \t\n\\");
> +}
> +
> const struct super_operations kernfs_sops = {
> .statfs = simple_statfs,
> .drop_inode = generic_delete_inode,
> @@ -47,6 +60,7 @@ const struct super_operations kernfs_sops = {
>
> .remount_fs = kernfs_sop_remount_fs,
> .show_options = kernfs_sop_show_options,
> + .show_path = kernfs_sop_show_path,
> };
>
> /**
> diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
> index c06c442..30f089e 100644
> --- a/include/linux/kernfs.h
> +++ b/include/linux/kernfs.h
> @@ -152,6 +152,8 @@ struct kernfs_syscall_ops {
> int (*rmdir)(struct kernfs_node *kn);
> int (*rename)(struct kernfs_node *kn, struct kernfs_node *new_parent,
> const char *new_name);
> + int (*show_path)(struct seq_file *sf, struct kernfs_node *kn,
> + struct kernfs_root *root);
> };
>
> struct kernfs_root {
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index 671dc05..9a0d7b3 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -1593,6 +1593,40 @@ static int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask)
> return 0;
> }
>
> +static int cgroup_show_path(struct seq_file *sf, struct kernfs_node *kf_node,
> + struct kernfs_root *kf_root)
> +{
> + int len = 0, ret = 0;
> + char *buf = NULL;
> + struct cgroup_namespace *ns = current->nsproxy->cgroup_ns;
> + struct cgroup_root *kf_cgroot = cgroup_root_from_kf(kf_root);
> + struct cgroup *ns_cgroup;
> +
> + mutex_lock(&cgroup_mutex);
Hm, I can't grab the cgroup mutex here because I already have the
namespace_sem. But that's required by cset_cgroup_from_root(). Can
I just call that under rcu_read_lock() instead? (Not without
changing the lockdep_assert_help()). Is there another way to get the
info needed here?
> + spin_lock_bh(&css_set_lock);
> + ns_cgroup = cset_cgroup_from_root(ns->root_cset, kf_cgroot);
> + len = kernfs_path_from_node(kf_node, ns_cgroup->kn, NULL, 0);
> + if (len > 0)
> + buf = kmalloc(len + 1, GFP_ATOMIC);
> + if (buf)
> + ret = kernfs_path_from_node(kf_node, ns_cgroup->kn, buf, len + 1);
> +
> + spin_unlock_bh(&css_set_lock);
> + mutex_unlock(&cgroup_mutex);
> +
> + if (len <= 0)
> + return len;
> + if (!buf)
> + return -ENOMEM;
> + if (ret == len) {
> + seq_escape(sf, buf, " \t\n\\");
> + ret = 0;
> + } else if (ret >= 0)
> + ret = -EINVAL;
> + kfree(buf);
> + return ret;
> +}
> +
> static int cgroup_show_options(struct seq_file *seq,
> struct kernfs_root *kf_root)
> {
> @@ -5430,6 +5464,7 @@ static struct kernfs_syscall_ops cgroup_kf_syscall_ops = {
> .mkdir = cgroup_mkdir,
> .rmdir = cgroup_rmdir,
> .rename = cgroup_rename,
> + .show_path = cgroup_show_path,
> };
>
> static void __init cgroup_init_subsys(struct cgroup_subsys *ss, bool early)
> --
> 2.7.4
>
> _______________________________________________
> Containers mailing list
> Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
> https://lists.linuxfoundation.org/mailman/listinfo/containers
WARNING: multiple messages have this Message-ID (diff)
From: "Serge E. Hallyn" <serge.hallyn@ubuntu.com>
To: serge.hallyn@ubuntu.com
Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
containers@lists.linux-foundation.org, hannes@cmpxchg.org,
ebiederm@xmission.com, gregkh@linuxfoundation.org, tj@kernel.org,
cgroups@vger.kernel.org, akpm@linux-foundation.org,
serge@hallyn.com
Subject: Re: [PATCH 2/2] mountinfo: implement show_path for kernfs and cgroup
Date: Sun, 17 Apr 2016 23:11:27 -0500 [thread overview]
Message-ID: <20160418041126.GA424@mail.hallyn.com> (raw)
In-Reply-To: <1460923472-29370-3-git-send-email-serge.hallyn@ubuntu.com>
On Sun, Apr 17, 2016 at 03:04:32PM -0500, serge.hallyn@ubuntu.com wrote:
> From: Serge Hallyn <serge.hallyn@ubuntu.com>
>
> When showing a cgroupfs entry in mountinfo, show the
> path of the mount root dentry relative to the reader's
> cgroup namespace root.
>
> Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
> ---
> fs/kernfs/mount.c | 14 ++++++++++++++
> include/linux/kernfs.h | 2 ++
> kernel/cgroup.c | 35 +++++++++++++++++++++++++++++++++++
> 3 files changed, 51 insertions(+)
>
> diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
> index f73541f..3b78724 100644
> --- a/fs/kernfs/mount.c
> +++ b/fs/kernfs/mount.c
> @@ -15,6 +15,7 @@
> #include <linux/slab.h>
> #include <linux/pagemap.h>
> #include <linux/namei.h>
> +#include <linux/seq_file.h>
>
> #include "kernfs-internal.h"
>
> @@ -40,6 +41,18 @@ static int kernfs_sop_show_options(struct seq_file *sf, struct dentry *dentry)
> return 0;
> }
>
> +static int kernfs_sop_show_path(struct seq_file *sf, struct dentry *dentry)
> +{
> + struct kernfs_node *node = dentry->d_fsdata;
> + struct kernfs_root *root = kernfs_root(node);
> + struct kernfs_syscall_ops *scops = root->syscall_ops;
> +
> + if (scops && scops->show_path)
> + return scops->show_path(sf, node, root);
> +
> + return seq_dentry(sf, dentry, " \t\n\\");
> +}
> +
> const struct super_operations kernfs_sops = {
> .statfs = simple_statfs,
> .drop_inode = generic_delete_inode,
> @@ -47,6 +60,7 @@ const struct super_operations kernfs_sops = {
>
> .remount_fs = kernfs_sop_remount_fs,
> .show_options = kernfs_sop_show_options,
> + .show_path = kernfs_sop_show_path,
> };
>
> /**
> diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
> index c06c442..30f089e 100644
> --- a/include/linux/kernfs.h
> +++ b/include/linux/kernfs.h
> @@ -152,6 +152,8 @@ struct kernfs_syscall_ops {
> int (*rmdir)(struct kernfs_node *kn);
> int (*rename)(struct kernfs_node *kn, struct kernfs_node *new_parent,
> const char *new_name);
> + int (*show_path)(struct seq_file *sf, struct kernfs_node *kn,
> + struct kernfs_root *root);
> };
>
> struct kernfs_root {
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index 671dc05..9a0d7b3 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -1593,6 +1593,40 @@ static int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask)
> return 0;
> }
>
> +static int cgroup_show_path(struct seq_file *sf, struct kernfs_node *kf_node,
> + struct kernfs_root *kf_root)
> +{
> + int len = 0, ret = 0;
> + char *buf = NULL;
> + struct cgroup_namespace *ns = current->nsproxy->cgroup_ns;
> + struct cgroup_root *kf_cgroot = cgroup_root_from_kf(kf_root);
> + struct cgroup *ns_cgroup;
> +
> + mutex_lock(&cgroup_mutex);
Hm, I can't grab the cgroup mutex here because I already have the
namespace_sem. But that's required by cset_cgroup_from_root(). Can
I just call that under rcu_read_lock() instead? (Not without
changing the lockdep_assert_help()). Is there another way to get the
info needed here?
> + spin_lock_bh(&css_set_lock);
> + ns_cgroup = cset_cgroup_from_root(ns->root_cset, kf_cgroot);
> + len = kernfs_path_from_node(kf_node, ns_cgroup->kn, NULL, 0);
> + if (len > 0)
> + buf = kmalloc(len + 1, GFP_ATOMIC);
> + if (buf)
> + ret = kernfs_path_from_node(kf_node, ns_cgroup->kn, buf, len + 1);
> +
> + spin_unlock_bh(&css_set_lock);
> + mutex_unlock(&cgroup_mutex);
> +
> + if (len <= 0)
> + return len;
> + if (!buf)
> + return -ENOMEM;
> + if (ret == len) {
> + seq_escape(sf, buf, " \t\n\\");
> + ret = 0;
> + } else if (ret >= 0)
> + ret = -EINVAL;
> + kfree(buf);
> + return ret;
> +}
> +
> static int cgroup_show_options(struct seq_file *seq,
> struct kernfs_root *kf_root)
> {
> @@ -5430,6 +5464,7 @@ static struct kernfs_syscall_ops cgroup_kf_syscall_ops = {
> .mkdir = cgroup_mkdir,
> .rmdir = cgroup_rmdir,
> .rename = cgroup_rename,
> + .show_path = cgroup_show_path,
> };
>
> static void __init cgroup_init_subsys(struct cgroup_subsys *ss, bool early)
> --
> 2.7.4
>
> _______________________________________________
> Containers mailing list
> Containers@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/containers
next prev parent reply other threads:[~2016-04-18 4:11 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-17 20:04 Show virtualized dentry root in mountinfo for cgroupfs serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-04-17 20:04 ` serge.hallyn
[not found] ` <1460923472-29370-1-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2016-04-17 20:04 ` [PATCH 1/2] kernfs_path_from_node_locked: don't overwrite nlen serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-04-17 20:04 ` serge.hallyn
[not found] ` <1460923472-29370-2-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2016-04-20 19:43 ` Tejun Heo
2016-04-20 19:43 ` Tejun Heo
[not found] ` <20160420194313.GA4775-piEFEHQLUPpN0TnZuCh8vA@public.gmane.org>
2016-05-02 16:32 ` Tejun Heo
2016-05-02 16:32 ` Tejun Heo
[not found] ` <20160502163256.GT7822-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2016-05-02 16:41 ` Greg KH
2016-05-02 16:41 ` Greg KH
2016-05-02 16:32 ` Tejun Heo
2016-04-17 20:04 ` [PATCH 2/2] mountinfo: implement show_path for kernfs and cgroup serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-04-17 20:04 ` serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA
2016-04-17 20:04 ` serge.hallyn
[not found] ` <1460923472-29370-3-git-send-email-serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2016-04-18 4:11 ` Serge E. Hallyn
2016-04-18 4:11 ` Serge E. Hallyn [this message]
2016-04-18 4:11 ` Serge E. Hallyn
[not found] ` <20160418041126.GA424-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2016-04-18 5:29 ` [PATCH 3/2] cgroup_show_path: use a new helper to get current cgns css_set Serge E. Hallyn
2016-04-18 5:29 ` Serge E. Hallyn
2016-04-18 5:29 ` Serge E. Hallyn
[not found] ` <20160418052905.GA3848-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2016-04-29 21:42 ` Serge E. Hallyn
2016-04-29 21:42 ` Serge E. Hallyn
[not found] ` <20160429214254.GA13615-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2016-05-02 16:35 ` Tejun Heo
2016-05-02 16:35 ` Tejun Heo
[not found] ` <20160502163526.GW7822-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2016-05-03 14:26 ` Serge E. Hallyn
2016-05-03 14:26 ` Serge E. Hallyn
2016-05-03 14:26 ` Serge E. Hallyn
2016-05-02 16:35 ` Tejun Heo
2016-04-29 21:42 ` Serge E. Hallyn
2016-04-19 1:12 ` [PATCH 2/2] mountinfo: implement show_path for kernfs and cgroup Eric W. Biederman
2016-04-19 1:12 ` Eric W. Biederman
[not found] ` <87mvoqqu48.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2016-04-19 1:44 ` Serge E. Hallyn
2016-04-19 1:44 ` Serge E. Hallyn
[not found] ` <20160419014419.GA19080-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2016-04-19 4:05 ` Serge E. Hallyn
2016-04-19 4:05 ` Serge E. Hallyn
2016-04-19 4:05 ` Serge E. Hallyn
[not found] ` <20160419040546.GA20350-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2016-04-26 2:42 ` Serge E. Hallyn
2016-04-26 2:42 ` Serge E. Hallyn
[not found] ` <20160426024207.GA2783-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2016-04-26 10:29 ` Karel Zak
2016-04-26 10:29 ` Karel Zak
2016-04-26 10:29 ` Karel Zak
[not found] ` <20160426102925.vkydkjtrsnibuc7c-xkT7n84Rsxv/9pzu0YdTqQ@public.gmane.org>
2016-04-26 14:36 ` Serge E. Hallyn
2016-04-26 14:36 ` Serge E. Hallyn
[not found] ` <20160426143622.GA11021-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2016-05-02 16:33 ` Tejun Heo
2016-05-02 16:33 ` Tejun Heo
2016-04-26 14:36 ` Serge E. Hallyn
2016-04-19 1:44 ` Serge E. Hallyn
2016-04-19 1:12 ` Eric W. Biederman
2016-05-02 16:34 ` Tejun Heo
2016-05-02 16:34 ` Tejun Heo
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=20160418041126.GA424@mail.hallyn.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=serge-A9i7LUbDfNHQT0dZR+AlfA@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.