Skip to content

Commit

Permalink
All working
Browse files Browse the repository at this point in the history
mount -> unmount -> mount -> unmount

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Aug 23, 2024
1 parent e855547 commit 2e3f20e
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 383 deletions.
5 changes: 5 additions & 0 deletions include/os/windows/spl/sys/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#define MNT_FORCE 0x00080000 /* force unmount or readonly change */
#define MNT_CMDFLAGS (MNT_UPDATE|MNT_NOBLOCK|MNT_RELOAD|MNT_FORCE)

#define MNT_UNMOUNTING 0x80000000 /* process of unmounting */

#define MNT_UNKNOWNPERMISSIONS MNT_IGNORE_OWNERSHIP

#define MFSTYPENAMELEN 16
Expand Down Expand Up @@ -125,6 +127,8 @@ struct mount

uint64_t mountflags;

KEVENT volume_removed_event;

// Linked list of mounts
list_node_t mount_node;

Expand Down Expand Up @@ -163,5 +167,6 @@ void vfs_mount_add(mount_t *mp);
void vfs_mount_remove(mount_t *mp);
int vfs_mount_count(void);
void vfs_mount_setarray(void **array, int max);
void vfs_mount_iterate(int (*func)(void *, void *), void *);

#endif /* SPL_MOUNT_H */
2 changes: 2 additions & 0 deletions include/os/windows/zfs/sys/zfs_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ extern void zfs_save_ntsecurity(struct vnode *vp);
void zfs_load_ntsecurity(struct vnode *vp);
struct vnode *zfs_parent(struct vnode *);
extern PVOID MapUserBuffer(IN OUT PIRP Irp);
extern NTSTATUS volume_create(PDEVICE_OBJECT DeviceObject, PFILE_OBJECT FileObject,

Check failure on line 175 in include/os/windows/zfs/sys/zfs_windows.h

View workflow job for this annotation

GitHub Actions / checkstyle

line > 80 characters
USHORT ShareAccess, uint64_t AllocationSize, ACCESS_MASK DesiredAccess);


/* IRP_MJ_SET_INFORMATION helpers */
Expand Down
2 changes: 1 addition & 1 deletion module/os/windows/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void
OpenZFS_Fini(PDRIVER_OBJECT DriverObject)
{
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "OpenZFS_Fini\n"));
DbgBreakPoint();

zfs_vfsops_fini();

if (STOR_DriverUnload != NULL) {
Expand Down
19 changes: 18 additions & 1 deletion module/os/windows/spl/spl-mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ vfs_mount_setarray(void **array, int max)
mutex_exit(&mount_list_lock);
}

void
vfs_mount_iterate(int (*func)(void *, void *), void *priv)
{
mount_t *node;

mutex_enter(&mount_list_lock);
for (node = list_head(&mount_list);
node;
node = list_next(&mount_list, node)) {

// call func, stop if not zero
if (func(node, priv) != 0)
break;
}
mutex_exit(&mount_list_lock);
}

int
vfs_busy(mount_t *mp, int flags)
{
Expand Down Expand Up @@ -221,7 +238,7 @@ vfs_getnewfsid(struct mount *mp)
int
vfs_isunmount(mount_t *mp)
{
return (0);
return (vfs_flags(mp) & MNT_UNMOUNTING);
}

int
Expand Down
30 changes: 27 additions & 3 deletions module/os/windows/spl/spl-vnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,27 @@ dnlc_lookup(struct vnode *dvp, char *name)
int
dnlc_purge_vfsp(struct mount *mp, int flags)
{
struct vnode *rvp;
IO_STATUS_BLOCK ioStatus;

mutex_enter(&vnode_all_list_lock);
for (rvp = list_head(&vnode_all_list);
rvp;
rvp = list_next(&vnode_all_list, rvp)) {

if (rvp->v_mount != mp)
continue;

if (vnode_isdir(rvp))
continue;
/*
if (vnode_isunlink(rvp))
continue;
*/
CcFlushCache(&rvp->SectionObjectPointers, NULL, NULL, &ioStatus);
}
mutex_exit(&vnode_all_list_lock);

return (0);
}

Expand All @@ -465,6 +486,7 @@ dnlc_remove(struct vnode *vp, char *name)
void
dnlc_update(struct vnode *vp, char *name, struct vnode *tp)
{

}

static int
Expand Down Expand Up @@ -1700,7 +1722,8 @@ vflush(struct mount *mp, struct vnode *skipvp, int flags)

mutex_enter(&rvp->v_mutex);

flush_file_objects(rvp);
// this hack is no longer needed
// flush_file_objects(rvp);

// vnode_recycle_int() will exit v_mutex
// re-check flags, due to releasing locks
Expand Down Expand Up @@ -1761,7 +1784,7 @@ vflush(struct mount *mp, struct vnode *skipvp, int flags)

dprintf("vflush end: deadlisted %d nodes\n", deadlist);

return (0);
return (reclaims > 0 ? EBUSY : 0);
}

