I’ve been noodling on the unioning file system problem for a few months now, the results of which are summarized here:
Yesterday, Jan Blunck posted his latest union mount patchset with my implementation of readdir():
The basic idea is that on the first readdir() of a unioned directory, we copy up all the visible entries from lower down in the file system into the topmost directory as a special kind of directory entry called a “fallthru.” A fallthru tells the VFS to look for that entry in a lower level of the union. Then we can use the native readdir() implementation of the topmost file system and everything Just Works.
This patch set isn’t ready for merging yet, but I think it is on the right track. If you’re interested in working on it too, here are a few of the known problems:
- We check to see if a directory is logically empty by calling vfs_readdir() from the rmdir() code. This is an icky interface violation. We could instead call union_copyup_dir() directly.
- readdir() only works if the topmost file system is writable, so readdir() won’t work on unions of all read-only file systems. We can mount a tmpfs layer on top to support this, but it would be nice if it were transparent to the user. Also, it would be nice if the tmpfs layer could kick out dentries created for readdir() when they are not being used.
- copyup on write only works for regular files and directories. block/char/fifo etc. don’t work (and maybe shouldn’t work?).
- symlinks are untested.
- The locking scheme currently allows for several potential deadlocks, mainly because we acquire locks in union stack order, and file systems can be in different orders in different union stacks. The key to this might be the fact that writeable file systems are only allowed on the top layer of the union; all the other layers are read-only.
If you want to work on any of these issues, talk to Jan Blunck first and see if he’s already solved them. (I am going on vacation for two weeks starting tomorrow and he’s the best person to talk to in any case.)