<div dir="ltr">Hi Andrei,<div><br></div><div>thank you.</div><div><br></div><div>So we can start working on fixing bugs in order for the zdtm tests to pass sending patches against </div><div><a href="https://github.com/avagin/criu/tree/remote">https://github.com/avagin/criu/tree/remote</a> ?<br></div><div><br></div><div>cheers,</div><div>rodrigo</div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-05-15 7:49 GMT+01: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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
I rebased these patches and added a few minor fixes:<br>
<a href="https://github.com/avagin/criu/tree/remote" rel="noreferrer" target="_blank">https://github.com/avagin/<wbr>criu/tree/remote</a><br>
<div><div class="h5"><br>
On Mon, May 14, 2018 at 01:29:47AM +0100, rodrigo-bruno wrote:<br>
&gt; From: Rodrigo Bruno &lt;<a href="mailto:rbruno@gsd.inesc-id.pt">rbruno@gsd.inesc-id.pt</a>&gt;<br>
&gt; <br>
&gt; ---<br>
&gt;  criu/img-remote.c         | 93 +++++++++++++++++++++++++++++-<wbr>---------<br>
&gt;  criu/include/img-remote.h | 28 ++++++++++--<br>
&gt;  2 files changed, 93 insertions(+), 28 deletions(-)<br>
&gt; <br>
&gt; diff --git a/criu/img-remote.c b/criu/img-remote.c<br>
&gt; index f812c52d..70db71e2 100644<br>
&gt; --- a/criu/img-remote.c<br>
&gt; +++ b/criu/img-remote.c<br>
&gt; @@ -470,8 +470,6 @@ static struct rimage *new_remote_image(char *path, char *snapshot_id)<br>
&gt;       buf-&gt;nbytes = 0;<br>
&gt;       INIT_LIST_HEAD(&amp;(rimg-&gt;buf_<wbr>head));<br>
&gt;       list_add_tail(&amp;(buf-&gt;l), &amp;(rimg-&gt;buf_head));<br>
&gt; -     rimg-&gt;curr_sent_buf = list_entry(rimg-&gt;buf_head.<wbr>next, struct rbuf, l);<br>
&gt; -     rimg-&gt;curr_sent_bytes = 0;<br>
&gt;  <br>
&gt;       if (pthread_mutex_init(&amp;(rimg-&gt;<wbr>in_use), NULL) != 0) {<br>
&gt;               pr_err(&quot;Remote image in_use mutex init failed\n&quot;);<br>
&gt; @@ -498,8 +496,6 @@ static struct rimage *clear_remote_image(struct rimage *rimg)<br>
&gt;  <br>
&gt;       list_entry(rimg-&gt;buf_head.<wbr>next, struct rbuf, l)-&gt;nbytes = 0;<br>
&gt;       rimg-&gt;size = 0;<br>
&gt; -     rimg-&gt;curr_sent_buf = list_entry(rimg-&gt;buf_head.<wbr>next, struct rbuf, l);<br>
&gt; -     rimg-&gt;curr_sent_bytes = 0;<br>
&gt;  <br>
&gt;       pthread_mutex_unlock(&amp;(rimg-&gt;<wbr>in_use));<br>
&gt;  <br>
&gt; @@ -669,18 +665,43 @@ err:<br>
&gt;       return NULL;<br>
&gt;  }<br>
&gt;  <br>
&gt; +<br>
&gt; +int64_t recv_image(int fd, struct rimage *rimg, uint64_t size, int flags, bool close_fd)<br>
&gt; +{<br>
&gt; +     int ret;<br>
&gt; +     struct roperation *op = malloc(sizeof(struct roperation));<br>
&gt; +     bzero(op, sizeof(struct roperation));<br>
&gt; +     op-&gt;fd = fd;<br>
&gt; +     op-&gt;rimg = rimg;<br>
&gt; +     op-&gt;size = size;<br>
&gt; +     op-&gt;flags = flags;<br>
&gt; +     op-&gt;close_fd = close_fd;<br>
&gt; +     op-&gt;curr_recv_buf = list_entry(rimg-&gt;buf_head.<wbr>next, struct rbuf, l);<br>
&gt; +     while ((ret = recv_image_async(op)) &lt; 0)<br>
&gt; +             if (ret != EAGAIN &amp;&amp; ret != EWOULDBLOCK)<br>
&gt; +                     return -1;<br>
&gt; +     return ret;<br>
&gt; +}<br>
&gt; +<br>
&gt;  /* Note: size is a limit on how much we want to read from the socket.  Zero means<br>
&gt;   * read until the socket is closed.<br>
&gt;   */<br>
&gt; -int64_t recv_image(int fd, struct rimage *rimg, uint64_t size, int flags, bool close_fd)<br>
&gt; +int64_t recv_image_async(struct roperation *op)<br>
&gt;  {<br>
&gt; -     struct rbuf *curr_buf = NULL;<br>
&gt; +     int fd = op-&gt;fd;<br>
&gt; +     struct rimage *rimg = op-&gt;rimg;<br>
&gt; +     uint64_t size = op-&gt;size;<br>
&gt; +     int flags = op-&gt;flags;<br>
&gt; +     bool close_fd = op-&gt;close_fd;<br>
&gt; +     struct rbuf *curr_buf = op-&gt;curr_recv_buf;<br>
&gt;       int n;<br>
&gt;  <br>
&gt; -     if (flags == O_APPEND)<br>
&gt; -             curr_buf = list_entry(rimg-&gt;buf_head.<wbr>prev, struct rbuf, l);<br>
&gt; -     else<br>
&gt; -             curr_buf = list_entry(rimg-&gt;buf_head.<wbr>next, struct rbuf, l);<br>
&gt; +     if (curr_buf == NULL) {<br>
&gt; +             if (flags == O_APPEND)<br>
&gt; +                     curr_buf = list_entry(rimg-&gt;buf_head.<wbr>prev, struct rbuf, l);<br>
&gt; +             else<br>
&gt; +                     curr_buf = list_entry(rimg-&gt;buf_head.<wbr>next, struct rbuf, l);<br>
&gt; +     }<br>
&gt;  <br>
&gt;       while (1) {<br>
&gt;               n = read(fd,<br>
&gt; @@ -712,6 +733,8 @@ int64_t recv_image(int fd, struct rimage *rimg, uint64_t size, int flags, bool c<br>
&gt;                                       close(fd);<br>
&gt;                               return rimg-&gt;size;<br>
&gt;                       }<br>
&gt; +             } else if (errno == EAGAIN || errno == EWOULDBLOCK) {<br>
&gt; +                     return errno;<br>
&gt;               } else {<br>
&gt;                       pr_perror(&quot;Read on %s:%s socket failed&quot;,<br>
&gt;                               rimg-&gt;path, rimg-&gt;snapshot_id);<br>
&gt; @@ -724,37 +747,59 @@ int64_t recv_image(int fd, struct rimage *rimg, uint64_t size, int flags, bool c<br>
&gt;  <br>
&gt;  int64_t send_image(int fd, struct rimage *rimg, int flags, bool close_fd)<br>
&gt;  {<br>
&gt; +     int ret;<br>
&gt; +     struct roperation *op = malloc(sizeof(struct roperation));<br>
&gt; +     bzero(op, sizeof(struct roperation));<br>
&gt; +     op-&gt;fd = fd;<br>
&gt; +     op-&gt;rimg = rimg;<br>
&gt; +     op-&gt;flags = flags;<br>
&gt; +     op-&gt;close_fd = close_fd;<br>
&gt; +     op-&gt;curr_sent_buf = list_entry(rimg-&gt;buf_head.<wbr>next, struct rbuf, l);<br>
&gt; +     while ((ret = send_image_async(op)) &lt; 0)<br>
&gt; +             if (ret != EAGAIN &amp;&amp; ret != EWOULDBLOCK)<br>
&gt; +                     return -1;<br>
&gt; +     return ret;<br>
&gt; +}<br>
&gt;  <br>
&gt; -     int n, nblocks = 0;<br>
&gt; +int64_t send_image_async(struct roperation *op)<br>
&gt; +{<br>
&gt; +     int fd = op-&gt;fd;<br>
&gt; +     struct rimage *rimg = op-&gt;rimg;<br>
&gt; +     int flags = op-&gt;flags;<br>
&gt; +     bool close_fd = op-&gt;close_fd;<br>
&gt; +     int n;<br>
&gt;  <br>
&gt;       if (flags != O_APPEND) {<br>
&gt; -             rimg-&gt;curr_sent_buf = list_entry(rimg-&gt;buf_head.<wbr>next, struct rbuf, l);<br>
&gt; -             rimg-&gt;curr_sent_bytes = 0;<br>
&gt; +             op-&gt;curr_sent_buf = list_entry(rimg-&gt;buf_head.<wbr>next, struct rbuf, l);<br>
&gt; +             op-&gt;curr_sent_bytes = 0;<br>
&gt;       }<br>
&gt;  <br>
&gt;       while (1) {<br>
&gt;               n = send(<br>
&gt;                   fd,<br>
&gt; -                 rimg-&gt;curr_sent_buf-&gt;buffer + rimg-&gt;curr_sent_bytes,<br>
&gt; -                 min(BUF_SIZE, rimg-&gt;curr_sent_buf-&gt;nbytes) - rimg-&gt;curr_sent_bytes,<br>
&gt; +                 op-&gt;curr_sent_buf-&gt;buffer + op-&gt;curr_sent_bytes,<br>
&gt; +                 min(BUF_SIZE, op-&gt;curr_sent_buf-&gt;nbytes) - op-&gt;curr_sent_bytes,<br>
&gt;                   MSG_NOSIGNAL);<br>
&gt;               if (n &gt; -1) {<br>
&gt; -                     rimg-&gt;curr_sent_bytes += n;<br>
&gt; -                     if (rimg-&gt;curr_sent_bytes == BUF_SIZE) {<br>
&gt; -                             rimg-&gt;curr_sent_buf =<br>
&gt; -                                 list_entry(rimg-&gt;curr_sent_<wbr>buf-&gt;l.next, struct rbuf, l);<br>
&gt; -                             nblocks++;<br>
&gt; -                             rimg-&gt;curr_sent_bytes = 0;<br>
&gt; -                     } else if (rimg-&gt;curr_sent_bytes == rimg-&gt;curr_sent_buf-&gt;nbytes) {<br>
&gt; +                     op-&gt;curr_sent_bytes += n;<br>
&gt; +                     if (op-&gt;curr_sent_bytes == BUF_SIZE) {<br>
&gt; +                             op-&gt;curr_sent_buf =<br>
&gt; +                                 list_entry(op-&gt;curr_sent_buf-&gt;<wbr>l.next, struct rbuf, l);<br>
&gt; +                             op-&gt;nblocks++;<br>
&gt; +                             op-&gt;curr_sent_bytes = 0;<br>
&gt; +                     } else if (op-&gt;curr_sent_bytes == op-&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 op-&gt;nblocks*BUF_SIZE + op-&gt;curr_sent_buf-&gt;nbytes;<br>
&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;                               rimg-&gt;path, rimg-&gt;snapshot_id);<br>
&gt;                       return 0;<br>
&gt; -             } else {<br>
&gt; +             } else if (errno == EAGAIN || errno == EWOULDBLOCK) {<br>
&gt; +                     return errno;<br>
&gt; +             }<br>
&gt; +             else {<br>
&gt;                       pr_perror(&quot;Write on %s:%s socket failed&quot;,<br>
&gt;                               rimg-&gt;path, rimg-&gt;snapshot_id);<br>
&gt;                       return -1;<br>
&gt; diff --git a/criu/include/img-remote.h b/criu/include/img-remote.h<br>
&gt; index 1771d310..0947e7f0 100644<br>
&gt; --- a/criu/include/img-remote.h<br>
&gt; +++ b/criu/include/img-remote.h<br>
&gt; @@ -36,10 +36,6 @@ struct rimage {<br>
&gt;       char snapshot_id[PATHLEN];<br>
&gt;       struct list_head l;<br>
&gt;       struct list_head buf_head;<br>
&gt; -     /* Used to track already sent buffers when the image is appended. */<br>
&gt; -     struct rbuf *curr_sent_buf;<br>
&gt; -     /* Similar to the previous field. Number of bytes sent in &#39;curr_sent_buf&#39;. */<br>
&gt; -     int curr_sent_bytes;<br>
&gt;       uint64_t size; /* number of bytes */<br>
&gt;       pthread_mutex_t in_use; /* Only one operation at a time, per image. */<br>
&gt;  };<br>
&gt; @@ -57,6 +53,28 @@ struct wthread {<br>
&gt;       sem_t wakeup_sem;<br>
&gt;  };<br>
&gt;  <br>
&gt; +/* Structure that describes the state of a remote operation on remote images. */<br>
&gt; +struct roperation {<br>
&gt; +     /* File descriptor being used. */<br>
&gt; +     int fd;<br>
&gt; +     /* Remote image being used. */<br>
&gt; +     struct rimage *rimg;<br>
&gt; +     /* Flags for the operation. */<br>
&gt; +     int flags;<br>
&gt; +     /* If fd should be closed when the operation is done. */<br>
&gt; +     bool close_fd;<br>
&gt; +     /* Note: recv operation only. How much bytes should be received. */<br>
&gt; +     uint64_t size;<br>
&gt; +     /* Note: recv operation only. Buffer being writen. */<br>
&gt; +     struct rbuf *curr_recv_buf;<br>
&gt; +     /* Note: send operation only. Number of blocks already sent. */<br>
&gt; +     int nblocks;<br>
&gt; +     /* Note: send operation only. Pointer to buffer being sent. */<br>
&gt; +     struct rbuf *curr_sent_buf;<br>
&gt; +     /* Note: send operation only. Number of bytes sent in &#39;curr_send_buf. */<br>
&gt; +     uint64_t curr_sent_bytes;<br>
&gt; +};<br>
&gt; +<br>
&gt;  /* This variable is used to indicate when the dump is finished. */<br>
&gt;  extern bool finished;<br>
&gt;  /* This is the proxy to cache TCP socket FD. */<br>
&gt; @@ -80,7 +98,9 @@ void *accept_remote_image_<wbr>connections(void *ptr);<br>
&gt;  <br>
&gt;  int64_t forward_image(struct rimage *rimg);<br>
&gt;  int64_t send_image(int fd, struct rimage *rimg, int flags, bool image_check);<br>
&gt; +int64_t send_image_async(struct roperation *op);<br>
&gt;  int64_t recv_image(int fd, struct rimage *rimg, uint64_t size, int flags, bool image_check);<br>
&gt; +int64_t recv_image_async(struct roperation *op);<br>
&gt;  <br>
&gt;  int64_t read_remote_header(int fd, char *snapshot_id, char *path, int *open_mode, uint64_t *size);<br>
&gt;  int64_t write_remote_header(int fd, char *snapshot_id, char *path, int open_mode, uint64_t size);<br>
&gt; -- <br>
&gt; 2.17.0<br>
&gt; <br>
</div></div>&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>