Caching in Network File System.

Hi All,

Could anybody help me?

I need to modify content of some files that client reads/writes on server
side.

I use sfilter sample for my prototype. I little changed it for attach to
network redirector. I modify content if at least one condition holds true:

  • the first is (pIrp->Flags & (IRP_PAGING_IO | IRP_NOCACHE)) != 0

or

  • (pfcb->FcbState & FCB_STATE_READCACHEING_ENABLED) == 0 for read
    (pfcb->FcbState & FCB_STATE_WRITECACHEING_ENABLED) == 0 for write.

It seems that it works.

The problem is how to synchronize changing content with potential changing
of FcbState flags?
Article “Caching in Network File Systems” on
http://www.osronline.com/article.cfm?article=226# wrote following:

To prevent the state from changing, the caller must acquire the FCB
resource; in order to avoid deadlocks while calling the redirector, it must
be owned exclusive (using the ERESOURCE in the FCB itself). Again, to do
this requies relying upon the implementation and published interface
available in the IFS Kit.
Note: this synchronization is only needed for user level cached requests,
since paging I/O or user level non-cached requests will already not be
cached as a matter of course. This is important because this lock cannot be
safely acquired when processing paging I/O - this would violate the existing
lock hierarchy and introduce the possibility of deadlocks.

But how to acquire FCB resource? I’m trying to use
ExAcquireResourceExclusiveLite in dispatch routine and ExReleaseResourceLite
in IoCompletion routine.
If I apply these routines for pfcb->Header.Resource, I get deadlock.
If I apply these routines for pfcb->Header.PagingIoResource, I get very
unstable working and crash system.
If I don’t acquire FCB resource, it seems it works, but I guess that I may
lose content.

Thanks,
Valery