<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 3, 2016 at 12:42 PM, Mike Rapoport <span dir="ltr">&lt;<a href="mailto:rppt@linux.vnet.ibm.com" target="_blank">rppt@linux.vnet.ibm.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>On Tue, Aug 02, 2016 at 04:39:37PM +0000, Katerina Koukiou wrote:<br>
&gt; This patch introduces --remote option and image-proxy/image-cache processes.<br>
&gt; This leaves user the option to decide if the checkpoint data are to be stored<br>
&gt; on disk or sent through socket to the image-proxy.<br>
&gt; The latter forwards the data to the destination node where image-cache receives<br>
&gt; them.<br>
&gt;<br>
&gt; The overall communication is performed as follows:<br>
&gt; rc_node CRIU dump -&gt; (sends images using a local socket) -&gt;     image-proxy<br>
&gt;                                                                          |<br>
&gt;                                                                          V<br>
&gt; dst_node: CRIU restore &lt;- (receives images from a local socket)   &lt;- image-cache<br>
&gt;<br>
&gt; Running criu with --remote option is like this:<br>
&gt;<br>
&gt; dst_node# criu image-cache --port &lt;port&gt; -o /tmp/image-cache.log<br>
&gt; --local-cache-path &lt;local_cache_path&gt; ...<br>
&gt; dst_node# criu restore --remote -o /tmp/image-cache.log<br>
&gt; --local-cache-path &lt;local_cache_path&gt; ...<br>
&gt; src_node# criu image-proxy --port &lt;port&gt; --address &lt;dst_node&gt; -o /tmp/image-proxy.log<br>
&gt; --local-proxy-path &lt;local_proxy_path&gt; ...<br>
&gt; src_node# criu dump -t &lt;pid&gt; --remote -o /tmp/dump.log<br>
&gt; --local-proxy-path &lt;local_proxy_path&gt; ...<br>
&gt;<br>
&gt; Signed-off-by: Rodrigo Bruno &lt;rbruno at <a href="http://gsd.inesc-id.pt" rel="noreferrer" target="_blank">gsd.inesc-id.pt</a>&gt;<br>
&gt; Signed-off-by: Katerina Koukiou &lt;<a href="mailto:k.koukiou@gmail.com" target="_blank">k.koukiou@gmail.com</a>&gt;<br>
&gt; ---<br>
&gt;  criu/Makefile.crtools        |   4 +<br>
&gt;  criu/cr-dump.c               |  15 +++<br>
&gt;  criu/crtools.c               |  30 ++++-<br>
&gt;  criu/image-desc.c            |   4 +-<br>
&gt;  criu/image.c                 |  26 ++++-<br>
&gt;  criu/img-remote.c            | 272 +++++++++++++++++++++++++++++++++++++++++++<br>
&gt;  criu/include/cr_options.h    |   3 +<br>
&gt;  criu/include/image.h         |   1 +<br>
&gt;  criu/include/protobuf-desc.h |   4 +<br>
&gt;  criu/include/util.h          |   1 +<br>
&gt;  criu/page-xfer.c             |  27 ++++-<br>
&gt;  criu/pagemap.c               |  48 ++++++--<br>
&gt;  criu/protobuf-desc.c         |   1 +<br>
&gt;  criu/util.c                  |  15 +++<br>
&gt;  images/Makefile              |   1 +<br>
&gt;  images/remote-image.proto    |  20 ++++<br>
&gt;  16 files changed, 449 insertions(+), 23 deletions(-)<br>
&gt;  create mode 100644 criu/img-remote.c<br>
&gt;  create mode 100644 images/remote-image.proto<br>
&gt;<br>
&gt; diff --git a/criu/Makefile.crtools b/criu/Makefile.crtools<br>
&gt; index 2665f92..8189960 100644<br>
&gt; --- a/criu/Makefile.crtools<br>
&gt; +++ b/criu/Makefile.crtools<br>
&gt; @@ -26,6 +26,10 @@ obj-y                      += files-reg.o<br>
&gt;  obj-y                        += fsnotify.o<br>
&gt;  obj-y                        += image-desc.o<br>
&gt;  obj-y                        += image.o<br>
&gt; +obj-y                        += img-remote.o<br>
&gt; +obj-y                        += img-proxy.o<br>
&gt; +obj-y                        += img-cache.o<br>
&gt; +obj-y                        += img-remote-proto.o<br>
&gt;  obj-y                        += ipc_ns.o<br>
&gt;  obj-y                        += irmap.o<br>
&gt;  obj-y                        += kcmp-ids.o<br>
&gt; diff --git a/criu/cr-dump.c b/criu/cr-dump.c<br>
&gt; index be83bec..a8b5ab6 100644<br>
&gt; --- a/criu/cr-dump.c<br>
&gt; +++ b/criu/cr-dump.c<br>
&gt; @@ -84,6 +84,8 @@<br>
&gt;<br>
&gt;  #include &quot;asm/dump.h&quot;<br>
&gt;<br>
&gt; +#include &quot;img-remote.h&quot;<br>
&gt; +<br>
&gt;  static char loc_buf[PAGE_SIZE];<br>
&gt;<br>
&gt;  void free_mappings(struct vm_area_list *vma_area_list)<br>
&gt; @@ -1483,6 +1485,11 @@ int cr_pre_dump_tasks(pid_t pid)<br>
&gt;       struct pstree_item *item;<br>
&gt;       int ret = -1;<br>
&gt;<br>
&gt; +     if (opts.remote &amp;&amp; push_snapshot_id() &lt; 0) {<br>
&gt; +             pr_err(&quot;Failed to push image namespace.\n&quot;);<br>
&gt; +             goto err;<br>
&gt; +     }<br>
&gt; +<br>
&gt;       root_item = alloc_pstree_item();<br>
&gt;       if (!root_item)<br>
&gt;               goto err;<br>
&gt; @@ -1613,6 +1620,9 @@ static int cr_dump_finish(int ret)<br>
&gt;<br>
&gt;       close_service_fd(CR_PROC_FD_OFF);<br>
&gt;<br>
&gt; +     if (opts.remote)<br>
&gt; +             finish_remote_dump();<br>
&gt; +<br>
<br>
</div></div>Please take care of possible errors.<br>
Would it be correct to call finish_remote_dump even is ret != 0?<br>
And, what happens if finish_remote_dump fails?<br></blockquote><div>Fixed that. <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div><br>
&gt;       if (ret) {<br>
&gt;               pr_err(&quot;Dumping FAILED.\n&quot;);<br>
&gt;       } else {<br>
&gt; @@ -1633,6 +1643,11 @@ int cr_dump_tasks(pid_t pid)<br>
&gt;       pr_info(&quot;Dumping processes (pid: %d)\n&quot;, pid);<br>
&gt;       pr_info(&quot;========================================\n&quot;);<br>
&gt;<br>
&gt; +     if (opts.remote &amp;&amp; push_snapshot_id() &lt; 0) {<br>
&gt; +             pr_err(&quot;Failed to push image namespace.\n&quot;);<br>
&gt; +             goto err;<br>
&gt; +     }<br>
&gt; +<br>
&gt;       root_item = alloc_pstree_item();<br>
&gt;       if (!root_item)<br>
&gt;               goto err;<br>
&gt; diff --git a/criu/crtools.c b/criu/crtools.c<br>
&gt; index a0b2fc9..4efca16 100644<br>
&gt; --- a/criu/crtools.c<br>
&gt; +++ b/criu/crtools.c<br>
&gt; @@ -48,6 +48,7 @@<br>
&gt;<br>
&gt;  #include &quot;setproctitle.h&quot;<br>
&gt;  #include &quot;sysctl.h&quot;<br>
&gt; +#include &quot;img-remote.h&quot;<br>
&gt;<br>
&gt;  struct cr_options opts;<br>
&gt;<br>
&gt; @@ -72,6 +73,10 @@ void init_opts(void)<br>
&gt;       opts.ghost_limit = DEFAULT_GHOST_LIMIT;<br>
&gt;       opts.timeout = DEFAULT_TIMEOUT;<br>
&gt;       opts.empty_ns = 0;<br>
&gt; +     opts.addr = DEFAULT_CACHE_HOST;<br>
&gt; +     opts.port = DEFAULT_CACHE_PORT;<br>
&gt; +     opts.local_cache_path = DEFAULT_IMG_PATH;<br>
&gt; +     opts.local_proxy_path = DEFAULT_IMG_PATH;<br>
&gt;  }<br>
&gt;<br>
&gt;  static int parse_join_ns(const char *ptr)<br>
&gt; @@ -279,6 +284,9 @@ int main(int argc, char *argv[], char *envp[])<br>
&gt;               { &quot;cgroup-props-file&quot;,          required_argument,      0, 1081 },<br>
&gt;               { &quot;cgroup-dump-controller&quot;,     required_argument,      0, 1082 },<br>
&gt;               { SK_INFLIGHT_PARAM,            no_argument,            0, 1083 },<br>
&gt; +             { &quot;remote&quot;,                     no_argument,            0, 1084 },<br>
&gt; +             { &quot;local-cache-path&quot;,           required_argument,      0, 1085 },<br>
&gt; +             { &quot;local-proxy-path&quot;,           required_argument,      0, 1086 },<br>
&gt;               { },<br>
&gt;       };<br>
&gt;<br>
&gt; @@ -587,6 +595,15 @@ int main(int argc, char *argv[], char *envp[])<br>
&gt;                       pr_msg(&quot;Will skip in-flight TCP connections\n&quot;);<br>
&gt;                       opts.tcp_skip_in_flight = true;<br>
&gt;                       break;<br>
&gt; +             case 1084:<br>
&gt; +                     opts.remote = true;<br>
&gt; +                     break;<br>
&gt; +             case 1085:<br>
&gt; +                     opts.local_cache_path = optarg;<br>
&gt; +                     break;<br>
&gt; +             case 1086:<br>
&gt; +                     opts.local_proxy_path = optarg;<br>
&gt; +                     break;<br>
&gt;               case &#39;V&#39;:<br>
&gt;                       pr_msg(&quot;Version: %s\n&quot;, CRIU_VERSION);<br>
&gt;                       if (strcmp(CRIU_GITID, &quot;0&quot;))<br>
&gt; @@ -727,6 +744,12 @@ int main(int argc, char *argv[], char *envp[])<br>
&gt;       if (!strcmp(argv[optind], &quot;page-server&quot;))<br>
&gt;               return cr_page_server(opts.daemon_mode, -1) &gt; 0 ? 0 : 1;<br>
&gt;<br>
&gt; +     if (!strcmp(argv[optind], &quot;image-cache&quot;))<br>
&gt; +             return image_cache(opts.local_cache_path, opts.port);<br>
&gt; +<br>
&gt; +     if (!strcmp(argv[optind], &quot;image-proxy&quot;))<br>
&gt; +             return image_proxy(opts.local_proxy_path, opts.addr, opts.port);<br>
&gt; +<br>
&gt;       if (!strcmp(argv[optind], &quot;service&quot;))<br>
&gt;               return cr_service(opts.daemon_mode);<br>
&gt;<br>
&gt; @@ -753,6 +776,8 @@ usage:<br>
&gt;  &quot;  criu page-server\n&quot;<br>
&gt;  &quot;  criu service [&lt;options&gt;]\n&quot;<br>
&gt;  &quot;  criu dedup\n&quot;<br>
&gt; +&quot;  criu image-cache [&lt;options&gt;]\n&quot;<br>
&gt; +&quot;  criu image-proxy [&lt;options&gt;]\n&quot;<br>
&gt;  &quot;\n&quot;<br>
&gt;  &quot;Commands:\n&quot;<br>
&gt;  &quot;  dump           checkpoint a process/tree identified by pid\n&quot;<br>
&gt; @@ -765,6 +790,8 @@ usage:<br>
&gt;  &quot;  dedup          remove duplicates in memory dump\n&quot;<br>
&gt;  &quot;  cpuinfo dump   writes cpu information into image file\n&quot;<br>
&gt;  &quot;  cpuinfo check  validates cpu information read from image file\n&quot;<br>
&gt; +&quot;  image-cache    launch destination-side cache for images sent from the source-side\n&quot;<br>
&gt; +&quot;  image-proxy    launch source-side proxy to sent images to the destination-side\n&quot;<br>
&gt;       );<br>
&gt;<br>
&gt;       if (usage_error) {<br>
&gt; @@ -791,6 +818,7 @@ usage:<br>
&gt;  &quot;                        restore making it the parent of the restored process\n&quot;<br>
&gt;  &quot;  --freeze-cgroup\n&quot;<br>
&gt;  &quot;                        use cgroup freezer to collect processes\n&quot;<br>
&gt; +&quot;  --remote              dump/restore images directly to/from remote node using image-proxy/image-cache\n&quot;<br>
&gt;  &quot;\n&quot;<br>
&gt;  &quot;* Special resources support:\n&quot;<br>
&gt;  &quot;  -x|--&quot; USK_EXT_PARAM &quot;inode,..&quot; &quot;      allow external unix connections (optionally can be assign socket&#39;s inode that allows one-sided dump)\n&quot;<br>
&gt; @@ -900,7 +928,7 @@ usage:<br>
&gt;  &quot;\n&quot;<br>
&gt;  &quot;Page/Service server options:\n&quot;<br>
&gt;  &quot;  --address ADDR        address of server or service\n&quot;<br>
&gt; -&quot;  --port PORT           port of page server\n&quot;<br>
&gt; +&quot;  --port PORT           port of page serve or service\n&quot;<br>
&gt;  &quot;  -d|--daemon           run in the background after creating socket\n&quot;<br>
&gt;  &quot;\n&quot;<br>
&gt;  &quot;Other options:\n&quot;<br>
&gt; diff --git a/criu/image-desc.c b/criu/image-desc.c<br>
&gt; index 2b31354..e146ef8 100644<br>
&gt; --- a/criu/image-desc.c<br>
&gt; +++ b/criu/image-desc.c<br>
&gt; @@ -102,13 +102,13 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {<br>
&gt;       [CR_FD_STATS] = {<br>
&gt;               .fmt    = &quot;stats-%s&quot;,<br>
&gt;               .magic  = STATS_MAGIC,<br>
&gt; -             .oflags = O_SERVICE,<br>
&gt; +             .oflags = O_SERVICE | O_FORCE_LOCAL,<br>
&gt;       },<br>
&gt;<br>
&gt;       [CR_FD_IRMAP_CACHE] = {<br>
&gt;               .fmt    = &quot;irmap-cache&quot;,<br>
&gt;               .magic  = IRMAP_CACHE_MAGIC,<br>
&gt; -             .oflags = O_SERVICE,<br>
&gt; +             .oflags = O_SERVICE | O_FORCE_LOCAL,<br>
&gt;       },<br>
&gt;<br>
&gt;       [CR_FD_FILE_LOCKS_PID] = {<br>
&gt; diff --git a/criu/image.c b/criu/image.c<br>
&gt; index a3bb285..d5ecea2 100644<br>
&gt; --- a/criu/image.c<br>
&gt; +++ b/criu/image.c<br>
&gt; @@ -13,6 +13,7 @@<br>
&gt;  #include &quot;protobuf.h&quot;<br>
&gt;  #include &quot;images/inventory.pb-c.h&quot;<br>
&gt;  #include &quot;images/pagemap.pb-c.h&quot;<br>
&gt; +#include &quot;img-remote.h&quot;<br>
&gt;<br>
&gt;  bool ns_per_id = false;<br>
&gt;  bool img_common_magic = true;<br>
&gt; @@ -309,9 +310,26 @@ static int do_open_image(struct cr_img *img, int dfd, int type, unsigned long of<br>
&gt;  {<br>
&gt;       int ret, flags;<br>
&gt;<br>
&gt; -     flags = oflags &amp; ~(O_NOBUF | O_SERVICE);<br>
&gt; +     flags = oflags &amp; ~(O_NOBUF | O_SERVICE | O_FORCE_LOCAL);<br>
&gt;<br>
&gt; -     ret = openat(dfd, path, flags, CR_FD_PERM);<br>
&gt; +     if (opts.remote &amp;&amp; !(oflags &amp; O_FORCE_LOCAL)) {<br>
&gt; +             char *snapshot_id = NULL;<br>
&gt; +<br>
&gt; +             snapshot_id = get_snapshot_id_from_idx(dfd);<br>
&gt; +<br>
&gt; +             if (snapshot_id == NULL)<br>
&gt; +                     ret = -1;<br>
&gt; +             else if (flags == O_RDONLY) {<br>
&gt; +                     pr_info(&quot;do_open_remote_image RDONLY path=%s snapshot_id=%s\n&quot;,<br>
&gt; +                                     path, snapshot_id);<br>
<br>
</div></div>IMHO, pr_debug will suffice here<br>
<span><br>
&gt; +                     ret = read_remote_image_connection(snapshot_id, path);<br>
&gt; +             } else {<br>
&gt; +                     pr_info(&quot;do_open_remote_image WDONLY path=%s snapshot_id=%s\n&quot;,<br>
&gt; +                                     path, snapshot_id);<br>
<br>
</span>and here<br></blockquote><div>Right, changed these. <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div><br>
&gt; +                     ret = write_remote_image_connection(snapshot_id, path, O_WRONLY);<br>
&gt; +             }<br>
&gt; +     } else<br>
&gt; +             ret = openat(dfd, path, flags, CR_FD_PERM);<br>
&gt;       if (ret &lt; 0) {<br>
&gt;               if (!(flags &amp; O_CREAT) &amp;&amp; (errno == ENOENT)) {<br>
&gt;                       pr_info(&quot;No %s image\n&quot;, path);<br>
&gt; @@ -413,7 +431,9 @@ int open_image_dir(char *dir)<br>
&gt;       close(fd);<br>
&gt;       fd = ret;<br>
&gt;<br>
&gt; -     if (opts.img_parent) {<br>
&gt; +     if (opts.remote) {<br>
&gt; +             init_snapshot_id(dir);<br>
&gt; +     } else if (opts.img_parent) {<br>
&gt;               ret = symlinkat(opts.img_parent, fd, CR_PARENT_LINK);<br>
&gt;               if (ret &lt; 0 &amp;&amp; errno != EEXIST) {<br>
&gt;                       pr_perror(&quot;Can&#39;t link parent snapshot&quot;);<br>
&gt; diff --git a/criu/img-remote.c b/criu/img-remote.c<br>
&gt; new file mode 100644<br>
&gt; index 0000000..05f3666<br>
&gt; --- /dev/null<br>
&gt; +++ b/criu/img-remote.c<br>
&gt; @@ -0,0 +1,272 @@<br>
&gt; +#include &lt;unistd.h&gt;<br>
&gt; +#include &lt;stdlib.h&gt;<br>
&gt; +#include &lt;sys/types.h&gt;<br>
&gt; +#include &lt;sys/socket.h&gt;<br>
&gt; +#include &lt;netinet/in.h&gt;<br>
&gt; +#include &lt;netdb.h&gt;<br>
&gt; +#include &quot;xmalloc.h&quot;<br>
&gt; +#include &quot;criu-log.h&quot;<br>
&gt; +#include &quot;img-remote.h&quot;<br>
&gt; +#include &quot;img-remote-proto.h&quot;<br>
&gt; +#include &quot;images/remote-image.pb-c.h&quot;<br>
&gt; +#include &quot;protobuf-desc.h&quot;<br>
&gt; +#include &lt;fcntl.h&gt;<br>
&gt; +#include &quot;servicefd.h&quot;<br>
&gt; +#include &quot;compiler.h&quot;<br>
&gt; +#include &quot;cr_options.h&quot;<br>
&gt; +<br>
&gt; +#define PB_LOCAL_IMAGE_SIZE PATHLEN<br>
&gt; +<br>
&gt; +static char *snapshot_id;<br>
&gt; +<br>
&gt; +LIST_HEAD(snapshot_head);<br>
&gt; +<br>
&gt; +/* A snapshot is a dump or pre-dump operation. Each snapshot is identified by an<br>
&gt; + * ID which corresponds to the working directory specefied by the user.<br>
&gt; + */<br>
&gt; +struct snapshot {<br>
&gt; +     char snapshot_id[PATHLEN];<br>
&gt; +     struct list_head l;<br>
&gt; +};<br>
&gt; +<br>
&gt; +struct snapshot *new_snapshot(char *snapshot_id)<br>
&gt; +{<br>
&gt; +     struct snapshot *s = malloc(sizeof(struct snapshot));<br>
&gt; +<br>
&gt; +     if (!s)<br>
&gt; +             pr_perror(&quot;Failed to allocate snapshot structure&quot;);<br>
<br>
</div></div>Shouldn&#39;t we propagate allocation error?<br>
<span><br>
&gt; +     strncpy(s-&gt;snapshot_id, snapshot_id, PATHLEN);<br>
<br>
</span>because this fill SIGSEGV otherwise ;-)<span></span></blockquote><div> <br>Fixed that. <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>
&gt; +     return s;<br>
&gt; +}<br>
&gt; +<br>
&gt; +void add_snapshot(struct snapshot *snapshot)<br>
&gt; +{<br>
&gt; +     list_add_tail(&amp;(snapshot-&gt;l), &amp;snapshot_head);<br>
&gt; +}<br>
&gt; +<br>
&gt; +static char *get_local_img_path(void)<br>
&gt; +{<br>
&gt; +     static char *local_img_path = NULL;<br>
&gt; +<br>
&gt; +     if (local_img_path != NULL)<br>
&gt; +             return local_img_path;<br>
&gt; +<br>
&gt; +     if (strcmp(opts.local_cache_path, DEFAULT_IMG_PATH))<br>
&gt; +             local_img_path = opts.local_cache_path;<br>
&gt; +     else if (strcmp(opts.local_proxy_path, DEFAULT_IMG_PATH))<br>
&gt; +             local_img_path = opts.local_proxy_path;<br>
&gt; +<br>
<br>
</span>It seems that if user will pass DEFAULT_IMG_PATH in opts.local_cache_path<br>
and in opts.local_proxy_path, the local_img_path will remain NULL...<br>
<span><br></span></blockquote><div>Fixed that. <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>
&gt; +     return local_img_path;<br>
&gt; +}<br>
&gt; +<br>
&gt; +int read_remote_image_connection(char *snapshot_id, char *path)<br>
&gt; +{<br>
&gt; +     int error;<br>
&gt; +     int sockfd = setup_UNIX_client_socket(get_local_img_path());<br>
&gt; +<br>
&gt; +     if (sockfd &lt; 0) {<br>
&gt; +             pr_perror(&quot;Error opening local connection for %s:%s&quot;, path, snapshot_id);<br>
&gt; +             return -1;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     if (write_header(sockfd, snapshot_id, path, O_RDONLY) &lt; 0) {<br>
&gt; +             pr_perror(&quot;Error writing header for %s:%s&quot;, path, snapshot_id);<br>
&gt; +             return -1;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     if (read_reply_header(sockfd, &amp;error) &lt; 0) {<br>
&gt; +             pr_perror(&quot;Error reading reply header for %s:%s&quot;, path, snapshot_id);<br>
&gt; +             return -1;<br>
&gt; +     }<br>
&gt; +     errno = error;<br>
<br>
</span>Can you please explain why do you assign errno value?<br>
<div><div><br></div></div></blockquote><div>Yes, the code is not mine; I just rebased it. But I can tell you what I understand.<br></div><div>In criu/image.c  when an image does not exist read_remote_image_connection<br></div><div>returns -1. In image.c we want to handle this case separately when <br>read_remote_image_connection returns -1 but the reason is error code ENOENT.<br>Then because read_reply_header does not assign errno but error variable,<br></div><div>we do the &quot;errno = error&quot; assignment by ourselves.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>
&gt; +     if (!error)<br>
&gt; +             return sockfd;<br>
&gt; +     else if (error == ENOENT) {<br>
&gt; +             pr_info(&quot;Image does not exist (%s:%s)\n&quot;, path, snapshot_id);<br>
&gt; +             close(sockfd);<br>
&gt; +             return -1;<br>
&gt; +     }<br>
&gt; +     pr_perror(&quot;Unexpected error returned: %d (%s:%s)\n&quot;, error, path, snapshot_id);<br>
&gt; +     close(sockfd);<br>
&gt; +     return -1;<br>
&gt; +}<br>
&gt; +<br>
&gt; +int write_remote_image_connection(char *snapshot_id, char *path, int flags)<br>
&gt; +{<br>
&gt; +     int sockfd = setup_UNIX_client_socket(get_local_img_path());<br>
&gt; +<br>
&gt; +     if (sockfd &lt; 0)<br>
&gt; +             return -1;<br>
&gt; +<br>
&gt; +     if (write_header(sockfd, snapshot_id, path, flags) &lt; 0) {<br>
&gt; +             pr_perror(&quot;Error writing header for %s:%s&quot;, path, snapshot_id);<br>
&gt; +             return -1;<br>
&gt; +     }<br>
&gt; +     return sockfd;<br>
&gt; +}<br>
&gt; +<br>
&gt; +int finish_remote_dump(void)<br>
&gt; +{<br>
&gt; +     pr_info(&quot;Dump side is calling finish\n&quot;);<br>
&gt; +     int fd = write_remote_image_connection(NULL_SNAPSHOT_ID, DUMP_FINISH, O_WRONLY);<br>
&gt; +<br>
&gt; +     if (fd == -1) {<br>
&gt; +             pr_perror(&quot;Unable to open finish dump connection&quot;);<br>
&gt; +             return -1;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     close(fd);<br>
&gt; +     return 0;<br>
&gt; +}<br>
&gt; +<br>
&gt; +int skip_remote_bytes(int fd, unsigned long len)<br>
&gt; +{<br>
&gt; +     static char buf[4096];<br>
&gt; +     int n = 0;<br>
&gt; +     unsigned long curr = 0;<br>
&gt; +<br>
&gt; +     for (; curr &lt; len; ) {<br>
&gt; +             n = read(fd, buf, min(len - curr, (unsigned long)4096));<br>
&gt; +             if (n == 0) {<br>
&gt; +                     pr_perror(&quot;Unexpected end of stream (skipping %lx/%lx bytes)&quot;,<br>
&gt; +                             curr, len);<br>
&gt; +                     return -1;<br>
&gt; +             } else if (n &gt; 0) {<br>
&gt; +                     curr += n;<br>
&gt; +             } else {<br>
&gt; +                     pr_perror(&quot;Error while skipping bytes from stream (%lx/%lx)&quot;,<br>
&gt; +                             curr, len);<br>
&gt; +                     return -1;<br>
&gt; +             }<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     if (curr != len) {<br>
&gt; +             pr_perror(&quot;Unable to skip the current number of bytes: %lx instead of %lx&quot;,<br>
&gt; +                     curr, len);<br>
&gt; +             return -1;<br>
&gt; +     }<br>
&gt; +     return 0;<br>
&gt; +}<br>
&gt; +<br>
&gt; +static int pull_snapshot_ids(void)<br>
&gt; +{<br>
&gt; +     int n, sockfd;<br>
&gt; +     SnapshotIdEntry *ls;<br>
&gt; +     struct snapshot *s = NULL;<br>
&gt; +<br>
&gt; +     sockfd = read_remote_image_connection(NULL_SNAPSHOT_ID, PARENT_IMG);<br>
&gt; +<br>
&gt; +     /* The connection was successful but there is not file. */<br>
&gt; +     if (sockfd &lt; 0 &amp;&amp; errno == ENOENT)<br>
&gt; +             return 0;<br>
&gt; +     else if (sockfd &lt; 0) {<br>
&gt; +             pr_perror(&quot;Unable to open snapshot id read connection&quot;);<br>
&gt; +             return -1;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     while (1) {<br>
&gt; +             n = pb_read_obj(sockfd, (void **)&amp;ls, PB_SNAPSHOT_ID);<br>
&gt; +             if (!n) {<br>
&gt; +                     close(sockfd);<br>
&gt; +                     return n;<br>
&gt; +             } else if (n &lt; 0) {<br>
&gt; +                     pr_perror(&quot;Unable to read remote snapshot ids&quot;);<br>
&gt; +                     close(sockfd);<br>
&gt; +                     return n;<br>
&gt; +             }<br>
&gt; +<br>
&gt; +             s = new_snapshot(ls-&gt;snapshot_id);<br>
&gt; +             if (!s) {<br>
&gt; +                     pr_perror(&quot;Unable create new snapshot structure&quot;);<br>
&gt; +                     close(sockfd);<br>
&gt; +                     return -1;<br>
&gt; +             }<br>
&gt; +             add_snapshot(s);<br>
&gt; +             pr_info(&quot;[read_snapshot ids] parent = %s\n&quot;, ls-&gt;snapshot_id);<br>
&gt; +     }<br>
&gt; +     free(ls);<br>
&gt; +     close(sockfd);<br>
&gt; +     return n;<br>
&gt; +}<br>
&gt; +<br>
&gt; +int push_snapshot_id(void)<br>
&gt; +{<br>
&gt; +     int n;<br>
&gt; +     SnapshotIdEntry rn = SNAPSHOT_ID_ENTRY__INIT;<br>
&gt; +     int sockfd = write_remote_image_connection(NULL_SNAPSHOT_ID, PARENT_IMG, O_APPEND);<br>
&gt; +<br>
&gt; +     if (sockfd &lt; 0) {<br>
&gt; +             pr_perror(&quot;Unable to open snapshot id push connection&quot;);<br>
&gt; +             return -1;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     rn.snapshot_id = xmalloc(sizeof(char) * PATHLEN);<br>
&gt; +     if (!rn.snapshot_id) {<br>
&gt; +             pr_perror(&quot;Unable to allocate snapshot id buffer&quot;);<br>
&gt; +             close(sockfd);<br>
&gt; +             return -1;<br>
&gt; +     }<br>
&gt; +     strncpy(rn.snapshot_id, snapshot_id, PATHLEN);<br>
&gt; +<br>
&gt; +     n = pb_write_obj(sockfd, &amp;rn, PB_SNAPSHOT_ID);<br>
&gt; +<br>
&gt; +     xfree(rn.snapshot_id);<br>
&gt; +     close(sockfd);<br>
&gt; +     return n;<br>
&gt; +}<br>
&gt; +<br>
&gt; +void init_snapshot_id(char *si)<br>
&gt; +{<br>
&gt; +     snapshot_id = si;<br>
&gt; +}<br>
&gt; +<br>
&gt; +char *get_curr_snapshot_id(void)<br>
&gt; +{<br>
&gt; +     return snapshot_id;<br>
&gt; +}<br>
&gt; +<br>
&gt; +int get_curr_snapshot_id_idx(void)<br>
&gt; +{<br>
&gt; +     struct snapshot *si;<br>
&gt; +     int idx = 0;<br>
&gt; +<br>
&gt; +     if (list_empty(&amp;snapshot_head))<br>
&gt; +             pull_snapshot_ids();<br>
&gt; +<br>
&gt; +     list_for_each_entry(si, &amp;snapshot_head, l) {<br>
&gt; +     if (!strncmp(si-&gt;snapshot_id, snapshot_id, PATHLEN))<br>
&gt; +                     return idx;<br>
&gt; +             idx++;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     pr_perror(&quot;Error, could not find current snapshot id (%s) fd&quot;, snapshot_id);<br>
&gt; +     return -1;<br>
&gt; +}<br>
&gt; +<br>
&gt; +char *get_snapshot_id_from_idx(int idx)<br>
&gt; +{<br>
&gt; +     struct snapshot *si;<br>
&gt; +<br>
&gt; +     if (list_empty(&amp;snapshot_head))<br>
&gt; +             pull_snapshot_ids();<br>
&gt; +<br>
&gt; +     /* Note: if idx is the service fd then we need the current<br>
&gt; +      * snapshot_id idx. Else we need a parent snapshot_id idx.<br>
&gt; +      */<br>
&gt; +     if (idx == get_service_fd(IMG_FD_OFF))<br>
&gt; +             idx = get_curr_snapshot_id_idx();<br>
&gt; +<br>
&gt; +     list_for_each_entry(si, &amp;snapshot_head, l) {<br>
&gt; +             if (!idx)<br>
&gt; +                     return si-&gt;snapshot_id;<br>
&gt; +             idx--;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     pr_perror(&quot;Error, could not find snapshot id for idx %d&quot;, idx);<br>
&gt; +     return NULL;<br>
&gt; +}<br>
&gt; +<br>
&gt; +int get_curr_parent_snapshot_id_idx(void)<br>
&gt; +{<br>
&gt; +     return get_curr_snapshot_id_idx() - 1;<br>
&gt; +}<br>
&gt; diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h<br>
&gt; index 8eeadc9..ada8369 100644<br>
&gt; --- a/criu/include/cr_options.h<br>
&gt; +++ b/criu/include/cr_options.h<br>
&gt; @@ -111,6 +111,9 @@ struct cr_options {<br>
&gt;       unsigned int            empty_ns;<br>
&gt;       bool                    tcp_skip_in_flight;<br>
&gt;       char                    *work_dir;<br>
&gt; +     bool                    remote;<br>
&gt; +     char                    *local_cache_path;<br>
&gt; +     char                    *local_proxy_path;<br>
&gt;  };<br>
&gt;<br>
&gt;  extern struct cr_options opts;<br>
&gt; diff --git a/criu/include/image.h b/criu/include/image.h<br>
&gt; index 65b7b0a..9ba6ab8 100644<br>
&gt; --- a/criu/include/image.h<br>
&gt; +++ b/criu/include/image.h<br>
&gt; @@ -104,6 +104,7 @@ extern bool img_common_magic;<br>
&gt;  #define O_DUMP               (O_WRONLY | O_CREAT | O_TRUNC)<br>
&gt;  #define O_SHOW               (O_RDONLY | O_NOBUF)<br>
&gt;  #define O_RSTR               (O_RDONLY)<br>
&gt; +#define O_FORCE_LOCAL   (O_SYNC)<br>
&gt;<br>
&gt;  struct cr_img {<br>
&gt;       union {<br>
&gt; diff --git a/criu/include/protobuf-desc.h b/criu/include/protobuf-desc.h<br>
&gt; index 6c76b49..43ac534 100644<br>
&gt; --- a/criu/include/protobuf-desc.h<br>
&gt; +++ b/criu/include/protobuf-desc.h<br>
&gt; @@ -59,6 +59,10 @@ enum {<br>
&gt;       PB_BINFMT_MISC,         /* 50 */<br>
&gt;       PB_TTY_DATA,<br>
&gt;       PB_AUTOFS,<br>
&gt; +     PB_REMOTE_IMAGE,        /* Header for images sent from proxy to cache.*/<br>
&gt; +     PB_LOCAL_IMAGE,         /* Header for reading/writing images from/to proxy or cache. */<br>
&gt; +     PB_LOCAL_IMAGE_REPLY,   /* Header for reading/writing images reply. */<br>
&gt; +     PB_SNAPSHOT_ID,         /* Contains a single id. Used for reading/writing ids from proxy or cache. */<br>
&gt;<br>
&gt;       /* PB_AUTOGEN_STOP */<br>
&gt;<br>
&gt; diff --git a/criu/include/util.h b/criu/include/util.h<br>
&gt; index 5b7cad1..63be0ea 100644<br>
&gt; --- a/criu/include/util.h<br>
&gt; +++ b/criu/include/util.h<br>
&gt; @@ -259,6 +259,7 @@ FILE *fopenat(int dirfd, char *path, char *cflags);<br>
&gt;  void split(char *str, char token, char ***out, int *n);<br>
&gt;<br>
&gt;  int fd_has_data(int lfd);<br>
&gt; +size_t read_into_buffer(int fd, char *buff, size_t size);<br>
&gt;<br>
&gt;  int make_yard(char *path);<br>
&gt;<br>
&gt; diff --git a/criu/page-xfer.c b/criu/page-xfer.c<br>
&gt; index 7978227..3c668d7 100644<br>
&gt; --- a/criu/page-xfer.c<br>
&gt; +++ b/criu/page-xfer.c<br>
&gt; @@ -17,6 +17,8 @@<br>
&gt;  #include &quot;protobuf.h&quot;<br>
&gt;  #include &quot;images/pagemap.pb-c.h&quot;<br>
&gt;<br>
&gt; +#include &quot;img-remote.h&quot;<br>
&gt; +<br>
&gt;  static int page_server_sk = -1;<br>
&gt;<br>
&gt;  struct page_server_iov {<br>
&gt; @@ -288,7 +290,9 @@ static int open_page_local_xfer(struct page_xfer *xfer, int fd_type, long id)<br>
&gt;                       goto out;<br>
&gt;<br>
&gt;               xfer-&gt;parent = xmalloc(sizeof(*xfer-&gt;parent));<br>
&gt; -             if (!xfer-&gt;parent) {<br>
&gt; +             if (!xfer-&gt;parent &amp;&amp; opts.remote) {<br>
&gt; +                     return -1;<br>
&gt; +             } else if (!xfer-&gt;parent) {<br>
<br>
</div></div>I think using<br>
<br>
                if (!xfer-&gt;parent) {<br>
                        if (!opts.remote)<br>
                                close(pfd);<br>
                        return -1;<br>
                }<br>
<br>
is little bit less obscure.<br>
<div><div><br></div></div></blockquote><div>You are right. Changed this. <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>
&gt;                       close(pfd);<br>
&gt;                       return -1;<br>
&gt;               }<br>
&gt; @@ -298,10 +302,12 @@ static int open_page_local_xfer(struct page_xfer *xfer, int fd_type, long id)<br>
&gt;                       pr_perror(&quot;No parent image found, though parent directory is set&quot;);<br>
&gt;                       xfree(xfer-&gt;parent);<br>
&gt;                       xfer-&gt;parent = NULL;<br>
&gt; -                     close(pfd);<br>
&gt; +                     if (!opts.remote)<br>
&gt; +                             close(pfd);<br>
&gt;                       goto out;<br>
&gt;               }<br>
&gt; -             close(pfd);<br>
&gt; +             if (!opts.remote)<br>
&gt; +                     close(pfd);<br>
&gt;       }<br>
&gt;<br>
&gt;  out:<br>
&gt; @@ -406,9 +412,16 @@ int check_parent_local_xfer(int fd_type, int id)<br>
&gt;       struct stat st;<br>
&gt;       int ret, pfd;<br>
&gt;<br>
&gt; -     pfd = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);<br>
&gt; -     if (pfd &lt; 0 &amp;&amp; errno == ENOENT)<br>
&gt; -             return 0;<br>
&gt; +     if (opts.remote) {<br>
&gt; +             pfd = get_curr_parent_snapshot_id_idx();<br>
&gt; +             pr_err(&quot;Unable to get parent snapsgot id&quot;);<br>
&gt; +             if (pfd == -1)<br>
&gt; +                     return -1;<br>
&gt; +     } else {<br>
&gt; +             pfd = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);<br>
&gt; +             if (pfd &lt; 0 &amp;&amp; errno == ENOENT)<br>
&gt; +                     return 0;<br>
&gt; +     }<br>
&gt;<br>
&gt;       snprintf(path, sizeof(path), imgset_template[fd_type].fmt, id);<br>
&gt;       ret = fstatat(pfd, path, &amp;st, 0);<br>
&gt; @@ -470,6 +483,8 @@ int check_parent_page_xfer(int fd_type, long id)<br>
&gt;  {<br>
&gt;       if (opts.use_page_server)<br>
&gt;               return check_parent_server_xfer(fd_type, id);<br>
&gt; +     else if (opts.remote)<br>
&gt; +             return get_curr_parent_snapshot_id_idx() == -1 ? 0 : 1;<br>
&gt;       else<br>
&gt;               return check_parent_local_xfer(fd_type, id);<br>
&gt;  }<br>
&gt; diff --git a/criu/pagemap.c b/criu/pagemap.c<br>
&gt; index dbe9cc4..693f967 100644<br>
&gt; --- a/criu/pagemap.c<br>
&gt; +++ b/criu/pagemap.c<br>
&gt; @@ -11,6 +11,8 @@<br>
&gt;  #include &quot;protobuf.h&quot;<br>
&gt;  #include &quot;images/pagemap.pb-c.h&quot;<br>
&gt;<br>
&gt; +#include &quot;img-remote.h&quot;<br>
&gt; +<br>
&gt;  #ifndef SEEK_DATA<br>
&gt;  #define SEEK_DATA    3<br>
&gt;  #define SEEK_HOLE    4<br>
&gt; @@ -124,11 +126,18 @@ int dedup_one_iovec(struct page_read *pr, struct iovec *iov)<br>
&gt;  static int get_pagemap(struct page_read *pr, struct iovec *iov)<br>
&gt;  {<br>
&gt;       PagemapEntry *pe;<br>
&gt; +     int ret;<br>
&gt;<br>
&gt; -     if (pr-&gt;curr_pme &gt;= pr-&gt;nr_pmes)<br>
&gt; -             return 0;<br>
&gt; +     if (opts.remote) {<br>
&gt; +             ret = pb_read_one_eof(pr-&gt;pmi, &amp;pe, PB_PAGEMAP);<br>
&gt; +             if (ret &lt;= 0)<br>
&gt; +                     return ret;<br>
&gt; +     } else {<br>
&gt; +             if (pr-&gt;curr_pme &gt;= pr-&gt;nr_pmes)<br>
&gt; +                     return 0;<br>
&gt;<br>
&gt; -     pe = pr-&gt;pmes[pr-&gt;curr_pme];<br>
&gt; +             pe = pr-&gt;pmes[pr-&gt;curr_pme];<br>
&gt; +     }<br>
&gt;<br>
&gt;       pagemap2iovec(pe, iov);<br>
&gt;<br>
&gt; @@ -261,7 +270,7 @@ static int read_pagemap_page(struct page_read *pr, unsigned long vaddr, int nr,<br>
&gt;               off_t current_vaddr = lseek(fd, pr-&gt;pi_off, SEEK_SET);<br>
&gt;<br>
&gt;               pr_debug(&quot;\tpr%u Read page from self %lx/%&quot;PRIx64&quot;\n&quot;, pr-&gt;id, pr-&gt;cvaddr, current_vaddr);<br>
&gt; -             ret = read(fd, buf, len);<br>
&gt; +             ret = read_into_buffer(fd, buf, len);<br>
&gt;               if (ret != len) {<br>
&gt;                       pr_perror(&quot;Can&#39;t read mapping page %d&quot;, ret);<br>
&gt;                       return -1;<br>
&gt; @@ -314,7 +323,7 @@ static void close_page_read(struct page_read *pr)<br>
&gt;       if (pr-&gt;pi)<br>
&gt;               close_image(pr-&gt;pi);<br>
&gt;<br>
&gt; -     if (pr-&gt;pmes)<br>
&gt; +     if (!opts.remote &amp;&amp; pr-&gt;pmes)<br>
&gt;               free_pagemaps(pr);<br>
&gt;  }<br>
&gt;<br>
&gt; @@ -323,9 +332,24 @@ static int try_open_parent(int dfd, int pid, struct page_read *pr, int pr_flags)<br>
&gt;       int pfd, ret;<br>
&gt;       struct page_read *parent = NULL;<br>
&gt;<br>
&gt; -     pfd = openat(dfd, CR_PARENT_LINK, O_RDONLY);<br>
&gt; -     if (pfd &lt; 0 &amp;&amp; errno == ENOENT)<br>
&gt; -             goto out;<br>
&gt; +     if (opts.remote) {<br>
&gt; +             /* Note: we are replacing a real directory FD for a snapshot_id<br>
&gt; +              * index. Since we need the parent of the current snapshot_id,<br>
&gt; +              * we want the current snapshot_id index minus one. It is<br>
&gt; +              * possible that dfd is already a snapshot_id index. We test it<br>
&gt; +              * by comparing it to the service FD. When opening an image (see<br>
&gt; +              * do_open_image) we convert the snapshot_id index into a real<br>
&gt; +              * snapshot_id.<br>
&gt; +              */<br>
&gt; +             pfd = dfd == get_service_fd(IMG_FD_OFF) ?<br>
&gt; +                     get_curr_snapshot_id_idx() - 1 : dfd - 1;<br>
&gt; +             if (pfd &lt; 0)<br>
&gt; +                     goto out;<br>
&gt; +     } else {<br>
&gt; +             pfd = openat(dfd, CR_PARENT_LINK, O_RDONLY);<br>
&gt; +             if (pfd &lt; 0 &amp;&amp; errno == ENOENT)<br>
&gt; +                     goto out;<br>
&gt; +     }<br>
&gt;<br>
&gt;       parent = xmalloc(sizeof(*parent));<br>
&gt;       if (!parent)<br>
&gt; @@ -348,7 +372,8 @@ out:<br>
&gt;  err_free:<br>
&gt;       xfree(parent);<br>
&gt;  err_cl:<br>
&gt; -     close(pfd);<br>
&gt; +     if (!opts.remote)<br>
&gt; +             close(pfd);<br>
&gt;       return -1;<br>
&gt;  }<br>
&gt;<br>
&gt; @@ -458,7 +483,7 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)<br>
&gt;               return -1;<br>
&gt;       }<br>
&gt;<br>
&gt; -     if (init_pagemaps(pr)) {<br>
&gt; +     if (!opts.remote &amp;&amp; init_pagemaps(pr)) {<br>
<br>
</div></div>Is there anything that prevents using init_pagemaps with opts.remote?<br>
Why cannot we just read the entire pagemap from the socket as we read it<br>
from local file?<br></blockquote><div> </div><div>I hadn&#39;t commented it out at start, but got an error. I am not sure what the exact problem is.<br></div><div>The thing is that img_raw_size(pr-&gt;pmi) inside init_pagemaps returns 0; <br></div><div>Tell me if you understand why that happens.<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div><br>
&gt;               close_page_read(pr);<br>
&gt;               return -1;<br>
&gt;       }<br>
&gt; @@ -467,7 +492,8 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)<br>
&gt;       pr-&gt;put_pagemap = put_pagemap;<br>
&gt;       pr-&gt;read_pages = read_pagemap_page;<br>
&gt;       pr-&gt;close = close_page_read;<br>
&gt; -     pr-&gt;seek_page = seek_pagemap_page;<br>
&gt; +     if (!opts.remote)<br>
&gt; +             pr-&gt;seek_page = seek_pagemap_page;<br>
&gt;       pr-&gt;id = ids++;<br>
&gt;<br>
&gt;       pr_debug(&quot;Opened page read %u (parent %u)\n&quot;,<br>
&gt; diff --git a/criu/protobuf-desc.c b/criu/protobuf-desc.c<br>
&gt; index 9352a76..c1850f9 100644<br>
&gt; --- a/criu/protobuf-desc.c<br>
&gt; +++ b/criu/protobuf-desc.c<br>
&gt; @@ -64,6 +64,7 @@<br>
&gt;  #include &quot;images/seccomp.pb-c.h&quot;<br>
&gt;  #include &quot;images/binfmt-misc.pb-c.h&quot;<br>
&gt;  #include &quot;images/autofs.pb-c.h&quot;<br>
&gt; +#include &quot;images/remote-image.pb-c.h&quot;<br>
&gt;<br>
&gt;  struct cr_pb_message_desc cr_pb_descs[PB_MAX];<br>
&gt;<br>
&gt; diff --git a/criu/util.c b/criu/util.c<br>
&gt; index c44d900..5e2f400 100644<br>
&gt; --- a/criu/util.c<br>
&gt; +++ b/criu/util.c<br>
&gt; @@ -1184,3 +1184,18 @@ int setup_tcp_client(char *addr)<br>
&gt;<br>
&gt;       return sk;<br>
&gt;  }<br>
&gt; +<br>
&gt; +size_t read_into_buffer(int fd, char *buff, size_t size)<br>
&gt; +{<br>
<br>
</div></div>Can you please explain why this wrapper is required?<br></blockquote><div>Actually it&#39;s not. It&#39;s only used one time. I moved the code.<br></div><div>So, thanks for the comments.<br></div><div>I &#39;ll resend the patches with the above fixes, and rebased on<br></div><div>criu-dev, not master. <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div><br>
&gt; +     size_t n = 0;<br>
&gt; +     size_t curr = 0;<br>
&gt; +<br>
&gt; +     while (1) {<br>
&gt; +             n  = read(fd, buff + curr, size - curr);<br>
&gt; +             if (n &lt; 1)<br>
&gt; +                     return n;<br>
&gt; +             curr += n;<br>
&gt; +             if (curr == size)<br>
&gt; +                     return size;<br>
&gt; +     }<br>
&gt; +}<br>
&gt; diff --git a/images/Makefile b/images/Makefile<br>
&gt; index cf50794..3753d62 100644<br>
&gt; --- a/images/Makefile<br>
&gt; +++ b/images/Makefile<br>
&gt; @@ -60,6 +60,7 @@ proto-obj-y += binfmt-misc.o<br>
&gt;  proto-obj-y  += time.o<br>
&gt;  proto-obj-y  += sysctl.o<br>
&gt;  proto-obj-y  += autofs.o<br>
&gt; +proto-obj-y  += remote-image.o<br>
&gt;<br>
&gt;  CFLAGS               += -iquote $(obj)/<br>
&gt;<br>
&gt; diff --git a/images/remote-image.proto b/images/remote-image.proto<br>
&gt; new file mode 100644<br>
&gt; index 0000000..1212627<br>
&gt; --- /dev/null<br>
&gt; +++ b/images/remote-image.proto<br>
&gt; @@ -0,0 +1,20 @@<br>
&gt; +message local_image_entry {<br>
&gt; +     required string name            = 1;<br>
&gt; +     required string snapshot_id     = 2;<br>
&gt; +     required uint32 open_mode       = 3;<br>
&gt; +}<br>
&gt; +<br>
&gt; +message remote_image_entry {<br>
&gt; +     required string name            = 1;<br>
&gt; +     required string snapshot_id     = 2;<br>
&gt; +     required uint32 open_mode       = 3;<br>
&gt; +     required uint64 size            = 4;<br>
&gt; +}<br>
&gt; +<br>
&gt; +message local_image_reply_entry {<br>
&gt; +     required uint32 error           = 1;<br>
&gt; +}<br>
&gt; +<br>
&gt; +message snapshot_id_entry {<br>
&gt; +     required string snapshot_id     = 1;<br>
&gt; +}<br>
&gt; --<br>
&gt; 2.7.3<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; CRIU mailing list<br>
&gt; <a href="mailto:CRIU@openvz.org" target="_blank">CRIU@openvz.org</a><br>
&gt; <a href="https://lists.openvz.org/mailman/listinfo/criu" rel="noreferrer" target="_blank">https://lists.openvz.org/mailman/listinfo/criu</a><br>
&gt;<br>
<br>
</blockquote></div><br></div></div>