[CRIU] [PATCH 10/16] restore: look up root for each file

Pavel Emelyanov xemul at parallels.com
Wed Apr 9 22:45:23 PDT 2014


On 04/10/2014 09:12 AM, Andrew Vagin wrote:
> On Wed, Apr 09, 2014 at 07:05:24PM +0400, Pavel Emelyanov wrote:
>> On 04/09/2014 03:35 AM, Andrey Vagin wrote:
>>> Signed-off-by: Andrey Vagin <avagin at openvz.org>
>>> ---
>>>  files-reg.c          | 16 +++++++++++++++-
>>>  include/proc_parse.h |  1 +
>>>  mount.c              |  1 +
>>>  3 files changed, 17 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/files-reg.c b/files-reg.c
>>> index 750b356..81736d5 100644
>>> --- a/files-reg.c
>>> +++ b/files-reg.c
>>> @@ -23,6 +23,7 @@
>>>  #include "fs-magic.h"
>>>  #include "asm/atomic.h"
>>>  #include "namespaces.h"
>>> +#include "proc_parse.h"
>>>  
>>>  #include "protobuf.h"
>>>  #include "protobuf/regfile.pb-c.h"
>>> @@ -608,9 +609,22 @@ int open_path(struct file_desc *d,
>>>  	struct reg_file_info *rfi;
>>>  	int tmp;
>>>  	char *orig_path = NULL;
>>> +	struct mount_info *m;
>>>  
>>>  	rfi = container_of(d, struct reg_file_info, d);
>>>  
>>> +	if (rfi->rfe->mnt_id >= 0) {
>>> +		m = lookup_mnt_id(rfi->rfe->mnt_id);
>>> +		if (m == NULL) {
>>> +			pr_err("Unable to look up the %d mntns: %s\n",
>>> +						rfi->rfe->mnt_id, rfi->path);
>>> +			return -1;
>>> +		}
>>> +
>>> +		if (mntns_collect_root(m->nsid->pid))
>>
>> We perform root lookup every single fd? Shouldn't it be per-task?
> 
> No, one task can have fd-s from a few namespaces...

I'd consider this as unlikely exception.

> 
>>
>>> +			return -1;
>>> +	}
>>> +
>>>  	if (rfi->remap) {
>>>  		mutex_lock(ghost_file_mutex);
>>>  		if (rfi_remap(rfi) < 0) {
>>> @@ -674,7 +688,7 @@ static int do_open_reg_noseek_flags(struct reg_file_info *rfi, void *arg)
>>>  	u32 flags = *(u32 *)arg;
>>>  	int fd;
>>>  
>>> -	fd = open(rfi->path, flags);
>>> +	fd = openat(mntns_root, rfi->path, flags);
>>
>> This should be the respective service fd, isn't it?
> 
> mntns_root is a service fd. I will rework this accoding with your
> previous comment.

OK, thanks.

>>
>>>  	if (fd < 0) {
>>>  		pr_perror("Can't open file %s on restore", rfi->path);
>>>  		return fd;
>>> diff --git a/include/proc_parse.h b/include/proc_parse.h
>>> index c42a48c..423b490 100644
>>> --- a/include/proc_parse.h
>>> +++ b/include/proc_parse.h
>>> @@ -116,6 +116,7 @@ struct mount_info {
>>>  	int		is_file;
>>>  	bool		is_root;
>>>  	struct mount_info *next;
>>> +	struct ns_id	*nsid;
>>>  
>>>  	/* tree linkage */
>>>  	struct mount_info *parent;
>>> diff --git a/mount.c b/mount.c
>>> index 9b40903..57f9d5f 100644
>>> --- a/mount.c
>>> +++ b/mount.c
>>> @@ -1445,6 +1445,7 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
>>>  		if (!pm)
>>>  			goto err;
>>>  
>>> +		pm->nsid = nsid;
>>>  		pm->next = *pms;
>>>  		*pms = pm;
>>>  
>>>
>>
>>
> .
> 




More information about the CRIU mailing list