All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
To: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	Dave Hansen
	<dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Subject: Re: [RFC cr-pipe-v13][PATCH 3/3] Restore open pipes
Date: Mon, 02 Feb 2009 19:02:57 -0500	[thread overview]
Message-ID: <498789B1.80601@cs.columbia.edu> (raw)
In-Reply-To: <87k5887n16.fsf-FLMGYpZoEPULwtHQx/6qkW3U47Q5hpJU@public.gmane.org>



Dan Smith wrote:
> OL> +/* restore a pipe */
> OL> +static int
> OL> +cr_read_fd_pipe(struct cr_ctx *ctx, struct cr_hdr_fd_data *hh, int rparent)
> OL> +{
> OL> +	struct file *file;
> OL> +	int fds[2], which, ret;
> OL> +
> OL> +	file = cr_obj_get_by_ref(ctx, hh->fd_objref, CR_OBJ_FILE);
> OL> +	if (IS_ERR(file))
> OL> +		return PTR_ERR(file);
> OL> +	else if (file)
> OL> +		return cr_attach_get_file(file);
> OL> +
> OL> +	/* first encounter of this pipe: create it */
> OL> +	ret = do_pipe(fds);

point (1)

> OL> +	if (ret < 0)
> OL> +		return ret;
> OL> +
> OL> +	which = (hh->f_flags & O_WRONLY ? 1 : 0);

point (2)

> OL> +
> OL> +	/*
> OL> +	 * Below we return the fd corersponding to one side of the pipe
> OL> +	 * for our caller to use. Now register the other side of the pipe
> OL> +	 * in the hash, to be picked up when that side is to be restored.
> OL> +	 */
> OL> +	file = cr_obj_add_file(ctx, fds[1-which], hh->fd_objref);
> OL> +	if (IS_ERR(file)) {
> OL> +		ret = PTR_ERR(file);
> OL> +		goto out;
> OL> +	}

point (3)

> OL> +
> OL> +	ret = cr_read_pipe(ctx, fds[which]);
> OL> + out:
> OL> +	sys_close(fds[1-which]);	/* this side isn't used anymore */

point (4)

> 
> This isn't always a valid thing to do, right?  I can think of two
> scenarios off the top of my head that will break here:
> 
> 1. The process has called pipe() but has not yet fork()'d
> 2. The process is using both sides of a pipe for a select()-based
>    event loop

In both scenarios, both ends of the pipes belong to a single process (and
only to it). Let's assume we restore the 'write' end first:

(1) we create the pipe (both ends)
(2) @which should be "1"
(3) we register the read-end file pointer (1-@which) in the objhash
(4) we close the file descriptor

At this point, the read end of the pipe should remain alive, because it
was put in the objhash and a reference was kept to it.

Some time later (probably when we process the next fd) we'll hit the
other end of the pipe, and we'll install it as is by taking the file
pointer from the objhash and attaching it to a new (empty) fd.

> 
> I worked up a quick test for #1, and it dies immediately on restart
> with a SIGPIPE.
> 

So the implementation of the logic above is ... inaccurate :(
I can reproduce it here; will take a closer look at it soon.

> I'll see if I can work up and post a patch to fix this if I can come
> up with something I think is reasonable.

Thanks,

Oren.

  parent reply	other threads:[~2009-02-03  0:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-27 21:23 [RFC cr-pipe-v13][PATCH 0/3] c/r of open pipes Oren Laadan
     [not found] ` <1233091395-24582-1-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-01-27 21:23   ` Oren Laadan
2009-01-27 21:23   ` [RFC cr-pipe-v13][PATCH 1/3] A new file type (CR_FD_OBJREF) for a file descriptor already setup Oren Laadan
2009-01-27 21:23   ` [RFC cr-pipe-v13][PATCH 2/3] Checkpoint open pipes Oren Laadan
     [not found]     ` <1233091395-24582-4-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-02-05  9:45       ` Cedric Le Goater
     [not found]         ` <498AB553.3090902-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2009-02-06  2:26           ` Nathan Lynch
     [not found]             ` <20090205202637.4d4f4a29-4v5LP+xe+1byhTdZtsIeww@public.gmane.org>
2009-02-06 13:05               ` Cedric Le Goater
2009-02-06 17:11               ` Dave Hansen
2009-02-06 17:20                 ` Cedric Le Goater
     [not found]                   ` <498C715B.4050303-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2009-02-06 17:24                     ` Dave Hansen
2009-02-07 12:54                       ` Cedric Le Goater
     [not found]                         ` <498D8489.6090904-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2009-02-09 14:39                           ` Cedric Le Goater
2009-01-27 21:23   ` [RFC cr-pipe-v13][PATCH 3/3] Restore " Oren Laadan
     [not found]     ` <1233091395-24582-5-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-02-02 17:43       ` Dan Smith
     [not found]         ` <87k5887n16.fsf-FLMGYpZoEPULwtHQx/6qkW3U47Q5hpJU@public.gmane.org>
2009-02-03  0:02           ` Oren Laadan [this message]
     [not found]             ` <498789B1.80601-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-02-03 16:23               ` Dan Smith
2009-01-27 21:29   ` [RFC cr-pipe-v13][PATCH 0/3] c/r of " Oren Laadan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=498789B1.80601@cs.columbia.edu \
    --to=orenl-eqauephvms7envbuuze7ea@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
    --cc=dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.