Commit graph

8953 commits

Author SHA1 Message Date
Kirill Tkhai
a75f0fa8bc ns: Simplify create_net_ns()
Merge code with the same functionality in one

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-15 21:44:53 +03:00
Kirill Tkhai
b54c7d3d88 net: Kill unused argument in open_net_ns()
Nobody uses it.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-15 21:42:44 +03:00
Andrei Vagin
ae291308ee test/zdtm/static/netns_sub.c 2018-02-15 19:51:55 +03:00
Andrew Vagin
d7d11e0e00 zdtm: add a test for nested network namespaces
This tests create a few processes which live in three network namespaces
and have a few sockets which are created in different network namespaces.

Acked-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-15 19:46:13 +03:00
Andrei Vagin
14731c5210 net: add a way to get a network namespace for a socket
Each sockets belongs to one network namespace and operates
in this network namespace.

socket_diag reports informations about sockets from
one network namespace, but it doesn't report sockets which
are not bound or connected to somewhere. So we need to have
a way to get network namespaces for such sockets.

Acked-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-15 19:45:49 +03:00
Andrei Vagin
37ea6ed0cd kerndat: check the SIOCGSKNS ioctl
This ioctl is called for a socket and returns a file descriptor
for network namespace where a socket has been created.

Acked-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-15 19:45:49 +03:00
Andrei Vagin
7a6a42d05b net: set a proper network namespace to create a socket
Each socket has to be restored from a proper network namespaces
where it was created.

We set a specified network namespace before restoring a socket.
A task network namespace is set after restoring all files.

v2: don't set the root netns for transport sockets

Acked-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-15 19:45:49 +03:00
Andrei Vagin
2b6ed5bffc util: move open_proc_fd to service_fd
We need this to avoid conflicts with file descriptors,
which has to be restored.

Currently open_proc_pid() doesn't used during restoring
file descriptors, but we are going to use it to restore
sockets in proper network namespaces.

Acked-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-15 19:45:49 +03:00
Andrei Vagin
6b7393c44e net: allow to dump and restore more than one network namespace
Restore all network namespaces from the root task and then set
a proper namespace for each task after restoring sockets, because
we need to switch network namespaces to restore sockets.

Each socket has to be created in a proper network namespace.

v2: fix a typo bug

Acked-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-15 19:45:49 +03:00
Andrei Vagin
a54d3cf110 net: save network namespaces for sockets
Each socket has to be restored in a proper namespaces where
it has been created.

Here is an issue about unconnected and unbound sockets,
they are not reported via socket-diag and we can't to
get their network namespaces.

v2: add a comment before get_socket_ns()
    remove nsid from sk_packet_entry

Acked-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-15 19:45:49 +03:00
Pavel Emelyanov
17f163a6f2 usernsd: Add debugging to catch BUG in unsd fd/flags mismatch
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2018-02-15 19:45:49 +03:00
Andrei Vagin
5902eb2155 net: rename pid into nsid for prepare_net_ns()
PID ussualy means processs ID, but prepare_net_ns works with namespaces.

travis-ci: success for Dump and restore nested network namespaces (rev4)
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2018-02-15 19:45:49 +03:00
Andrei Vagin
4ea9cf336a netlink: add ns_id as a generic argument to receive_callback
ns_id will be used to collect sockets and other per-netns
resources

travis-ci: success for Dump and restore nested network namespaces (rev4)
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2018-02-15 19:45:49 +03:00
Andrei Vagin
bbbe4f264a restore: call close_pid_proc() if a child is shared a parent fd table
There are a number of global variables around this descriptor
(e.g. open_proc_fd) and their values are saved in memory which
are not shared between processes.

