[Btrfs-devel] 3 thoughts about important and outstanding features

Chris Mason chris.mason at oracle.com
Mon Jan 21 09:09:58 PST 2008


On Monday 21 January 2008, Jan Engelhardt wrote:
> On Jan 21 2008 11:46, Chris Mason wrote:
> >> So basically I'm looking for functions to:
> >> - insert a chunk into a file
> >> - delete a chunk from a file
> >> - move a chunk from one file into another
> >
> >Like most filesystems, btrfs stores metadata for extents keyed by the
> > offset into the file.  So, in order to insert one byte in the middle of
> > the file, you have to change all of the extent pointers after that byte
> > in the file by one.   This can be slow, although it is certainly faster
> > than copying all the data.
> >
> >It is very hard to provide slicing operations in place due to races with
> >truncate.  I'm not eager to dive into all of those corner cases.
>
> Would not it work if we just lock the full inode? In other words...

What makes truncate so much fun is that it feels like that should be enough.  
But, mmap reads and writes can do operations that do not wait for the inode 
mutex, and avoiding races with direct_io is a huge challenge.

You could lock the mutex, then remove and/or lock every page in the file, 
exclude against O_DIRECT and it should mostly work.   But, it is definitely 
non-trivial.

-chris



More information about the Btrfs-devel mailing list