[CRIU] [PATCH 03/11] tty: Introduce dump_one_tty helper

Pavel Emelyanov xemul at parallels.com
Tue Oct 7 13:46:28 PDT 2014


On 10/06/2014 05:15 PM, Cyrill Gorcunov wrote:
> Depending on tty major/minor numbers we will
> need different dumping routines so choose one
> here.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  tty.c | 33 +++++++++++++++++++++++++++------
>  1 file changed, 27 insertions(+), 6 deletions(-)
> 
> diff --git a/tty.c b/tty.c
> index bd8d21179667..ab1a576eb4d8 100644
> --- a/tty.c
> +++ b/tty.c
> @@ -1160,14 +1160,11 @@ out:
>  	return ret;
>  }
>  
> -static int dump_one_pty(int lfd, u32 id, const struct fd_parms *p)
> +static int dump_one_pty(int lfd, u32 id, const struct fd_parms *p, int major, int minor)
>  {
>  	TtyFileEntry e = TTY_FILE_ENTRY__INIT;
> -	int ret = 0, major, index;
> +	int ret = 0, index;
>  
> -	pr_info("Dumping tty %d with id %#x\n", lfd, id);
> -
> -	major = major(p->stat.st_rdev);
>  	index = parse_index(id, lfd, major);
>  	if (index < 0)
>  		return -1;
> @@ -1205,9 +1202,33 @@ static int dump_one_pty(int lfd, u32 id, const struct fd_parms *p)
>  	return ret;
>  }
>  
> +static int dump_one_tty(int lfd, u32 id, const struct fd_parms *p)
> +{
> +	int major = major(p->stat.st_rdev);
> +	int minor = minor(p->stat.st_rdev);
> +
> +	pr_info("Dumping tty (%d:%d) %d with id %#x\n",
> +		major, minor, lfd, id);
> +
> +	switch (major) {
> +	case TTYAUX_MAJOR:
> +		if (minor == 0 || minor == 2)
> +			return dump_one_pty(lfd, id, p, major, minor);
> +		break;
> +	case UNIX98_PTY_MASTER_MAJOR ... (UNIX98_PTY_MASTER_MAJOR + UNIX98_PTY_MAJOR_COUNT - 1):
> +	case UNIX98_PTY_SLAVE_MAJOR:
> +		return dump_one_pty(lfd, id, p, major, minor);
> +	default:
> +		break;
> +	}

We already have similar switch in files.c. Please, don't introduce
another one. If will will need to distinguish ptys from smth else
let's extend the switch from files.c and introduce another fdtype_ops.

> +
> +	pr_err("Unsupported tty (%d:%d) device\n", major, minor);
> +	return -1;
> +}
> +
>  const struct fdtype_ops tty_dump_ops = {
>  	.type	= FD_TYPES__TTY,
> -	.dump	= dump_one_pty,
> +	.dump	= dump_one_tty,
>  };
>  
>  int tty_prep_fds(void)
> 



More information about the CRIU mailing list