[CRIU] [PATCH 28/32] tools: cpt2 -- Add writing of pstree entries
Pavel Emelyanov
xemul at parallels.com
Mon Apr 1 07:04:22 EDT 2013
On 04/01/2013 02:54 PM, Cyrill Gorcunov wrote:
> On Mon, Apr 01, 2013 at 02:29:23PM +0400, Pavel Emelyanov wrote:
>>> + list_for_each_entry(task, &task_list, list) {
>>> + ret = write_pstree_item(pstree_fd, task, &e,
>>> + threads, max_threads);
>>> + if (ret)
>>> + goto out;
>>> + list_for_each_entry(child, &task->children, list) {
>>> + ret = write_pstree_item(pstree_fd, child,
>>> + &e, threads, max_threads);
>>> + if (ret)
>>> + goto out;
>>> + }
>>> + }
>>
>> Does task_list contain all tasks? In that case we'll write some tasks twice.
>> Does it contain only even-levels of tasks? O_O
>
> At first task_list gathers all tasks from cpt file, then we walk over
> the tree and connect tasks to respective parents, to have process tree
> at the end of ptocess.
So task_list contains all the tasks. Why do we write each entry _and_ _it's_
_children_ on every loop? Won't children be in image twice after this?
> read_tasks
> ...
> hash_add(pids_hash, &task->hash, task->ti.cpt_pid);
> list_add_tail(&task->list, &task_list);
>
> list_for_each_entry_safe(task, tmp, &task_list, list)
> collect_task(task);
>
> static void collect_task(struct task_struct *task)
> {
> struct task_struct *t;
>
> /*
> * We don't care if there is some of PIDs
> * are screwed, the crtools will refuse to
> * restore if someone pass us coeeupted data.
> *
> * Thus we only collect threads and children.
> */
> t = task_lookup_pid(task->ti.cpt_ppid);
> if (t) {
> task->parent = t;
> list_move(&task->list, &t->children);
> return;
> }
>
> t = task_lookup_pid(task->ti.cpt_rppid);
> if (t) {
> list_move(&task->list, &t->threads);
> t->n_threads++;
>
> if (max_threads < t->n_threads)
> max_threads = t->n_threads;
> return;
> }
> }
> .
>
More information about the CRIU
mailing list