Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dd: buffer partial blocks in the output writer #4545

Merged
merged 5 commits into from Nov 27, 2023

Conversation

jfinkels
Copy link
Collaborator

This pull request adds buffering of partial blocks in the output block writer until they are completed.

The test case that demonstrates this buffering behavior is

mkfifo fifo
dd ibs=3 obs=3 if=fifo &
(printf 'ab'; sleep 1; printf 'cd') > dd.fifo

The "ab" forms a partial block, which is buffered and not written immediately. Then when the "cd" comes in, the complete block "abc" is written, followed by the partial block "d".

To override the behavior set bs=N, like this:

dd bs=3 ibs=1 obs=1 if=fifo

Fixes GNU test case tests/dd/reblock.sh.

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!


UCommand::new()
.arg(format!(
"({TESTS_BINARY} printf 'ab'; {TESTS_BINARY} sleep 0.1; {TESTS_BINARY} printf 'cd') > {fifoname}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are failing for reasons I don't understand yet. It seems that the two bytes "ab" and the two bytes "cd" are sometimes being read by dd one byte at a time, resulting in one partial block read comprising the byte "a" and a separate partial block read comprising the byte "b" (or "c" and "d", respectively). It seems to be happening only when I run a large set of tests, like cargo test test_dd, and not when I run the tests individually or as a pair, as in cargo test test_dd::test_reading_partial_blocks_from_fifo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to using explicit Command, let's see if that helps.

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!

src/uu/dd/src/bufferedoutput.rs Outdated Show resolved Hide resolved
src/uu/dd/src/bufferedoutput.rs Show resolved Hide resolved
src/uu/dd/src/bufferedoutput.rs Outdated Show resolved Hide resolved
src/uu/dd/src/parseargs.rs Show resolved Hide resolved
@sylvestre
Copy link
Sponsor Contributor

@jfinkels ping here too ? :)

@jfinkels
Copy link
Collaborator Author

jfinkels commented May 7, 2023 via email

@github-actions
Copy link

github-actions bot commented May 7, 2023

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!

1 similar comment
@github-actions
Copy link

github-actions bot commented May 7, 2023

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!

@sylvestre
Copy link
Sponsor Contributor

@jfinkels it is conflicting with your other pr, sorry

Copy link
Sponsor Contributor

@sylvestre sylvestre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need rebasing

@jfinkels
Copy link
Collaborator Author

jfinkels commented Jul 3, 2023

I'm starting to have some more time again, so I'll take another look at this. Thanks for your patience

@github-actions
Copy link

github-actions bot commented Jul 4, 2023

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!
Skip an intermittent issue tests/tail-2/inotify-dir-recreate

@github-actions
Copy link

github-actions bot commented Jul 4, 2023

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!
Skip an intermittent issue tests/tail-2/inotify-dir-recreate

@github-actions
Copy link

github-actions bot commented Jul 5, 2023

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!

@sylvestre
Copy link
Sponsor Contributor

@jfinkels sorry it is taking too long :/
it needs rebasing

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting back to this!

src/uu/dd/src/bufferedoutput.rs Outdated Show resolved Hide resolved
src/uu/dd/src/bufferedoutput.rs Outdated Show resolved Hide resolved
src/uu/dd/src/dd.rs Outdated Show resolved Hide resolved
src/uu/dd/src/dd.rs Outdated Show resolved Hide resolved
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!
Congrats! The gnu test tests/tail/symlink is no longer failing!

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!
Congrats! The gnu test tests/tail/symlink is no longer failing!

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!
Congrats! The gnu test tests/tail/inotify-dir-recreate is no longer failing!

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!

@jfinkels
Copy link
Collaborator Author

Looks like the remaining build failures are known issues:

So this should be reviewed again.

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!
Congrats! The gnu test tests/tail/symlink is no longer failing!

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!
GNU test failed: tests/tail/retry. tests/tail/retry is passing on 'main'. Maybe you have to rebase?

Add the `Settings.buffered` field to indicate whether partial output
blocks should be buffered until they are complete.
Correct the behavior of `dd` so that the termination condition of the
main loop uses the number of bytes read, not the number of bytes
written, when the `count` command-line option is given in bytes
instead of blocks.
Add buffering of partial blocks in the output block writer until they
are completed.
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/dd/reblock is no longer failing!
Congrats! The gnu test tests/tail/symlink is no longer failing!

@sylvestre
Copy link
Sponsor Contributor

Impressive number of tests, bravo :)

@sylvestre
Copy link
Sponsor Contributor

we even this that at the coverage level
codecov/project Successful in 2s — 84.10% (+0.06%) compared to cd4f455

@sylvestre sylvestre merged commit 88d63be into uutils:main Nov 27, 2023
51 of 53 checks passed
@jfinkels jfinkels deleted the dd-reblock branch November 28, 2023 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants