[2/7] cgroup: Added rcu node string wrapper for in-cgroup usage.

Submitted by Valeriy Vdovin on April 1, 2020, 3:41 p.m.

Details

Message ID 1585755688-20348-3-git-send-email-valeriy.vdovin@virtuozzo.com
State New
Series "Make release_agent per-cgroup property. Run release_agent in proper ve."
Headers show

Commit Message

Valeriy Vdovin April 1, 2020, 3:41 p.m.
This will be used in further patches in same patchset.

Signed-off-by: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>
---
 include/linux/cgroup.h |  7 +++++++
 kernel/cgroup.c        | 11 +++++++++++
 2 files changed, 18 insertions(+)

Patch hide | download patch | download mbox

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index bd48216..36c7b8f8 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -233,6 +233,13 @@  struct cgroup_name {
 	char name[];
 };
 
+struct cgroup_rcu_string {
+	struct rcu_head rcu_head;
+	char val[];
+};
+
+struct cgroup_rcu_string *cgroup_rcu_strdup(const char *str, int len);
+
 struct cgroup {
 	unsigned long flags;		/* "unsigned long" so bitops work */
 
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 50d4b3d..3df28a2 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -774,6 +774,17 @@  static struct inode *cgroup_new_inode(umode_t mode, struct super_block *sb)
 	return inode;
 }
 
+struct cgroup_rcu_string *cgroup_rcu_strdup(const char *str, int len)
+{
+	struct cgroup_rcu_string *result;
+
+	result = kmalloc(sizeof(*result) + len + 1, GFP_KERNEL);
+	if (!result)
+		return NULL;
+	strcpy(result->val, str);
+	return result;
+}
+
 static struct cgroup_name *cgroup_alloc_name(struct dentry *dentry)
 {
 	struct cgroup_name *name;

Comments

Pavel Tikhomirov April 2, 2020, 8:17 a.m.
On 4/1/20 6:41 PM, Valeriy Vdovin wrote:
> This will be used in further patches in same patchset.
> 
> Signed-off-by: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>
> ---
>   include/linux/cgroup.h |  7 +++++++
>   kernel/cgroup.c        | 11 +++++++++++
>   2 files changed, 18 insertions(+)
> 
> diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
> index bd48216..36c7b8f8 100644
> --- a/include/linux/cgroup.h
> +++ b/include/linux/cgroup.h
> @@ -233,6 +233,13 @@ struct cgroup_name {
>   	char name[];
>   };
>   
> +struct cgroup_rcu_string {
> +	struct rcu_head rcu_head;
> +	char val[];
> +};
> +
> +struct cgroup_rcu_string *cgroup_rcu_strdup(const char *str, int len);
> +
>   struct cgroup {
>   	unsigned long flags;		/* "unsigned long" so bitops work */
>   
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index 50d4b3d..3df28a2 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -774,6 +774,17 @@ static struct inode *cgroup_new_inode(umode_t mode, struct super_block *sb)
>   	return inode;
>   }
>   
> +struct cgroup_rcu_string *cgroup_rcu_strdup(const char *str, int len)
> +{
> +	struct cgroup_rcu_string *result;
> +
> +	result = kmalloc(sizeof(*result) + len + 1, GFP_KERNEL);
> +	if (!result)
> +		return NULL;
> +	strcpy(result->val, str);

You might want to switch to use strlcpy instead to be able to catch 
buffer overflow errors here.

> +	return result;
> +}
> +
>   static struct cgroup_name *cgroup_alloc_name(struct dentry *dentry)
>   {
>   	struct cgroup_name *name;
>