Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not forcefully free all VCBs upon IRP_MJ_SHUTDOWN request #103

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 60 additions & 3 deletions src/btrfs.c
Expand Up @@ -4845,6 +4845,7 @@ static NTSTATUS drv_shutdown(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
NTSTATUS Status;
BOOL top_level;
device_extension* Vcb = DeviceObject->DeviceExtension;
LIST_ENTRY *Vcble, *le;

FsRtlEnterFileSystem();

Expand All @@ -4862,12 +4863,68 @@ static NTSTATUS drv_shutdown(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
shutting_down = TRUE;
KeSetEvent(&mountmgr_thread_event, 0, FALSE);

while (!IsListEmpty(&VcbList)) {
Vcb = CONTAINING_RECORD(VcbList.Flink, device_extension, list_entry);
Vcble = VcbList.Flink;
while (Vcble != &VcbList) {
Vcb = CONTAINING_RECORD(Vcble, device_extension, list_entry);

TRACE("shutting down Vcb %p\n", Vcb);

uninit(Vcb, TRUE);
if (Vcb->balance.thread) {
Vcb->balance.paused = FALSE;
Vcb->balance.stopping = TRUE;
KeSetEvent(&Vcb->balance.event, 0, FALSE);
KeWaitForSingleObject(&Vcb->balance.finished, Executive, KernelMode, FALSE, NULL);
}

if (Vcb->scrub.thread) {
Vcb->scrub.paused = FALSE;
Vcb->scrub.stopping = TRUE;
KeSetEvent(&Vcb->scrub.event, 0, FALSE);
KeWaitForSingleObject(&Vcb->scrub.finished, Executive, KernelMode, FALSE, NULL);
}

if (Vcb->running_sends != 0) {
BOOL send_cancelled = FALSE;

ExAcquireResourceExclusiveLite(&Vcb->send_load_lock, TRUE);

le = Vcb->send_ops.Flink;
while (le != &Vcb->send_ops) {
send_info* send = CONTAINING_RECORD(le, send_info, list_entry);

if (!send->cancelling) {
send->cancelling = TRUE;
send_cancelled = TRUE;
send->ccb = NULL;
KeSetEvent(&send->cleared_event, 0, FALSE);
}

le = le->Flink;
}

ExReleaseResourceLite(&Vcb->send_load_lock);

if (send_cancelled) {
while (Vcb->running_sends != 0) {
ExAcquireResourceExclusiveLite(&Vcb->send_load_lock, TRUE);
ExReleaseResourceLite(&Vcb->send_load_lock);
}
}
}

ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);

if (Vcb->need_write && !Vcb->readonly) {
Status = do_write(Vcb, Irp);

if (!NT_SUCCESS(Status))
ERR("do_write returned %08x\n", Status);
}

Vcb->removing = TRUE;

ExReleaseResourceLite(&Vcb->tree_lock);
Vcble = Vcble->Flink;
}

#ifdef _DEBUG
Expand Down