7. How it works

Autodir uses modules to get specific functionality. The core Autodir implements generic functionality that modules can exploit and add specific functionality to.

At any moment only one module can be added to Autodir. If there are two modules, for example autohome and autogroup, then two processes of Autodir should be created so that each process can have one of the required modules attached to it.

For further explanation I chose the autohome module which handles transparent home directory creation.

Assumptions

  • The autohome module creates user home directories on demand if these do not exist already.

  • It is assumed that user accounts exists, but the accompanying home directories do not - either because these accounts were created with the -M option with useradd or because these accounts were imported from LDAP, NIS or some other external database for which home directories are yet to be created.

  • It also assumed for this explanation only that all user home directories are expected to be in the /home directory.

KISS

Keep it Simple: Some fine details are intentionally kept aside to make the explanation easy to understand.

First the autofs file system is mounted on the /home directory by Autodir. The Linux kernel is informed that /home is managed by a user space application, Autodir, from now on.

Autofs?

Do not bother too much about the autofs file system if you do not understand about it. Just think of it as a special kind of file system, similar to memory based file systems but with some additional special properties.


                                +----------------+
                                |  Linux Kernel  |
                                +----------------+
                                  /        \
                                 /          \
                                /            \
                               /              \
   +-------------+       +--------+       +------------+        +-----------------+
   | Application |------>| /home  |<----->|  Autodir   |<------>| autohome module |
   +-------------+       +--------+       +------------+        +-----------------+
                              \                                          /
                               \  +----------------+                    /
                                +-|   /autohome    |<------------------+
                                  +----------------+

Whenever an application or daemon needs access to a user's home directory, for example /home/userhome1, they directly enter into /home/userhome1 to access it. The kernel, which notices this, informs Autodir if the userhome1 directory does not yet exist already in /home.

Autodir, in turn, passes this request to the autohome module. The autohome module does not touch the /home directory. Instead it manages real home directories somewhere else, for example in /autohome as shown in the above figure.

The autohome module creates a real home directory if it does not exist in the /autohome directory. After it is successfully created or failed to be created, whatever the outcome, autohome reports back to Autodir. When the directory creation task has completed successfully, the path to real home directory is provided to Autodir.

If the autohome module reports success, Autodir creates userhome1 directory under /home and mounts the real home directory from /autohome on it. At the end of the process, Autodir informs the kernel whether the whole operation was successful or not. Accordingly, the kernel allows applications to enter the directory, or, in case of failure, it reports that no such directory exists.