From 20a1ddd8617c514031477d05680d0bf9d397b4b6 Mon Sep 17 00:00:00 2001 From: Avik Sil Date: Mon, 31 Aug 2020 15:35:42 +0530 Subject: [PATCH 1/2] Use taskq for Storport IOs in PASSIVE_LEVEL --- ZFSin/driver.c | 2 +- ZFSin/zfs/include/sys/wzvol.h | 1 + ZFSin/zfs/module/zfs/zfs_windows_zvol.c | 1 + ZFSin/zfs/module/zfs/zfs_windows_zvol_scsi.c | 24 +++++++++++++++++++- ZFSin/zfs/module/zfs/zfs_windows_zvol_wmi.c | 1 + ZFSin/zfs/module/zfs/zvol.c | 9 ++++++++ 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ZFSin/driver.c b/ZFSin/driver.c index dfc740ee..153cf197 100644 --- a/ZFSin/driver.c +++ b/ZFSin/driver.c @@ -5,6 +5,7 @@ #include //#include +#include #include #include "Trace.h" @@ -95,7 +96,6 @@ NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING pRe } //extern unsigned long spl_hostid; -extern int random_get_bytes(void *ptr, unsigned long len); void spl_create_hostid(HANDLE h, PUNICODE_STRING pRegistryPath) { diff --git a/ZFSin/zfs/include/sys/wzvol.h b/ZFSin/zfs/include/sys/wzvol.h index a45ae827..4cfa318b 100644 --- a/ZFSin/zfs/include/sys/wzvol.h +++ b/ZFSin/zfs/include/sys/wzvol.h @@ -216,6 +216,7 @@ typedef struct _MP_WorkRtnParms { PEPROCESS pReqProcess; MpWkRtnAction Action; ULONG SecondsToDelay; + taskq_ent_t ent; CHAR pQueueWorkItem[1]; // IO_WORKITEM structure: keep at the end of this block (dynamically allocated). } MP_WorkRtnParms, *pMP_WorkRtnParms; diff --git a/ZFSin/zfs/module/zfs/zfs_windows_zvol.c b/ZFSin/zfs/module/zfs/zfs_windows_zvol.c index 74508b9d..1e8f6588 100644 --- a/ZFSin/zfs/module/zfs/zfs_windows_zvol.c +++ b/ZFSin/zfs/module/zfs/zfs_windows_zvol.c @@ -28,6 +28,7 @@ #include #include #include +#include #include extern PDRIVER_OBJECT WIN_DriverObject; diff --git a/ZFSin/zfs/module/zfs/zfs_windows_zvol_scsi.c b/ZFSin/zfs/module/zfs/zfs_windows_zvol_scsi.c index b7f0d41b..3a88fa69 100644 --- a/ZFSin/zfs/module/zfs/zfs_windows_zvol_scsi.c +++ b/ZFSin/zfs/module/zfs/zfs_windows_zvol_scsi.c @@ -45,6 +45,7 @@ //#include //#include //#include +#include #include //#include @@ -93,6 +94,7 @@ * when the refcnt reaches 0 it is safe to free the remove lock cb. */ extern wzvolDriverInfo STOR_wzvolDriverInfo; +extern taskq_t *storport_taskq; inline int resolveArrayIndex(int t, int l, int nbL) { return (t * nbL) + l; } static inline void wzvol_decref_target(wzvolContext* zvc) @@ -678,7 +680,7 @@ ScsiOpWrite( /* */ /**************************************************************************************************/ UCHAR -ScsiReadWriteSetup( +ScsiReadWriteSetupNotPassive( __in pHW_HBA_EXT pHBAExt, // Adapter device-object extension from StorPort. __in PSCSI_REQUEST_BLOCK pSrb, __in MpWkRtnAction WkRtnAction, @@ -721,6 +723,26 @@ ScsiReadWriteSetup( return SRB_STATUS_SUCCESS; } // End ScsiReadWriteSetup. +UCHAR +ScsiReadWriteSetup( + __in pHW_HBA_EXT pHBAExt, // Adapter device-object extension from StorPort. + __in PSCSI_REQUEST_BLOCK pSrb, + __in MpWkRtnAction WkRtnAction, + __in PUCHAR pResult +) +{ + if(KeGetCurrentIrql() != PASSIVE_LEVEL) + return ScsiReadWriteSetupNotPassive(pHBAExt, pSrb, WkRtnAction, pResult); + else { + PHW_SRB_EXTENSION pSrbExt = pSrb->SrbExtension; + pMP_WorkRtnParms pWkRtnParms = &pSrbExt->WkRtnParms; + taskq_init_ent(&pWkRtnParms->ent); + taskq_dispatch_ent(storport_taskq, wzvol_WkRtn, pWkRtnParms, 0, &pWkRtnParms->ent); + *pResult = ResultQueued; + return SRB_STATUS_SUCCESS; + } +} + /**************************************************************************************************/ /* */ /**************************************************************************************************/ diff --git a/ZFSin/zfs/module/zfs/zfs_windows_zvol_wmi.c b/ZFSin/zfs/module/zfs/zfs_windows_zvol_wmi.c index ee3d1f52..0c0547b4 100644 --- a/ZFSin/zfs/module/zfs/zfs_windows_zvol_wmi.c +++ b/ZFSin/zfs/module/zfs/zfs_windows_zvol_wmi.c @@ -22,6 +22,7 @@ * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. \***************************************************************************/ +#include #include #include #include diff --git a/ZFSin/zfs/module/zfs/zvol.c b/ZFSin/zfs/module/zfs/zvol.c index 076b5c38..d2f54337 100644 --- a/ZFSin/zfs/module/zfs/zvol.c +++ b/ZFSin/zfs/module/zfs/zvol.c @@ -90,9 +90,11 @@ #include "zfs_namecheck.h" +unsigned int zvol_threads = 32; uint64_t zvol_inhibit_dev = 0; dev_info_t zfs_dip_real = { 0 }; dev_info_t *zfs_dip = &zfs_dip_real; +taskq_t *storport_taskq; extern int zfs_major; extern int zfs_bmajor; @@ -2840,7 +2842,13 @@ zvol_busy(void) int zvol_init(void) { + int threads = MIN(MAX(zvol_threads, 1), 1024); + dprintf("zvol_init\n"); + storport_taskq = taskq_create(ZVOL_DRIVER, threads, maxclsyspri, + threads * 2, INT_MAX, 0); + if (storport_taskq == NULL) + return (-ENOMEM); VERIFY(ddi_soft_state_init(&zfsdev_state, sizeof (zfs_soft_state_t), 1) == 0); #ifdef illumos @@ -2858,4 +2866,5 @@ zvol_fini(void) mutex_destroy(&zfsdev_state_lock); #endif ddi_soft_state_fini(&zfsdev_state); + taskq_destroy(storport_taskq); } From a517a89fcadf0adacb289b0192f96f4328c23472 Mon Sep 17 00:00:00 2001 From: Avik Sil Date: Wed, 2 Sep 2020 09:04:28 +0530 Subject: [PATCH 2/2] Add wzvol_TaskQueuingWkRtn routine --- ZFSin/zfs/module/zfs/zfs_windows_zvol_scsi.c | 39 +++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/ZFSin/zfs/module/zfs/zfs_windows_zvol_scsi.c b/ZFSin/zfs/module/zfs/zfs_windows_zvol_scsi.c index 3a88fa69..0bf8df99 100644 --- a/ZFSin/zfs/module/zfs/zfs_windows_zvol_scsi.c +++ b/ZFSin/zfs/module/zfs/zfs_windows_zvol_scsi.c @@ -671,6 +671,21 @@ ScsiOpWrite( return status; } // End ScsiOpWrite. +VOID +wzvol_TaskQueuingWkRtn( + __in PVOID pDummy, // Not used. + __in PVOID pWkParms // Parm list pointer. +) +{ + pMP_WorkRtnParms pWkRtnParms = (pMP_WorkRtnParms)pWkParms; + + UNREFERENCED_PARAMETER(pDummy); + IoUninitializeWorkItem((PIO_WORKITEM)pWkRtnParms->pQueueWorkItem); + + taskq_init_ent(&pWkRtnParms->ent); + taskq_dispatch_ent(storport_taskq, wzvol_WkRtn, pWkRtnParms, 0, &pWkRtnParms->ent); +} + /**************************************************************************************************/ /* */ /* This routine does the setup for reading or writing. The reading/writing could be effected */ @@ -680,7 +695,7 @@ ScsiOpWrite( /* */ /**************************************************************************************************/ UCHAR -ScsiReadWriteSetupNotPassive( +ScsiReadWriteSetup( __in pHW_HBA_EXT pHBAExt, // Adapter device-object extension from StorPort. __in PSCSI_REQUEST_BLOCK pSrb, __in MpWkRtnAction WkRtnAction, @@ -716,33 +731,13 @@ ScsiReadWriteSetupNotPassive( // Queue work item, which will run in the System process. - IoQueueWorkItem((PIO_WORKITEM)pWkRtnParms->pQueueWorkItem, wzvol_GeneralWkRtn, DelayedWorkQueue, pWkRtnParms); + IoQueueWorkItem((PIO_WORKITEM)pWkRtnParms->pQueueWorkItem, wzvol_TaskQueuingWkRtn, DelayedWorkQueue, pWkRtnParms); *pResult = ResultQueued; // Indicate queuing. return SRB_STATUS_SUCCESS; } // End ScsiReadWriteSetup. -UCHAR -ScsiReadWriteSetup( - __in pHW_HBA_EXT pHBAExt, // Adapter device-object extension from StorPort. - __in PSCSI_REQUEST_BLOCK pSrb, - __in MpWkRtnAction WkRtnAction, - __in PUCHAR pResult -) -{ - if(KeGetCurrentIrql() != PASSIVE_LEVEL) - return ScsiReadWriteSetupNotPassive(pHBAExt, pSrb, WkRtnAction, pResult); - else { - PHW_SRB_EXTENSION pSrbExt = pSrb->SrbExtension; - pMP_WorkRtnParms pWkRtnParms = &pSrbExt->WkRtnParms; - taskq_init_ent(&pWkRtnParms->ent); - taskq_dispatch_ent(storport_taskq, wzvol_WkRtn, pWkRtnParms, 0, &pWkRtnParms->ent); - *pResult = ResultQueued; - return SRB_STATUS_SUCCESS; - } -} - /**************************************************************************************************/ /* */ /**************************************************************************************************/