[Unionfs] Strange behavior when adding a branch

Shaya Potter spotter at cs.columbia.edu
Sun Jul 8 13:33:40 EDT 2007


For all it's worth, I agree w/ Yoav's view of how the semantics should be.

Yoav Weiss wrote:
> Hi,
> 
> I tested unionfs's ability to add branches to a live system, and 
> encountered behavior that seems wrong.
> 
> When a process has an open file descriptor and a branch is added while 
> the file is being read, data from the new branch is returned.  This 
> leads to unexpected results in some situations, and I don't see where 
> such behavior is desirable.
> 
> I'd expect the old descriptor to remain linked to the file in the old 
> branch, and the overwritten file getting a new inode so that new 
> processes opening the file will see the new copy.  This is similar to 
> the non-unionfs situation where a file is unlinked and replaced while 
> being used by some process.  The old process keeps a link to the deleted 
> file, and a new file with a different inode will be available for new 
> processes. Any reason unionfs should behave differently rather than 
> preserve these semantics ?
> 
> Here's a script that demonstrates the problem:
> ------------------------------------------------------------------------
> #!/usr/bin/env python
> 
> import os
> 
> # Prepare an environment with two same-named files.
> os.system("rm -rf /tmp/uniontest")
> os.mkdir("/tmp/uniontest"); os.chdir("/tmp/uniontest")
> os.mkdir("dir1"); os.mkdir("dir2"); os.mkdir("dir3"); os.mkdir("mnt")
> file("dir1/file","w").write("pre-branch\n"+"\r"*4096)
> file("dir2/file","w").write("\r"*4096+"post-branch\n")
> 
> # Mount the unionfs.
> os.system("mount -t unionfs -o dirs=./dir3=rw:./dir1=ro unionfs ./mnt")
> 
> # Get a descriptor and read the first page.
> f=file("mnt/file")
> print f.read(4096)
> 
> # Add a branch and read the second page from the same descriptor.
> os.system("unionctl ./mnt --add --mode ro /tmp/uniontest/dir2")
> print f.read(4096)
> 
> # Point proven.  Cleanup.
> f.close()
> os.system("umount ./mnt")
> ------------------------------------------------------------------------
> 
> As the script shows, the process gets data from the new branch without 
> reopening the file.  Is this the expected behavior ?  Is there a known 
> way to avoid it and use branches safely ?
> 
>     Yoav Weiss
> _______________________________________________
> unionfs mailing list: http://unionfs.filesystems.org/
> unionfs at mail.fsl.cs.sunysb.edu
> http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs


More information about the unionfs mailing list