[Devel] [PATCH criu 1/3] mount: Add export_mnt_ns_roots helper

Andrei Vagin avagin at gmail.com
Tue Oct 24 01:27:01 MSK 2017


On Thu, Oct 12, 2017 at 10:21:29AM +0300, Cyrill Gorcunov wrote:
> This helper produce space separated list of
> mount namespace roots which can be exported
> then into environment variable.
> 
> https://jira.sw.ru/browse/PSBM-71861
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
> ---
>  criu/include/mount.h |  2 ++
>  criu/mount.c         | 34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/criu/include/mount.h b/criu/include/mount.h
> index 35e1b49..e19f767 100644
> --- a/criu/include/mount.h
> +++ b/criu/include/mount.h
> @@ -93,6 +93,8 @@ extern int open_mountpoint(struct mount_info *pm);
>  extern struct mount_info *collect_mntinfo(struct ns_id *ns, bool for_dump);
>  extern int prepare_mnt_ns(void);
>  
> +extern char *export_mnt_ns_roots(char *dst, size_t size);
> +
>  extern int pivot_root(const char *new_root, const char *put_old);
>  
>  extern struct mount_info *lookup_overlayfs(char *rpath, unsigned int s_dev,
> diff --git a/criu/mount.c b/criu/mount.c
> index c483c2e..57df5da 100644
> --- a/criu/mount.c
> +++ b/criu/mount.c
> @@ -2788,6 +2788,40 @@ static inline int print_ns_root(struct ns_id *ns, int remap_id, char *buf, int b
>  	return snprintf(buf, bs, "%s/%d-%010d", mnt_roots, ns->id, remap_id);
>  }
>  
> +/*
> + * Construct space separated list of mount namespace roots
> + * so that we could export it via environment variable and
> + * process in restore scripts.
> + */
> +char *export_mnt_ns_roots(char *dst, size_t size)
> +{
> +	struct ns_id *nsid;
> +	char *p = dst;
> +	size_t len;
> +
> +	if (size == 0)
> +		return dst;
> +
> +	dst[0] = '\0';
> +	for (nsid = ns_ids; nsid; nsid = nsid->next) {
> +		if (nsid->nd != &mnt_ns_desc)
> +			continue;
> +
> +		len = print_ns_root(nsid, 0, p, size);
> +		if (len >= (size - 2)) {
> +			p[(size - 1)] = '\0';
> +			return dst;
> +		}
> +
> +		size -= len;
> +		p += len;
> +		p[0] = ' ';
> +		p++, size--;
> +	}
> +
	do you forget to add \0 to the end?

	if (p != dst)
		*(p - 1) = 0;

> +	return dst;
> +}
> +
>  static int create_mnt_roots(void)
>  {
>  	int exit_code = -1;
> -- 
> 2.7.5
> 
> _______________________________________________
> Devel mailing list
> Devel at openvz.org
> https://lists.openvz.org/mailman/listinfo/devel


More information about the Devel mailing list