Synch vs. async processing of IRP_MN_MOUNT_VOLUME

Hi,

Sorry, if this question was discussed many times here.

What is the prefered way of processing in the filter driver of synchronous
I/O requests, e.g. IRP_MN_MOUNT_VOLUME, and why?

Synchronously, by waiting in dispatch routine and signaling in completion:

Dispatch()
{

SetCompletion(Irp, Completion, &event, TRUE, TRUE, TRUE);
status = CallDriver(deviceObject, Irp);
if (status == STATUS_PENDING) {
WaitForSingleObject(&event);
}

//
// Perform necessary postprocessing here,
// such as attaching to the mounted LV.
//

CompleteRequest(Irp);
return(status);
}

Completion()
{
// Do not mark Irp as pending

SetEvent(event);

return(STATUS_MORE_PROCESSING_REQUIRED);
}

Or asynchronously?

Dispatch()
{

InitializeContext(Irp, &context);
SetCompletion(Completion, context);

MarkIrpPending(Irp)
CallDriver(deviceObject, Irp);

return(STATUS_PENDING);
}

Completion()
{
QueueWorkItem(&context->WorkItem);

if (Irp->PendingReturned) {
MarkIrpPending(Irp);
}

return(STATUS_MORE_PROCESSING_REQUIRED);
}

WorkItem()
{
//
// Perform necessary postprocesing
// such as attaching to the mounted LV.
//

CompleteRequest(Irp);
}

Any your comments will be very appreciated.
Thanks in advance.

Best regards,
Leonid.

Your second example (asynch) has two obvious errors in the completion
routine:

(1) It marks the IRP pending AFTER it queues it. You cannot manipulate the
IRP after you have enqueued it to a worker thread because the worker thread
might start immediately processing it, preempting you in the process.

(2) It marks the IRP pending at all - you do not need to do that in your
completion routine because you already did it in your dispatch entry point.

Either approach (synchronous or asynchronous) works. However, there is no
advantage to the asynchronous case because the I/O manager will block & wait
for it to complete anyway. Thus, you incur additional overhead without
additional benefit.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: Leonid Zhigunov [mailto:xxxxx@progate.spb.ru]
Sent: Friday, May 17, 2002 4:55 AM
To: File Systems Developers
Subject: [ntfsd] Synch vs. async processing of IRP_MN_MOUNT_VOLUME

Hi,

Sorry, if this question was discussed many times here.

What is the prefered way of processing in the filter driver of synchronous
I/O requests, e.g. IRP_MN_MOUNT_VOLUME, and why?

Synchronously, by waiting in dispatch routine and signaling in completion:

Dispatch()
{

SetCompletion(Irp, Completion, &event, TRUE, TRUE, TRUE);
status = CallDriver(deviceObject, Irp);
if (status == STATUS_PENDING) {
WaitForSingleObject(&event);
}

//
// Perform necessary postprocessing here,
// such as attaching to the mounted LV.
//

CompleteRequest(Irp);
return(status);
}

Completion()
{
// Do not mark Irp as pending

SetEvent(event);

return(STATUS_MORE_PROCESSING_REQUIRED);
}

Or asynchronously?

Dispatch()
{

InitializeContext(Irp, &context);
SetCompletion(Completion, context);

MarkIrpPending(Irp)
CallDriver(deviceObject, Irp);

return(STATUS_PENDING);
}

Completion()
{
QueueWorkItem(&context->WorkItem);

if (Irp->PendingReturned) {
MarkIrpPending(Irp);
}

return(STATUS_MORE_PROCESSING_REQUIRED);
}

WorkItem()
{
//
// Perform necessary postprocesing
// such as attaching to the mounted LV.
//

CompleteRequest(Irp);
}

Any your comments will be very appreciated.
Thanks in advance.

Best regards,
Leonid.


You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to %%email.unsub%%