2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 14:25:49 +00:00
Commit Graph

9350 Commits

Author SHA1 Message Date
Dmitry Safonov
8dcc764b86 x86/crtools: Add fork() err-path handle
Error-path for failed fork().
Looks originally forgotten, oops!
Also print a message on failed fork().

Signed-off-by: Dmitry Safonov <dima@arista.com>
2018-02-13 10:14:42 +03:00
Kirill Tkhai
5a7248bda2 inotify: Fix open_*notify_fd() never fails
We ignore restore_one_*notify() error code, while we mustn't.
Make open function fail when we can't restore them.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-13 10:09:01 +03:00
Kirill Tkhai
7f750e20c3 inotify: Do not DDOS by debug message on restore watch descriptor
Imagine, we have to restore inotify with watch descriptor 0x34d71d6.
Then we have:

1.235021     5578: fsnotify:           Watch got       0x1 but 0x34d71d6 expected
...
...
527.378042   5578: fsnotify:           Watch got 0x34d71d3 but 0x34d71d6 expected
527.378042   5578: fsnotify:           Watch got 0x34d71d4 but 0x34d71d6 expected
527.378042   5578: fsnotify:           Watch got 0x34d71d5 but 0x34d71d6 expected

Stop doing this and stop generating GBs of debug messages.
We already have print message before restore_one_inotify().
Let's add just one more after it.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-13 10:09:01 +03:00
Radostin Stoyanov
a33d3739e4 Fix typos
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-02-07 21:14:26 +03:00
Kirill Tkhai
e7449021bd zdtm: Add scm06 test
zdtm: Add scm06 test

From: Kirill Tkhai <ktkhai@virtuozzo.com>

