[CRIU] [PATCH v3 13/26] files: Merge states iteration into open_fdinfos()

Kirill Tkhai ktkhai at virtuozzo.com
Tue Dec 6 09:57:33 PST 2016


On 06.12.2016 20:35, Pavel Emelyanov wrote:
> On 12/05/2016 05:09 PM, Kirill Tkhai wrote:
>> TTY masters and slaves have no post_open stage,
>> so these two blocks may safely have their stages merged together.
>>
>> The third is eventpoll, but two above do not depend
>> on it (their .post_open do not depend on eventpoll .open).
>> Unix sockets would have been, but this isn't implemented yet.
>>
>> So, we may safely execute all stages for different
>> file types separatelly.
> 
> So first you plan to run all the stages for, e.g. unix sockets and
> after this -- for eventpolls. What if an eventpoll is sent over unix
> socket? I know it's not supported now, but will this problem sit in
> the code after this set?

There won't a problem, because the next step is merging all file types 
in the single list instead of current separate lists: fds, tty_slaves etc.
It's not in this patchset, as I wrote in cover letter, but it will
be easily made after. There are need a couple dependencies between
ttys; eventpoll already has all necessary dependencies (see [PATCH v3 22/26]
eventpoll: Make post_open stage may fail).

After the lists are merged, eventpoll will be able to sent to a task,
which unix queue needs the eventpoll, like a slave fle.
 
>> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
>> ---
>>  criu/files.c |   62 +++++++++++++++++++++++-----------------------------------
>>  1 file changed, 25 insertions(+), 37 deletions(-)
>>
>> diff --git a/criu/files.c b/criu/files.c
>> index 6554ca2..4039803 100644
>> --- a/criu/files.c
>> +++ b/criu/files.c
>> @@ -1061,15 +1061,17 @@ static int open_fdinfo(int pid, struct fdinfo_list_entry *fle, int state)
>>  	return states[state].cb(pid, fle);
>>  }
>>  
>> -static int open_fdinfos(int pid, struct list_head *list, int state)
>> +static int open_fdinfos(int pid, struct list_head *list)
>>  {
>> -	int ret = 0;
>> +	int state, ret = 0;
>>  	struct fdinfo_list_entry *fle;
>>  
>> -	list_for_each_entry(fle, list, ps_list) {
>> -		ret = open_fdinfo(pid, fle, state);
>> -		if (ret)
>> -			break;
>> +	for (state = 0; state < ARRAY_SIZE(states); state++) {
>> +		list_for_each_entry(fle, list, ps_list) {
>> +			ret = open_fdinfo(pid, fle, state);
>> +			if (ret)
>> +				break;
>> +		}
>>  	}
>>  
>>  	return ret;
>> @@ -1111,7 +1113,6 @@ int close_old_fds(void)
>>  int prepare_fds(struct pstree_item *me)
>>  {
>>  	u32 ret = 0;
>> -	int state;
>>  
>>  	pr_info("Opening fdinfo-s\n");
>>  
>> @@ -1142,41 +1143,28 @@ int prepare_fds(struct pstree_item *me)
>>  		}
>>  	}
>>  
>> -	for (state = 0; state < ARRAY_SIZE(states); state++) {
>> -		ret = open_fdinfos(me->pid.virt, &rsti(me)->fds, state);
>> -		if (ret)
>> -			break;
>> -
>> -		/*
>> -		 * Now handle TTYs. Slaves are delayed to be sure masters
>> -		 * are already opened.
>> -		 */
>> -		ret = open_fdinfos(me->pid.virt, &rsti(me)->tty_slaves, state);
>> -		if (ret)
>> -			break;
>> +	ret = open_fdinfos(me->pid.virt, &rsti(me)->fds);
>> +	if (ret)
>> +		goto out_w;
>>  
>> -		/*
>> -		 * The eventpoll descriptors require all the other ones
>> -		 * to be already restored, thus we store them in a separate
>> -		 * list and restore at the very end.
>> -		 */
>> -		ret = open_fdinfos(me->pid.virt, &rsti(me)->eventpoll, state);
>> -		if (ret)
>> -			break;
>> -	}
>> +	/*
>> +	 * Now handle TTYs. Slaves are delayed to be sure masters
>> +	 * are already opened.
>> +	 */
>> +	ret = open_fdinfos(me->pid.virt, &rsti(me)->tty_slaves);
>> +	if (ret)
>> +		goto out_w;
>>  
>> +	/*
>> +	 * The eventpoll descriptors require all the other ones
>> +	 * to be already restored, thus we store them in a separate
>> +	 * list and restore at the very end.
>> +	 */
>> +	ret = open_fdinfos(me->pid.virt, &rsti(me)->eventpoll);
>>  	if (ret)
>>  		goto out_w;
>>  
>> -	for (state = 0; state < ARRAY_SIZE(states); state++) {
>> -		/*
>> -		 * Opening current TTYs require session to be already set up,
>> -		 * thus slave peers already handled now it's time for cttys,
>> -		 */
>> -		ret = open_fdinfos(me->pid.virt, &rsti(me)->tty_ctty, state);
>> -		if (ret)
>> -			break;
>> -	}
>> +	ret = open_fdinfos(me->pid.virt, &rsti(me)->tty_ctty);
>>  out_w:
>>  	close_service_fd(TRANSPORT_FD_OFF);
>>  	if (rsti(me)->fdt)
>>
>> .
>>
> 


More information about the CRIU mailing list