[v9,2/9] cgroup: added rcu node string wrapper for in-cgroup usage.

Submitted by Valeriy Vdovin on April 16, 2020, 3:09 p.m.

Details

Message ID 1587049785-68528-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 16, 2020, 3:09 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        | 15 +++++++++++++++
 2 files changed, 22 insertions(+)

Patch hide | download patch | download mbox

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index aa91e47..d671309 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -210,6 +210,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 9ca8af9..1f799a8 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -772,6 +772,21 @@  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;
+	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;
+}
+
 static struct cgroup_name *cgroup_alloc_name(struct dentry *dentry)
 {
 	struct cgroup_name *name;

Comments

Kirill Tkhai April 16, 2020, 3:39 p.m.
On 16.04.2020 18:09, 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        | 15 +++++++++++++++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
> index aa91e47..d671309 100644
> --- a/include/linux/cgroup.h
> +++ b/include/linux/cgroup.h
> @@ -210,6 +210,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 9ca8af9..1f799a8 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -772,6 +772,21 @@ 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;
> +	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);

Here is wrong indent, it has to be fixed. Except that, the rest looks OK for me.

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>

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