How 'honest' is fstat(1)?

Oliver Fromme olli at lurza.secnetix.de
Wed Apr 12 13:32:26 UTC 2006


Mikhail Teterin <mi+mx at aldan.algebra.com> wrote:
 > As a policy I try to keep my /, /usr, and other filesystems (except /var 
 > and /home) mounted readonly. (Not so much for security as for safety.)

That's not a bad idea, basically.

 > When I need to make a modification, I remount them:
 > 
 >         mount -orw -u /
 > 
 > make the change, and remount back:
 > 
 >         mount -oro -u /usr/local

Note that you will lose any additional options that way,
such as "nosuid".  To retain the current options, use a
command like this:

        mount -u -o current,ro /usr/local

Or to use the options from your /etc/fstab:

        mount -u -o fstab,ro /usr/local

 > This works for "small" changes, but sometimes, however, after a bigger on 
 > (such as rebuilding of some ports), the last step fails with "busy".

Maybe there are still things in the softupdates backlog.
Those don't appear in fstat(1) output because they're not
associated with a particular process or descriptor.
Is the FS still busy after waiting a few minutes?

However, I _think_ the unmount() should just block in that
case until all softupdates changes are flushed to disk,
not report EBUSY.  But I'm not 100% sure.

 > At this time nothing should have a file open, and nothing does according to 
 > fstat. The command:
 > 
 >          fstat | awk '$5 == "/usr/local" && $NF != "r"'
 > 
 > does not list anything.

Does it list anything when you omit the check for $NF!="r"?
Did you try to use lsof(8) instead (from ports collection)?

 > My only guess is, the earlier versions of the just reinstalled executables are 
 > still running and that trigger's the rarely noticed bug.

It would be a bug, because running executables should not
be open for writing.

In the past, the mount update code (-u flag) had bugs which
could even lead to FS corruption when you switched back and
forth between ro and rw multiple times.  But I believe those
bugs were fixed.

Best regards
   Oliver

-- 
Oliver Fromme,  secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"If you aim the gun at your foot and pull the trigger, it's
UNIX's job to ensure reliable delivery of the bullet to
where you aimed the gun (in this case, Mr. Foot)."
        -- Terry Lambert, FreeBSD-hackers mailing list.


More information about the freebsd-fs mailing list