crtools: make pid parameter optional for open_image_ro()

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
crtools: dump pstree to image file without pid number

Pid number is redundant - this file is one for the whole tree.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Make parasite_prep_file work on fd

It doesn't need the whole fdset actually. Plus, this makes new
fdset implementation simpler.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Make dump_task_core work on fd

This routine is used for dumping tasks, threads and zombies. For the
last two the whole fdset is not allocated thus it will be better to
use single fd in this case.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
show: Fix and clean cr_show_all

Don't allocate fdset to show sk queues and don't fail on pstree
fd opening :)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Don't include sk-queues fd in task set

This fd is global, so make it such. It will stop being just a global
variable soon.

Plus, remove the pid arg from format.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Allocate task fdset when needed

Move the fdset allocation inside dump_one_task and do it only for
non-zombies.

This makes sure we don't need to re-use an fdset, since we do allocate
it only when required.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
fdset: Kill ability to re-use fdset

It's not required any longer. Now fdsets are allocated one-by-one only
when required and there's no need in adding new fds to existing sets.

Thus just remove the last arg from cr_fdset_open.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
show: Don't allocate fdset to show thread

Just use the open_image_ro for this.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
fdset: Helper for getting fd out of a set

This patch does

s/$fdset->fds[$nr]/fdset_fd($fdset, $nr)/

over the code.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
fdset: Introduce two fdsets -- task and ns

Write two helpers for opening an fdset for task and one for ns.

This probably can be done with some "generic" macro(s), but this
time it's simpler not to produce more code of that type.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
fdset: Reorder CR_FD_ types

Move pstree and sk-queues below, they are not per-task/-ns and
will be global soon.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
fdset: Introduce new fdsets

Current fdsets are ugly, limited (bitmask will exhaust in several months) and
suffer from unknown problems with fdsets reuse :(

With new approach (this set) the images management is simple. The basic function
is open_image, which gives you an fd for an image. If you want to pre-open several
images at once instead of calling open_image every single time, you can use the
new fdsets.

Images CR_FD_ descriptors should be grouped like

_CR_FD_FOO_FROM,
CR_FD_FOO_ITEM1,
CR_FD_FOO_ITEM2,
..
CR_FD_FOO_ITEMN,
_CR_FD_FOO_TO,

After this you can call cr_fd_open() specifying ranges -- _FROM and _TO macros,
it will give you an cr_fdset object. Then the fdset_fd(set, type) will give you
the descriptor of the open "set" group corresponding to the "type" type.

3 groups are introduced in this set -- tasks, ns and global.

That's it.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
fdset: Introduce glbal fdset

This contains reg-files and sk-queues images, as they contain data
which is potentially generated by every task, so keep it open all
the time dump goes.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Don't forget to close fdset when task dump ends

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
show: Fix 'all' mode showing

After we removed the pid from pstree image file the -t or -p option for show
command no longer makes sense. Make 'show' mode rely on -D option to find out
where to find the root (i.e. pstree.img) file.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
lock: Introduce futex_t and appropriate helpers

Instead of open-coded u32 variables poking lets use
futex_t type and appropriate helpers where needed.

This should increase readability.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
lock: Add own type and helpers for mutexes

To be consistent. Mutexes are futex based but have
own semantics so better to be able to distinguish
the types.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
show: Introduce ->show callback for fdset

Each fdset item now has the callback which will show a contents of a magic-described
image file. Per-task and global show code is reworked to walk the respective fdsets
and calling ->show on each file.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Remove unused fd arg from open_fe_fd

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>