Skip to content

Commit d12c388

Browse files
committed
Clean up locking in zfs_write().
There are three paths: if pagingio and pagefile; lock Main Resource, then PagingIo if pagingio and !pagefile; lock only PagingIo if !pagingio; lock only MainResource Use Exclusive locks for write path. This should avoid the deadlock we had between zfs_file_cleanup() -> CcMgr -> zfs_write(PAGINGIO) which tried to lock MainResource twice. Signed-off-by: Jorgen Lundman <lundman@lundman.net>
1 parent 4cf9479 commit d12c388

1 file changed

Lines changed: 36 additions & 25 deletions

File tree

module/os/windows/zfs/zfs_vnops_windows.c

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5569,16 +5569,6 @@ zfs_write_wrap(PDEVICE_OBJECT DeviceObject, PIRP Irp,
55695569
&offset, *length, FALSE);
55705570
}
55715571

5572-
if (paging_io) {
5573-
if (!ExAcquireResourceSharedLite(
5574-
vp->FileHeader.PagingIoResource, wait)) {
5575-
Status = STATUS_PENDING;
5576-
IoMarkIrpPending(Irp);
5577-
goto end;
5578-
} else
5579-
paging_lock = TRUE;
5580-
}
5581-
55825572
pagefile = vp->FileHeader.Flags2 & FSRTL_FLAG2_IS_PAGING_FILE &&
55835573
paging_io;
55845574

@@ -5593,25 +5583,46 @@ zfs_write_wrap(PDEVICE_OBJECT DeviceObject, PIRP Irp,
55935583
}
55945584
#endif
55955585

5596-
if (pagefile) {
5597-
if (!ExAcquireResourceSharedLite(vp->FileHeader.Resource,
5598-
wait)) {
5599-
Status = STATUS_PENDING;
5600-
IoMarkIrpPending(Irp);
5601-
goto end;
5602-
} else {
5603-
acquired_vp_lock = TRUE;
5586+
// 1) if pagefile - grab MainResource, then PagingIoResource
5587+
// 2) elif pagingio - grab only PagingIoResource
5588+
// 3) elif normal io - grab only MainResource
5589+
5590+
if (paging_io) {
5591+
5592+
wait = TRUE;
5593+
5594+
if (pagefile) {
5595+
if (!ExAcquireResourceExclusiveLite(
5596+
vp->FileHeader.Resource,
5597+
wait)) {
5598+
Status = STATUS_PENDING;
5599+
IoMarkIrpPending(Irp);
5600+
goto end;
5601+
} else {
5602+
acquired_vp_lock = TRUE;
5603+
}
56045604
}
5605-
} else if (!ExIsResourceAcquiredExclusiveLite(
5606-
vp->FileHeader.Resource)) {
56075605

56085606
if (!ExAcquireResourceExclusiveLite(
5609-
vp->FileHeader.Resource, wait)) {
5607+
vp->FileHeader.PagingIoResource, wait)) {
56105608
Status = STATUS_PENDING;
56115609
IoMarkIrpPending(Irp);
56125610
goto end;
56135611
} else {
5614-
acquired_vp_lock = TRUE;
5612+
paging_lock = TRUE;
5613+
}
5614+
} else {
5615+
if (!ExIsResourceAcquiredExclusiveLite(
5616+
vp->FileHeader.Resource)) {
5617+
5618+
if (!ExAcquireResourceExclusiveLite(
5619+
vp->FileHeader.Resource, wait)) {
5620+
Status = STATUS_PENDING;
5621+
IoMarkIrpPending(Irp);
5622+
goto end;
5623+
} else {
5624+
acquired_vp_lock = TRUE;
5625+
}
56155626
}
56165627
}
56175628

@@ -5891,12 +5902,12 @@ zfs_write_wrap(PDEVICE_OBJECT DeviceObject, PIRP Irp,
58915902
FileObject->CurrentByteOffset.QuadPart);
58925903
}
58935904

5894-
if (acquired_vp_lock)
5895-
ExReleaseResourceLite(vp->FileHeader.Resource);
5896-
58975905
if (paging_lock)
58985906
ExReleaseResourceLite(vp->FileHeader.PagingIoResource);
58995907

5908+
if (acquired_vp_lock)
5909+
ExReleaseResourceLite(vp->FileHeader.Resource);
5910+
59005911
return (Status);
59015912
}
59025913

0 commit comments

Comments
 (0)