travis-ci: success for Dump and restore nested network namespaces (rev4)
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2018-02-15 19:45:49 +03:00
Pavel Emelyanov
5759076cea criu: Version 3.7
This time we shifted the update one month, due to the amount of
changes not being very big. And got pretty big update, including
a set of bugfixes and new functionality.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-12-19 21:08:35 +03:00
Andrei Vagin
03fb0b8223 syscall: fix arguments for preadv()
It has two arguments "pos_l and "pos_h" instead of one "off". It is used
to handle 64-bit offsets on 32-bit kernels.

SYSCALL_DEFINE5(preadv, unsigned long, fd, const struct iovec __user *, vec,
                unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)

https://github.com/checkpoint-restore/criu/issues/424
Signed-off-by: Andrei Vagin <avagin@openvz.org>
Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-19 10:46:38 +03:00
Vitaly Ostrosablin
88fbd37f53 criu: Don't fail if ghost file has no parent dirs.
Due to way CRIU handles paths (as relative to workdir), there's a case,
where migration would fail. Simple example is a ghost file in filesystem
root (with root being cwd). For example, "/unlinked" becomes "unlinked".
And original code piece scans path for other slashes, which would be
missing in this case. But it's still a perfectly valid case, and there's
no need to fail. So if there's no parent dir - we just don't need to
create one and we can just return 0 here instead of failing.

Signed-off-by: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-19 10:46:38 +03:00
Andrei Vagin
8720f1da1f test: check that corked udp sockets are not dumped
The kernel doesn't have an interface to get a sent queue for udp
sockets, so currently we can't dump them and criu dump has to fail in
such cases.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-19 10:46:38 +03:00
Andrei Vagin
53211331e0 sk-inet: detect corked sockets by getting a proper sock opt
Now we block all sockets with non-zero idiag_wqueue, but it doesn't mean
that a CORK option is enabled for a socket. A packet can be in a network
stack and it is accounted into idiag_wqueue.

https://github.com/checkpoint-restore/criu/issues/409

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-19 10:46:38 +03:00
Pavel Tikhomirov
8bc39c78d8 pr_err: add \n where we miss them
Except for several false positives done by:
find -type f -name "*.c" -not -path "./test/*" -exec sed -i
's/\(\<pr_err.*[^\][^n]\)\("[,)]\)/\1\\n\2/g' {} \;

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:17:47 +03:00
Pavel Begunkov
2d7abe53fc locks: skip 'lease correction' for non-regular files
Leases can be set only on regular files. Thus, as optimization we can
skip attempts to find associated leases in 'correct_file_leases_type'
for other fd types.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:16:04 +03:00
Pavel Begunkov
8835e6973e zdtm: Test inherited file leases
-- check childs' errors in file_leases03
-- test c/r of lease transfered to child process

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:16:04 +03:00
Pavel Begunkov
6c86fcb5a7 locks: Remove duplicated locks
CRIU creates dictinct lock record for each file descriptor on the same
OFD. The patch removes this duplicates. To do so, it adds new field into
struct file_lock, which stores pid of fd, on which lock was found.
'owner pid' is not actually helpful, because the original fd, on which
lock have been set, can be already closed.

Also it purges crutches doing the same stuff but only for file leases.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:16:04 +03:00
Pavel Begunkov
0781cb3320 zdtm: Add file lease tests
Test cases:
0. Basic non-breaking read/write leases.
1. Multiple read leases and OFDs with no lease for the same file.
2. Breaking leases.
3. Multiple fds (dup + inherited) for single lease (mutual OFD).

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:16:04 +03:00
Pavel Begunkov
8038462d2d locks: Add leases c/r for kernels v4.0 and older
Information about locks in /proc/<pid>/fdinfo is presented only since
kernel v4.1. This patch adds logic to *note_file_lock* to match leases
and OFDs.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:16:04 +03:00
Pavel Begunkov
90fc8622e2 locks: Add c/r of breaking leases (kernel>=v4.1)
restore of breaking leases is executed in 2 steps:
1. restore the lease in a state it was before break
2. break it by opening associated file.

The patch fixes type of broken leases to 'target lease type',
because procfs always returns 'READ' in this case.

