Re: [ANNOUNCEMENT PATCH COW] proof of concept impementation of cowlinks

From: Jan Harkes
Date: Tue May 25 2004 - 17:48:41 EST


On Fri, May 21, 2004 at 06:23:12PM -0500, Rob Landley wrote:
> > /* are we copying the entire source file? */
> > if (*ppos != 0 || count != in_file->f_dentry->d_inode->i_size)
> > goto copy_local;
>
> Is there a race condition for i_size to change between the api getting called
> and the copy being done? More to the point, is there some way to specify a
> count of -1 or something to easily say "to end of file"?

I don't think so, what does the existing sendfile to a socket
implementation do?

Sure there is something you could call a race, but it doesn't seem all
that serious to me. If someone writes to the source file a couple of
seconds after the copy completes we would get the exact same situation.

The only problem here is that it is possible for the write to arrive
between the stat of the source file to get the number of bytes we want
to copy and the actual sendfile call. That would invalidate the cached
inode data and by the time call sendfile the example code falls back to
a local copy operation because count != i_size.

But if the filesystem provided a more powerful copy operation than just
copy whole file A to file B it could actually do what the user asked for
without needing to fall back on the local copy operation.

An application that wants to make sure the source file is not modified
before, during or after the copy operation, both by the local client and
possibly by any remote clients, probably should lock it with flock or
fcntl.

Jan

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/