[CRIU] [PATCH v3 13/33] user_ns: Name loading UsernsEntry mappings on restore "old format"
Kirill Tkhai
ktkhai at virtuozzo.com
Thu Feb 16 04:08:31 PST 2017
Split prepare_userns() in two functions.
Also, this commit fixes the problem, which existed before my patchset.
We do not populate userns_entry on restore, though it's need and used
at least by the chain prepare_mnt_ns()->sb_opt_cb()->userns_uid().
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/namespaces.c | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/criu/namespaces.c b/criu/namespaces.c
index eca7713dd..3f1190e5e 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -1646,19 +1646,48 @@ int stop_usernsd(void)
return ret;
}
-int prepare_userns(struct pstree_item *item)
+static int do_read_old_user_ns_img(struct ns_id *ns, void *arg)
{
+ int ret, *count = arg;
struct cr_img *img;
UsernsEntry *e;
- int ret;
- img = open_image(CR_FD_USERNS, O_RSTR, item->ids->user_ns_id);
+ if (++*count > 1) {
+ pr_err("More then one user_ns, img format can't be old\n");
+ return -1;
+ }
+
+ img = open_image(CR_FD_USERNS, O_RSTR, ns->id);
if (!img)
return -1;
ret = pb_read_one(img, &e, PB_USERNS);
close_image(img);
if (ret < 0)
return -1;
+ ns->user.e = e;
+ userns_entry = e;
+ root_user_ns = ns;
+ return 0;
+}
+
+static int read_old_user_ns_img(void)
+{
+ int ret, count = 0;
+
+ if (!(root_ns_mask & CLONE_NEWUSER))
+ return 0;
+ /* If new format img has already been read */
+ if (root_user_ns)
+ return 0;
+ /* Old format img is only for root_user_ns. More or less is error */
+ ret = walk_namespaces(&user_ns_desc, do_read_old_user_ns_img, &count);
+
+ return ret;
+}
+
+int prepare_userns(struct pstree_item *item)
+{
+ UsernsEntry *e = userns_entry;
if (write_id_map(item->pid->real, e->uid_map, e->n_uid_map, "uid_map"))
return -1;
@@ -1885,6 +1914,9 @@ int prepare_namespace_before_tasks(void)
if (read_mnt_ns_img())
goto err_img;
+ if (read_old_user_ns_img())
+ goto err_img;
+
return 0;
err_img:
More information about the CRIU
mailing list