Also, it adds 'updated' field in lock structure. It's used to remove all
duplicated records for single lease from the image, which wasn't
corrected by 'correct_lease_type'.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:16:04 +03:00
Pavel Begunkov
49cd3eb2ad locks: Add c/r of non broken leases (kernel>=v4.1)
Leases in breaking state are not supported. In that case criu will
report an error during the dumping. Also lock info in
/proc/<pid>/fdinfo should be presented (since kernel 4.1).

Before taking out new lease it modifies process fsuid to match file uid
(see fcntl F_SETLEASE).

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:16:04 +03:00
Andrei Vagin
b2494eae61 test/docker: check a continaer with a read-only file system
Now it's probably one valide use case, because there is no way to commit
a container when a container is being checkpointed.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:13:37 +03:00
Andrei Vagin
1971cab9fc zdtm/tempfs_subns: sync children with the main process
All static tests has to stop any activity before C/R.

./tempfs_subns --pidfile=tempfs_subns.pid --outfile=tempfs_subns.out --dirname=tempfs_subns.test
Run criu dump
Unable to kill 128: [Errno 3] No such process
Run criu restore
7: Old mounts lost: []
7: New mounts appeared: [('/rootfs/criu/test', '/'), ('/', '/proc'), ('/', '/dev/pts')]
:

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:13:37 +03:00
Pierre-Olivier Mercier
7470b163de compel: add missing header required by musl
This fix compilation issue regarding undeclared NULL and memcpy when using musl
on ARM.

Signed-off-by: Pierre-Olivier Mercier <nemunaire@nemunai.re>
2017-12-12 09:13:31 +03:00
Andrei Vagin
5a4c27a8e1 pipe: dump all data from a pipe
Currently we use an additional pipe to steal data from a pipe, but we
don't check that we steal all data. And the additional pipe can have a
smaller size.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:13:31 +03:00
Andrei Vagin
6dd3e4e39d test: check a pipe with a custom size
CRIU doesn't handle correctly pipes with sizes which are bigger than a
default one.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:13:30 +03:00
Pavel Tikhomirov
5bf9f9b6a6 remap: don't free rpath and don't shfree_last gf
a) As we shmalloced rpath it can not be xfreed. b) As we shmalloc
variables in collect_remap_ghost() far away from open_remap_ghost()
where we want to free them, there is no guaranty that our shmalloc was
last and we can't use shfree_last().

