mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 08:23:05 -05:00
tst: memfs: code cleanup and testing
This commit is contained in:
parent
0ab35fde1a
commit
b672312c79
@ -44,9 +44,9 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
|
||||
ULONG FileInfoTimeout = INFINITE;
|
||||
ULONG MaxFileNodes = 1024;
|
||||
ULONG MaxFileSize = 16 * 1024 * 1024;
|
||||
ULONG SlowioMaxDelay = 0; // From -M : maximum delay in milliseconds
|
||||
ULONG SlowioPercentDelay = 0; // From -D : percent of IO to slow down
|
||||
ULONG SlowioRarefyDelay = 0; // From -R : adjust the rarity of long delays
|
||||
ULONG SlowioMaxDelay = 0; /* -M: maximum slow IO delay in millis */
|
||||
ULONG SlowioPercentDelay = 0; /* -P: percent of slow IO to make pending */
|
||||
ULONG SlowioRarefyDelay = 0; /* -R: adjust the rarity of pending slow IO */
|
||||
PWSTR FileSystemName = 0;
|
||||
PWSTR MountPoint = 0;
|
||||
PWSTR VolumePrefix = 0;
|
||||
@ -205,8 +205,8 @@ usage:
|
||||
" -n MaxFileNodes\n"
|
||||
" -s MaxFileSize [bytes]\n"
|
||||
" -M MaxDelay [maximum slow IO delay in millis]\n"
|
||||
" -P PercentDelay [percent of IO to make slow IO]\n"
|
||||
" -R RarefyDelay [adjust the rarity of slow IO]\n"
|
||||
" -P PercentDelay [percent of slow IO to make pending]\n"
|
||||
" -R RarefyDelay [adjust the rarity of pending slow IO]\n"
|
||||
" -F FileSystemName\n"
|
||||
" -S RootSddl [file rights: FA, etc; NO generic rights: GA, etc.]\n"
|
||||
" -u \\Server\\Share [UNC prefix (single backslash)]\n"
|
||||
|
@ -679,25 +679,29 @@ static inline UINT64 Hash(UINT64 x)
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline UINT32 PseudoRandom(UINT32 to)
|
||||
static inline ULONG PseudoRandom(ULONG to)
|
||||
{
|
||||
/* John Oberschelp's PRNG */
|
||||
static UINT64 spin = 0;
|
||||
InterlockedIncrement(&spin);
|
||||
return Hash(spin) % to;
|
||||
}
|
||||
|
||||
static inline UINT32 SlowioMillisecondsOfDelay(FSP_FILE_SYSTEM *FileSystem)
|
||||
static inline BOOLEAN SlowioReturnPending(FSP_FILE_SYSTEM *FileSystem)
|
||||
{
|
||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||
return 0 != Memfs->SlowioMaxDelay ?
|
||||
PseudoRandom(Memfs->SlowioMaxDelay + 1) >> PseudoRandom(Memfs->SlowioRarefyDelay + 1) : 0;
|
||||
if (0 == Memfs->SlowioMaxDelay)
|
||||
return FALSE;
|
||||
return PseudoRandom(100) < Memfs->SlowioPercentDelay;
|
||||
}
|
||||
|
||||
static inline bool SlowioReturnPending(FSP_FILE_SYSTEM *FileSystem)
|
||||
static inline VOID SlowioSnooze(FSP_FILE_SYSTEM *FileSystem)
|
||||
{
|
||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||
return 0 != Memfs->SlowioMaxDelay &&
|
||||
PseudoRandom(100) < Memfs->SlowioPercentDelay;
|
||||
if (0 == Memfs->SlowioMaxDelay)
|
||||
return;
|
||||
ULONG millis = PseudoRandom(Memfs->SlowioMaxDelay + 1) >> PseudoRandom(Memfs->SlowioRarefyDelay + 1);
|
||||
Sleep(millis);
|
||||
}
|
||||
|
||||
void SlowioReadThread(
|
||||
@ -708,10 +712,7 @@ void SlowioReadThread(
|
||||
UINT64 EndOffset,
|
||||
UINT64 RequestHint)
|
||||
{
|
||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||
|
||||
if (UINT32 ms = SlowioMillisecondsOfDelay(FileSystem))
|
||||
Sleep(ms);
|
||||
SlowioSnooze(FileSystem);
|
||||
|
||||
memcpy(Buffer, (PUINT8)FileNode->FileData + Offset, (size_t)(EndOffset - Offset));
|
||||
UINT32 BytesTransferred = (ULONG)(EndOffset - Offset);
|
||||
@ -725,6 +726,7 @@ void SlowioReadThread(
|
||||
ResponseBuf.IoStatus.Information = BytesTransferred; // bytes read
|
||||
FspFileSystemSendResponse(FileSystem, &ResponseBuf);
|
||||
|
||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||
InterlockedDecrement(&Memfs->SlowioThreadsRunning);
|
||||
}
|
||||
|
||||
@ -737,10 +739,7 @@ void SlowioWriteThread(
|
||||
UINT64 RequestHint,
|
||||
FSP_FSCTL_FILE_INFO *FileInfo)
|
||||
{
|
||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||
|
||||
if (UINT32 ms = SlowioMillisecondsOfDelay(FileSystem))
|
||||
Sleep(ms);
|
||||
SlowioSnooze(FileSystem);
|
||||
|
||||
memcpy((PUINT8)FileNode->FileData + Offset, Buffer, (size_t)(EndOffset - Offset));
|
||||
UINT32 BytesTransferred = (ULONG)(EndOffset - Offset);
|
||||
@ -755,6 +754,7 @@ void SlowioWriteThread(
|
||||
ResponseBuf.Rsp.Write.FileInfo = *FileInfo; // FileInfo of file after Write
|
||||
FspFileSystemSendResponse(FileSystem, &ResponseBuf);
|
||||
|
||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||
InterlockedDecrement(&Memfs->SlowioThreadsRunning);
|
||||
}
|
||||
|
||||
@ -763,10 +763,7 @@ void SlowioReadDirectoryThread(
|
||||
ULONG BytesTransferred,
|
||||
UINT64 RequestHint)
|
||||
{
|
||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||
|
||||
if (UINT32 ms = SlowioMillisecondsOfDelay(FileSystem))
|
||||
Sleep(ms);
|
||||
SlowioSnooze(FileSystem);
|
||||
|
||||
FSP_FSCTL_TRANSACT_RSP ResponseBuf;
|
||||
memset(&ResponseBuf, 0, sizeof ResponseBuf);
|
||||
@ -777,6 +774,7 @@ void SlowioReadDirectoryThread(
|
||||
ResponseBuf.IoStatus.Information = BytesTransferred; // bytes of directory info read
|
||||
FspFileSystemSendResponse(FileSystem, &ResponseBuf);
|
||||
|
||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||
InterlockedDecrement(&Memfs->SlowioThreadsRunning);
|
||||
}
|
||||
#endif
|
||||
@ -1184,8 +1182,7 @@ static NTSTATUS Read(FSP_FILE_SYSTEM *FileSystem,
|
||||
return STATUS_PENDING;
|
||||
}
|
||||
regular:
|
||||
if (UINT32 ms = SlowioMillisecondsOfDelay(FileSystem))
|
||||
Sleep(ms);
|
||||
SlowioSnooze(FileSystem);
|
||||
#endif
|
||||
|
||||
memcpy(Buffer, (PUINT8)FileNode->FileData + Offset, (size_t)(EndOffset - Offset));
|
||||
@ -1261,8 +1258,7 @@ static NTSTATUS Write(FSP_FILE_SYSTEM *FileSystem,
|
||||
return STATUS_PENDING;
|
||||
}
|
||||
regular:
|
||||
if (UINT32 ms = SlowioMillisecondsOfDelay(FileSystem))
|
||||
Sleep(ms);
|
||||
SlowioSnooze(FileSystem);
|
||||
#endif
|
||||
|
||||
memcpy((PUINT8)FileNode->FileData + Offset, Buffer, (size_t)(EndOffset - Offset));
|
||||
@ -1653,8 +1649,7 @@ static NTSTATUS ReadDirectory(FSP_FILE_SYSTEM *FileSystem,
|
||||
return STATUS_PENDING;
|
||||
}
|
||||
regular:
|
||||
if (UINT32 ms = SlowioMillisecondsOfDelay(FileSystem))
|
||||
Sleep(ms);
|
||||
SlowioSnooze(FileSystem);
|
||||
#endif
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
Loading…
x
Reference in New Issue
Block a user