[Devel] [PATCH VZ8 v2 04/14] cgroup: added rcu node string wrapper for in-cgroup usage. This will be used in further patches in same patchset.

Valeriy Vdovin valeriy.vdovin at virtuozzo.com
Wed Feb 10 13:02:55 MSK 2021


Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>

Reviewed-by: Kirill Tkhai <ktkhai at virtuozzo.com>
(Cherry-picked from e828803a5d776125c9c329f194aff74fb4ec181a)
Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
Reviewed-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 include/linux/cgroup-defs.h |  5 +++++
 include/linux/cgroup.h      |  4 ++++
 kernel/cgroup/cgroup-v1.c   | 15 +++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index a3b309ab1a90..772fcee71f37 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -360,6 +360,11 @@ struct cgroup_freezer_state {
 	int nr_frozen_tasks;
 };
 
+struct cgroup_rcu_string {
+	struct rcu_head rcu_head;
+	char val[];
+};
+
 struct cgroup {
 	/* self css with NULL ->ss, points back to this cgroup */
 	struct cgroup_subsys_state self;
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index c0a42c3d43fa..808b31605d07 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -689,6 +689,10 @@ static inline union kernfs_node_id *cgroup_get_kernfs_id(struct cgroup *cgrp)
 
 void cgroup_path_from_kernfs_id(const union kernfs_node_id *id,
 					char *buf, size_t buflen);
+
+struct cgroup_rcu_string;
+
+struct cgroup_rcu_string *cgroup_rcu_strdup(const char *str, int len);
 #else /* !CONFIG_CGROUPS */
 
 struct cgroup_subsys_state;
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
index db10a1ed282a..fb06fc9d96ca 100644
--- a/kernel/cgroup/cgroup-v1.c
+++ b/kernel/cgroup/cgroup-v1.c
@@ -231,6 +231,21 @@ static void cgroup_pidlist_destroy_work_fn(struct work_struct *work)
 	kfree(tofree);
 }
 
+struct cgroup_rcu_string *cgroup_rcu_strdup(const char *str, int len)
+{
+	struct cgroup_rcu_string *result;
+	size_t buflen = len + 1;
+
+	result = kmalloc(sizeof(*result) + buflen, GFP_KERNEL);
+	if (!result)
+		return ERR_PTR(-ENOMEM);
+	if (strlcpy(result->val, str, buflen) >= buflen) {
+		kfree(result);
+		return ERR_PTR(-ENAMETOOLONG);
+	}
+	return result;
+}
+
 /*
  * pidlist_uniq - given a kmalloc()ed list, strip out all duplicate entries
  * Returns the number of unique elements.
-- 
2.27.0



More information about the Devel mailing list