<div dir="ltr">







<p class=""><span class="">In our case, the peer will be gone, and the restored process is in the middle of a blocking read.  As such the ideal for us is to receive an error for that read (in other words, abort the connection immediately/rst).  We&#39;d also be fine with having to specify this specific tcp connection/file descriptor so it knows to do this on restore.</span></p></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 21, 2015 at 12:03 PM, Pavel Emelyanov <span dir="ltr">&lt;<a href="mailto:xemul@parallels.com" target="_blank">xemul@parallels.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 04/21/2015 09:54 PM, Ross Boucher wrote:<br>
&gt; The tcp restore relies on the other side of the tcp connection still being open<br>
&gt; though, right?<br>
<br>
</span>Well, no. The TCP repair we use doesn&#39;t care about it. Just once we did the restore<br>
and _if_ the peer is not there, the remote kernel would respond with RST on _any_<br>
packet from restored socket and the connection would abort.<br>
<br>
So if we&#39;re talking about restore procedure only -- then criu doesn&#39;t care. If we&#39;re<br>
talking about &quot;successful restore&quot; as the result user wants, then yes, peer should<br>
still be alive and criu does everything it can to make it such.<br>
<span class=""><br>
&gt; In my case that won&#39;t be very easy. It would be much easier for me<br>
&gt; to just re-establish the connection if I could notify myself somehow that the<br>
&gt; process is restored. (I&#39;m playing around right now with running a timer in another<br>
&gt; thread to try and do that...)<br>
<br>
</span>Unix sockets are not the same as TCP I would say. But, since you&#39;re OK with connecting<br>
the socket back upon restore, then we can teach CRIU do all this for you.<br>
<span class="HOEnZb"><font color="#888888"><br>
-- Pavel<br>
</font></span><span class="im HOEnZb"><br>
&gt; On Tue, Apr 21, 2015 at 11:52 AM, Pavel Emelyanov &lt;<a href="mailto:xemul@parallels.com">xemul@parallels.com</a> &lt;mailto:<a href="mailto:xemul@parallels.com">xemul@parallels.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;     On 04/21/2015 07:46 PM, Ross Boucher wrote:<br>
&gt;     &gt; Thanks, this is all very interesting. How does the story change for tcp sockets?<br>
&gt;<br>
&gt;     For TCP we can &quot;lock&quot; the connection so that the peer doesn&#39;t see the<br>
&gt;     socket gets closed. We either put iptables rule that blocks all the<br>
&gt;     packets or (in case of containers) unplug container&#39;s virtual NIC from<br>
&gt;     the network. So while the connection is locked we can kill the socket,<br>
&gt;     then create it back. And the TCP-repair thing helps us &quot;connect&quot; the<br>
&gt;     socket back w/o actually doing the connect.<br>
&gt;<br>
&gt;     For unix socket we don&#39;t have ability to &quot;lock&quot; the connection in the<br>
&gt;     first place. So once we dumped the task we cannot keep peer from noticing<br>
&gt;     this. This thing was the main reason for not implementing this.<br>
&gt;<br>
&gt;     -- Pavel<br>
&gt;<br>
</span><div class="HOEnZb"><div class="h5">&gt;     &gt; On Tue, Apr 21, 2015 at 5:03 AM, Pavel Emelyanov &lt;<a href="mailto:xemul@parallels.com">xemul@parallels.com</a> &lt;mailto:<a href="mailto:xemul@parallels.com">xemul@parallels.com</a>&gt; &lt;mailto:<a href="mailto:xemul@parallels.com">xemul@parallels.com</a> &lt;mailto:<a href="mailto:xemul@parallels.com">xemul@parallels.com</a>&gt;&gt;&gt; wrote:<br>
&gt;     &gt;<br>
&gt;     &gt;     On 04/19/2015 04:48 AM, Ross Boucher wrote:<br>
&gt;     &gt;     &gt; Hey everyone,<br>
&gt;     &gt;<br>
&gt;     &gt;     Hi, Ross.<br>
&gt;     &gt;<br>
&gt;     &gt;     &gt; I&#39;ve been trying to figure out both what happens when you checkpoint an open socket<br>
&gt;     &gt;     &gt; and what my options are for restoring that socket (or maybe doing something else at<br>
&gt;     &gt;     &gt; that point in time). It might be best to just describe the program I have and what<br>
&gt;     &gt;     &gt; I want to accomplish.<br>
&gt;     &gt;     &gt;<br>
&gt;     &gt;     &gt; I have two programs communicating over a socket. Program A opens a socket and listens<br>
&gt;     &gt;     &gt; for connections, and then program B connects to it. They essentially exchange messages<br>
&gt;     &gt;     &gt; forever in a pattern something like:<br>
&gt;     &gt;     &gt;<br>
&gt;     &gt;     &gt; A -&gt; B send next message<br>
&gt;     &gt;     &gt; B -&gt; A ok, here&#39;s the next message<br>
&gt;     &gt;     &gt;<br>
&gt;     &gt;     &gt; Obviously, in between, A performs some actions. The goal is to checkpoint A after each<br>
&gt;     &gt;     &gt; message is processed and before the next is received (while leaving the process<br>
&gt;     &gt;     &gt; running), so that we can restore to any previous state and reprocess possibly changed<br>
&gt;     &gt;     &gt; messages.<br>
&gt;     &gt;<br>
&gt;     &gt;     First thing that comes to mind is that --track-mem thing definitely makes sense for<br>
&gt;     &gt;     such frequent C/R-s. But that&#39;s a side note :)<br>
&gt;     &gt;<br>
&gt;     &gt;     &gt; It&#39;s completely fine for our use case to have to re-establish that socket connection,<br>
&gt;     &gt;     &gt; we don&#39;t actually need or want to try and magically use the same socket (since program<br>
&gt;     &gt;     &gt; B has probably moved on to other things in between).<br>
&gt;     &gt;<br>
&gt;     &gt;     Hm.. OK.<br>
&gt;     &gt;<br>
&gt;     &gt;     &gt; Is this a use case for a criu plugin?<br>
&gt;     &gt;<br>
&gt;     &gt;     Well, I would say it is, but there are two things about it. First is that we don&#39;t have any<br>
&gt;     &gt;     hooks in CRIU code for sockets, so patching will be required. And the second is -- many<br>
&gt;     &gt;     people are asking for handling the connected unix socket, so I think we&#39;d better patch<br>
&gt;     &gt;     criu itself to provide some sane API rather than make everybody invent their own plugins :)<br>
&gt;     &gt;<br>
&gt;     &gt;     So, I see two options for such an API.<br>
&gt;     &gt;<br>
&gt;     &gt;     The first is to extend the --ext-unix-sk to accept socket ID as an argument that would<br>
&gt;     &gt;     force even stream sockets to be marked as &quot;external&quot; and not block the dump. On restore<br>
&gt;     &gt;     the --ext-unix-sk with $ID would make CRIU connect the restored unix socket back to its<br>
&gt;     &gt;     original path. Optionally we can make the argument look like $ID:$PATH and connect to<br>
&gt;     &gt;     $PATH instead.<br>
&gt;     &gt;<br>
&gt;     &gt;     The other option would be to still teach dump accept the --ext-unix-sk $ID parameter. On<br>
&gt;     &gt;     restore you can create the connection yourself and then pass it into CRIU with --inherit-fd<br>
&gt;     &gt;     argument. We already have fd inheritance for pipes and files [1], but we can patch CRIU<br>
&gt;     &gt;     to support it for sockets too.<br>
&gt;     &gt;<br>
&gt;     &gt;     [1] <a href="http://criu.org/Inheriting_FDs_on_restore" target="_blank">http://criu.org/Inheriting_FDs_on_restore</a><br>
&gt;     &gt;<br>
&gt;     &gt;     &gt; I&#39;ve tried playing around with the ext-unix-sk flag but I haven&#39;t quite figured anything<br>
&gt;     &gt;     &gt; out yet.<br>
&gt;     &gt;<br>
&gt;     &gt;     The --ext-unix-sk is for datagram sockets as they are stateless and we can just close and<br>
&gt;     &gt;     re-open one back w/o any risk that the peer notices it.<br>
&gt;     &gt;<br>
&gt;     &gt;     &gt; Any help would be appreciated. Thanks!<br>
&gt;     &gt;<br>
&gt;     &gt;     -- Pavel<br>
&gt;     &gt;<br>
&gt;     &gt;<br>
&gt;<br>
&gt;<br>
<br>
</div></div></blockquote></div><br></div>