Re: st_dev and st_ino for pipes

From: Kostik Belousov <kostikbel_at_gmail.com>
Date: Tue, 4 Oct 2011 13:20:48 +0300
On Tue, Oct 04, 2011 at 05:37:27PM +1100, Peter Jeremy wrote:
> On 2011-Oct-03 01:04:05 +0300, Kostik Belousov <kostikbel_at_gmail.com> wrote:
> >Our implementation of pipes does not provide useful values for st_dev
> >and st_ino when stat(2) is done on an anonymous pipe. It was noted by the
> ...
> >Patch below implements the requirement, by the cost of the small overhead
> >at the pipe creation time, and slightly bigger cost at the destruction.
> 
> Does it need to be so complex?  This information isn't needed by the
> kernel and, to be "meaningful", all that is required is that the
> (st_dev,st_ino) pair is unique within the system.  Given this,
> wouldn't it be sufficient to fake up a st_dev and then just make
> st_ino be a counter that starts from 0 and increments (atomically?) on
> every new pipe?  No need to retain state or "free" anything when the
> pipe is destroyed.  (If necessary, pick a new fake st_dev when st_ino
> wraps).
Yes, you described the problem. The (st_dev, st_ino) pair must
be globally unique in system, not only for the pipes, but for whole
domain of file descriptors. This is the reason that I allocate a value
for pipe st_dev using the same devfs mechanism as it is done for device
numbers. Using simple incrementing counter for pipe inodes, together with
allocating yet another st_dev gives essentially the same complications
wrt KPI, and feels unclean.

> 
> >--- a/sys/kern/sys_pipe.c
> >+++ b/sys/kern/sys_pipe.c
> ...
> >+static ino_t pipedev_ino;
> ..
> >+	ub->st_dev = pipedev_ino;
> 
> st_dev is a dev_t and hence pipedev_ino (which seems misnamed to me)
> should probably be dev_t rather than ino_t
Fixed.

Thank you.

Received on Tue Oct 04 2011 - 08:20:59 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:18 UTC