A little internals on using USB drives (localdev) in LTSP with LTSPFS

For some time I had a problem with USB drives on my LTSP client: the attached devices did not unmount automatically and of course if I just plugged the drive from the USB slot, some changes (file modifications or deletions, etc.) were lost. Sometimes a little filesystem corruption could occur too. Just the basic stuff that can happen if you plug a removable device without unmounting it first. The more I had to use USB drives, the more frustrating this bug became. Finally I took the time to track it down and found the problem.

To cut to the point: the devices were not automatically unmounted because I had Gnome's System Monitor running as an applet on my Gnome panel _and_ the harddisk monitoring was turned on in System Monitor's preferences. As it turns out, the System Monitor polls all mounted filesystems every 500ms (I think this is the default interval). The bug can easily be eliminated by clearing the "Harddisk" checkbox in the "Monitoring Resources" list of System Monitor's preference pane. Of course the same happens if you open up System Monitor and switch to the "File Systems" tab. So beware of system monitoring applications that monitor filesystem activity too. It'd be nice if one could select one by one (or using a regular expression) which devices (or mount points) should be monitored for activity. But it seems you can't have it all at the moment.

Towards the end of my debugging session I ended up going through the source of LTSPFS, which is the package used for local device support in LTSP. The source package is called ltspfs and it contains three binary packages: ltspfs, ltspfsd and ltspfsd-core.

The package description tells you the following:
"Fuse based remote filesystem daemon for LTSP thin clients.
LtspFS is a remote filesystem consisting of two parts:
  1. A network server daemon that runs on the LTSP terminal (/client).
  2. A FUSE module that runs in userspace on the server, that connects with the daemon on the LTSP client.


I was interested in the automatic unmount of the LTSPFS mount points (and the USB drives). Looking into the files in the src subdirectory I've found two significant timing values (both in ltspfs.h):
  • #define AUTOMOUNT_TIMEOUT 5: this means that the ltspfsd daemon (that is running on the thin client) automatically unmounts the filesystem on the USB drive after 5 seconds of inactivity (ie. meaning that no activity comes from the ltspfs client -the process that is running in the user's session on the terminal server-)
  • #define PING_INTERVAL 30: the ltspfs process (that runs in the user's session on the terminal server) issues a "ping" request to the ltspfsd daemon every 30 seconds. If no "success" reply is received from the ltspfsd daemon, then the ltspfs client assumes the daemon is gone and umounts the ltspfs FUSE filesystem on the terminal server so no dead mounts stay around.
PS: as for the particular problem with using ltspfs and Gnome's System Monitor ... imho the blame lies on the latter. System Monitor states to be monitoring disk activity. Now a FUSE based ltspfs is anything, but a "disk". Smile System Monitor should indeed watch only disks and not every mounted filesystem it can get it's hand on.