This patch fixes an exit code if a page-server is started
as a daemon. Now the criu exits with a pid of a page server,
it's meaningless, because pid is usually bigger than 128.
travis-ci: success for series starting with [1/2] page-server: don't return a server pid from page-server
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Currently we check errno, but musl-libc doesn't zero it,
if fscanf() has returned EOF without errors.
travis-ci: success for A few fixes for Alpine Linux
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
They are not implemented in musl-libc (alpine).
travis-ci: success for A few fixes for Alpine Linux
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
In the case when one eventpoll in polled by another eventpoll,
we should wait till the polled epoll is opened. So, as the stage
FLE_RESTORED is after FLE_OPEN, it's also OK.
travis-ci: success for eventpoll: Fix dependency check
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
The callers of rfi_remap() are interested in a errno,
linkat_hard() returns. So, preserve errno before we
call rm_parent_dirs().
Reported-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
We are going to create slave pty-s to bind-mount them,
but at this moment we don't have file_desc-s and actually
can't open /dev/ptmx by path.
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Save one syscall and analyze recvmsg() error code to check
that there is no data in the socket.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
As a slight side effect even expected fle is checked for being
task_fle(), but that's OK.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Acked-by: Kirill Tkhai <ktkhai@virtuozzo.com>
The tail of the recv_fd_from_peer() matches this routine :)
So call one and rename, since it no longer keeps fd for
future only.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Acked-by: Kirill Tkhai <ktkhai@virtuozzo.com>
We've received tmp, which is not expected one, so check for it.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Acked-by: Kirill Tkhai <ktkhai@virtuozzo.com>
These chnages allows us to:
* avoid difference between the root mount namespace and other mount namespaces
* support a read-only root mount
* don't create temporary directories in the root mount
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Andrew Vagin reported the problem found by a checker:
CID 174702 (#1 of 1): Out-of-bounds access (INCOMPATIBLE_CAST)
incompatible_cast: Pointer &f->raw.counter points to an object whose
effective type is int (32 bits, signed) but is dereferenced as a wider
unsigned long (64 bits, unsigned). This may lead to memory corruption.
It looks like, this points to real problem, which may happen on big-endian
platforms. In the code I relay on the fact, that FDS_EVENT_BIT has a small
number and the value, it determines, fits into int type without problems.
But it's correct only for little-endian.
In case of big-endian, if the word size is 8 bytes, then FDS_EVENT value
is in the last bytes, so there is an access to wrong memory.
To fix the problem, I suggest to use little-endian byte order to work
with task_st futex. Then, the bits from 0 to 31 will be in the low adresses,
i.e. in task_st futex. There is new primitives test_and_set_bit_le() and
set_bit_le() borrowed from the linux kernel for that.
This fixes the problem, but I suppose, the checker does not see the problem
so deep, and just compares the types size, so it will fail again.
So, let's enlarge the bit field size to silence it.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Iterate over currently unrestored files only.
v4: New
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Since we keep files of all types in a single list (fds), it's possible
to use only function for that and to call it unconditionally.
v4: New
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Nobody uses pid, so let's kill it. Also, pass pstree_item parameter
to open_fdinfos() instead of list, as this function operates on fds
list only.
v4: New
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Since eventpoll opening time is set by dependencies
(see epoll_not_ready_tfd()), we may safely store them
in generic list.
v4: New
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Since tty opening order is set by dependencies,
we may safely store all ttys in generic list.
v4: New
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Fixup ctty right after it's open. It'll need for
merging tty files in single fds list: set ctty
before next fle in list is processed. See next
patch for the details.
v4: New
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Firstly masters, then slaves and lastly ctty.
v4: New
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This make open fds asynchronous. Now we restore them in a poll-style.
Every ->open callback operates like a poll. It returns 1, i.e. "call me again",
if some events have not received yet, or 0, if restoring of a fle
has finished.
We iterate over list of file descriptors and look at its return value.
If there were not progress in restoring of a fle, we sleep on task_st
futex. As all events are sent together with changing task_st, we will
be woken up, when there is a some new work for us.
v6: Add a comment about open method return values
v5: Clear FDS_EVENT every beginning of cycle.
Use 0, -1 and 1 for successful return error and "again" request.
v4: unix: 1)standalone sockets return ORV_AGAIN after first open
to reopen fd by generic code
2)do not call post_open_unix_sk() for !standalone sockets
inet, epoll: return ORV_AGAIN after first open to reopen fd by generic code
autofs: iterate used list instead of fds list
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This breaks everything, because files.c can't have
a deal with this yet. But next patch will teach it.
v5: Use hard-coded 0, -1 and 1 for successful return,
error and "again" request.
v4: tty: merge new_fd assignment to receive_tty()
and return this function result directly.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Return results of work separate: a new fd is in a parameter,
a status is in return value.
In next patches we will use return value "1" to indicate,
that open callback should be called once again, and restore
for this fle has not finished yet. So, we need to be able
to differ file descriptor with number 1 and "again" request.
We do not use negative value like -2 for this purpose,
because we want to allow fles to be served out before
they are completelly restored. So, if a fle is successefuly open,
but it's need one more call of open to complete its restore,
then we return 1 and populate new_fd in not negative value.
See "files: Kill struct file_desc_ops::post_open" for the details.
Also, export open_pipe()
v5: Use 0 and -1 for successful return and error.
v6: Rebase on new criu
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This is need to make receiving a fle non-blocking.
We will sleep on task_st futex instead of this.
v5: Do not set event in send_fd_to_self()
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Currently, it's just an additional check. But later this will be used
int the following way. Return value "1" means, that fle is not ready
for restore, and the caller should recall this method once again later.
See "[PATCH] files: Kill struct file_desc_ops::post_open" for the details.
v5: Use "1" for return
v2: Use generic FLE_OPEN and FLE_RESTORED to determ if a fle is ready
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This point we think it's a first call of open(),
so the state must be FLE_INITIALIZED.
v6: New
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Timerfd's post_open state does not depend on another objects,
so it may be safely merged into open stage.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
The step to make file opening use the only futex.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This is need for waiting, while port has users, using task_st futex.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Use task_st futex notifier instead of per-socket.
The step to make file opening use the only futex.
v2: Use internal bound and listen states instead of generic
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This is need for waiting a peer using task_st futex.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Add fle open stages. Set a stage after every operation.
v2: Do not merge filetype specific state with generic.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
The idea is symilar to kernel's wake_up() and wait_event().
One task needs some event. It checks the event has not
happened yet (fle hasn't received, unix peer hasn't bound, etc)
and calls get_fds_event(). Other task makes the event
(sends a fle, binds the peer to a name, etc) and calls set_fds_event().
So, while there is no an event, the first task is sleeping,
and the second wakes it up later:
Task A: clear_fds_event();
if (!socket_bound)
wait_fds_event(); /* sleep */
Task B: bind_socket();
set_fds_event(); /* wake up */
For the details of using see next patches.
v5: Use bit operations.
Split clear_fds_event from wait function.
v2: Do not wait for foreign transport sock is ready,
as it's guarantied by we create it before CR_STATE_FORKING.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
(was "files: Wait transport_fd before sending a fd to peer"
and "pstree: Add task_st futex")
We are going to move to the the single per-task bit field
for notifications about file opening events. Introduce
pstree_item::task_st for that.
v5: Add FDS_EVENT_BIT description.
v2: Do not wait until a peer's socket is created
as it's guarantied by we create it before CR_STATE_FORKING.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
TTY masters and slaves have no post_open stage,
so these two blocks may safely have their stages merged together.
The third is eventpoll, but two above do not depend
on it (their .post_open do not depend on eventpoll .open).
Unix sockets would have been, but this isn't implemented yet.
So, we may safely execute all stages for different
file types separatelly.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Since "receive" stage is used only for slave fds
and nobody depends on slave fds receiving is finished,
we may move it functionality in "post_open" stage.
This just makes slave fds to be received a little bit later.
In other words, only masters have post_open stage,
and only slaves have receive stage. So, in the case of
A and B files:
A->open
B->open
A->recv
A->post_open
B->recv
B->post_open
A->post_open can't depend on B->recv. This follows
just from analyzing of all file types post_open methods.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Since we are going to get rid of stage at all, kill this function
and call post_open_fd() unconditionally. It can handle the case,
when file_desc_ops::post_open is NULL
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Since transport socket is per-process, we do not need
fd parameter in this function anymore.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Since transport fd is per-task, this method is not need anymore.
Kill it.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Move reopen_fd_as() from receive_fd() to this function.
Note, that recv_fd_from_peer() has other callers, and
all of them are OK with receiving real fds (before,
they received arbitrary fds, and they OK with any fds).
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Don't wait for "prepare" stage of every peer's fd. Just
send everything to a peer's global transport socket, and
the peer will find appropriate fd, it needs at the moment.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
For moving to a single transport socket scheme, we should be able
to receive a fd, which is not need at the moment, but it will
be used in the future. So, we receive a further fd, and then
continue to wait the fd, we really need now.
v3: Delete excess BUG_ON().
Rename main patch funtion to keep_fd_for_future().
Rename second funtion to task_fle(), and make it
have "task" argument.
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
No functional changes
v3: Also do real_pid futex initialization
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
No functional changes
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
No functional changes
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
For moving to a single transport socket scheme, we need to be able to differ
fds in receive queue from each other. Add a fle pointer as identifier for that.
v2: Rebase on compel
travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
System call sys_futex() requires that (from futex(2)):
"On all platforms, futexes are four-byte integers
that must be aligned on a four-byte boundary".
travis-ci: success for locks: Mask futexes aligned
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
1. LOGROTATEDIR is not used since commit f4e9a1d
("make: don't install service and logrotate configs").
2. SYSTEMDUNITDIR is not used since commit 10d5e9a
("criu: scripts: remove criu service files").
3. install-tree target was *never* used, makes no sense
to keep it.
While at it, also
- sort the variables in "export" statement to match
the order of appearance in Makefile;
- don't export DESTDIR (it is exported by default as
it always comes from the make command line);
- remove unused variable from INSTALL.md.
travis-ci: success for Makefile.install fixes
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>