img: Open images "at" functionality

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-pipe: Support holes in page-pipe iov map

Holes are regions, that don't have pages in them (i.e. -- no
pages in pipes). These holes are in separate iovs array since
we should have straight arrays of iovs for non-holes, which is
in turd required to push it into vmsplice in _one_ chunk.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-xfer: Write holes and non-holes in sorted way

The pagemap.img contains sorted iovs. Need to keep this array also
sorted even if holes are in there for simpler read on restore.

Separate ->write_hole callback since dump of hole and non-hole
will differ significantly.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-read: New abstraction for restoring pages

Now we have 2 forms of storing pages -- legacy pages.img and
new pagemap + pages image. We'll have one more (ovz) and the
pagemap + pages will be stacked (snapshot restore). Thus it's
handy to have this as an page-reader object.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
cr: Preparations for snapshot

1. Directory with images may have a "parent" symlink pointing to the
   place where the previous snapshot is
2. Each pagemap will have "in_parent" bit, which means, that the
   pages for this pagemap entry are not in the respective page.img
   but in parent
3. New --leave-running option to use with --snapshot not to kill
   tasks after snapshot

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

It's quite simple -- get parent's pagemap before dumping memory,
then collect _full_ pagemap of task putting holes into page-pipe
when the page is (soft-dirty-clear && in-parent-map). At the end
reset task's soft-dirty bits.

This requires kernel support from
http://comments.gmane.org/gmane.linux.kernel.mm/98283

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: Restore memory from stack of snapshots

This one is a little bit more tricky that dump. On restore we
should open the chain of pagemap-s (by "parent" links). Then for
every pagemap with in_parent set we should go to parent and ask
for the page. Parent, in turn, should properly determine where
the respective page is in his pagemap and position the page.img's
position respectively.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
page-pipe: Print full layout of page-pipe in log (in debug loglevel)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: Test for manual (for now) testing

This guy touches a random page once per second and backs-up
what was touched. At the end it checks whether everything is
OK. It can be used to test how snapshots work -- take several
snapshots with several seconds pauses in betweem and restore
form the last.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
log: log_init -- Check for dup return code

Don't pass negative descriptor to install_service_fd

CID 996213 (#1 of 1): Improper use of negative value (NEGATIVE_RETURNS)
7. negative_returns: "new_logfd" is passed to a parameter that cannot be negative.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
shmem: restore_shmem_content -- Use close_safe

Don't call close() with degative fd. For consistency
simply use close_safe here. All fds touched are initialized
either to valid fd or to value < 0 which pretty good handled
by close_safe helper.

CID 996212 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
10. negative_returns: "fd" is passed to a parameter that cannot be negative.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
proc-parse: Rework error paths

On error paths we don't explicitly close procfile.

CID 996191 (#5 of 6): Resource leak (RESOURCE_LEAK)
22. leaked_storage: Variable "f" going out of scope leaks the storage it points to.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Fix typos in messages from test suite

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Fix typos in log messages

Someone has to do it, right?..

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Fix typos in comments

This is less useful than fixing typos in output messages, but anyway.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
kerndat: Introduce the storage of kernel run-time info

One of such things we use right now is the device for anon shmem
mappings backing. In the furure this can be extended to check for
various kernel features.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
soft-dirty: Check that kernel reports soft-dirty bits

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Add test for memory snapshots

Two args (optional) -- number of snaps (3 defail) and pause
between them (4 defail).

Uses memory toucher from zdtm/.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mem: Comment page-read, page-xfer and page-pipe

These three are quite complex things, so write general comments about
what they are doing.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
crtools: Tune --help test

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