Skip to content

Commit

Permalink
Handle short-reads in pipe recv
Browse files Browse the repository at this point in the history
Turns out that pipes can return short reads, especially
when used with MSYS/cygwin shells. Loop until the
desired amount is reached. dmu recv requires the
correct amount to be read.

This helps zfs recv

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Jun 27, 2024
1 parent dcb8a94 commit b0f716a
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions module/os/windows/zfs/zfs_file_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,28 @@ zfs_file_read(zfs_file_t *fp, void *buf, size_t count, ssize_t *resid)
{
NTSTATUS ntstatus;
IO_STATUS_BLOCK ioStatusBlock;
ntstatus = ZwReadFile(fp->f_handle, NULL, NULL, NULL,
&ioStatusBlock, buf, count, NULL, NULL);
if (STATUS_SUCCESS != ntstatus)
return (EIO);
size_t bytesRead = 0;

while (bytesRead < count) {
ULONG remainingLength = count - bytesRead;

/* So we can get short-reads from pipes under MSYS2 */
ntstatus = ZwReadFile(fp->f_handle, NULL, NULL, NULL,
&ioStatusBlock, (PUCHAR)buf + bytesRead, remainingLength,
NULL, NULL);
if (STATUS_SUCCESS != ntstatus)
return (EIO);

// No more data to read, break the loop
if (ioStatusBlock.Information == 0)
break;

bytesRead += (ULONG)ioStatusBlock.Information;
}

// Double check for short reads
VERIFY3U(count, ==, bytesRead);

if (resid)
*resid = 0;
return (0);
Expand Down

0 comments on commit b0f716a

Please sign in to comment.