[PATCH] root-hopping for pre-2.3.41-3

From: almesber@lrc.di.epfl.ch
Date: Tue Jan 25 2000 - 03:43:54 EST


Hi Linus,

I'm sending you a patch for pre-2.3.41-3 that allows the use of chroot to
change the root directory from an initrd or similar to a mounted file
system, and to cleanly unmount the former root. This is much cleaner than
the current "change_root on exit from linuxrc" magic, and it also allows
again the use of NFS-root with parameter selection at run time.

In the long run, this change obsoletes the following kernel features:
 - /proc/sys/kernel/real-root-dev
 - kernel-based NFS root
 - kernel-based BOOTP/RARP
 - /linuxrc, change_root, and all the magic surrounding them

In particular, the patch addresses the following three problems:

 - /proc/mounts and quota warning messages had meaningless and possibly
   ambiguous path names after a chroot. My patch prefixes the path names
   with the number of the (non-root) device where the path name
   construction stopped, which makes them unambiguous.

   As a side-effect, struct vfsmount.mnt_dirname is no longer read
   (fs/super.c still maintains it, though). I didn't eliminate it
   completely in case something out there still accesses it.

 - with the proliferation of kernel threads, it has become increasingly
   unlikely that our root file system is ever sufficiently idle to
   unmount (i.e. after initrd), even though nobody is actually using it.
   Also, our "next root" will keep the "old root" busy be being mounted.
   This patch adds two umount flags MNT_DETACH and MNT_CHROOT to help
   unmounting almost idle file systems.

    - MNT_DETACH: detaches file systems mounted on top of the file system
      we're trying to get rid of. They become the roots of their own
      directory hierarchies. (Obviously, excessive use of this feature
      can cause headache ;-)

    - MNT_CHROOT: root and cwd of all processes referencing the root of
      the file system are changed to current->fs->root. This is mainly
      for kernel threads which may not share the fs structure with init.

   MNT_DETACH and MNT_CHROOT are only performed if the unmount succeeds,
   i.e. if the file system is busy for any other reason, the flags are
   ignored.

 - do_umount turned attempts to umount ROOT_DEV into a read-only remount
   even if our root has changed. Now it applies this magic only if we're
   trying to umount current->fs->root.

I've tested the patch with 2.3.40 and got a clean build with
pre-2.3.41-3, so I'm reasonably confident that it doesn't cause any major
trouble. A few people have downloaded earlier versions of my patch and I
didn't get any negative feedback, and one favorable comment. Not sure if
they actually tried to run it, though :-)

There is one change where I'm not 100% sure if it's correct: I've moved
sb->s_root = NULL; in fs/super.c:d_umount after operations which may
sleep. I don't think there is any race on this, particularly in the
intended usage scenario, but it's probably better if you have a quick
look at it.

A patch to util-linux and some usage examples are in
ftp://icaftp.epfl.ch/pub/people/almesber/misc/umount-root-5.tar.gz

Once this patch is in, I can work on updating Documentation/initrd.txt,
which is rather misleading nowadays.

Cheers, Werner

-- 
  _________________________________________________________________________
 / Werner Almesberger, ICA, EPFL, CH       werner.almesberger@ica.epfl.ch /
/_IN_N_032__Tel_+41_21_693_6621__Fax_+41_21_693_6610_____________________/


- 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 : Mon Jan 31 2000 - 21:00:14 EST