fixes commit 0c675a5e9d ("files: remove link_remaps when everything
has been restored")

When create_ghost() fails for some reason that produces a segfault for me.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:44 +03:00
Mike Rapoport
0131a85115 zdtm: use {read,write}_data in fifo tests
Reading and writing large buffers may result in short read/write. In cases
we expect the entire buffer to be transferred use {read,write}_data rather
than plain read/write syscalls.

Reported-by: Mr Jenkins
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:44 +03:00
Mike Rapoport
d8c974d651 zdtm: lib: add {read,write}_data helpers
Some tests expect that all the data will be handled in a single invocation
of read/write system call. But it possible to have short read/write on a
loaded system and this is not an error.
Add helper functions that will reliably read/write the entire buffer.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:44 +03:00
Mike Rapoport
8797645636 lazy-pages: do not allow background fetch before restore is finished
If we start backroung memory fetch before restore is completely finished,
we may try to write to the memory areas which were not yet remapped to
proper place and are not registered with userfaultfd.
Add synchronization between restore and the lazy-pages so that lazy-pages
will only handle #PFs before all the tasks are restored.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:44 +03:00
Mike Rapoport
83e75c3c1d page-server: implement epoll->hangup_event
The remote page read has nothing to do if the page-server on the source has
closed the connection. Just report an error and abort.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:44 +03:00
Mike Rapoport
dcfe17e7aa util: epoll: add processing of EPOLL{RD}HUP
Currently when we poll a file descriptor, we only process EPOLLIN events
and if a connection is closed the receiving side has no means to deal with
it.
Add a callback for EPOLL{RD}HUP events and the default implementation for
these events that removes the file descriptor from epoll and closes it.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:44 +03:00
Mike Rapoport
2a0a5221b8 util: epoll: rename revent to read event
A bit more readable and will be easy to distinguish from upcoming
hevent^Whangup_event.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:43 +03:00
Mike Rapoport
06e252dedc util: epoll: move comment about timeout decrease to uffd.c
The generic epoll_wait wrapper should not do any assumptions about timeout.
It's it up to lazy-pages daemon to make (future) policy decisions.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:43 +03:00
Mike Rapoport
3dfae093c1 lazy-pages: drop_iovs: mark iov as not queued
If we receive only part of the IOV from the page-server we recalculate the
IOV so it will point to the area we still have to fetch. During the split,
the IOV covering the remaining area may remain marked as 'queued' and we'll
never retry fetching it.
Marking the IOV as not queued will ensure its pages will be requested
again.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:16 +03:00
Mike Rapoport
7ce804ed9f page-xfer: remote-pages: allow receiving partial data
Since commit e609267f681062b4370e528a50f635222e0c2330 ("page-pipe: allow to
share pipes between page pipe buffers") the assumption that we will receive
the exact amount of pages we've requested with PS_IOV_GET does not always
hold.
In the case we serve pages data from the images using 'page-server
--lazy-page' the IOVs seen by the pagemap may cross page-pipe buffer
boundaries and read_page_pipe will clamp the pages in the response to those
boundaries.
Adjust page_server_read so it will not try to receive more pages than
page-server is going to send.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:16 +03:00
Mike Rapoport
23d086c263 debug_show_page_pipe: add PPB's pipe offset
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:16 +03:00
Andrei Vagin
e85646875f zdtm/maps006: modify test so that file and anon vma-s are mixed
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:16 +03:00
Andrei Vagin
cef1efe5bd page-pipe: allow to share pipes between page pipe buffers
Now criu create a new pipe buffer, if a previous one has another set of
flags. In this case, a pipe is not full and we can use it for the
next page buffer.

We need 88 pipes to pre-dump the zdtm/static/fork test without this
patch, and we need only 17 pipes with this patch.

Acked-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:16 +03:00
Andrei Vagin
6feebf3aad page-pipe: move code to resize a pipe in a separate function
v2: and move it upper, because it is going to be used in ppb_alloc()

Acked-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:16 +03:00
Andrei Vagin
e3c6784b8f parasite: remove restriction to a number of iovec-s
vmsplice can't splice more than UIO_MAXIOV, but we can
call it a few times from a parasite.

v2: s/nr/nr_segs/

Acked-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:12:16 +03:00
Adrian Reber
c949e75968 crtools: also print the current kernel version
In addition to writing the CRIU version to the log file this adds the
current kernel version to the log file:

(00.000008) Version: 3.5 (gitid v3.5-511-ga8cc6cf)
(00.000303) Running on node01 Linux 3.10.0-513.el7.x86_64 #1 SMP Tue Feb 29 06:78:90 EST 2017 x86_64

v2:
 - small changes as suggested by Dmitry (thanks)

Signed-off-by: Adrian Reber <areber@redhat.com>
Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:16:33 +03:00
Andrei Vagin
dc384c0e30 netfilter: use ipv4 iptables rules to block IPv4-mapped IPv6 addresses
If ipv6 socket has an IPv4-mapped address, it is used to handle ipv4
connection, so we have to use ipv4 iptables rules to block this
connection.

Reported-by: Mr Jenkins
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:14:05 +03:00
Andrei Vagin
c31d423eeb compel: use a correct name format for vma files in /proc/pid/map_files/
Currently we use the "map_files/%p-%p" format, but actually it should
be "map_files/%lx-%lx".

The kernel could handle both formats, but recently Alexey Dobriyan fixed
the kernel and it accept only the second format.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:13:50 +03:00