[v2,11/57] pid: Add equel_pid() helper

Submitted by Kirill Tkhai on March 28, 2017, 3:35 p.m.

Details

Message ID 149071534795.12770.13601766831126849900.stgit@localhost.localdomain
State New
Series "Nested pid namespaces support"
Headers show

Commit Message

Kirill Tkhai March 28, 2017, 3:35 p.m.
This allows to compare pids values on the whole hierarhy.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/include/pid.h |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/include/pid.h b/criu/include/pid.h
index 475b17a3..478e5d0b 100644
--- a/criu/include/pid.h
+++ b/criu/include/pid.h
@@ -4,6 +4,7 @@ 
 #include <compel/task-state.h>
 #include "stdbool.h"
 #include "rbtree.h"
+#include "log.h"
 
 /*
  * Task states, used in e.g. struct pid's state.
@@ -45,6 +46,22 @@  struct pid {
 	} ns[1]; /* Must be at the end of struct pid */
 };
 
+#define equal_pid(a, b)							\
+({									\
+	int ___i, ___ret = true;					\
+	if (a->level == b->level) {					\
+		for (___i = 0; ___i < a->level; ___i++)			\
+			if (a->ns[___i].virt != b->ns[___i].virt) {	\
+				___ret = false;				\
+				break;					\
+			}						\
+	} else {							\
+		pr_err("Wrong pid nesting level\n");			\
+		___ret = false;						\
+	}								\
+	___ret;								\
+})
+
 /*
  * When we have to restore a shared resource, we mush select which
  * task should do it, and make other(s) wait for it. In order to

Comments

Andrey Vagin April 7, 2017, 12:33 a.m.
On Tue, Mar 28, 2017 at 06:35:47PM +0300, Kirill Tkhai wrote:
> This allows to compare pids values on the whole hierarhy.
> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>  criu/include/pid.h |   17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/criu/include/pid.h b/criu/include/pid.h
> index 475b17a3..478e5d0b 100644
> --- a/criu/include/pid.h
> +++ b/criu/include/pid.h
> @@ -4,6 +4,7 @@
>  #include <compel/task-state.h>
>  #include "stdbool.h"
>  #include "rbtree.h"
> +#include "log.h"
>  
>  /*
>   * Task states, used in e.g. struct pid's state.
> @@ -45,6 +46,22 @@ struct pid {
>  	} ns[1]; /* Must be at the end of struct pid */
>  };
>  
> +#define equal_pid(a, b)							\
> +({									\
> +	int ___i, ___ret = true;					\
> +	if (a->level == b->level) {					\
> +		for (___i = 0; ___i < a->level; ___i++)			\
> +			if (a->ns[___i].virt != b->ns[___i].virt) {	\
> +				___ret = false;				\
> +				break;					\
> +			}						\
> +	} else {							\
> +		pr_err("Wrong pid nesting level\n");			\

Why do we need this message here?

> +		___ret = false;						\
> +	}								\
> +	___ret;								\
> +})
> +
>  /*
>   * When we have to restore a shared resource, we mush select which
>   * task should do it, and make other(s) wait for it. In order to
>
Kirill Tkhai April 7, 2017, 9 a.m.
On 07.04.2017 03:33, Andrei Vagin wrote:
> On Tue, Mar 28, 2017 at 06:35:47PM +0300, Kirill Tkhai wrote:
>> This allows to compare pids values on the whole hierarhy.
>>
>> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
>> ---
>>  criu/include/pid.h |   17 +++++++++++++++++
>>  1 file changed, 17 insertions(+)
>>
>> diff --git a/criu/include/pid.h b/criu/include/pid.h
>> index 475b17a3..478e5d0b 100644
>> --- a/criu/include/pid.h
>> +++ b/criu/include/pid.h
>> @@ -4,6 +4,7 @@
>>  #include <compel/task-state.h>
>>  #include "stdbool.h"
>>  #include "rbtree.h"
>> +#include "log.h"
>>  
>>  /*
>>   * Task states, used in e.g. struct pid's state.
>> @@ -45,6 +46,22 @@ struct pid {
>>  	} ns[1]; /* Must be at the end of struct pid */
>>  };
>>  
>> +#define equal_pid(a, b)							\
>> +({									\
>> +	int ___i, ___ret = true;					\
>> +	if (a->level == b->level) {					\
>> +		for (___i = 0; ___i < a->level; ___i++)			\
>> +			if (a->ns[___i].virt != b->ns[___i].virt) {	\
>> +				___ret = false;				\
>> +				break;					\
>> +			}						\
>> +	} else {							\
>> +		pr_err("Wrong pid nesting level\n");			\
> 
> Why do we need this message here?

It's a debug message to report that we compare variables of different dimensions
 
>> +		___ret = false;						\
>> +	}								\
>> +	___ret;								\
>> +})
>> +
>>  /*
>>   * When we have to restore a shared resource, we mush select which
>>   * task should do it, and make other(s) wait for it. In order to
>>