Skip to content

Commit

Permalink
Work around for deltree race
Browse files Browse the repository at this point in the history
If we have pending deletes, wait for them to complete before we
deny directory deletion
  • Loading branch information
lundman committed Dec 21, 2018
1 parent 8e3add3 commit 34fa6c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
3 changes: 1 addition & 2 deletions ZFSin/spl/module/spl/spl-vnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,9 @@ int vnode_getwithvid(vnode_t *vp, uint64_t id)
atomic_inc_32(&vp->v_iocount);
#endif
}

// If we release last hold with REJECT, we will remove REJECT.
// It is expected it removes last hold in vnode_recycle.
if ((vp->v_flags & VNODE_REJECT) && (vp->v_iocount == 0))
if (error == 0 && (vp->v_flags & VNODE_REJECT) && (vp->v_iocount == 0))
vp->v_flags &= ~VNODE_REJECT;

mutex_exit(&vp->v_mutex);
Expand Down
25 changes: 13 additions & 12 deletions ZFSin/zfs/module/zfs/zfs_vnops_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ void zfs_dirlist_free(zfs_dirlist_t *zccb)
* Call vnode_setunlink if zfs_zaccess_delete() allows it
* TODO: provide credentials
*/
static uint64_t delete_pending = 0;
NTSTATUS zfs_setunlink(vnode_t *vp, vnode_t *dvp) {

NTSTATUS Status = STATUS_UNSUCCESSFUL;
Expand Down Expand Up @@ -245,21 +246,17 @@ NTSTATUS zfs_setunlink(vnode_t *vp, vnode_t *dvp) {
// are not empty.
if (S_ISDIR(zp->z_mode)) {

mutex_enter(&zp->z_lock);
int nodeadlock = 0;
while (zp->z_size == 3 && delete_pending != 0) {
dprintf("%s: delete_pending waiting\n", __func__);
delay(1);
if (nodeadlock > 10) break;
}

if (zp->z_size > 2) {

// We are about to deny the delete, make sure there are no
// rmdirs in transit

if (zp->z_size > 2) {

mutex_exit(&zp->z_lock);
Status = STATUS_DIRECTORY_NOT_EMPTY;
goto err;
}
Status = STATUS_DIRECTORY_NOT_EMPTY;
goto err;
}
mutex_exit(&zp->z_lock);
}

int error = zfs_zaccess_delete(dzp, zp, 0);
Expand Down Expand Up @@ -4415,6 +4412,8 @@ int zfs_fileobject_close(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATI
/* We can free memory, check if we also should delete file */
if (vnode_deleted(vp)) {

atomic_inc_64(&delete_pending);

// Mark it dead, stopping grabs
vnode_setreject(vp);
vnode_unlock(vp);
Expand All @@ -4430,6 +4429,8 @@ int zfs_fileobject_close(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATI
dprintf("delete vnode %p\n", vp);
Status = delete_entry(DeviceObject, Irp, IrpSp);

atomic_dec_64(&delete_pending);

} else { /* If vp is not deleted */

vnode_unlock(vp);
Expand Down
3 changes: 2 additions & 1 deletion ZFSin/zfs/module/zfs/zfs_znode.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz,
zp->z_gid = 0;
zp->z_size = 0;
zp->z_name_cache = NULL;
zp->z_fastpath = B_FALSE;

vp = ZTOV(zp); /* Does nothing in OSX */

Expand Down Expand Up @@ -1394,7 +1395,7 @@ zfs_zget_ext(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp,
ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);

//ZTOV(zp) = NULL;
dprintf("ZFS: vnode_get() returned %d\n", err);
dprintf("%s: vnode_get() returned %d\n", __func__, err);
kpreempt(KPREEMPT_SYNC);
IOSleep(hz >> 2);
if (crutch_count++ > 50) {
Expand Down

0 comments on commit 34fa6c7

Please sign in to comment.