On Jun 6, 2008, at 1:44 AM, Tim Schooley wrote:
Good day!
So here's the setup:
1) I have a kext that creates an IOBlockStorageDriver. I setup and
tear
down block devices from userspace with an application.
2) I format these devices by calling standard format commands,
such as
newfs_{hfs,msdos,...}.
3) Using an application, and the DiskArbitration calls (namely
DADiskMountWithArguments and DADiskUnmount), I mount these devices
to a
directory on the filesystem.
The problem I have is this:
2.1) I try to unmount a mounted device using DADiskUnmount.
2.2) This fails because the device is "busy".
- There are no IO operations happening.
- There are no files open by users.
- The only file open on the mount point is (output from lsof):
fseventsd 34 root 12u REG 14,4 0 999999999
<mountpoint>/.fseventsd/0000000000006478
2.3) If I use the kDADiskUnmountOptionForce option in the call to
DADiskUnmount, it corrupts the filesystem.
So my questions are:
3.0) Is the fseventsd causing this busy mount point issue?
Yes.
3.1) What is this fseventsd doing sticking its nose into my
mountpoint?
It is looking for file creations/changes on the device so it can
report them to Spotlight for (re)indexing, or to other clients of
fseventsd (like TimeMachine backup).
It sticks it's nose in your mount point to create an event log file,
which it then holds open until the disk is unmounted. The intent of
the log file is to ensure that you don't have to rescan the entire
disk due to last minute changes (or that last minute changes will not
be indexed or backed up). Typically such changes represent events
that have occurred, but for which fseventd clients have either been
stopped or are not reading and reacting to events (e.g. at shutdown
time, due to non-ordered shutdown of processes). It technically
doesn't actually need to keep this log file open if it's not actively
logging something, but it does so anyway.
fseventsd registers a callback with
DARegisterDiskUnmountApprovalCallback to permit it to get
notification
of the pending unmount. If you have failed to register an unmount
completion callback, a direct call to the unmount is considered
synchronous instead of asynchronous, and the unmount will fail, since
it does not give fseventd time to close down the log.
3.2) Can I stop the fseventsd from doing this?
Yes. The mount option MNT_NOBROWSE ("-o nobrowse" on the mount
command line) will prevent fseventd from listening for events on the
volume. It will also disable TimeMachine, Spotlight indexing, and
other clients of fseventd, so this is generally not a good idea.
3.3) Am I missing some sort of call to the fseventsd?
No, but you are missing registering an unmount completion callback
with DiskArbitration so that the DADiskUnmount is not synchrnously
answered with the only answer available at the time it returns
("busy").
-- Terry