On Tue, Jun 10, 2025 at 09:21:38AM +0100, Al Viro wrote: > Once attach_recursive_mnt() has created all copies of original subtree, > it needs to put them in place(s). > > Steps needed for those are slightly different: > 1) in 'move' case, original copy doesn't need any rbtree > manipulations (everything's already in the same namespace where it will > be), but it needs to be detached from the current location > 2) in 'attach' case, original may be in anon namespace; if it is, > all those mounts need to removed from their current namespace before > insertion into the target one > 3) additional copies have a couple of extra twists - in case > of cross-userns propagation we need to lock everything other the root of > subtree and in case when we end up inserting under an existing mount, > that mount needs to be found (for original copy we have it explicitly > passed by the caller). > > Quite a bit of that can be unified; as the first step, make commit_tree() > helper (inserting mounts into namespace, hashing the root of subtree > and marking the namespace as updated) usable in all cases; (2) and (3) > are already using it and for (1) we only need to make the insertion of > mounts into namespace conditional. > > Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx> > --- Reviewed-by: Christian Brauner <brauner@xxxxxxxxxx>