[CRIU] [PATCH] link-remap: open link-remap files from correct mountpoints (v3)

Pavel Emelyanov xemul at parallels.com
Wed Aug 6 04:34:13 PDT 2014


> -static inline int rfi_remap(struct reg_file_info *rfi)
> +static int rfi_remap(struct reg_file_info *rfi)
>  {
> -	return link(rfi->remap->path, rfi->path);
> +	struct mount_info *mi, *rmi, *tmi;
> +	char _path[PATH_MAX], *path = _path;
> +	char _rpath[PATH_MAX], *rpath = _rpath;
> +	int mntns_root;
> +
> +	if (rfi->rfe->mnt_id == -1) {
> +		/* Know nothing about mountpoints */
> +		mntns_root = mntns_get_root_by_mnt_id(-1);
> +		return linkat(mntns_root, rfi->remap->path, mntns_root, rfi->path, 0);

Can we properly setup rpath and path here and make goto linkat at the end of
this routine?

> +	}
> +
> +	mi = lookup_mnt_id(rfi->rfe->mnt_id);
> +
> +	if (rfi->rfe->mnt_id == rfi->remap->mnt_id) {
> +		/* Both links on the same mount point */
> +		tmi = mi;
> +		path = rfi->path;
> +		rpath = rfi->remap->path;
> +		goto out;
> +	}
> +
> +	rmi = lookup_mnt_id(rfi->remap->mnt_id);
> +
> +	/*
> +	 * Find the common bind-mount. We know that one mount point was
> +	 * really mounted and all other were bind-mounted from it, so the
> +	 * lowest mount must contains all bind-mounts.
> +	 */
> +	for (tmi = mi; tmi->bind; tmi = tmi->bind);
> +
> +	BUG_ON(tmi->s_dev != rmi->s_dev);
> +	BUG_ON(tmi->s_dev != mi->s_dev);
> +
> +	/* Calcalate paths on the device (root mount) */
> +	convert_path_from_another_mp(rfi->path, path, sizeof(_path), mi, tmi);
> +	convert_path_from_another_mp(rfi->remap->path, rpath, sizeof(_rpath), rmi, tmi);
> +
> +out:
> +	pr_debug("%d: Link %s -> %s\n", tmi->mnt_id, rpath, path);
> +
> +	mntns_root = mntns_get_root_by_mnt_id(tmi->mnt_id);

This one will lookup mnt again. Can we avoid it?

> +
> +	return linkat(mntns_root, rpath, mntns_root, path, 0);
>  }
>  
>  int open_path(struct file_desc *d,



More information about the CRIU mailing list