Safe Removal of Active Disk Devices08/12/2009
Earlier this year, the Foundation sponsored Edward Tomasz Napierala to fix FreeBSD’s #1 reported bug: a USB disk causing a panic when detached before unmounting. Edward describes the project as follows:
One of the long-standing problems encountered by FreeBSD users was the fact that the system could often crash after a mounted disk device – for example, a USB flash drive – was removed. This behavior was not only annoying, but also made a bad impression about the overall stability and robustness of the operating system.
The project was not about fixing one buggy driver, as it could seem at first glance. Fixing the problem involved changes in CAM (Common Access Method, FreeBSD SCSI subsystem), GEOM framework, Virtual Filesystem layer, and finally the UFS filesystem. (Ironically, there were no problems with the USB itself.) There were no big design changes of any sort; just an iterative process of finding a way to crash the system, tracking down the bug that was causing it, fixing it, and proceeding to the next one. Most of the fixes were backported to FreeBSD 7-STABLE and will appear in FreeBSD 7.2.
It is now possible to remove mounted devices – and to unmount them afterwards – without any user-unfriendly behavior, such as crashes. Also, the system became more robust in the presence of non-USB disk removal, such as SCSI or SATA drive detachment or failure.