[v2,26/36] ns: Add ns_owner

Submitted by Kirill Tkhai on Feb. 3, 2017, 4:15 p.m.

Details

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

Commit Message

Kirill Tkhai Feb. 3, 2017, 4:15 p.m.
Add a struct ns_id member to store information,
where the ns copy may be obtained.

It's "/proc/[pid]/fd/[fd]", or "/proc/[pid]/ns/[ns]"
in dependence of ns_owner::fd value.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/include/namespaces.h |    8 ++++++++
 criu/namespaces.c         |    2 ++
 2 files changed, 10 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 21dc8beb7..546de7c5d 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -81,6 +81,13 @@  enum ns_type {
 	NS_OTHER,
 };
 
+struct ns_owner {
+	struct {
+		pid_t pid;	/* Owner pid */
+		int fd; 	/* Owner fd, or -1 if it's /proc/[pid]/ns/[ns] file */
+	};
+};
+
 struct ns_id {
 	unsigned int kid;
 	unsigned int id;
@@ -90,6 +97,7 @@  struct ns_id {
 	struct list_head children;
 	struct list_head siblings;
 	struct ns_id *user_ns;
+	struct ns_owner owner;
 	struct ns_id *next;
 	enum ns_type type;
 
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 538074ab9..6151219d8 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -302,6 +302,8 @@  struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid,
 		nsid->type = type;
 		nsid_add(nsid, nd, id, pid);
 		nsid->ns_populated = false;
+		nsid->owner.pid = -1;
+		nsid->owner.fd = -1;
 		INIT_LIST_HEAD(&nsid->children);
 		INIT_LIST_HEAD(&nsid->siblings);
 	}

Comments

Andrey Vagin Feb. 6, 2017, 10:40 p.m.
On Fri, Feb 03, 2017 at 07:15:26PM +0300, Kirill Tkhai wrote:
> Add a struct ns_id member to store information,
> where the ns copy may be obtained.
> 
> It's "/proc/[pid]/fd/[fd]", or "/proc/[pid]/ns/[ns]"
> in dependence of ns_owner::fd value.

https://patchwork.criu.org/patch/3457/

Have you seen this patch? Maybe it will be useful for this task.

This patch adds a new subsystem which is called fdstore and it
allows to create a storage for file descriptors and this storage
are shared between processes. It will work faster that opening a file
descriptor via usernsd.

> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>  criu/include/namespaces.h |    8 ++++++++
>  criu/namespaces.c         |    2 ++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
> index 21dc8beb7..546de7c5d 100644
> --- a/criu/include/namespaces.h
> +++ b/criu/include/namespaces.h
> @@ -81,6 +81,13 @@ enum ns_type {
>  	NS_OTHER,
>  };
>  
> +struct ns_owner {
> +	struct {
> +		pid_t pid;	/* Owner pid */
> +		int fd; 	/* Owner fd, or -1 if it's /proc/[pid]/ns/[ns] file */
> +	};
> +};
> +
>  struct ns_id {
>  	unsigned int kid;
>  	unsigned int id;
> @@ -90,6 +97,7 @@ struct ns_id {
>  	struct list_head children;
>  	struct list_head siblings;
>  	struct ns_id *user_ns;
> +	struct ns_owner owner;
>  	struct ns_id *next;
>  	enum ns_type type;
>  
> diff --git a/criu/namespaces.c b/criu/namespaces.c
> index 538074ab9..6151219d8 100644
> --- a/criu/namespaces.c
> +++ b/criu/namespaces.c
> @@ -302,6 +302,8 @@ struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid,
>  		nsid->type = type;
>  		nsid_add(nsid, nd, id, pid);
>  		nsid->ns_populated = false;
> +		nsid->owner.pid = -1;
> +		nsid->owner.fd = -1;
>  		INIT_LIST_HEAD(&nsid->children);
>  		INIT_LIST_HEAD(&nsid->siblings);
>  	}
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
Kirill Tkhai Feb. 7, 2017, 8:37 a.m.
On 07.02.2017 01:40, Andrei Vagin wrote:
> On Fri, Feb 03, 2017 at 07:15:26PM +0300, Kirill Tkhai wrote:
>> Add a struct ns_id member to store information,
>> where the ns copy may be obtained.
>>
>> It's "/proc/[pid]/fd/[fd]", or "/proc/[pid]/ns/[ns]"
>> in dependence of ns_owner::fd value.
> 
> https://patchwork.criu.org/patch/3457/
> 
> Have you seen this patch? Maybe it will be useful for this task.
> 
> This patch adds a new subsystem which is called fdstore and it
> allows to create a storage for file descriptors and this storage
> are shared between processes. It will work faster that opening a file
> descriptor via usernsd.

I think it wouldn't be a problem to rebase on fdstore, when it's in criu.
 
>>
>> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
>> ---
>>  criu/include/namespaces.h |    8 ++++++++
>>  criu/namespaces.c         |    2 ++
>>  2 files changed, 10 insertions(+)
>>
>> diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
>> index 21dc8beb7..546de7c5d 100644
>> --- a/criu/include/namespaces.h
>> +++ b/criu/include/namespaces.h
>> @@ -81,6 +81,13 @@ enum ns_type {
>>  	NS_OTHER,
>>  };
>>  
>> +struct ns_owner {
>> +	struct {
>> +		pid_t pid;	/* Owner pid */
>> +		int fd; 	/* Owner fd, or -1 if it's /proc/[pid]/ns/[ns] file */
>> +	};
>> +};
>> +
>>  struct ns_id {
>>  	unsigned int kid;
>>  	unsigned int id;
>> @@ -90,6 +97,7 @@ struct ns_id {
>>  	struct list_head children;
>>  	struct list_head siblings;
>>  	struct ns_id *user_ns;
>> +	struct ns_owner owner;
>>  	struct ns_id *next;
>>  	enum ns_type type;
>>  
>> diff --git a/criu/namespaces.c b/criu/namespaces.c
>> index 538074ab9..6151219d8 100644
>> --- a/criu/namespaces.c
>> +++ b/criu/namespaces.c
>> @@ -302,6 +302,8 @@ struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid,
>>  		nsid->type = type;
>>  		nsid_add(nsid, nd, id, pid);
>>  		nsid->ns_populated = false;
>> +		nsid->owner.pid = -1;
>> +		nsid->owner.fd = -1;
>>  		INIT_LIST_HEAD(&nsid->children);
>>  		INIT_LIST_HEAD(&nsid->siblings);
>>  	}
>>
>> _______________________________________________
>> CRIU mailing list
>> CRIU@openvz.org
>> https://lists.openvz.org/mailman/listinfo/criu