I currently have a successful HSM filter which recalls on Create. By
carefully inspecting flags etc, I have eliminated a great deal of spurious
recalls. In addition the user-mode agent keeps an eye on the file server so
ensuring that long recalls (stalling the IRP_MJ_CREATE) do not cause said
file server any major problems. My ‘stub’ file is a reparse point, with the
OFFLINE file attribute set and the primary data stream removed by making it
a sparse file with no actual data.
However I am now experimenting with recall on I/O (Read, Write,
AcquireForSectionSynchronization) and have hit a problem. I suspect I am
missing something fundamental, but doc reading, Googling, searching NTFSD
etc have all failed to illuminate it!
In (post) processing the Create when I see the reparse point for a file I
want to recall on I/O, I set some flags then reissue the IRP…
SetFlag (pData->Iopb->Parameters.Create.Options,
FILE_OPEN_REPARSE_POINT);
SetFlag (pData->Iopb->Parameters.Create.SecurityContext->DesiredAccess,
FILE_WRITE_ATTRIBUTES);
FltSetCallbackDataDirty (pData);
FltReissueSynchronousIo (pFltObjects->Instance, pData);
This gets the ‘stub’ file open so the caller gets his handle. I also
associate a StreamHandle context so I can detect this state in
pre-processing Read, AcquireForSectionSynchronization etc.
When I see the I/O for the file (detected by the StreamHandle context), I
use a worker thread to proces the recall, via FltAllocateGenericWorkItem. An
IRP can be pended, but FASTIO and FS_FILTER (as found in AFSS) is stalled
using
KeWaitForSingleObject (&pSHContext->sEvent, Executive, KernelMode,
FALSE, NULL);
In either case, when the worker thread calls FltWriteFile to repopulate the
file data, it blocks. Is this some kind of serialization? I was hoping that
this call could ‘overtake’ the Read or AFSS which was about to start. If it
cannot, how do you get around this? Do I have to use a different FileObject?
In which case do I then hit sharing problems with the user open?
Any light shed on this issue would be much appreciated.
By the way, I shall be at Plugfest#20, so if I need some significant
re-education beyond email and NTFSD, perhaps we can arrange that!
Thanks in anticipation,
John