patch for ext2fs unmount problem at shutdown

Don Lewis truckman at
Tue Sep 6 01:41:53 PDT 2005

On  6 Sep, Poul-Henning Kamp wrote:
> In message <200509060757.j867v42t031957 at>, Don Lewis writes:
>>> Why is this necessary ?  As far as I know we do an orderly unmount
>>> of all filesystems at shutdown, so shouldn't ext2fs release the
>>> buffers at that time ?
>>We count the busy buffers before unmounting anything, and skip the
>>unmount if the count is nonzero.
> I guess this has an interesting historical explanation, but I have
> a hard time seeing how we could arrive at this logic if we started
> from scratch today.
> My best guess is that this is an attempt to detect disk errors: The
> sync(2) call would push as much as possible onto disks and by
> skipping the unmount we would not hang waiting for the dead disk.

I suspect both that is one possible reason, and another reason would be
to avoid marking the file system clean if any writes timed out.

> I think we should do away with the nbusy check, including the 35
> lines of softupdate magic and call vfs_unmountall() in all circumstances
> (but retain the check for !cold, RB_NOSYNC and panic).
> Instead we should add a flag to VFS_UNMOUNT that means "don't hang
> forever" and use that in vfs_unmountall().

That makes sense longer term, but for quite some time we've had a number
of users who have been rather unhappy to find out that every time they
reboot with a mounted ext2fs file system that *all* of their file
systems are marked dirty and require attention from fsck.

> Calling sync(2) up front still makes sense as it will take advantage
> of any parallism possible to multiple drives.
> Poul-Henning
> PS: Considering power management, sleep/suspend modes etc, it would
> make sense to add a "MNT_CLEAN" flag to pass to VOP_FSYNC which
> instructed the filesystem to flush everything to disk, and reset
> any "dirty" flags on the disk to "clean" but leave the filesystem
> mounted.  (On subsequent I/O the first thing the filesystem must
> do is set the dirty flag again.  That way it would be as safe (as
> possible) to power a sleeping/suspend machine off.

Yup.  That would also be especially useful for removable media.  If file
systems mounted on removable media were marked clean fairly soon after
going idle, then it is quite likely that if the media was removed
without unmounting the file system that the file system would be clean.

More information about the freebsd-current mailing list