[CRIU] [PATCH RFC 2/2] mount: "get fs type by mount id" helper introduced

Pavel Emelyanov xemul at virtuozzo.com
Thu Mar 10 00:57:40 PST 2016


On 02/24/2016 01:54 PM, Stanislav Kinsburskiy wrote:
> This helper takes mount id, discovers struct mountinfo and takes fs magic from
> fstype object, is present. Returns error otherwise.
> 
> Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
> ---
>  files.c              |    5 +++--
>  include/mount.h      |    1 +
>  include/proc_parse.h |    1 +
>  mount.c              |   24 +++++++++++++++++++++---
>  4 files changed, 26 insertions(+), 5 deletions(-)
> 
> diff --git a/files.c b/files.c
> index 3a96985..04fd9eb 100644
> --- a/files.c
> +++ b/files.c
> @@ -280,8 +280,9 @@ static int fill_fd_params(struct parasite_ctl *ctl, int fd, int lfd,
>  	if (parse_fdinfo_pid(ctl->pid.real, fd, FD_TYPES__UND, NULL, &fdinfo))
>  		return -1;
>  
> -	if (get_fstype_by_fd(lfd, &fs_type))
> -		return -1;
> +	if (get_fstype_by_mntid(fdinfo.mnt_id, &fs_type))

I don't like that we always try to scan (quite big) mountpoints list
to check whether it's NFS or not. We need an optimization in aufs-like
manner -- if we have NFS mp in the list, do the scan, if we don't --
always report -ENOENT and fall back to statfs.

> +		if (get_fstype_by_fd(lfd, &fs_type))
> +			return -1;
>  
>  	p->fs_type	= fs_type;
>  	p->ctl		= ctl;
> diff --git a/include/mount.h b/include/mount.h
> index 4989b41..eb9546f 100644
> --- a/include/mount.h
> +++ b/include/mount.h
> @@ -128,5 +128,6 @@ extern void cleanup_mnt_ns(void);
>  
>  extern int get_fstype_by_fd(int fd, unsigned int *type);
>  extern int get_fstype_by_path(const char *path, unsigned int *type);
> +extern int get_fstype_by_mntid(unsigned int id, unsigned int *type);
>  
>  #endif /* __CR_MOUNT_H__ */
> diff --git a/include/proc_parse.h b/include/proc_parse.h
> index 9e932db..8521eff 100644
> --- a/include/proc_parse.h
> +++ b/include/proc_parse.h
> @@ -117,6 +117,7 @@ struct fstype {
>  	int (*parse)(struct mount_info *pm);
>  	bool (*can_mount)(struct mount_info *pm);
>  	mount_fn_t mount;
> +	unsigned int fs_magic;
>  };
>  
>  struct vm_area_list;
> diff --git a/mount.c b/mount.c
> index f5d8773..355cd88 100644
> --- a/mount.c
> +++ b/mount.c
> @@ -237,6 +237,21 @@ int get_fstype_by_path(const char *path, unsigned int *type)
>  	return 0;
>  }
>  
> +int get_fstype_by_mntid(unsigned int id, unsigned int *type)
> +{
> +	struct mount_info *m;
> +
> +	m = lookup_mnt_id(id);
> +	if (!m)
> +		return -EINVAL;
> +
> +	if (m->fstype->fs_magic == 0)
> +		return -ENOENT;
> +
> +	*type = m->fstype->fs_magic;
> +	return 0;
> +}
> +
>  struct mount_info *lookup_mnt_sdev(unsigned int s_dev)
>  {
>  	struct mount_info *m;
> @@ -1810,11 +1825,13 @@ static struct fstype fstypes[32] = {
>  		.code = FSTYPE__NFS,
>  		.mount = nfs_mount,
>  		.can_mount = nfs_can_mount,
> +		.fs_magic = NFS_SUPER_MAGIC,
>  	}, {
>  		.name = "nfs4",
>  		.code = FSTYPE__NFS4,
>  		.mount = nfs_mount,
>  		.can_mount = nfs_can_mount,
> +		.fs_magic = NFS_SUPER_MAGIC,
>  	}
>  };
>  
> @@ -2631,10 +2648,11 @@ static int do_mount_one(struct mount_info *mi)
>  		return -1;
>  
>  	if (mi->fstype->code == FSTYPE__UNSUPPORTED) {
> -		unsigned int fs_type;
> +		unsigned int fstype = mi->fstype->fs_magic;
>  
> -		if (get_fstype_by_path(mi->mountpoint, &fs_type))
> -			return -1;
> +		if (fstype == 0)
> +			if (get_fstype_by_path(mi->mountpoint, &fstype))
> +				return -1;
>  
>  		if (fstype == BTRFS_SUPER_MAGIC)
>  			mi->fstype = find_fstype_by_name("btrfs");
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
> .
> 



More information about the CRIU mailing list