Skip to content

Commit 131aca7

Browse files
committed
Correct file_cleanup to avoid deadlock
1) Always call flush 2) Call purge if delete_on_exit && last_close 3) Always call Uninit Signed-off-by: Jorgen Lundman <lundman@lundman.net>
1 parent e6ead8e commit 131aca7

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

module/os/windows/zfs/zfs_vnops_windows.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6721,7 +6721,8 @@ zfs_fileobject_cleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp,
67216721
PFILE_OBJECT FileObject = IrpSp->FileObject;
67226722
struct vnode *vp = FileObject->FsContext;
67236723
zfs_ccb_t *zccb = FileObject->FsContext2;
6724-
boolean_t flush = B_TRUE;
6724+
boolean_t purge = B_FALSE;
6725+
boolean_t locked = B_FALSE;
67256726

67266727
if (zmo->type != MOUNT_TYPE_VCB) {
67276728
Status = STATUS_SUCCESS;
@@ -6747,8 +6748,6 @@ zfs_fileobject_cleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp,
67476748
// messages belonging to other devices.
67486749
fzmo = vp->v_mount;
67496750

6750-
boolean_t locked = TRUE;
6751-
67526751
FsRtlCheckOplock(vp_oplock(vp), Irp, NULL, NULL, NULL);
67536752

67546753
znode_t *zp = VTOZ(vp); // zp for notify removal
@@ -6760,6 +6759,7 @@ zfs_fileobject_cleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp,
67606759
// ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, true);
67616760

67626761
ExAcquireResourceExclusiveLite(vp->FileHeader.Resource, TRUE);
6762+
locked = B_TRUE;
67636763

67646764
IoRemoveShareAccess(FileObject, &vp->share_access);
67656765

@@ -6834,7 +6834,7 @@ zfs_fileobject_cleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp,
68346834

68356835
zp = NULL;
68366836

6837-
flush = B_FALSE;
6837+
purge = B_TRUE;
68386838
// FILE_CLEANUP_UNKNOWN FILE_CLEANUP_WRONG_DEVICE FILE_CLEANUP_FILE_REMAINS
68396839
// FILE_CLEANUP_FILE_DELETED FILE_CLEANUP_LINK_DELETED
68406840
// FILE_CLEANUP_STREAM_DELETED FILE_CLEANUP_POSIX_STYLE_DELETE
@@ -6852,36 +6852,35 @@ zfs_fileobject_cleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp,
68526852
/* Not deleting, but lastclose */
68536853
}
68546854

6855-
6856-
if (flush &&
6857-
(FileObject->Flags & FO_CACHE_SUPPORTED) &&
6855+
if ((FileObject->Flags & FO_CACHE_SUPPORTED) &&
68586856
FileObject->SectionObjectPointer &&
68596857
FileObject->SectionObjectPointer->DataSectionObject) {
68606858
IO_STATUS_BLOCK iosb;
68616859

6862-
if (locked) {
6863-
ExReleaseResourceLite(vp->FileHeader.Resource);
6864-
locked = FALSE;
6865-
}
6866-
6860+
// Always flush
68676861
CcFlushCache(FileObject->SectionObjectPointer, NULL, 0,
68686862
&iosb);
68696863

68706864
if (!NT_SUCCESS(iosb.Status))
68716865
dprintf("CcFlushCache returned %08lx\n",
68726866
iosb.Status);
68736867

6874-
if (!ExIsResourceAcquiredSharedLite(
6875-
vp->FileHeader.PagingIoResource)) {
6876-
ExAcquireResourceExclusiveLite(
6877-
vp->FileHeader.PagingIoResource,
6878-
TRUE);
6879-
ExReleaseResourceLite(
6880-
vp->FileHeader.PagingIoResource);
6881-
}
6868+
if (purge) {
6869+
// Only purge in delete branch
68826870

6883-
CcPurgeCacheSection(FileObject->SectionObjectPointer,
6884-
NULL, 0, FALSE);
6871+
if (!ExIsResourceAcquiredSharedLite(
6872+
vp->FileHeader.PagingIoResource)) {
6873+
ExAcquireResourceExclusiveLite(
6874+
vp->FileHeader.PagingIoResource,
6875+
TRUE);
6876+
ExReleaseResourceLite(
6877+
vp->FileHeader.PagingIoResource);
6878+
}
6879+
6880+
dprintf("Purging cache due to delet\n");
6881+
CcPurgeCacheSection(FileObject->SectionObjectPointer,
6882+
NULL, 0, FALSE);
6883+
}
68856884

68866885
dprintf("flushed cache on close (fo = %p, vp = %p, "
68876886
"AllocationSize = %I64x, FileSize = %I64x, "
@@ -6897,7 +6896,7 @@ zfs_fileobject_cleanup(PDEVICE_OBJECT DeviceObject, PIRP Irp,
68976896
ExReleaseResourceLite(vp->FileHeader.Resource);
68986897

68996898
// ExReleaseResourceLite(&vp->Vcb->tree_lock);
6900-
if (zccb && zccb->cacheinit) {
6899+
if (zccb && zccb->cacheinit && FileObject->PrivateCacheMap) {
69016900
dprintf("CcUninitializeCacheMap on vp %p fo %p, Vpb %p\n",
69026901
vp, FileObject, FileObject->Vpb);
69036902
atomic_dec_64(&zccb->cacheinit);

0 commit comments

Comments
 (0)