[CRIU] [PATCH v2 00/28] Rework file opening scheme to make it asynchronous

Kirill Tkhai ktkhai at virtuozzo.com
Wed Nov 30 08:28:42 PST 2016


This series rework file opening scheme. Currently, we have 4 stages of opening:
1)prepare
2)create
3)receive
4)post_create

It's became too complex, but now we bumped in the situation with unix sockets,
when even 4 stages is not enough. So, it will became more complex in this way.

Also, the problem is in the scheme is synchronous. You should wait receiving
of master fle (or pipe fd) and just to sleep, even if you have to restore another
files, which are not depend on receiving foreign fd. So, the restored tasks stand
in a chain and this is not good for performance.

The patchset aims to solve these problems. It makes open scheme asynchronous,
and not using blocking syscalls like receive. The restorer iterates over
file list and call ->open method for each file. If file is ready to be restored,
it restores. Otherwise, "repeat" answer (ORV_AGAIN) is returned, and we try
to restore it after our other files are restored (or changed their stage),
or some extenal event is received.

External event receiving is implemented using global futex task_st. It's
organized similar to the way the try_to_wake_up() is made in linux kernel.

If you change a stage of a fle, which may be interested for other task,
you change the stage and set FDS_EVENT bit to the other task's task_st.
If there was no the bit, you wake the futex up (it's possible to say,
FDS_EVENT is similar to TASK_RUNNING).

The other task follows the next scheme. It clears FDS_EVENT in its task_st,
and polls the fles, which it's interested in. If nothing changes it sleep
on futex again. If there is a changes, it handles it using ->open. See
"files: Implement {set,get}_fds_event()" for "try_to_wake_up" details.
Full polling is implemented in "files: Kill struct file_desc_ops::post_open".

It's possible to make restore async further, but now it's a moment,
when patches is too more and the main goal is implemented. Further, is
possible to merge different types of files in the single list
(fds, eventpoll, tty slaves and ctty).

v2: Do not wait while foreign transport socket is created, use global
    CR_STATE_FORKING synchronization point instead.
    Do not merge generic and file specific states in FLE_*.
    Rebase on fresh criu-dev and compel.
---

Kirill Tkhai (28):
      files: Create per-process transport sock and bind it
      pstree: Add task_st futex
      files: Send/receive fds with pointers on their struct fdinfo_list_entry in receiver
      files: Move closing fle's transport_fd to recv_fd_from_peer()
      files: Move derefferencing of TRANSPORT_FD_OFF to send_fd_to_peer()
      files: Add fle_init() for initialization new fdinfo_list_entry
      files: Allow to receive further fds
      files: Make sending fds to peers async
      files: Receive real fd numbers using recv_fd_from_peer()
      files: Kill file_desc_ops::want_transport()
      files: Kill fd parameter of transport_name_gen()
      files: Use collect_gen_fd() in tty_collect_fd()
      files: Kill want_post_open_stage()
      files: Kill fd_open_state::receive_fd stage
      files: Merge states iteration into open_fdinfos()
      files: Implement {set,get}_fds_event()
      files: Add fdinfo_list_entry::stage
      unix: Link connected to peer sockets to its list
      unix: Wait a peer using task_st futex
      inet: Link sockets in port_type list
      inet: Use task_st futex for notification instead of per-port
      timerfd: Kill post_open stage
      files: Add open stages enum
      eventpoll: Make post_open stage may fail
      files: Set fds event after sending fd to peer
      files: Add new_fd parameter to file_desc_ops::open()
      files: Make recv_fd_from_peer() non-block
      files: Kill struct file_desc_ops::post_open


 criu/autofs.c          |   29 +++
 criu/cr-restore.c      |    9 -
 criu/eventfd.c         |    5 -
 criu/eventpoll.c       |   42 ++++-
 criu/fifo.c            |    9 +
 criu/files-ext.c       |    5 -
 criu/files-reg.c       |   10 +
 criu/files.c           |  426 +++++++++++++++++++++++-------------------------
 criu/fsnotify.c        |   10 +
 criu/include/files.h   |   41 +++--
 criu/include/pipes.h   |    1 
 criu/include/pstree.h  |    7 +
 criu/include/sk-inet.h |    1 
 criu/include/tty.h     |    2 
 criu/namespaces.c      |    5 -
 criu/pipes.c           |   46 ++---
 criu/pstree.c          |    1 
 criu/signalfd.c        |    5 -
 criu/sk-inet.c         |   51 ++++--
 criu/sk-netlink.c      |    5 -
 criu/sk-packet.c       |    5 -
 criu/sk-unix.c         |  128 +++++++++-----
 criu/timerfd.c         |   25 +--
 criu/tty.c             |   67 +++-----
 criu/tun.c             |    9 +
 criu/util.c            |    3 
 include/common/lock.h  |    5 +
 27 files changed, 532 insertions(+), 420 deletions(-)

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


More information about the CRIU mailing list