Dear all,
I met a big headache about cache coherence in my ext2 file system driver:
I use one volume stream object for all the meta data (including directory, file ind/dind/tind blocks) and file streams for separate files.
See such case: ( One block size is 1024 (0x400) bytes.)
| | | | | | | | | |
…| | File block 1 | | File block 2 | | Meta data 1 | | File block 3 | |…
| || |_____________ | |_____________| || |
File block 1 2 3 belong to a file stream, and meta data1 belongs to the volume stream object. The meta data 1 is the ind-block. When making modifications on it, I use CcPinRead with one block size (0x400).
When paging writing for the file stream, I’ll split the writing stream into two groups to avoid writing the meta data block.
But when I receive paging writing for the volume object, the starting address is (File block 1), and the size is 0x1000 (PAGE_SIZE, 4 blocks).
I’ve tried ways to solve it, but no progress …
1, I use CcFlushCache/CcPurgeCacheSection when expanding file size in cached write (IRP_MJ_WRITE). But I’ll be blocked in CcPurgeCacheSection.
…
if (!Nocache && FileExtended) {
…
for(i=0; i {
CcFlushCache( &(Vcb->SectionObject),
(PLARGE_INTEGER)&(ext2_bdl[i].Lba),
ext2_bdl[i].Length,
NULL);
if (Vcb->SectionObject.DataSectionObject != NULL)
{
ExAcquireSharedStarveExclusive(&Vcb->PagingIoResource, TRUE);
ExReleaseResource(&Vcb->PagingIoResource);
CcPurgeCacheSection( &(Vcb->SectionObject),
(PLARGE_INTEGER)&(ext2_bdl[i].Lba),
ext2_bdl[i].Length,
FALSE );
}
}
2, I let the above codes in paging writing, just before sending file writing irp to the disk drivers.
This time, system hangs perhaps because deadlocks. But I can’t figure it out.
When it hang, I got 2 locks exclusived owned by one thread and 2 locks for another.
Thread 1: –> Ext2Cleanup -> (Acquire Vcb->MainResource/Fcb->MainResource) -> CcFlushCache to File Stream.
Thread 2: —>Ext2Write -> (Unknown eresource acquired / Fcb->PagingioResource) -> CcFlushCache to Volume Stream.
3, I split the process CcFlushCache and CcPurgeCacheSection and let Ext2Cleanup release Vcb->MainResource before CcFlushCache.
Do CcFlushCache in cached writing and CcPurgeCacheSection in pagingio writing.
No dead locks occur but new problems arise … I’m analyzing this case now with hoping to solve the problems.
Does Anyone have a clue ? Any words will be sincerely appreciated.
Thanks in advance,
Matt