[v9,5/9] ve/cgroup: saving root_css to ve

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

Details

Message ID 1587049785-68528-6-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.
Signed-off-by: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>
---
 include/linux/ve.h | 7 +++++++
 kernel/ve/ve.c     | 6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/include/linux/ve.h b/include/linux/ve.h
index 362dae1..02e00e9 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -127,6 +127,13 @@  struct ve_struct {
 	struct kmapset_key	sysfs_perms_key;
 
 	struct workqueue_struct	*wq;
+
+	/*
+	 * All tasks, that belong to this ve, live
+	 * in cgroups, that are children to cgroups
+	 * that form this css_set.
+	 */
+	struct css_set		*root_css_set;
 };
 
 struct ve_devmnt {
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 0f7392d..eedb85d 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -450,6 +450,8 @@  static void ve_grab_context(struct ve_struct *ve)
 
 	get_task_struct(tsk);
 	ve->init_task = tsk;
+	ve->root_css_set = tsk->cgroups;
+	get_css_set(ve->root_css_set);
 	ve->init_cred = (struct cred *)get_current_cred();
 	rcu_assign_pointer(ve->ve_ns, get_nsproxy(tsk->nsproxy));
 	ve->ve_netns =  get_net(ve->ve_ns->net_ns);
@@ -462,6 +464,9 @@  static void ve_drop_context(struct ve_struct *ve)
 	put_net(ve->ve_netns);
 	ve->ve_netns = NULL;
 
+	put_css_set_taskexit(ve->root_css_set);
+	ve->root_css_set = NULL;
+
 	/* Allows to dereference init_cred and init_task if ve_ns is set */
 	rcu_assign_pointer(ve->ve_ns, NULL);
 	synchronize_rcu();
@@ -474,7 +479,6 @@  static void ve_drop_context(struct ve_struct *ve)
 
 	put_task_struct(ve->init_task);
 	ve->init_task = NULL;
-
 }
 
 static const struct timespec zero_time = { };

Comments

Kirill Tkhai April 16, 2020, 3:42 p.m.
On 16.04.2020 18:09, Valeriy Vdovin wrote:
> Signed-off-by: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>

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

> ---
>  include/linux/ve.h | 7 +++++++
>  kernel/ve/ve.c     | 6 +++++-
>  2 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/ve.h b/include/linux/ve.h
> index 362dae1..02e00e9 100644
> --- a/include/linux/ve.h
> +++ b/include/linux/ve.h
> @@ -127,6 +127,13 @@ struct ve_struct {
>  	struct kmapset_key	sysfs_perms_key;
>  
>  	struct workqueue_struct	*wq;
> +
> +	/*
> +	 * All tasks, that belong to this ve, live
> +	 * in cgroups, that are children to cgroups
> +	 * that form this css_set.
> +	 */
> +	struct css_set		*root_css_set;
>  };
>  
>  struct ve_devmnt {
> diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
> index 0f7392d..eedb85d 100644
> --- a/kernel/ve/ve.c
> +++ b/kernel/ve/ve.c
> @@ -450,6 +450,8 @@ static void ve_grab_context(struct ve_struct *ve)
>  
>  	get_task_struct(tsk);
>  	ve->init_task = tsk;
> +	ve->root_css_set = tsk->cgroups;
> +	get_css_set(ve->root_css_set);
>  	ve->init_cred = (struct cred *)get_current_cred();
>  	rcu_assign_pointer(ve->ve_ns, get_nsproxy(tsk->nsproxy));
>  	ve->ve_netns =  get_net(ve->ve_ns->net_ns);
> @@ -462,6 +464,9 @@ static void ve_drop_context(struct ve_struct *ve)
>  	put_net(ve->ve_netns);
>  	ve->ve_netns = NULL;
>  
> +	put_css_set_taskexit(ve->root_css_set);
> +	ve->root_css_set = NULL;
> +
>  	/* Allows to dereference init_cred and init_task if ve_ns is set */
>  	rcu_assign_pointer(ve->ve_ns, NULL);
>  	synchronize_rcu();
> @@ -474,7 +479,6 @@ static void ve_drop_context(struct ve_struct *ve)
>  
>  	put_task_struct(ve->init_task);
>  	ve->init_task = NULL;
> -
>  }
>  
>  static const struct timespec zero_time = { };
>