<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-10-12 11:54 GMT+03:00 Pavel Emelyanov <span dir="ltr"><<a href="mailto:xemul@virtuozzo.com" target="_blank">xemul@virtuozzo.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span class="gmail-">On 09/11/2016 08:14 PM, Eugene Batalov wrote:<br>
> We reuse minimal subset of criu restore command logic sufficient<br>
> to locate all the link remaps in all ps tree mnt namespaces.<br>
> No ps tree processes are created but all the ps tree mnt<br>
> namespaces and mountpoints are created. After creation of ps<br>
> tree mnt namespaces each link remap is deleted in its namespace.<br>
><br>
> Exact logic is the following:<br>
> 1. check_img_inventory() - prepare_pstree(). These calls are needed to<br>
> initialize root_ns_mask that is used during ps tree mnt namespaces<br>
> creation.<br>
<br>
</span>The root_ns_mask() is set up only in prepare_pstree() (which does much<br>
more than just this). But what is check_img_inventory() for?<br></blockquote><div><br></div><div>check_img_inventory() call is intended to check that criu dump files that we pass to criu gc are supported and somewhat valid.<br></div><div>check_img_inventory() is also called in the beginning of criu restore and cr_lazy_pages.<br></div><div>So it looks like we should have it in cr-gc.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<span class="gmail-"><br>
> 2. prepare_shared_fdinfo() - collect_remaps_and_regfiles(). These calls<br>
> are needed to collect information about link remaps and reg files of<br>
> ps tree from dump.<br>
<br>
</span>Why prepare_shared_fdinfo() needed?<br></blockquote><div><br></div><div>prepare_shared_fdinfo() is needed because during collect_remaps_and_regfiles() call collect_one_regfile() is called<br></div><div>and collect_one_regfile() calls file_desc_add().</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<span class="gmail-"><br>
> 3. gc_setup_mntns() (if needed) creates all the ps tree mnt namespaces<br>
> and performs mounting of proper fs hierachies into them.<br>
<br>
</span>The read_mntns_img() does this, no?<br></blockquote><div><br></div><div>No. The whole logic of gc_setup_mntns() does this. The main component of gc_setup_mntns() is prepare_mnt_ns() call that instantiates</div><div>all the ps tree mnt namespaces and their root file systems.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div class="gmail-HOEnZb"><div class="gmail-h5"><br>
> 4. prepare_remaps() call is needed to associate link remaps and reg<br>
> files structs we've read from dump. It also works with ps tree fs<br>
> so mnt namespaces should be created before this call.<br>
><br>
> 5. gc_link_remaps() - delete all the link remaps in their mnt namespaces.<br>
><br>
> Signed-off-by: Eugene Batalov <<a href="mailto:eabatalov89@gmail.com">eabatalov89@gmail.com</a>><br>
> ---<br>
> criu/cr-gc.c | 104 ++++++++++++++++++++++++++++++<wbr>++++++++++++++++-<br>
> criu/files-reg.c | 37 +++++++++++++++++<br>
> criu/include/files-reg.h | 1 +<br>
> 3 files changed, 141 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/criu/cr-gc.c b/criu/cr-gc.c<br>
> index bdd3723..e248e66 100644<br>
> --- a/criu/cr-gc.c<br>
> +++ b/criu/cr-gc.c<br>
> @@ -1,6 +1,108 @@<br>
> +#include <sched.h><br>
> +#include <unistd.h><br>
> +<br>
> +#include "criu-log.h"<br>
> #include "crtools.h"<br>
> +#include "pstree.h"<br>
> +#include "files.h"<br>
> +#include "files-reg.h"<br>
> +#include "mount.h"<br>
> +#include "namespaces.h"<br>
> +#include "util.h"<br>
><br>
> -int cr_gc(void)<br>
> +static int root_mntns = -1;<br>
> +<br>
> +static int gc_setup_mntns(void)<br>
> +{<br>
> + if (mntns_maybe_create_roots() < 0)<br>
> + return -1;<br>
> +<br>
> + if (read_mnt_ns_img() < 0)<br>
> + return -1;<br>
> +<br>
> + if (root_ns_mask & CLONE_NEWNS) {<br>
> + /* prepare_mnt_ns() expects that root mnt ns is already created */<br>
> + if (unshare(CLONE_NEWNS)) {<br>
> + pr_perror("Couldn't create root mount namespace\n");<br>
> + return -1;<br>
> + }<br>
> +<br>
> + root_mntns = open_proc(PROC_SELF, "ns/mnt");<br>
> + if (root_mntns < 0)<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (prepare_mnt_ns() < 0)<br>
> + return -1;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int gc_cleanup_mntns(void)<br>
> +{<br>
> + int ret = depopulate_roots_yard(root_<wbr>mntns, false);<br>
> +<br>
> + if ((root_mntns != -1) && close(root_mntns)) {<br>
> + pr_perror("Couldn't close root mntns fd");<br>
> + ret = -1;<br>
> + }<br>
> +<br>
> + return ret;<br>
> +}<br>
> +<br>
> +static int gc_do(void)<br>
> {<br>
> + if (gc_link_remaps() < 0)<br>
> + return -1;<br>
> +<br>
> return 0;<br>
> }<br>
> +<br>
> +int cr_gc(void)<br>
> +{<br>
> + int ret = 0;<br>
> +<br>
> + if (check_img_inventory() < 0) {<br>
> + ret = -1;<br>
> + goto exit;<br>
> + }<br>
> +<br>
> + if (prepare_task_entries() < 0) {<br>
> + ret = -1;<br>
> + goto exit;<br>
> + }<br>
> +<br>
> + if (prepare_pstree() < 0) {<br>
> + ret = -1;<br>
> + goto exit;<br>
> + }<br>
> +<br>
> + if (prepare_shared_fdinfo() < 0) {<br>
> + ret = -1;<br>
> + goto exit;<br>
> + }<br>
> +<br>
> + if (collect_remaps_and_regfiles()<wbr>) {<br>
> + ret = -1;<br>
> + goto exit;<br>
> + }<br>
> +<br>
> + if (gc_setup_mntns()) {<br>
> + ret = -1;<br>
> + goto exit;<br>
> + }<br>
> +<br>
> + if (prepare_remaps() < 0) {<br>
> + ret = -1;<br>
> + goto exit;<br>
> + }<br>
> +<br>
> + if (gc_do())<br>
> + ret = -1;<br>
> +<br>
> +exit:<br>
> + if (gc_cleanup_mntns())<br>
> + ret = -1;<br>
> +<br>
> + return ret;<br>
> +}<br>
> diff --git a/criu/files-reg.c b/criu/files-reg.c<br>
> index 45100f9..07e9772 100644<br>
> --- a/criu/files-reg.c<br>
> +++ b/criu/files-reg.c<br>
> @@ -712,6 +712,43 @@ static void __rollback_link_remaps(bool do_unlink)<br>
> void delete_link_remaps(void) { __rollback_link_remaps(true); }<br>
> void free_link_remaps(void) { __rollback_link_remaps(false); }<br>
><br>
> +int gc_link_remaps(void)<br>
> +{<br>
> + struct remap_info *ri;<br>
> + struct file_remap *remap;<br>
> +<br>
> + list_for_each_entry(ri, &remaps, list) {<br>
> + if (ri->rfe->remap_type != REMAP_TYPE__LINKED)<br>
> + continue;<br>
> +<br>
> + remap = ri->rfi->remap;<br>
> + struct ns_id *remap_mntns = lookup_nsid_by_mnt_id(remap-><wbr>rmnt_id);<br>
> +<br>
> + if (!remap_mntns) {<br>
> + pr_err("Can't get remap %s mnt ns %d\n",<br>
> + remap->rpath, remap->rmnt_id);<br>
> + return -1;<br>
> + }<br>
> +<br>
> + if (remap_mntns->nd->cflag != CLONE_NEWNS) {<br>
> + pr_err("Wrong clone flag of remap mntns %x (id:%d)",<br>
> + remap_mntns->nd->cflag, remap->rmnt_id);<br>
> + return -1;<br>
> + }<br>
> +<br>
> + /*<br>
> + * We are root ps tree item in restore cmd terms.<br>
> + * All the mnt namespaces and their fds are created<br>
> + * by root ps tree item on restore.<br>
> + * So we can simply use mnt ns fds here.<br>
> + */<br>
> + if (clean_one_remap(remap, remap_mntns->mnt.root_fd))<br>
> + return -1;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> static int create_link_remap(char *path, int len, int lfd,<br>
> u32 *idp, struct ns_id *nsid)<br>
> {<br>
> diff --git a/criu/include/files-reg.h b/criu/include/files-reg.h<br>
> index 6cc2454..ff54303 100644<br>
> --- a/criu/include/files-reg.h<br>
> +++ b/criu/include/files-reg.h<br>
> @@ -52,6 +52,7 @@ extern void delete_link_remaps(void);<br>
> extern void free_link_remaps(void);<br>
> extern int prepare_remaps(void);<br>
> extern void try_clean_remaps(void);<br>
> +extern int gc_link_remaps(void);<br>
><br>
> extern int strip_deleted(struct fd_link *link);<br>
><br>
><br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Best regards,<br>Eugene Batalov.</div>
</div></div>