gitignore: Add syscall generated files

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
files: Restore fdflags on proper fd

After reopen_fd_as the original fd is closed.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
inet: Introduce helpers for binding and connecting inet socket on restore

Just a codemove.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
inet: Move inet sk cpt and rst structs to header

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: Prepare sk-inet for dumping and restoring tcp connections

First of all -- to make crtools dump/restore established tcp sockets
you have to specify the --tcp-established options. By doing so you
inform crtools that

a) you know, that after dump there will be a netfilter rules blocking
   the dumped connections

b) you guarantee, that before restore this netfilter block is still
   there

What else this patch does is simple -- collects establised sockets and
calls the dump/restore tcp function (now empty) where appropriate.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
net: Add code for locking a tcp connection with netfilter

Between dump and restore of a tcp conn we have to keep the connection
blocked, since the socket doesn't exists in the kernel at this time
and any packet from peer will result in RST. Thus, add the -j DROP rule
for every connection we're about to repair.

Later, when we support containers, this will be extended to stop the
whole networking in a CT instead of cherry-peeking connections.

It does system("iptables ...") for this, but I'd prefer using the
libnetfilter-devel sometime in the future.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: Initial image description

Introduce the image file for tcp info, its entry and the show method.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: Put connection locking management over the code

When dump finished with error we should unlock all locked
previously connections.

When restoring we should collect connctions and unlock them
all at the end.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: Dump and restore support

What it does is uses the tcp repair engine from the kernel.

On dump the connection is locked with netfilter, socket is put
in the repair state and then its internals are dumped.

On restore we create a socket, put it into repair, dress it up
and then unlock all the connections at the very end.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: Basic test of tcp conn

Only manual mode at the moment. Need to automate it later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: Automate TCP stream c/r

This test is very basic :( Need more work on it.
One note about --close arg to crtools -- bash leaves all
fds open when laucnhing progams, and for restore this is
critical, as one of them can be busy. Iterating over all
the possibel fds and closing them is "do not want" thing.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test, app-emu: Add HelloWorld java test

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
proc: add a static buffer to prevent segv (v3)

A few of our functions use buffer and string functions.
All these functions require that a string contains '\0' at the end.
Before this patch we didn't guarantee that.

I've seen segmentation fault in parse_pid_stat_small.

v2: simplify code
v3: remove assignment, because it's redundant and a size of object file
become bigger.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
show: Beautify output of the -c data dump

Calculate the best width for address and print them all with it.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: Show queue contents when -c is given

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: Fix queue contents restore

The wrong descriptor was passed to the read_img_buf.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
help: Reformat the help text

* Split dump/restore options from show ones
* Structure the former list
* Add the --tcp-established one

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: Add code for "check"-ing TCP repair support

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Collect more stats about pages being dumped

Dumped pages are those taken to the image
Skipped pages are those, sitting in RAM, but left there (file shared pages)
Total is the total amount of pages that fit into vmarea

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Stop using mincore and switch to /proc/pid/pagemap

We use mincore to check which pages we should take with us into
the image. The anonymour present or swapped should go, file present
but not cow-ed should not.

The mincore syscall wasn't very helpful with this -- it didn't detect
swap, but did detect some non present pages (pagecache). Plus it
didn't know anything about cow-ing filemaps.

Andrey Morton suggested to use the pagemap file in proc, but it lacked
the importaint stuff -- the cow filemap bit. Now it's there and we
can switch to using it.

The mincore usage for shared memory is still there, as for _that_ case
it's correct.

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