Re: [PATCH] cowlinks v2

From: Eric W. Biederman
Date: Sun Mar 28 2004 - 15:08:57 EST

Jamie Lokier <jamie@xxxxxxxxxxxxx> writes:

> Eric W. Biederman wrote:
> > > The addictive thing about the prototype implementation was that you
> > > could do ``ln --cow / /some/other/directory'' and you would have an
> > > atomic snapshot of your filesystem. Definitely not a feature for the
> > > first implementation but certainly something to dream about.
> >
> > Addictive but broken by design. If any of the files inside your
> > directory tree have hard links outside of the tree there is no way
> > short of recursing through all of the subdirectories directories to
> > tell if a given inode has is in use. Except in the special case
> > where you are taking a cow copy of the entire filesystem. At which
> > point a magic mount option is likely a better interface.
> I don't understand this explanation. Can you explain again? What is
> the problem with inodes being in use?

A COW on a directory implies a COW on everything in it. So the implication
is an atomic snapshot of that directory and everything below it.

Assuming no files are open and in use. The implementation would
create the cow link on the directory just like it would on a file.
Then when you open/modify a directory or file the cow copies would be
taken up to the point of the original cow directory so you have a
separate directory structure.

All of which works great until you have a file that has one hard link
in your cow directory structure and another hard link outside of
any cow. An application can come in and modify the file through that
second cow link causing problems.

So the problem is not really with open files at the time of the cow
although there is a variation of it there as well. At the time of the
cow it is possible to look through the dcache and find all of the
files that are in the cow directory or a subdirectory of the it. Then
you can make those cow files. But again you run into the problem of
an application using a file through a link that is not a subdirectory
of the cow directory.

So in the presence of hard links doing cow on a directory other than
the root directory can not be implemented correctly short of doing a
complete recursive directory copy at the time you create the cow. At
which point you might as well just copy the directories in user space.
At least the race conditions are easily apparent.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at