Skip to content

Commit

Permalink
Implement vfs-busy() and vfs-unbusy()
Browse files Browse the repository at this point in the history
Which is used to guard against mount/unmount
requests.

Signed-off-by: Jorgen Lundman <lundman@lundman.net>
  • Loading branch information
lundman committed Oct 12, 2023
1 parent 11cb959 commit fee66c7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
3 changes: 3 additions & 0 deletions include/os/windows/spl/sys/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ typedef struct mount mount_t;
typedef struct mount vfsp_t;
#define LK_NOWAIT 1

int spl_vfs_init(void);
void spl_vfs_fini(void);

int vfs_busy(mount_t *mp, int flags);
void vfs_unbusy(mount_t *mp);
int vfs_isrdonly(mount_t *mp);
Expand Down
30 changes: 30 additions & 0 deletions module/os/windows/spl/spl-mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,45 @@
#include <sys/types.h>
#include <sys/mount.h>

/*
* In Unix, this lock is to protect the list of
* mounted file-systems, to add and remove mounts.
* XNU uses mount_lock() to hold all, then calls
* lck_rw_lock_shared(mount_t) to hold this specific
* mount - in future we can make this enhancement.
*/
static kmutex_t vfs_main_lock;


int
spl_vfs_init(void)
{
mutex_init(&vfs_main_lock, NULL, MUTEX_DEFAULT, NULL);
return (0);
}

void
spl_vfs_fini(void)
{
mutex_destroy(&vfs_main_lock);
}

int
vfs_busy(mount_t *mp, int flags)
{
mutex_enter(&vfs_main_lock);
if (mp == NULL) {
mutex_exit(&vfs_main_lock);
return (EINVAL);
}

return (0);
}

void
vfs_unbusy(mount_t *mp)
{
mutex_exit(&vfs_main_lock);
}

int
Expand Down
2 changes: 2 additions & 0 deletions module/os/windows/spl/spl-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ spl_start(PUNICODE_STRING RegistryPath)
spl_mutex_subsystem_init();
spl_kmem_init(total_memory);

spl_vfs_init();
spl_vnode_init();
spl_kmem_thread_init();
spl_kmem_mp_init();
Expand All @@ -565,6 +566,7 @@ spl_stop(void)
{
spl_kmem_thread_fini();
spl_vnode_fini();
spl_vfs_fini();
spl_taskq_fini();
spl_rwlock_fini();
spl_tsd_fini();
Expand Down
36 changes: 27 additions & 9 deletions module/os/windows/zfs/zfs_vnops_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,17 @@ zfs_AcquireForLazyWrite(void *Context, BOOLEAN Wait)
dprintf("%s:fo %p\n", __func__, fo);

/* Confirm we are mounted, and stop unmounting */
if ((zfsvfs->z_vfs == NULL) ||
zfsvfs->z_unmounted ||
zfs_enter(zfsvfs, FTAG) != 0)
if (vfs_busy(zfsvfs->z_vfs, 0) != 0)
return (FALSE);

if (zfsvfs->z_unmounted ||
zfs_enter(zfsvfs, FTAG) != 0) {
vfs_unbusy(zfsvfs);
return (FALSE);
}

vfs_unbusy(zfsvfs);

if (vp == NULL ||
VTOZ(vp) == NULL ||
VN_HOLD(vp) != 0) {
Expand Down Expand Up @@ -204,10 +210,16 @@ zfs_AcquireForReadAhead(void *Context, BOOLEAN Wait)

dprintf("%s:\n", __func__);

if ((zfsvfs->z_vfs == NULL) ||
zfsvfs->z_unmounted ||
zfs_enter(zfsvfs, FTAG) != 0)
if (vfs_busy(zfsvfs->z_vfs, 0) != 0)
return (FALSE);

if (zfsvfs->z_unmounted ||
zfs_enter(zfsvfs, FTAG) != 0) {
vfs_unbusy(zfsvfs);
return (FALSE);
}

vfs_unbusy(zfsvfs);

if (vp == NULL ||
VTOZ(vp) == NULL ||
Expand Down Expand Up @@ -7938,10 +7950,16 @@ fastio_acquire_for_mod_write(PFILE_OBJECT FileObject,
NTSTATUS Status = STATUS_INVALID_PARAMETER;
dprintf("%s: \n", __func__);

if ((zfsvfs->z_vfs == NULL) ||
zfsvfs->z_unmounted ||
zfs_enter(zfsvfs, FTAG) != 0)
if (vfs_busy(zfsvfs->z_vfs, 0) != 0)
return (STATUS_INVALID_PARAMETER);

if (zfsvfs->z_unmounted ||
zfs_enter(zfsvfs, FTAG) != 0) {
vfs_unbusy(zfsvfs);
return (STATUS_INVALID_PARAMETER);
}

vfs_unbusy(zfsvfs);

vp = FileObject->FsContext;

Expand Down
4 changes: 3 additions & 1 deletion module/os/windows/zfs/zfs_vnops_windows_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,9 @@ zfs_windows_unmount(zfs_cmd_t *zc)

out_unlock:
// counter to getzfvfs
vfs_unbusy(zfsvfs->z_vfs);
zfsvfs->z_vfs = NULL;
vfs_unbusy(zmo);

}
return (error);
}

0 comments on commit fee66c7

Please sign in to comment.