This test makes looped unix sockets queues and tries
to iterate over them after the restore.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
37385e36b8 files: Allow to send unix sockets over unix sockets
Everything is ready. Message queue restores are in
the second stage of open for all types of unix sockets.
We just need to make scm wait before restore_unix_queue()
and allow to dump such scm context.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
75a52d666b unix: Move dump_sk_queue() before peer resolution
When we allow unix sockets sent over unix sockets,
dump_sk_queue() may dump and resolve some peers.
So, we need run it firstly and avoid linking our
peer_node to peer's peer_list.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
5e56a8c959 unix: Add fake queuer for standalone dgram sockets
Similar to previous patch, this makes the second end
of dgram socketpair to be open till post open. This
allows to delay restore of message queue.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
4e627abb57 unix: Add fake queuer for standalone stream sockets in established state
This makes the second end of socketpair to live till post_open.
We need it alive if we want to restore message queue later.
Otherwise, we do not have a queuer, which fd is used to actually
write messages.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
66d437f8aa unix: Split collect_one_unixsk()
Extract the functionality, which makes socket memory initialization.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
3164411e9e files: Implement find_unused_file_desc_id()
This function will be used to allocate id for fake files
(don't confuse with fake fds, e.g. fles).

Suggested-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
b49c0506b8 unix: Postpone restore_sk_common() of standalone sockets
restore_sk_common() may shutdown a socket, and queuer
won't be able to connect to it. So, this action must
be postponed.

We have this problem since long ago, but we are lucky
we haven't bumped in it.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
c39504fd26 unix: Make unix_sk_info::queuer pointer
Use pointer to the queuer instead of its id.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
4bc52ac069 unix: Move queue restore of interconnected pair to post open
Actually, there is no functional changes. We just postpone
restore of the queues. This will be used in the further
patches to restore unix sockets sent over unix sockets.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
d65d32acc1 unix: Rework peer transfer in open_unixsk_pair_master()
After previous patch, master and slave ends of socketpair
are owned by the only task. So, we may avoid using
of send_desc_to_peer() of the second end, and just
reopen it with right pid.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
3f6ad095e1 files: Export setup_and_serve_out()
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
5603f2cd24 unix: Add fake interconnected sockets
We're going to split interconnected pair restore
on two stages. Since we need the second end
to restore message queue in (future) post open,
we add it to the process, who is owner of the first
end.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
98ccdffb39 sk-unix: Remove unused code in interconnected_pair()
Since new file engine was introduced, we don't care
which particular pid should be master or slave.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
d809a5579a unix: Generalize get_fle_for_scm()
This adds a new argument and changes debug print
(it will be used for any fle, not only for scm).

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
6d1bf25e94 files: Add force_master argument to collect_desc_fle()
This functional allows to make a fle a master on
the time of collection. We will use it to add fake
files when we need to do this after add_fake_fds_masters().

This will be used to add second end of socketpair as
a fake fle (as the first end is placed in the right
place, we will force add the second end there).
See next patches.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
60827596a4 unix: Move post_open_unix_sk() to open_unixsk_standalone() and rename it
Since this function is used by standalone sockets only,
we move it to appropriate place. No functional changes.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
b1c2e425a9 files: Allow epolls sent over unix socket
Since epoll restore is split in two parts,
epoll_create() does not depend on another
files state. Since epoll is created, it
can be sent to everywhere. So, there is
no circular dependences, and we allow epolls
sent over unix socket.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Kirill Tkhai
8192507466 zdtm: Add scm05 test
Create socketpair and epoll. Add one end of the socketpair
to epoll and then twice send it over another end.

After restore check, that epoll can be received
via socket, and that it contains event.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-02-07 01:11:44 +03:00
Pavel Tikhomirov
c79bef860a criu: fix leaks detected by coverity scan
1) fix sfle memory leak on get_fle_for_scm error
2) fix gfd open descriptor leak on get_fle_for_scm error
3-6) fix buf memory leak on read and pwrite errors

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2018-02-03 10:56:13 +03:00
Andrei Vagin
6a3878e529 travis: don't fail a build when the s390 job failed
Builds for s390x fail due to a qemu bug.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-02 10:19:36 +03:00
Andrei Vagin
4fa17310ba zdtm: fix a lint warning
$ make lint
flake8 --config=scripts/flake8.cfg test/zdtm.py
test/zdtm.py:323:19: F841 local variable 'e' is assigned to but never used

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-02 00:55:51 +03:00
Kirill Tkhai
e8210261e5 zdtm: Fix fd01 cleanup
waitpid() does not return child pid, when child has not exited.
So, we can't use it to find pids of children.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-02-01 21:12:48 +03:00
Pavel Tikhomirov
1125ec85b6 mount: fix cwd_fd leak on clone error
We should close cwd_fd on error paths, found by Coverity Scan:

