[CRIU] [PATCH] Add inherit fd support
Andrew Vagin
avagin at parallels.com
Thu Dec 4 02:29:53 PST 2014
On Wed, Dec 03, 2014 at 01:04:18PM -0800, Saied Kazemi wrote:
> There are cases where a process's file descriptor cannot be restored
> from the checkpointed image. For example, a pipe file descriptor with
> one end in the checkpointed process and the other end in a separate
> process (that was not part of the checkpointed process tree) cannot be
> restored because after checkpoint the pipe would be broken and removed.
>
> There are also cases where the user wants to use a new file during
> restore instead of the original file in the checkpointed image. For
> example, the user wants to change the log file of a process from
> /path/to/oldlog to /path/to/newlog.
>
> In these cases, criu's caller should set up a new file descriptor to be
> inherited by the restored process and specify it with the --inherit-fd
> command line option. The argument of --inherit-fd has the format
> fd[%d]:%s, where %d tells criu which of its own file descriptor to use
> for restoring file identified by %s.
>
> As a debugging aid, if the argument has the format debug[%d]:%s, it tells
> criu to write out the string after colon to the file descriptor %d. This
> can be used to leave a "restore marker" in the output stream of the process.
>
> It's important to note that inherit fd support breaks applications
> that depend on the state of the file descriptor being inherited. So,
> consider inherit fd only for specific use cases that you know for sure
> won't break the application.
>
> For examples please visit http://criu.org/Category:HOWTO.
>
> Signed-off-by: Saied Kazemi <saied at google.com>
...
> @@ -302,6 +314,20 @@ static int open_pipe(struct file_desc *d)
>
> pi = container_of(d, struct pipe_info, d);
>
> + /*
> + * If the pipe is in the inherit fd list,
> + * it should be inherited rather than created.
> + */
> + pipe_name = pipe_id_string(pi->pe->pipe_id);
> + if (pipe_name == NULL)
> + return -1;
> + tmp = inherit_fd_lookup_id(pipe_name);
> + if (tmp >= 0) {
> + pr_info("Pipe %s will be restored from inherit fd %d\n",
> + pipe_name, tmp);
> + return tmp;
A process can have more than one descriptor associated with a pipe. This
code doesn't handle this case.
I think inherit_fd_lookup_id must return dup(inh->inh_fd).
More information about the CRIU
mailing list