<div dir="ltr">Hi,<br><div class="gmail_extra"><br><div class="gmail_quote">2017-04-24 18:00 GMT+01:00 Pavel Emelyanov <span dir="ltr">&lt;<a href="mailto:xemul@virtuozzo.com" target="_blank">xemul@virtuozzo.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 04/24/2017 04:52 PM, Mike Rapoport wrote:<br>
&gt; On Mon, Apr 24, 2017 at 03:10:04PM +0300, Pavel Emelyanov wrote:<br>
<span class="">&gt;&gt; On 04/21/2017 06:25 PM, Mike Rapoport wrote:<br>
&gt;&gt;&gt; When --remote option is specified, read_local_page tries to pread from a<br>
&gt;&gt;&gt; socket, and fails with &quot;Illegal seek&quot; error.<br>
&gt;&gt;&gt; Restore single pread call for regular image files case and use read syscall<br>
&gt;&gt;&gt; instead of pread for the --remote case.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Signed-off-by: Mike Rapoport &lt;<a href="mailto:rppt@linux.vnet.ibm.com">rppt@linux.vnet.ibm.com</a>&gt;<br>
</span><span class="">&gt;&gt;&gt; ---<br>
&gt;&gt;&gt;  criu/pagemap.c | 18 +++++++++++++-----<br>
&gt;&gt;&gt;  1 file changed, 13 insertions(+), 5 deletions(-)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; diff --git a/criu/pagemap.c b/criu/pagemap.c<br>
&gt;&gt;&gt; index 6c741b4..7d25c6f 100644<br>
&gt;&gt;&gt; --- a/criu/pagemap.c<br>
&gt;&gt;&gt; +++ b/criu/pagemap.c<br>
&gt;&gt;&gt; @@ -265,15 +265,23 @@ static int read_local_page(struct page_read *pr, unsigned long vaddr,<br>
&gt;&gt;&gt;             return -1;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     pr_debug(&quot;\tpr%d-%u Read page from self %lx/%&quot;PRIx64&quot;\n&quot;, pr-&gt;pid, pr-&gt;id, pr-&gt;cvaddr, pr-&gt;pi_off);<br>
&gt;&gt;&gt; -   while (1) {<br>
&gt;&gt;&gt; +   if (!opts.remote) {<br>
&gt;&gt;<br>
</span>&gt;&gt; Maybe it&#39;s better to introduce separate -&gt;maybe_read_page callback for opts.remote case?<br>
&gt;&gt; This would let us localize the cache/proxy pages reading code in one place.<br>
&gt;<br>
&gt; Well, we could. E.g. something like the patch below (untested). Note that<br>
&gt; we already have maybe_read_page_remote for the remote lazy restore case,<br>
&gt; and, ideally, the cache/proxy and lazy cases should use the same code to<br>
&gt; read pages.<br>
<br>
Yup. I like this patch :)<br>
Rodrigo, what do you think?<br></blockquote><div><br></div><div><br></div><div>I agree.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
&gt; ----------------<br>
&gt; diff --git a/criu/pagemap.c b/criu/pagemap.c<br>
&gt; index 6c741b4..353c469 100644<br>
&gt; --- a/criu/pagemap.c<br>
&gt; +++ b/criu/pagemap.c<br>
&gt; @@ -255,7 +255,6 @@ static int read_local_page(struct page_read *pr, unsigned long vaddr,<br>
&gt;  {<br>
&gt;       int fd = img_raw_fd(pr-&gt;pi);<br>
&gt;       int ret;<br>
&gt; -     size_t curr = 0;<br>
&gt;<br>
&gt;       /*<br>
&gt;        * Flush any pending async requests if any not to break the<br>
&gt; @@ -265,15 +264,10 @@ static int read_local_page(struct page_read *pr, unsigned long vaddr,<br>
<span class="">&gt;               return -1;<br>
&gt;<br>
&gt;       pr_debug(&quot;\tpr%d-%u Read page from self %lx/%&quot;PRIx64&quot;\n&quot;, pr-&gt;pid, pr-&gt;id, pr-&gt;cvaddr, pr-&gt;pi_off);<br>
&gt; -     while (1) {<br>
</span>&gt; -             ret = pread(fd, buf + curr, len - curr, pr-&gt;pi_off + curr);<br>
&gt; -             if (ret &lt; 1) {<br>
&gt; -                     pr_perror(&quot;Can&#39;t read mapping page %d&quot;, ret);<br>
&gt; -                     return -1;<br>
&gt; -             }<br>
<span class="">&gt; -             curr += ret;<br>
&gt; -             if (curr == len)<br>
&gt; -                     break;<br>
</span>&gt; +     ret = pread(fd, buf, len, pr-&gt;pi_off);<br>
<span class="">&gt; +     if (ret != len) {<br>
</span><span class="">&gt; +             pr_perror(&quot;Can&#39;t read mapping page %d&quot;, ret);<br>
&gt; +             return -1;<br>
&gt;       }<br>
&gt;<br>
</span>&gt;       if (opts.auto_dedup) {<br>
&gt; @@ -390,6 +384,40 @@ static int maybe_read_page_local(struct page_read *pr, unsigned long vaddr,<br>
&gt;       return ret;<br>
&gt;  }<br>
&gt;<br>
&gt; +static int maybe_read_page_img_cache(<wbr>struct page_read *pr, unsigned long vaddr,<br>
&gt; +                                  int nr, void *buf, unsigned flags)<br>
&gt; +{<br>
&gt; +     unsigned long len = nr * PAGE_SIZE;<br>
&gt; +     int fd = img_raw_fd(pr-&gt;pi);<br>
&gt; +     int ret;<br>
&gt; +     size_t curr = 0;<br>
&gt; +<br>
&gt; +     pr_debug(&quot;\tpr%d-%u Read page from self %lx/%&quot;PRIx64&quot;\n&quot;, pr-&gt;pid, pr-&gt;id, pr-&gt;cvaddr, pr-&gt;pi_off);<br>
<span class="">&gt; +     while (1) {<br>
&gt; +             ret = read(fd, buf + curr, len - curr);<br>
&gt; +             if (ret &lt; 0) {<br>
&gt; +                     pr_perror(&quot;Can&#39;t read mapping page %d&quot;, ret);<br>
&gt; +                     return -1;<br>
&gt; +             }<br>
&gt; +             curr += ret;<br>
&gt; +             if (curr == len)<br>
&gt; +                     break;<br>
&gt; +     }<br>
</span>&gt; +<br>
&gt; +     if (opts.auto_dedup) {<br>
&gt; +             ret = punch_hole(pr, pr-&gt;pi_off, len, false);<br>
&gt; +             if (ret == -1)<br>
<span class="">&gt; +                     return -1;<br>
&gt; +     }<br>
&gt; +<br>
</span>&gt; +     if (ret == 0 &amp;&amp; pr-&gt;io_complete)<br>
&gt; +             ret = pr-&gt;io_complete(pr, vaddr, nr);<br>
&gt; +<br>
&gt; +     pr-&gt;pi_off += len;<br>
&gt; +<br>
&gt; +     return ret;<br>
&gt; +}<br>
&gt; +<br>
&gt;  static int read_page_complete(int pid, unsigned long vaddr, int nr_pages, void *priv)<br>
&gt;  {<br>
&gt;       int ret = 0;<br>
&gt; @@ -803,7 +831,9 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)<br>
&gt;       pr-&gt;id = ids++;<br>
&gt;       pr-&gt;pid = pid;<br>
&gt;<br>
&gt; -     if (remote)<br>
&gt; +     if (opts.remote)<br>
&gt; +             pr-&gt;maybe_read_page = maybe_read_page_img_cache;<br>
&gt; +     else if (remote)<br>
&gt;               pr-&gt;maybe_read_page = maybe_read_page_remote;<br>
&gt;       else<br>
&gt;               pr-&gt;maybe_read_page = maybe_read_page_local;<br>
&gt; ----------------<br>
&gt;<br>
&gt;<br>
&gt;&gt; -- Pavel<br>
<span class="">&gt;&gt;<br>
&gt;&gt;&gt;             ret = pread(fd, buf + curr, len - curr, pr-&gt;pi_off + curr);<br>
&gt;&gt;&gt; -           if (ret &lt; 1) {<br>
&gt;&gt;&gt; +           if (ret != len) {<br>
&gt;&gt;&gt;                     pr_perror(&quot;Can&#39;t read mapping page %d&quot;, ret);<br>
&gt;&gt;&gt;                     return -1;<br>
&gt;&gt;&gt;             }<br>
&gt;&gt;&gt; -           curr += ret;<br>
&gt;&gt;&gt; -           if (curr == len)<br>
&gt;&gt;&gt; -                   break;<br>
&gt;&gt;&gt; +   } else {<br>
&gt;&gt;&gt; +           while (1) {<br>
&gt;&gt;&gt; +                   ret = read(fd, buf + curr, len - curr);<br>
&gt;&gt;&gt; +                   if (ret &lt; 0) {<br>
&gt;&gt;&gt; +                           pr_perror(&quot;Can&#39;t read mapping page %d&quot;, ret);<br>
&gt;&gt;&gt; +                           return -1;<br>
&gt;&gt;&gt; +                   }<br>
&gt;&gt;&gt; +                   curr += ret;<br>
&gt;&gt;&gt; +                   if (curr == len)<br>
&gt;&gt;&gt; +                           break;<br>
&gt;&gt;&gt; +           }<br>
&gt;&gt;&gt;     }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     if (opts.auto_dedup) {<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
</span>&gt; .<br>
&gt;<br>
<br>
</blockquote></div><br></div></div>