*** CID 187162:  Resource leaks  (RESOURCE_LEAK)
/criu/mount.c: 1370 in open_mountpoint()
1364                     */
1365                    pid = clone_noasan(ns_open_mountpoint, CLONE_VFORK | CLONE_VM
1366                                    | CLONE_FILES | CLONE_IO | CLONE_SIGHAND
1367                                    | CLONE_SYSVSEM, &ca);
1368                    if (pid == -1) {
1369                            pr_perror("Can't clone helper process");
>>>     CID 187162:  Resource leaks  (RESOURCE_LEAK)
>>>     Handle variable "cwd_fd" going out of scope leaks the handle.
1370                            return -1;
1371                    }
1372
1373                    errno = 0;
1374                    if (waitpid(pid, &status, __WALL) != pid || !WIFEXITED(status)
1375                                    || WEXITSTATUS(status)) {

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2018-01-31 21:23:50 +03:00
Pavel Tikhomirov
c4be26821e mount: fix uninitialized use of fd on switch_ns error
close_safe can operate uninitialized fd in case of error in switch_ns,
found by Coverity Scan:

*** CID 187164:  Uninitialized variables  (UNINIT)
/criu/mount.c: 1313 in open_mountpoint()
1307     err:
1308            return 1;
1309     }
1310
1311     int open_mountpoint(struct mount_info *pm)
1312     {
>>>     CID 187164:  Uninitialized variables  (UNINIT)
>>>     Declaring variable "fd" without initializer.
1313            int fd, cwd_fd, ns_old = -1;
1314
1315            /* No overmounts and children - the entire mount is visible */
1316            if (list_empty(&pm->children) && !mnt_is_overmounted(pm))
1317                    return __open_mountpoint(pm, -1);
1318

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2018-01-31 21:23:50 +03:00
Andrei Vagin
a180cf7ee1 zdtm: suppress useless error messages
Start test
./mxcsr --pidfile=mxcsr.pid --outfile=mxcsr.out
Run criu dump
Unable to kill 44: [Errno 3] No such process <--------------- this one
Run criu restore
Run criu dump

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>
2018-01-31 21:13:51 +03:00
Radostin Stoyanov
0ea9dd99c5 remote: Fix incorrect handling of port option
The `port` option is converted from unsigned short integer to
network byte order twice. Unfortunately the 2nd conversion
reverses the 1st one.

Example:

	#include <stdio.h>
	#include <arpa/inet.h>
	#include <stdlib.h>

	int main()
	{
	    printf("%d\n", htons(atoi("1234"))); /* 53764 */
	    printf("%d\n", htons(htons(atoi("1234")))); /* 1234 */
	    return 0;
	}

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-01-31 21:12:54 +03:00
Dmitry Safonov
347f210893 kdat/net: Init kerndat even if nsid aren't supported
We should continue even if kdat feature isn't supported:

[criu]# ./criu/criu dump -t `pidof pypy` --shell-job
Warn  (criu/kerndat.c:804): Can't load /run/criu.kdat
Warn  (criu/libnetlink.c:55): ERROR -95 reported by netlink
Error (criu/net.c:3042): Unable to create a veth pair: -95
Warn  (criu/net.c:3064): NSID isn't reported for network links

Cc: Andrei Vagin <avagin@virtuozzo.com>
Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
2018-01-28 11:27:10 +03:00
Andrei Vagin
be6c539c3d criu: fix two issue with possible out-of-bound access
Signed-off-by: Andrei Vagin <avagin@openvz.org>
2018-01-28 11:27:10 +03:00
Andrei Vagin
19148bd623 bfd: avoid out-of-bound access
Write a nullbyte only if there is enought space for it.

Cc: Stephen Röttger <stephen.roettger@gmail.com>
Reported-by: Stephen Röttger <stephen.roettger@gmail.com>
Signed-off-by: Andrei Vagin <avagin@openvz.org>
2018-01-28 11:27:10 +03:00
Andrei Vagin
a740b4e438 kerndat: call kerndat_link_nsid()
It was droped during one of rebases.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-01-25 03:35:55 +03:00
Pavel Tikhomirov
6dd7eedbfa files: change error to warning in linkat_hard error path
We print errors in all error cases when calling linkat_hard anyway, but
for some errors like EEXIST we are fine and just skip them, so we should
not print error here.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2018-01-25 03:34:57 +03:00
Pavel Tikhomirov
778d6d7b70 zdtm: check ghost restores on readonly fs if it is also a ghost in other writable bind
It is a test for convert_path_from_another_mp fix, it is a bit tricky as
we don't fully support ghosts on readonly fs, but only if the ghost can
be remaped on some _other_ bindmount (luckily we have same ghost on other
bind). Moreover wrong absolute path generated with old convert_path_from
_another_mp for lnkat don't always fail, only in case we want to do
linkat on mount in _other_ mountns and absolute path makes us do it in
local mountns and local path is readonly and we fail. =)

v2: remove unused headers

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2018-01-25 03:34:57 +03:00
Pavel Tikhomirov
41cdad6c2d files: make convert_path_from_another_mp always return relative path
If dmi->ns_mountpoint is "/" then in dst we will return "/..." -
absolute path but we want here path relative to dmi mount. Adding "./"
before the path guaranties that it will be always relative.

