[Unionfs] Strange behavior when adding a branch
Yoav Weiss
union342 at unpatched.net
Sun Jul 8 13:28:08 EDT 2007
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
More information about the unionfs
mailing list