Hangs at acquiring Vcb->PagingIoResouce.

Dear all,

I got a problem when implementing removable disk ejection. For the case that
you just modify the volume (Ex: copy some files or dires to it), then click
the ejection icon to eject the USB disk, system will hang there. The bug
does not occur
everytime, but very often.

I dumped all the threads via “!process 0 7” in windbg. But I can get only
one thread that is related to my driver: SampleFSD. The followings are the
detail of the thread stack:

ChildEBP RetAddr Args to Child
ed43b664 804fe882 00000000 81534a44 818973a0 nt!KiSwapThread+0xc5
ed43b68c 804e8100 815ba508 00000000 00000000 nt!KeWaitForSingleObject+0x1a1
ed43b6cc 804e75e2 81534a44 00534a44 ed43b6e4 nt!ExpWaitForResource+0x1ac
ed43b6dc 804e7627 ed43b700 804e75d2 81534a44
nt!ExpAcquireResourceExclusiveLite+0x64
ed43b6e4 804e75d2 81534a44 00000001 81534920
nt!ExAcquireResourceExclusiveLite+0x4b
ed43b700 804e7627 ed43b808 b7062034 81534a44
nt!ExpAcquireResourceExclusiveLite+0x55
ed43b708 b7062034 81534a44 00000001 81534920
nt!ExAcquireResourceExclusiveLite+0x4b
ed43b808 b7063b55 81617168 81534920 8150d5c8
SampleFSD!SampleWriteVolume+0x4f8 (Try to acquire Vcb->PagingIoResource,
because it’s a pagingio. But so strange that it hangs here.)
ed43b850 b704bd3d 81617168 00000004 ed43b8a0 SampleFSD!SampleWrite+0x19a

ed43b8b4 804f1f5e ed43b8f0 ed43b90c 816747e8 nt!IopfCallDriver+0x35
ed43b8c8 8050e7a3 8159be18 ed43b8f0 ed43b978 nt!IoSynchronousPageWrite+0xa6
ed43b994 8050e3bf e29be000 e29be00c 00000019 nt!MiFlushSectionInternal+0x36a
ed43b9d4 804e1e60 81674820 00000000 00003000 nt!MmFlushSection+0x1cb
ed43baa8 b7063cc6 81534a00 00000000 00000000 nt!CcFlushCache+0x399
ed43bad0 b7060ead 815349d8 00000000 81534920
SampleFSD!SampleFlushVolume+0xe6 (Vcb->MainResource is acquired before
CcFlushCache(&Vcb->SectionObjectPoitners…))
ed43bb28 b7060af9 8150e928 815349d8 81534920
SampleFSD!SamplePnpQueryRemove+0xa6
ed43bb74 b704bdd0 8150e928 0000001b ed43bbc4 SampleFSD!SamplePnp+0x12f

ed43bbd8 80597521 81534920 815e1030 00000001 nt!IopfCallDriver+0x35
ed43bc04 80563f05 81534920 ed43bc24 ed43bc54 nt!IopSynchronousCall+0xca
ed43bc4c 805bb38e 815e1030 815e1030 e2b1f5c8 nt!IopRemoveDevice+0x86
ed43bc74 8056470f 815f0b48 00000001 e2b1f5c8
nt!IopDeleteLockedDeviceNode+0x38e
ed43bcb0 805eda7b 81567850 e2b1f500 00000000
nt!IopDeleteLockedDeviceNodes+0xb0
ed43bd3c 80569d38 00000004 80675028 e2a5de88
nt!PiProcessQueryRemoveAndEject+0x5b8
ed43bd54 805833d4 ed43bd74 815e0f08 8053db1c
nt!PiProcessTargetDeviceEvent+0x33
ed43bd78 804e9c49 815e0f08 00000000 00000000 nt!PiWalkDeviceList+0xf7
ed43bda8 80525faf 815e0f08 00000000 00000000 nt!ExpWorkerThread+0xae
ed43bddc 80539ec2 804e9b84 00000001 00000000 nt!PspSystemThreadStartup+0x69
00000000 00000000 00000000 00000000 00000000 nt!KiThreadStartup+0x16

SamplePnp/SamplePnpQueryRemove were called for this case, then it tried to
lock the volume after acqiuring the
Vcb->MainResource, and flushed the cache via CcFlushCache. Theh CcFlushCache
caused a re-entry of the driver for
paging writing. At this monment, the paging writing was trying to acqure
Vcb->PagingIoResource, and hung there.

Vcb->PagingIoResouce was not acquired by any threads. The thread should not
hang at this point and there’s no
deadlocks.

Anyone has a clue to help me out ?

Thanks in advance.

Matt