Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756015AbcCQHc4 (ORCPT ); Thu, 17 Mar 2016 03:32:56 -0400 Received: from mail-lf0-f51.google.com ([209.85.215.51]:36364 "EHLO mail-lf0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752954AbcCQHcx (ORCPT ); Thu, 17 Mar 2016 03:32:53 -0400 Date: Thu, 17 Mar 2016 10:32:44 +0300 From: Cyrill Gorcunov To: Peter Hurley Cc: LKML , Jiri Slaby , Greg Kroah-Hartman , Andrey Vagin , Pavel Emelianov , Vladimir Davydov , Konstantin Khorenko Subject: Re: [RFC] tty: n_tty -- Add new TIOCPEEKRAW ioctl to peek unread data Message-ID: <20160317073244.GR2231@uranus.lan> References: <20160312141830.GM1989@uranus.lan> <56EA2CF2.8090801@hurleysoftware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56EA2CF2.8090801@hurleysoftware.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2234 Lines: 54 On Wed, Mar 16, 2016 at 09:05:06PM -0700, Peter Hurley wrote: > > Here is a new ioctl code which simply copies data from read buffer > > into the userspace without any additional processing (just like > > terminal is sitting in a raw mode). > > Maybe I'm overlooking something obvious, but why not do just that; > ie., save the termios, reset termios to raw mode and read the entire > ldisc read buffer? > > Note that saving and resetting termios to raw mode is only necessary > for the slave side, as the master side is always in raw mode. Hi Peter! Yes we can do that, but there is one significant problem: when we read the buffer (draining it) and then during later stages of checkpoint something fails -- we need to bring the dumping program back to the former state so it won't notice that someone has been dumping it. Which means code flow like - read ldisk buffer - ... some other work for checkpoint sake ... - ... obtained some error ... - write ldisk buffer back to restore original content and if here write fails (for any reason), the program being dupmed will loose ldisk buffer content. we simply can't allow this to happen because otherwise checkpoint will work in destructive way. Moreover there is an option in criu where we allow to dump program and leave it in running state, say someone needs a snapshot of a state, thus we always must work in non- destructive manner. Sure, not modifying the kernel would be a preferred way for me too. > > Then, two options for restore are: > 1) set termios to raw mode, write to peer, restore the saved termios; or > 2) restore the saved termios and write to peer. > > option 1 will preserve the contents as read but not preserve the line > termination state; ie., it will be possible to read multiple lines > with a single canonical read. > > option 2 will preserve the line termination state (for the most part) > but not necessarily the contents which might be re-interpreted. > > These two options are not necessarily exclusive; it may be possible > to construct a mixed mode for restore based on the original saved > termios that reconstitutes both line termination state and read buffer > contents. > > One thing not accounted for is the column position.