mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jörn Engel" <joern@wohnheim.fh-wedel.de>
To: Chris Wedgwood <cw@f00f.org>
Cc: Jan Blunck <j.blunck@tu-harburg.de>,
	Linus Torvalds <torvalds@osdl.org>, Andrew Morton <akpm@osdl.org>,
	Linux-Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ramfs: pretend dirent sizes
Date: Thu, 21 Jul 2005 09:20:03 +0200	[thread overview]
Message-ID: <20050721072003.GA17431@wohnheim.fh-wedel.de> (raw)
In-Reply-To: <20050720181101.GB11609@taniwha.stupidest.org>

On Wed, 20 July 2005 11:11:01 -0700, Chris Wedgwood wrote:
> On Wed, Jul 20, 2005 at 01:21:27PM +0200, J?rn Engel wrote:
> 
> > To my understanding, you can lseek to any "proper" offset inside a
> > directory.  Proper means that the offset marks the beginning of a
> > new dirent (or end of file) in the interpretation of the filesystem.
> 
> But you can never tell where these are in general.

Correct.  Any filesystem can have any definition of proper.

> > Userspace doesn't have any means to figure out, which addresses are
> > proper and which aren't.  Except that getdents(2) moves the fd
> > offset to a proper address, which likely will remain proper until
> > the fd is closed.
> 
> I don't see why or how this can be true in general (it might be, but I
> don't see how myself).  If we are half way through scanning a
> directory and people start messing with it we could end up somewhere
> bogus (in which case f_op->readdir I guess is expected to try and do
> something sane here?)

If you read a large directory, it will take you quite a while to go
through the thousands of getdents() invocations.  Someone messing with
the directory meanwhile should be expected and shouldn't cause
userspace to get complete garbage.  If userspace doesn't learn about
all new dirents, that's fine.  If it receives old ones, that were
since deleted, that's fine.  But under no circumstances should you
hand out garbage.

Ext2, iirc, solves this problem by never shrinking directories.  Old
dirents can be invalid and won't get passed to userspace anymore.  But
they don't move around.  Hence, a linear read of the directory gives
you exactly above properties.

> > Reopening the same directory may result in a formerly proper offset
> > isn't anymore.
> 
> For that to be the case where is the state kept to ensure your current
> offset is valid?

Depends on the fs.  Ext2, as seen above, only needs file->offset as
state.  But image a questionable optimization for an uncommon case.
Whenever the last reader or an ext2 directory closes the fd, it is
safe to shuffle things around.  At this time, a "directory
defragmenter" takes the directory and squeezes all holes out of it.
The new, repacked directory consumes less space, which is nice.

Alternatively, the directory defragmenter could create a new
directory, copy all valid contents of the old one over, and new open()
on the directory will get the new copy, while old file descriptors
still point to the old one.

In both cases, what used to be a proper offset in one fd can be
complete bogus for another one.

And no, I don't want to add directory defragmenters to ext2.  It was
just a stupid example of what is possible.

Jörn

-- 
Linux [...] existed just for discussion between people who wanted
to show off how geeky they were.
-- Rob Enderle

  parent reply	other threads:[~2005-07-21  7:20 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-15  3:01 Jan Blunck
2005-07-15  3:11 ` Andrew Morton
2005-07-15 10:16   ` Jan Blunck
2005-07-15 18:52 ` Linus Torvalds
2005-07-16  0:39   ` Chris Wedgwood
2005-07-19  9:28     ` Jan Blunck
2005-07-19 16:16       ` Chris Wedgwood
2005-07-19 18:22         ` Jan Blunck
2005-07-19 18:32           ` Chris Wedgwood
2005-07-19 19:14             ` Jan Blunck
2005-07-19 19:16               ` Chris Wedgwood
2005-07-20 11:21                 ` Jörn Engel
2005-07-20 18:11                   ` Chris Wedgwood
2005-07-20 18:48                     ` Jan Blunck
2005-07-20 18:52                       ` Peter Staubach
2005-07-21  7:26                       ` Jörn Engel
2005-07-21  7:20                     ` Jörn Engel [this message]
2005-07-21  7:25                       ` Chris Wedgwood
2005-07-21  7:27                         ` Jörn Engel
2005-07-20 18:24                 ` Jan Blunck
2005-07-20 18:50                   ` Peter Staubach
2005-07-19  9:46   ` Jan Blunck
     [not found] <4qoKs-6yv-13@gated-at.bofh.it>
     [not found] ` <4qoU5-6CQ-3@gated-at.bofh.it>
     [not found]   ` <4qvsI-32Y-17@gated-at.bofh.it>
2005-07-15 13:12     ` Bodo Eggert
2005-07-19  9:13       ` Jan Blunck

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=20050721072003.GA17431@wohnheim.fh-wedel.de \
    --to=joern@wohnheim.fh-wedel.de \
    --cc=akpm@osdl.org \
    --cc=cw@f00f.org \
    --cc=j.blunck@tu-harburg.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®