[CRIU] [PATCH 1/5] mnt: add --ext-mount-map auto option

Andrew Vagin avagin at odin.com
Mon Apr 13 01:24:06 PDT 2015


On Fri, Apr 10, 2015 at 02:34:37PM +0000, Tycho Andersen wrote:
> +static int resolve_external_mounts(struct mount_info *info)
> +{
> +	struct mount_info *m;
> +	struct ns_id *ns = NULL, *iter;
> +
> +	for (iter = ns_ids; iter->next; iter = iter->next) {
> +		if (iter->pid == getpid() && iter->nd == &mnt_ns_desc) {
> +			ns = iter;
> +			break;
> +		}
> +	}
> +
> +	if (!ns) {
> +		pr_err("Failed to find criu pid's mount ns!");
> +		return -1;
> +	}
> +
> +	for (m = info; m; m = m->next) {
> +		int ret, size;
> +		char *p;
> +		struct ext_mount *em;
> +		struct mount_info *match;
> +
> +		if (m->parent == NULL || m->is_ns_root)
> +			continue;
> +
> +		ret = try_resolve_ext_mount(m);
> +		if (ret < 0 && ret != -ENOTSUP) {
> +			return -1;
> +		} else if (ret == -ENOTSUP && !opts.autodetect_ext_mounts) {
> +			continue;
> +		} else if (ret == 0) {
> +			continue;
> +		}
> +
> +		match = find_best_external_match(ns->mnt.mntinfo_list, m);
> +		if (!match)
> +			continue;
> +
> +		size = strlen(match->mountpoint + 1) + strlen(m->root) + 1;
> +		p = xmalloc(sizeof(char) * size);
> +		if (!p)
> +			return -1;
> +
> +		ret = snprintf(p, size+1, "%s%s", match->mountpoint + 1, m->root);

Is it ok if match->root isn't /?

> +		if (ret < 0 || ret >= size) {
> +			free(p);
> +			return -1;
> +		}
> +
> +		em = xmalloc(sizeof(struct ext_mount));
> +		if (!em) {
> +			free(p);
> +			return -1;
> +		}
> +
> +		em->val = AUTODETECTED_MOUNT;
> +		em->key = p;
> +
> +		m->external = em;
> +
> +		xfree(m->source);
> +		m->source = p;
> +
> +		pr_info("autodetected external mount %s for %s\n", p, m->mountpoint);
> +	}
> +
> +	return 0;
> +}
> +


More information about the CRIU mailing list