int
Expand Down Expand Up @@ -1995,14 +2018,15 @@ vnode_decouplefileobject(vnode_t *vp, FILE_OBJECT *fileobject)
if (fileobject && fileobject->FsContext) {
dprintf("%s: fo %p -X-> %p\n", __func__, fileobject, vp);

vnode_fileobject_remove(vp, fileobject);

// If we are flushing, we do nothing here.
if (vp->v_flags & VNODE_FLUSHING) {
dprintf("Already flushing; FS re-entry\n");
return;
}

// if (vnode_flushcache(vp, fileobject, FALSE))
vnode_fileobject_remove(vp, fileobject);

// fileobject->FsContext = NULL;
}
Expand Down
67 changes: 20 additions & 47 deletions module/os/windows/zfs/zfs_ioctl_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ zfs_ioc_unregister_fs(void)

OpenZFS_Driver_Extension *DriverExtension =
(OpenZFS_Driver_Extension *)IoGetDriverObjectExtension(WIN_DriverObject, WIN_DriverObject);
DbgBreakPoint();

if (DriverExtension->fsDiskDeviceObject != NULL) {
IoUnregisterFsRegistrationChange(WIN_DriverObject,
DriverNotificationRoutine);
Expand Down Expand Up @@ -1025,6 +1025,9 @@ static DEVPROPKEY DEVPKEY_Device_HardwareIds =
#undef INITGUID
#endif

extern void
zfs_windows_unmount_free(PUNICODE_STRING symlink_name);

_Function_class_(DRIVER_NOTIFICATION_CALLBACK_ROUTINE)
NTSTATUS __stdcall
volume_notification(PVOID NotificationStructure, PVOID Context)
Expand All @@ -1034,8 +1037,10 @@ volume_notification(PVOID NotificationStructure, PVOID Context)

if (RtlCompareMemory(&dicn->Event, &GUID_DEVICE_INTERFACE_ARRIVAL, sizeof(GUID)) == sizeof(GUID))
xprintf("%s arrival: %wZ\n", __func__, dicn->SymbolicLinkName);
else if (RtlCompareMemory(&dicn->Event, &GUID_DEVICE_INTERFACE_REMOVAL, sizeof(GUID)) == sizeof(GUID))
else if (RtlCompareMemory(&dicn->Event, &GUID_DEVICE_INTERFACE_REMOVAL, sizeof(GUID)) == sizeof(GUID)) {
xprintf("%s removal: %wZ\n", __func__, dicn->SymbolicLinkName);
zfs_windows_unmount_free(dicn->SymbolicLinkName);
}

return (STATUS_SUCCESS);
}
Expand Down Expand Up @@ -1084,18 +1089,21 @@ OpenZFS_AddDevice(
)
{
NTSTATUS status;
UNICODE_STRING ntUnicodeString; // NT Device Name
UNICODE_STRING ntWin32NameString; // Win32 Name
int err;

static UNICODE_STRING sddl = RTL_CONSTANT_STRING(
L"D:P(A;;GA;;;SY)(A;;GRGWGX;;;BA)"
"(A;;GRGWGX;;;WD)(A;;GRGX;;;RC)");
// Or use &SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RW_RES_R

if (PhysicalDeviceObject == NULL) {
DbgBreakPoint();
return (STATUS_NO_MORE_ENTRIES);
}

ZFS_DRIVER_EXTENSION(DriverObject, DriverExtension);

xprintf("%s called: PhysicalDeviceObject %p\n", __func__, PhysicalDeviceObject);
// DbgBreakPoint();

if (DriverExtension == NULL) {
dprintf("No DriverExtension? Help!\n");
return (STATUS_INVALID_PARAMETER);
Expand Down Expand Up @@ -1128,37 +1136,14 @@ OpenZFS_AddDevice(
zmo_bus->FunctionalDeviceObject = DriverExtension->FunctionalDeviceObject;
zmo_bus->PhysicalDeviceObject = PhysicalDeviceObject;


// status = IoReportDetectedDevice(WIN_DriverObject, InterfaceTypeUndefined, 0xFFFFFFFF, 0xFFFFFFFF,
// NULL, NULL, 0, &zmo_bus->PNPDeviceObject);

// xprintf("%s called: PhysicalDeviceObject %p\n", __func__, zmo_bus->PhysicalDeviceObject);
// status = IoRegisterDeviceInterface(zmo_bus->PhysicalDeviceObject, &BtrfsBusInterface, NULL,
// &zmo_bus->deviceInterfaceName);

zmo_bus->AttachedDevice = IoAttachDeviceToDeviceStack(DriverExtension->FunctionalDeviceObject,
zmo_bus->PhysicalDeviceObject);
DriverExtension->LowerDeviceObject = zmo_bus->AttachedDevice;

DriverExtension->FunctionalDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;

// status = IoSetDeviceInterfaceState(&zmo_bus->deviceInterfaceName, TRUE);

// IoInvalidateDeviceRelations(zmo_bus->PhysicalDeviceObject, BusRelations);

#if 1
NTSTATUS ntStatus;
UNICODE_STRING ntUnicodeString; // NT Device Name
UNICODE_STRING ntWin32NameString; // Win32 Name
int err;

static UNICODE_STRING sddl = RTL_CONSTANT_STRING(
L"D:P(A;;GA;;;SY)(A;;GRGWGX;;;BA)"
"(A;;GRGWGX;;;WD)(A;;GRGX;;;RC)");
// Or use &SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RW_RES_R

RtlInitUnicodeString(&ntUnicodeString, ZFS_DEV_KERNEL);
ntStatus = IoCreateDeviceSecure(
status = IoCreateDeviceSecure(
WIN_DriverObject,
sizeof (mount_t),
&ntUnicodeString, // Device name "\Device\SIOCTL"
Expand All @@ -1169,15 +1154,11 @@ OpenZFS_AddDevice(
NULL,
&DriverExtension->ioctlDeviceObject); // Returned ptr to Device Object

if (!NT_SUCCESS(ntStatus)) {
if (!NT_SUCCESS(status)) {
dprintf("ZFS: Couldn't create the device object "
"/dev/zfs (%S)\n", ZFS_DEV_KERNEL);
return (ntStatus);
return (status);
}
// dprintf("ZFS: created kernel device node: %p: name %S\n",
// DriverExtension->ioctlDeviceObject, ZFS_DEV_KERNEL);

// ObReferenceObject(ioctlDeviceObject);

mount_t *dgl;
dgl = DriverExtension->ioctlDeviceObject->DeviceExtension;
Expand All @@ -1186,29 +1167,21 @@ OpenZFS_AddDevice(

// Initialize a Unicode String containing the Win32 name
// for our device.
#if 1

RtlInitUnicodeString(&ntWin32NameString, ZFS_DEV_DOS);
// RtlInitUnicodeString(&ntWin32NameString, L"\\DosDevices\\Global\\OpenZFS");

// Create a symbolic link between our device name and the Win32 name
ntStatus = IoCreateSymbolicLink(
status = IoCreateSymbolicLink(
&ntWin32NameString, &ntUnicodeString);

if (!NT_SUCCESS(ntStatus)) {
if (!NT_SUCCESS(status)) {
dprintf("ZFS: Couldn't create userland symbolic link to "
"/dev/zfs (%wZ)\n", ZFS_DEV);
// ObDereferenceObject(ioctlDeviceObject);
IoDeleteDevice(DriverExtension->ioctlDeviceObject);
return (-1);
}
#endif
// dprintf("ZFS: created userland device symlink\n");

DriverExtension->ioctlDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
#endif


xprintf("bus is up and running\n");
return (STATUS_SUCCESS);
}

Expand Down
Loading

0 comments on commit 2e3f20e

Please sign in to comment.