[Devel] [PATCH RHEL7 COMMIT] cgroup: add function to lookup a cgroup by pathname

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jun 9 07:44:58 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.5.11
------>
commit 975cd6a892ba93e05a521c5dd6334d47a9b1395b
Author: Vladimir Davydov <vdavydov at parallels.com>
Date:   Tue Jun 9 18:44:58 2015 +0400

    cgroup: add function to lookup a cgroup by pathname
    
    Will be used later.
    
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
    Reviewed-by: Cyrill Gorcunov <gorcunov at openvz.org>
    
    Related to patchset:
    
    https://jira.sw.ru/browse/PSBM-34035
    
    Vladimir Davydov (6):
      cgroup: add function to lookup a cgroup by pathname
      cgroup: make cgroup_kernel_attach safe against cgroup removal
      ub: rename functions for reading/writing cgroup resources
      ub: rework connection between ub and mem/blkio cgroups
      memcg: pass struct mem_cgroup instead of cgroup to ub-related methods
      ub: introduce ub_total_pages
---
 fs/internal.h          |  2 --
 include/linux/cgroup.h |  2 ++
 include/linux/fs.h     |  2 ++
 kernel/cgroup.c        | 23 +++++++++++++++++++++++
 4 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/fs/internal.h b/fs/internal.h
index a592cd3..fc66b23 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -47,8 +47,6 @@ extern void __init chrdev_init(void);
  */
 extern int __inode_permission(struct inode *, int);
 extern int user_path_mountpoint_at(int, const char __user *, unsigned int, struct path *);
-extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
-			   const char *, unsigned int, struct path *);
 
 /*
  * namespace.c
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 0108a98..52fe02a 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -50,6 +50,8 @@ enum cgroup_open_flags {
 
 struct vfsmount *cgroup_kernel_mount(struct cgroup_sb_opts *opts);
 struct cgroup *cgroup_get_root(struct vfsmount *mnt);
+struct cgroup *cgroup_kernel_lookup(struct vfsmount *mnt,
+				    const char *pathname);
 struct cgroup *cgroup_kernel_open(struct cgroup *parent,
 		enum cgroup_open_flags flags, const char *name);
 int cgroup_kernel_remove(struct cgroup *parent, const char *name);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index a2044f6..e770944 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1596,6 +1596,8 @@ extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct ino
 extern int vfs_rmdir(struct inode *, struct dentry *);
 extern int vfs_unlink(struct inode *, struct dentry *, struct inode **);
 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *, struct inode **);
+extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
+			   const char *, unsigned int, struct path *);
 
 /*
  * VFS dentry helper functions.
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 6c87800..7ec90e4 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -5575,6 +5575,29 @@ struct cgroup *cgroup_get_root(struct vfsmount *mnt)
 }
 EXPORT_SYMBOL(cgroup_get_root);
 
+struct cgroup *cgroup_kernel_lookup(struct vfsmount *mnt,
+				    const char *pathname)
+{
+	int err;
+	struct path path;
+	struct dentry *dentry;
+	struct cgroup *cgrp;
+
+	err = vfs_path_lookup(mnt->mnt_root, mnt, pathname,
+			      LOOKUP_DIRECTORY, &path);
+	if (err)
+		return ERR_PTR(err);
+	dentry = path.dentry;
+	if (dentry->d_inode) {
+		cgrp = __d_cgrp(dentry);
+		atomic_inc(&cgrp->count);
+	} else
+		cgrp = ERR_PTR(-ENOENT);
+	path_put(&path);
+	return cgrp;
+}
+EXPORT_SYMBOL(cgroup_kernel_lookup);
+
 struct cgroup *cgroup_kernel_open(struct cgroup *parent,
 		enum cgroup_open_flags flags, const char *name)
 {



More information about the Devel mailing list