All of lore.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	LKML <linux-kernel@vger.kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Pavel Emelyanov <xemul@parallels.com>,
	Jiri Slaby <jslaby@suse.cz>
Subject: Re: [RFC] tty: Add get- ioctls to fetch tty status
Date: Sat, 22 Sep 2012 18:43:37 -0700	[thread overview]
Message-ID: <87txupfr92.fsf@xmission.com> (raw)
In-Reply-To: <20120922180639.GC11610@moon> (Cyrill Gorcunov's message of "Sat, 22 Sep 2012 22:06:39 +0400")


I don't know where this conversation comes from but putting ptys in
sysfs in combination with the newinstance mount option is completely
broken unless the device name and device number duplication is handled,
which I don't see here.

Cyrill Gorcunov <gorcunov@openvz.org> writes:
>
> Guys, you mean something like below? Look, I must admit I'm not really
> sure if I've done all locking right, and there is no need for additional
> kref counting on tty_struct. Could you please check if it looks more-less
> sane (I've tested it but still...)
>
> ---
> From: Cyrill Gorcunov <gorcunov@openvz.org>
> Subject: tty, pty: Add pty_state attribute to fetch tty flags
>
> For checkpoint/restore we need to know if tty has
> exclusive or packet mode set, as well as if pty
> is currently locked (just to be able to restore
> this characteristics).
>
> To serve this the pty_state attribute is introduced
> for pty devices. A typical output looks like
>
>  | [root@neptune ~]# cat /sys/devices/virtual/tty/ptmp0/pty_state
>  | locked: 0 exclusive: 0 packet: 0
>
> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
> CC: Alan Cox <alan@lxorguk.ukuu.org.uk>
> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> CC: "H. Peter Anvin" <hpa@zytor.com>
> CC: Jiri Slaby <jslaby@suse.cz>
> CC: Pavel Emelyanov <xemul@parallels.com>
> ---
>  drivers/tty/pty.c |   45 ++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 44 insertions(+), 1 deletion(-)
>
> Index: tty.git/drivers/tty/pty.c
> ===================================================================
> --- tty.git.orig/drivers/tty/pty.c
> +++ tty.git/drivers/tty/pty.c
> @@ -283,6 +283,46 @@ done:
>  	return 0;
>  }
>  
> +static ssize_t pty_show_state(struct device *dev,
> +			      struct device_attribute *attr,
> +			      char *buf)
> +{
> +	struct tty_struct *tty = dev_get_drvdata(dev);
> +	int locked, exclusive, packet;
> +
> +	tty_lock(tty);
> +	locked = test_bit(TTY_PTY_LOCK, &tty->flags);
> +	exclusive = test_bit(TTY_EXCLUSIVE, &tty->flags);
> +	packet = tty->packet;
> +	tty_unlock(tty);
> +
> +	return snprintf(buf, PAGE_SIZE, "locked: %d exclusive: %d packet: %d\n",
> +			locked, exclusive, packet);
> +}
> +
> +static DEVICE_ATTR(pty_state, S_IRUSR | S_IRGRP, pty_show_state, NULL);
> +
> +static struct attribute *pty_state_dev_attrs[] = {
> +	&dev_attr_pty_state.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group pty_dev_attr_group = {
> +	.attrs = pty_state_dev_attrs,
> +};
> +
> +static const struct attribute_group *pty_dev_attr_groups[] = {
> +	&pty_dev_attr_group,
> +	NULL,
> +};
> +
> +static int pty_register_attr(struct tty_driver *driver, struct tty_struct *tty)
> +{
> +	struct device *dev = tty_register_device_attr(driver, tty->index, tty->dev,
> +						      (void *)tty, pty_dev_attr_groups);
> +	return PTR_RET(dev);
> +}
> +
>  /**
>   *	pty_common_install		-	set up the pty pair
>   *	@driver: the pty driver
> @@ -351,7 +391,9 @@ static int pty_common_install(struct tty
>  
>  	tty_driver_kref_get(driver);
>  	tty->count++;
> -	return 0;
> +
> +	return pty_register_attr(driver, tty);
> +
>  err_free_termios:
>  	if (legacy)
>  		tty_free_termios(tty);
> @@ -368,6 +410,7 @@ err:
>  
>  static void pty_cleanup(struct tty_struct *tty)
>  {
> +	tty_unregister_device(tty->driver, tty->index);
>  	kfree(tty->port);
>  }
>  
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

  parent reply	other threads:[~2012-09-23  1:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-13  9:56 [RFC] tty: Add get- ioctls to fetch tty status Cyrill Gorcunov
2012-09-13 11:46 ` Jiri Slaby
2012-09-13 11:51   ` Cyrill Gorcunov
2012-09-13 12:51 ` Alan Cox
2012-09-13 12:54   ` Cyrill Gorcunov
2012-09-13 16:25     ` Alan Cox
2012-09-13 16:41       ` Cyrill Gorcunov
2012-09-22 18:06       ` Cyrill Gorcunov
2012-09-22 20:07         ` Greg Kroah-Hartman
2012-09-22 20:11           ` Cyrill Gorcunov
2012-09-22 21:52             ` Cyrill Gorcunov
2012-09-23  1:09               ` Greg Kroah-Hartman
2012-09-23  6:40                 ` Cyrill Gorcunov
2012-09-23 14:46                   ` H. Peter Anvin
2012-09-23 15:21                     ` Cyrill Gorcunov
2012-09-24 14:14                     ` Cyrill Gorcunov
2012-09-27 14:05                       ` Cyrill Gorcunov
2012-09-27 14:14                         ` Alan Cox
2012-09-27 14:14                           ` Cyrill Gorcunov
2012-09-27 14:17                             ` H. Peter Anvin
2012-09-27 14:21                               ` Cyrill Gorcunov
2012-09-27 14:43                                 ` H. Peter Anvin
2012-09-27 14:48                                   ` Cyrill Gorcunov
2012-09-27 15:05                                     ` H. Peter Anvin
2012-09-27 15:13                                 ` Alan Cox
2012-09-27 15:23                                   ` Cyrill Gorcunov
2012-09-27 16:00                                     ` Alan Cox
2012-09-27 16:06                                       ` Cyrill Gorcunov
2012-09-27 15:47                                   ` Cyrill Gorcunov
2012-09-22 23:15           ` Alan Cox
2012-09-23  1:43         ` Eric W. Biederman [this message]
2012-09-23  6:40           ` Cyrill Gorcunov
2012-09-23 14:44             ` H. Peter Anvin
2012-09-23 15:22               ` Cyrill Gorcunov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87txupfr92.fsf@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=gorcunov@openvz.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xemul@parallels.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.