[Devel] [PATCH RH8] ve: fix reading container state from cgroup

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Fri Jul 9 17:42:12 MSK 2021


1) ve->op_sem is needed to remove race with ve_start_container when
ve->is_running == 0 but ve->ve_ns != NULL already, and for a short
moment we would print "STOPPING" if read state on container start

2) add !ve->ve_ns check for showing STOPPED just to be more consistent
with vz7 and don't show STOPPED if we still see non-null ve->ve_ns.

So now we have:

RUNNING                 | STOPPED
is_running==true        | is_running==false
                        | ve_ns==NULL
			| !cgroup_is_populated()

Before these patch we were able to see STARTING instead of STOPPING and
vice versa.

https://jira.sw.ru/browse/PSBM-82766

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Reviewed-by: Kirill Tkhai <ktkhai at virtuozzo.com>

rebase to vz8:
Reworked:
- bring back ve_ns check from vz7 for consistency
- leave cgroup_is_populated as it looks like a valid replacement for
nr_threads_ve
- remove rcu_access_pointer as we are under ve->op_sem anyway

https://jira.sw.ru/browse/PSBM-131412
https://jira.sw.ru/browse/PSBM-127798
(cherry-picked from commit 1c182ff3216c ("ve: fix reading container
state from cgroup"))
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 kernel/ve/ve.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 9667f9051c02..dc920cdf5921 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1147,15 +1147,17 @@ static int ve_state_show(struct seq_file *sf, void *v)
 	struct cgroup_subsys_state *css = seq_css(sf);
 	struct ve_struct *ve = css_to_ve(css);
 
+	down_read(&ve->op_sem);
 	if (ve->is_running)
 		seq_puts(sf, "RUNNING");
-	else if (!cgroup_is_populated(css->cgroup))
+	else if (!cgroup_is_populated(css->cgroup) && !ve->ve_ns)
 		seq_puts(sf, "STOPPED");
-	else if (rcu_access_pointer(ve->ve_ns))
+	else if (ve->ve_ns)
 		seq_puts(sf, "STOPPING");
 	else
 		seq_puts(sf, "STARTING");
 	seq_putc(sf, '\n');
+	up_read(&ve->op_sem);
 
 	return 0;
 }
-- 
2.31.1



More information about the Devel mailing list