<div dir="ltr">Hi,<br><div class="gmail_extra"><br><div class="gmail_quote">2017-03-24 4:57 GMT+00:00 Andrei Vagin <span dir="ltr">&lt;<a href="mailto:avagin@virtuozzo.com" target="_blank">avagin@virtuozzo.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Sun, Mar 19, 2017 at 09:55:23PM +0000, rodrigo-bruno wrote:<br>
&gt; Signed-off-by: rodrigo-bruno &lt;<a href="mailto:rbruno@gsd.inesc-id.pt">rbruno@gsd.inesc-id.pt</a>&gt;<br>
&gt; ---<br>
&gt;  criu/img-remote-proto.c | 2 +-<br>
&gt;  1 file changed, 1 insertion(+), 1 deletion(-)<br>
&gt;<br>
&gt; diff --git a/criu/img-remote-proto.c b/criu/img-remote-proto.c<br>
&gt; index 3751b6f..51584bb 100644<br>
&gt; --- a/criu/img-remote-proto.c<br>
&gt; +++ b/criu/img-remote-proto.c<br>
&gt; @@ -743,7 +743,7 @@ int64_t send_image(int fd, struct rimage *rimg, int flags, bool close_fd)<br>
&gt;                       } else if (rimg-&gt;curr_sent_bytes == rimg-&gt;curr_sent_buf-&gt;nbytes) {<br>
&gt;                               if (close_fd)<br>
&gt;                                       close(fd);<br>
&gt; -                            return nblocks*BUF_SIZE + rimg-&gt;curr_sent_buf-&gt;nbytes;<br>
&gt; +                            return ((int64_t)nblocks*BUF_SIZE) + rimg-&gt;curr_sent_buf-&gt;nbytes;<br>
<br>
</span>I&#39;m not sure that I understand the logic of this function. For me it<br>
looks incorrect.<br>
<br>
The first thing is that I don&#39;t understand why you need to spit data to<br>
blocks.<br></blockquote><div><br></div><div>Data is split into blocks because the image proxy does not know the size of the image beforehand.</div><div>I.e., CRIU dump operation will open several images and will write directly to the proxy (through a UNIX</div><div>socket). If we are able to know, upon image opening, how much data we CRIU dump will need, them</div><div>we can avoid blocks. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
The second thing is that I think the following line is incorrect:<br>
<br>
min(BUF_SIZE, rimg-&gt;curr_sent_buf-&gt;nbytes) - rimg-&gt;curr_sent_bytes,<br>
<br>
nbytes is a constant in this function and it should be incorrect if<br>
nbytes is greater than BUF_SIZE and it isn&#39;t multiple to BUF_SIZE.<br>
<span class="gmail-"><br></span></blockquote><div><br></div><div>nbytes is the number of bytes that are being used in a block.</div><div>BUF_SIZE is the maximum number of used bytes in a block.</div><div>curr_sent_bytes is the number of bytes sent from the current block.</div><div><br></div><div>To send an image, we iterate through all blocks, sending one at a time.</div><div><br></div><div>min(BUF_SIZE, rimg-&gt;curr_sent_buf-&gt;nbytes) -&gt; tells us how many bytes are being used in the block.<br></div><div><br></div><div>min(BUF_SIZE, rimg-&gt;curr_sent_buf-&gt;nbytes) - rimg-&gt;curr_sent_bytes -&gt; tells us how many used bytes</div><div>still need to be sent.</div><div><br></div><div>Addressing your question: by design, nbytes should never be greater than BUF_SIZE (unless </div><div>there is a bug...). Is should always be true that nbytes &lt;= BUF_SIZE.</div><div><br></div><div>Nevertheless, I&#39;m open to suggestions to improve the code/design of the function :-)</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
&gt;                       }<br>
&gt;               } else if (errno == EPIPE || errno == ECONNRESET) {<br>
&gt;                       pr_warn(&quot;Connection for %s:%s was closed early than expected\n&quot;,<br>
&gt; --<br>
&gt; 2.1.4<br>
&gt;<br>
</span>&gt; ______________________________<wbr>_________________<br>
&gt; CRIU mailing list<br>
&gt; <a href="mailto:CRIU@openvz.org">CRIU@openvz.org</a><br>
&gt; <a href="https://lists.openvz.org/mailman/listinfo/criu" rel="noreferrer" target="_blank">https://lists.openvz.org/<wbr>mailman/listinfo/criu</a><br>
</blockquote></div><br></div></div>