[CRIU] [PATCH 10/17] dump: dump user namespaces
Pavel Emelyanov
xemul at parallels.com
Thu Nov 6 03:41:49 PST 2014
> @@ -1819,6 +1819,16 @@ int cr_dump_tasks(pid_t pid)
> if (collect_namespaces(true) < 0)
> goto err;
>
> + if (root_ns_mask & CLONE_NEWUSER) {
> + /*
> + * User namespace is dumped before files to get uid and gid
> + * mappings, which are used for convirting local id-s to
> + * userns id-s (userns_uid(), userns_gid())
> + */
> + if (dump_user_ns(root_item->pid.real, root_item->ids->user_ns_id))
> + goto err;
> + }
Plz, move it into collect_namespaces() and make it use the walk_namespaces()
routine.
> +
> glob_imgset = cr_glob_imgset_open(O_DUMP);
> if (!glob_imgset)
> goto err;
>
> int userns_gid(int gid)
> {
> - return userns_id(gid);
> + UsernsEntry *e = &userns_entry;
> + return userns_id(gid, e->gid_map, e->n_gid_map);
> }
>
> -static int dump_user_ns(pid_t pid, int ns_id)
> +static int parse_id_map(pid_t pid, char *name, UidGidExtent ***pb_exts)
Plz, move the parser code into proc_parse.c file.
> {
> - pr_err("User namesapces are not supported yet\n");
> + UidGidExtent *extents = NULL;
> + int len = 0, size = 0, ret, i;
> + FILE *f;
> +
> + f = fopen_proc(pid, "%s", name);
> + if (f == NULL)
> + return -1;
> +
> + ret = -1;
> + while (1) {
> + UidGidExtent *ext;
> +
> + if (len == size) {
> + UidGidExtent *t;
> +
> + size = size * 2 + 1;
> + t = xrealloc(extents, size * sizeof(UidGidExtent));
> + if (t == NULL)
> + break;
> + extents = t;
> + }
> +
> + ext = &extents[len];
> +
> + uid_gid_extent__init(ext);
> + ret = fscanf(f, "%d %d %d", &ext->first,
> + &ext->lower_first, &ext->count);
> + if (ret != 3) {
> + if (errno != 0) {
> + pr_perror("Unable to parse extents");
> + ret = -1;
> + } else
> + ret = 0;
> + break;
> + }
> + pr_info("id_map: %d %d %d\n", ext->first, ext->lower_first, ext->count);
> + len++;
> + }
> +
More information about the CRIU
mailing list