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

Kirill Tkhai ktkhai at virtuozzo.com
Mon Jan 25 13:08:27 MSK 2021


On 20.01.2021 12:56, Valeriy Vdovin wrote:
> 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 5ee5f10e3de7..4fd566414274 100644
> --- a/include/linux/cgroup-defs.h
> +++ b/include/linux/cgroup-defs.h
> @@ -362,6 +362,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 dfd9460986ee..76e38ac63333 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.
> 



More information about the Devel mailing list