https://jira.sw.ru/browse/PSBM-72351
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2018-01-25 03:34:57 +03:00
Radostin Stoyanov
00524c298e img-remote: Fix typo in comment
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-01-25 03:30:02 +03:00
Radostin Stoyanov
ae1e61bb58 crtools: Fix typo
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2018-01-25 03:29:15 +03:00
Kirill Tkhai
51c4dc7c25 zdtm: Add fd01 test
Fork tasks and create fds with different numbers.
Some children share file with parent (CLONE_FILES).
Check, than we can suspend and resume in this case.

v2: New

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-01-16 20:43:22 +03:00
Kirill Tkhai
c19df1ac02 files: Make tasks set their own service_fd_base
Currently, we set rlim(RLIMIT_NOFILE) unlimited
and service_fd_rlim_cur to place service fds.
This leads to a signify problem: every task uses
the biggest possible files_struct in kernel, and
it consumes excess memory after restore
in comparation to dump. In some situations this
may end in restore fail as there is no enough
memory in memory cgroup of on node.

The patch fixes the problem by introducing
task-measured service_fd_base. It's calculated
in dependence of max used file fd and is placed
near the right border of kernel-allocated memory
hunk for task's fds (see alloc_fdtable() for
details). This reduces kernel-allocated files_struct
to 512 fds for the most process in standard linux
system (I've analysed the processes in my work system).

Also, since the "standard processes" will have the same
service_fd_base, clone_service_fd() won't have to
actualy dup() their service fds for them like we
have at the moment. This is the one of reasons why
we still keep service fds as a range of fds,
and do not try to use unused holes in task fds.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>

v2: Add a handle for very big fd numbers near service_fd_rlim_cur.
v3: Fix excess accounting for nr equal to pow 2 minus 1.
2018-01-16 20:43:22 +03:00
Kirill Tkhai
129bb14611 files: Prepare clone_service_fd() for overlaping ranges.
In normal life this is impossible. But in case of big
fdt::nr number (many processes, sharing the same files),
and custom service_fd_base, normal (!CLONE_FILES) child
of such process may have overlaping service fds with
parent's fdt. This patch introduces "memmove()" behavior
(currently there is "memcpy()" behavior) and this will
be used in next patch.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-01-16 20:43:22 +03:00
Kirill Tkhai
a589166642 files: Refactor clone_service_fd()
This patch just moves part of clone_service_fd()
to separate function, that change readability of the code.

There are no functional changes, only refactoring.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-01-16 20:43:22 +03:00
Kirill Tkhai
fa26f01bb4 files: Do setup_newborn_fds() later
This patch makes the call of service fds relocation after
root_prepare_shared()->prepare_fd_pid(). Next patches
will make service_fd_base depend on task's max fd used,
and for root_item we need to read all fles to know
the maximum of them.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-01-16 20:43:22 +03:00
Kirill Tkhai
4fc7cdecf5 files: Close old service fd in clone_service_fd()
Next patches will make service_fd_base not contant.
It will be "floating" and change from task to task.
This patch makes preparation for that: it closes
old service fd after it's duplicated.

Currently the code is unused as in case of
!(rsti(me)->clone_flags & CLONE_FILES), the child
has the same id as its parent, and the duplication
just does not occur.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-01-16 20:43:22 +03:00
Kirill Tkhai
d300d172a7 files: Pass pstree_item argument to clone_service_fd()
Refactoring for next patches.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-01-16 20:43:22 +03:00
Kirill Tkhai
3c66f6c9f4 files: Count inh_fd_max
This patch counts maximum of inherited fds.
The value will be used in next patch.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-01-16 20:43:22 +03:00
Kirill Tkhai
55187ec9c5 files: Rename service_fd_rlim_cur to service_fd_base_cur
Next patches will make service fds numbers not connected
not rlimit. Change the name to better fit its goal.

Also, leave service_fd_rlim_cur variable to have cached
access to rlimit value.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>

v2: More comments
2018-01-16 20:43:22 +03:00
Kirill Tkhai
8d1eb0b89a sfds: Protect service fds
Mark area, where service fds modifications are prohibited.

v4: New

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2018-01-16 20:43:22 +03:00