Taking an External Disk Offline Safely *Without* Locking Its Volumes

I am working on a feature in which the DB resides on an external storage device such as a Fibre channel drive. As part of the shutdown process, I want to take the storage drive offline. Currently I do it this way (code is in C++ but this is only a high level description):

For each volume in the disk:

  1. Flush it (by calling FlushFileBuffers with its handle)

  2. Lock it (via calling DeviceIoControl with the FSCTL_LOCK_VOLUME code)

  3. Dismount it (via the FSCTL_DISMOUNT_VOLUME code)

  4. Take it offline (via the IOCTL_VOLUME_OFFLINE code)

Only if all the volumes associated with the disk go through the series of the above 4 steps successfully, I take the disk offline, by using the IOTCTL_DISK_SET_DISK_ATTRIBUTES and IOCTL_UPDATE_DISK_PROPERTIES control codes.

The problem I ran into is that very frequently, users open files that reside on the external disk via other programs such as notepad. In that case, step 2 - Locking the volume - will fail and in turn this will fail the entire shutdown attempt, which causes the program to get stuck because I don't allow the shutdown to complete without the lock being successful. The reason is that from what I understand, this is the only reliable way to force a full flush of all unwritten data to the disk, which is essential in preventing the disk from being in an inconsistent state (files ending up as half-written, etc.).

So basically I'd like to know if there's a reliable way to guarantee a full flush of data to the disk without locking its volumes. I noticed that for example the MS Failover Cluster doesn't lock any volume when taking a shared disk offline, does anyone happen to know how that works?

Thanks!

Amit

5
Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article