Re: [RFC] union-mount stuff

From: Neil Brown (neilb@cse.unsw.edu.au)
Date: Wed Jun 07 2000 - 20:27:55 EST


On Wednesday June 7, viro@math.psu.edu wrote:
>
> Frankly, I'm sorely tempted to say that cd to mountpoint always
> makes the mountpoint busy and leaves the mounted fs alone. IOW, if we
> have / on /dev/foo and /usr on /dev/bar then opening /usr/bin should make
> bar busy (as it does now), but opening /usr should make _foo_ busy.
> Benefits: makes for easy, consistent logics with union-mounts
> (nothing has to be changed whatever we add to/remove from the set, no
> ambiguity wrt what can be umounted, etc.).
> Losses: differs from the current behaviour, may confuse some
> programs. Notice that all difference is in treatment of mountpoint/root -
> everything else works as usual.

I tried to come up with a model which is a generalisation of the "old"
behaviour, and provides agreeable semantics for new behaviours.
This is what I came up with:

A "mount" is an ordered list (pile) of directories.
One of these elements is the "mountpoint", and it is particularly
distiguished because ".." from the "mount" goes through ".." of the
"mountpoint". ".." of all other directories is not accessable.

Each directory in the pile has two flags (well, three if you count
IS_MOUNTPOINT).

IS_WRITABLE: You can create things in here.
IS_VISIBLE: You can see inside this.

Thus, a traditional mount has two directories in the pile.
The bottom one IS_MOUNTPOINT
The top one IS_WRITABLE|IS_VISIBLE

With mount -o union, you can set what ever flags you like, though
having IS_WRITABLE and not IS_VISIBLE would be a problem.
However you can only have one IS_MOUNTPOINT directory.

Now the rules:

1/ on "lookup", you do a lookup in each IS_VISIBLE directory from the
    top down until you find a match or you hit the bottom.

2/ If you decide to create something (*) then it goes in the uppermost
   IS_WRITABLE directory.

3/ "stat" (of ".") sees the IS_MOUNTPOINT directory if it IS_VISIBLE,
   otherwise the lowest IS_VISIBLE directory.
   Possibly n_links could be fiddled, but I don't know how important
   that is.

4/ The "mount" keeps only the IS_MOUNTPOINT directory busy.

5/ An open or cd to the mount makes the directory which "stat" sees
   busy.

6/ A mount is not allowed if it would change 'the directory which
   "stat" sees', and that directory is "busy".

(*) It is unclear to me when creation should be allowed.
   If I say "mkdir fred", and fred does not exist in or above the
   uppermost IS_WRITABLE directory, but does exist is a lower
   IS_VISIBLE directory, should the create succeed or fail?
   Would that same be true for
     open("fred", O_CREAT) which is "create if it doesn't exist"
  or open("fred", O_CREAT|O_EXCL) which is "create and it mustn't exist".

NeilBrown

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



This archive was generated by hypermail 2b29 : Thu Jun 15 2000 - 21:00:15 EST